Advertisement
hungvb

[VB] Instructions for making a Flash game hack

Sep 23rd, 2021
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 9.93 KB | None | 0 0
  1. Module ReadWritingMemory
  2. Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Integer, ByVal bInheritHandle As Integer, ByVal dwProcessId As Integer) As Integer
  3.  
  4. Private Declare Function WriteProcessMemory1 Lib "kernel32" Alias "WriteProcessMemory" (ByVal hProcess As Integer, ByVal lpBaseAddress As Integer, ByRef lpBuffer As Integer, ByVal nSize As Integer, ByRef lpNumberOfBytesWritten As Integer) As Integer
  5. Private Declare Function WriteProcessMemory2 Lib "kernel32" Alias "WriteProcessMemory" (ByVal hProcess As Integer, ByVal lpBaseAddress As Integer, ByRef lpBuffer As Single, ByVal nSize As Integer, ByRef lpNumberOfBytesWritten As Integer) As Single
  6. Private Declare Function WriteProcessMemory3 Lib "kernel32" Alias "WriteProcessMemory" (ByVal hProcess As Integer, ByVal lpBaseAddress As Integer, ByRef lpBuffer As Long, ByVal nSize As Integer, ByRef lpNumberOfBytesWritten As Integer) As Long
  7.  
  8. Private Declare Function ReadProcessMemory1 Lib "kernel32" Alias "ReadProcessMemory" (ByVal hProcess As Integer, ByVal lpBaseAddress As Integer, ByRef lpBuffer As Integer, ByVal nSize As Integer, ByRef lpNumberOfBytesWritten As Integer) As Integer
  9. Private Declare Function ReadProcessMemory2 Lib "kernel32" Alias "ReadProcessMemory" (ByVal hProcess As Integer, ByVal lpBaseAddress As Integer, ByRef lpBuffer As Single, ByVal nSize As Integer, ByRef lpNumberOfBytesWritten As Integer) As Single
  10. Private Declare Function ReadProcessMemory3 Lib "kernel32" Alias "ReadProcessMemory" (ByVal hProcess As Integer, ByVal lpBaseAddress As Integer, ByRef lpBuffer As Long, ByVal nSize As Integer, ByRef lpNumberOfBytesWritten As Integer) As Long
  11.  
  12. Const PROCESS_ALL_ACCESS = &H1F0FF
  13.  
  14. Public Function WriteDMAInteger(ByVal Process As String, ByVal Address As Integer, ByVal Offsets As Integer(), ByVal Value As Integer, ByVal Level As Integer, Optional ByVal nsize As Integer = 4) As Boolean
  15. Try
  16. Dim lvl As Integer = Address
  17. For i As Integer = 1 To Level
  18. lvl = ReadInteger(Process, lvl, nsize) + Offsets(i - 1)
  19. Next
  20. WriteInteger(Process, lvl, Value, nsize)
  21. Return True
  22. Catch ex As Exception
  23. Return False
  24. End Try
  25. End Function
  26.  
  27. Public Function ReadDMAInteger(ByVal Process As String, ByVal Address As Integer, ByVal Offsets As Integer(), ByVal Level As Integer, Optional ByVal nsize As Integer = 4) As Integer
  28. Try
  29. Dim lvl As Integer = Address
  30. For i As Integer = 1 To Level
  31. lvl = ReadInteger(Process, lvl, nsize) + Offsets(i - 1)
  32. Next
  33. Dim vBuffer As Integer
  34. vBuffer = ReadInteger(Process, lvl, nsize)
  35. Return vBuffer
  36. Catch ex As Exception
  37.  
  38. End Try
  39. End Function
  40.  
  41. Public Function WriteDMAFloat(ByVal Process As String, ByVal Address As Integer, ByVal Offsets As Integer(), ByVal Value As Single, ByVal Level As Integer, Optional ByVal nsize As Integer = 4) As Boolean
  42. Try
  43. Dim lvl As Integer = Address
  44. For i As Integer = 1 To Level
  45. lvl = ReadFloat(Process, lvl, nsize) + Offsets(i - 1)
  46. Next
  47. WriteFloat(Process, lvl, Value, nsize)
  48. Return True
  49. Catch ex As Exception
  50. Return False
  51. End Try
  52. End Function
  53.  
  54. Public Function ReadDMAFloat(ByVal Process As String, ByVal Address As Integer, ByVal Offsets As Integer(), ByVal Level As Integer, Optional ByVal nsize As Integer = 4) As Single
  55. Try
  56. Dim lvl As Integer = Address
  57. For i As Integer = 1 To Level
  58. lvl = ReadFloat(Process, lvl, nsize) + Offsets(i - 1)
  59. Next
  60. Dim vBuffer As Single
  61. vBuffer = ReadFloat(Process, lvl, nsize)
  62. Return vBuffer
  63. Catch ex As Exception
  64.  
  65. End Try
  66. End Function
  67.  
  68. Public Function WriteDMALong(ByVal Process As String, ByVal Address As Integer, ByVal Offsets As Integer(), ByVal Value As Long, ByVal Level As Integer, Optional ByVal nsize As Integer = 4) As Boolean
  69. Try
  70. Dim lvl As Integer = Address
  71. For i As Integer = 1 To Level
  72. lvl = ReadLong(Process, lvl, nsize) + Offsets(i - 1)
  73. Next
  74. WriteLong(Process, lvl, Value, nsize)
  75. Return True
  76. Catch ex As Exception
  77. Return False
  78. End Try
  79. End Function
  80.  
  81. Public Function ReadDMALong(ByVal Process As String, ByVal Address As Integer, ByVal Offsets As Integer(), ByVal Level As Integer, Optional ByVal nsize As Integer = 4) As Long
  82. Try
  83. Dim lvl As Integer = Address
  84. For i As Integer = 1 To Level
  85. lvl = ReadLong(Process, lvl, nsize) + Offsets(i - 1)
  86. Next
  87. Dim vBuffer As Long
  88. vBuffer = ReadLong(Process, lvl, nsize)
  89. Return vBuffer
  90. Catch ex As Exception
  91.  
  92. End Try
  93. End Function
  94.  
  95. Public Sub WriteNOPs(ByVal ProcessName As String, ByVal Address As Long, ByVal NOPNum As Integer)
  96. Dim C As Integer
  97. Dim B As Integer
  98. If ProcessName.EndsWith(".exe") Then
  99. ProcessName = ProcessName.Replace(".exe", "")
  100. End If
  101. Dim MyP As Process() = Process.GetProcessesByName(ProcessName)
  102. If MyP.Length = 0 Then
  103. MessageBox.Show(ProcessName & " isn't open!")
  104. Exit Sub
  105. End If
  106. Dim hProcess As IntPtr = OpenProcess(PROCESS_ALL_ACCESS, 0, MyP(0).Id)
  107. If hProcess = IntPtr.Zero Then
  108. MessageBox.Show("Failed to open " & ProcessName & "!")
  109. Exit Sub
  110. End If
  111.  
  112. B = 0
  113. For C = 1 To NOPNum
  114. Call WriteProcessMemory1(hProcess, Address + B, &H90, 1, 0&)
  115. B = B + 1
  116. Next C
  117. End Sub
  118.  
  119. Public Sub WriteXBytes(ByVal ProcessName As String, ByVal Address As Long, ByVal Value As String)
  120. If ProcessName.EndsWith(".exe") Then
  121. ProcessName = ProcessName.Replace(".exe", "")
  122. End If
  123. Dim MyP As Process() = Process.GetProcessesByName(ProcessName)
  124. If MyP.Length = 0 Then
  125. MessageBox.Show(ProcessName & " isn't open!")
  126. Exit Sub
  127. End If
  128. Dim hProcess As IntPtr = OpenProcess(PROCESS_ALL_ACCESS, 0, MyP(0).Id)
  129. If hProcess = IntPtr.Zero Then
  130. MessageBox.Show("Failed to open " & ProcessName & "!")
  131. Exit Sub
  132. End If
  133.  
  134. Dim C As Integer
  135. Dim B As Integer
  136. Dim D As Integer
  137. Dim V As Byte
  138.  
  139. B = 0
  140. D = 1
  141. For C = 1 To Math.Round((Len(Value) / 2))
  142. V = Val("&H" & Mid$(Value, D, 2))
  143. Call WriteProcessMemory1(hProcess, Address + B, V, 1, 0&)
  144. B = B + 1
  145. D = D + 2
  146. Next C
  147.  
  148. End Sub
  149.  
  150. Public Sub WriteInteger(ByVal ProcessName As String, ByVal Address As Integer, ByVal Value As Integer, Optional ByVal nsize As Integer = 4)
  151. If ProcessName.EndsWith(".exe") Then
  152. ProcessName = ProcessName.Replace(".exe", "")
  153. End If
  154. Dim MyP As Process() = Process.GetProcessesByName(ProcessName)
  155. If MyP.Length = 0 Then
  156. MessageBox.Show(ProcessName & " isn't open!")
  157. Exit Sub
  158. End If
  159. Dim hProcess As IntPtr = OpenProcess(PROCESS_ALL_ACCESS, 0, MyP(0).Id)
  160. If hProcess = IntPtr.Zero Then
  161. MessageBox.Show("Failed to open " & ProcessName & "!")
  162. Exit Sub
  163. End If
  164.  
  165. Dim hAddress, vBuffer As Integer
  166. hAddress = Address
  167. vBuffer = Value
  168. WriteProcessMemory1(hProcess, hAddress, CInt(vBuffer), nsize, 0)
  169. End Sub
  170.  
  171. Public Sub WriteFloat(ByVal ProcessName As String, ByVal Address As Integer, ByVal Value As Single, Optional ByVal nsize As Integer = 4)
  172. If ProcessName.EndsWith(".exe") Then
  173. ProcessName = ProcessName.Replace(".exe", "")
  174. End If
  175. Dim MyP As Process() = Process.GetProcessesByName(ProcessName)
  176. If MyP.Length = 0 Then
  177. MessageBox.Show(ProcessName & " isn't open!")
  178. Exit Sub
  179. End If
  180. Dim hProcess As IntPtr = OpenProcess(PROCESS_ALL_ACCESS, 0, MyP(0).Id)
  181. If hProcess = IntPtr.Zero Then
  182. MessageBox.Show("Failed to open " & ProcessName & "!")
  183. Exit Sub
  184. End If
  185.  
  186. Dim hAddress As Integer
  187. Dim vBuffer As Single
  188.  
  189. hAddress = Address
  190. vBuffer = Value
  191. WriteProcessMemory2(hProcess, hAddress, vBuffer, nsize, 0)
  192. End Sub
  193.  
  194. Public Sub WriteLong(ByVal ProcessName As String, ByVal Address As Integer, ByVal Value As Long, Optional ByVal nsize As Integer = 4)
  195. If ProcessName.EndsWith(".exe") Then
  196. ProcessName = ProcessName.Replace(".exe", "")
  197. End If
  198. Dim MyP As Process() = Process.GetProcessesByName(ProcessName)
  199. If MyP.Length = 0 Then
  200. MessageBox.Show(ProcessName & " isn't open!")
  201. Exit Sub
  202. End If
  203. Dim hProcess As IntPtr = OpenProcess(PROCESS_ALL_ACCESS, 0, MyP(0).Id)
  204. If hProcess = IntPtr.Zero Then
  205. MessageBox.Show("Failed to open " & ProcessName & "!")
  206. Exit Sub
  207. End If
  208.  
  209. Dim hAddress As Integer
  210. Dim vBuffer As Long
  211.  
  212. hAddress = Address
  213. vBuffer = Value
  214. WriteProcessMemory3(hProcess, hAddress, vBuffer, nsize, 0)
  215. End Sub
  216.  
  217. Public Function ReadInteger(ByVal ProcessName As String, ByVal Address As Integer, Optional ByVal nsize As Integer = 4) As Integer
  218. If ProcessName.EndsWith(".exe") Then
  219. ProcessName = ProcessName.Replace(".exe", "")
  220. End If
  221. Dim MyP As Process() = Process.GetProcessesByName(ProcessName)
  222. If MyP.Length = 0 Then
  223. MessageBox.Show(ProcessName & " isn't open!")
  224. Exit Function
  225. End If
  226. Dim hProcess As IntPtr = OpenProcess(PROCESS_ALL_ACCESS, 0, MyP(0).Id)
  227. If hProcess = IntPtr.Zero Then
  228. MessageBox.Show("Failed to open " & ProcessName & "!")
  229. Exit Function
  230. End If
  231.  
  232. Dim hAddress, vBuffer As Integer
  233. hAddress = Address
  234. ReadProcessMemory1(hProcess, hAddress, vBuffer, nsize, 0)
  235. Return vBuffer
  236. End Function
  237.  
  238. Public Function ReadFloat(ByVal ProcessName As String, ByVal Address As Integer, Optional ByVal nsize As Integer = 4) As Single
  239. If ProcessName.EndsWith(".exe") Then
  240. ProcessName = ProcessName.Replace(".exe", "")
  241. End If
  242. Dim MyP As Process() = Process.GetProcessesByName(ProcessName)
  243. If MyP.Length = 0 Then
  244. MessageBox.Show(ProcessName & " isn't open!")
  245. Exit Function
  246. End If
  247. Dim hProcess As IntPtr = OpenProcess(PROCESS_ALL_ACCESS, 0, MyP(0).Id)
  248. If hProcess = IntPtr.Zero Then
  249. MessageBox.Show("Failed to open " & ProcessName & "!")
  250. Exit Function
  251. End If
  252.  
  253. Dim hAddress As Integer
  254. Dim vBuffer As Single
  255.  
  256. hAddress = Address
  257. ReadProcessMemory2(hProcess, hAddress, vBuffer, nsize, 0)
  258. Return vBuffer
  259. End Function
  260.  
  261. Public Function ReadLong(ByVal ProcessName As String, ByVal Address As Integer, Optional ByVal nsize As Integer = 4) As Long
  262. If ProcessName.EndsWith(".exe") Then
  263. ProcessName = ProcessName.Replace(".exe", "")
  264. End If
  265. Dim MyP As Process() = Process.GetProcessesByName(ProcessName)
  266. If MyP.Length = 0 Then
  267. MessageBox.Show(ProcessName & " isn't open!")
  268. Exit Function
  269. End If
  270. Dim hProcess As IntPtr = OpenProcess(PROCESS_ALL_ACCESS, 0, MyP(0).Id)
  271. If hProcess = IntPtr.Zero Then
  272. MessageBox.Show("Failed to open " & ProcessName & "!")
  273. Exit Function
  274. End If
  275.  
  276. Dim hAddress As Integer
  277. Dim vBuffer As Long
  278.  
  279. hAddress = Address
  280. ReadProcessMemory3(hProcess, hAddress, vBuffer, nsize, 0)
  281. Return vBuffer
  282. End Function
  283.  
  284. End Module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement