Sixem

.NET Game Trainer Module Read/Write

Nov 9th, 2012
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 11.92 KB | None | 0 0
  1. 'Written by Cless of CEF (Cheat Engine Forums)
  2.  
  3.  'Examples Read
  4.  '       Me.Text = ReadPointerInteger(Game exe name, &HPointer,&HOffset).ToString()
  5.  '       Me.Text = ReadPointerInteger("gta_sa", &HB71A38,&H540).ToString()
  6.  '       Me.Text = ReadPointerInteger("gta_sa", &HB71A38,&H540,&H544).ToString()
  7.  'Examples Write
  8.  '       WritePointerInteger(Game exe name,&HPointer,Value,&HOffset)
  9.  '       WritePointerInteger("gta_sa",&HB71A38,1000,&H540)
  10.  '       WritePointerInteger("gta_sa",&HB71A38,1000,&H540, &H544)
  11.  
  12. Module Trainer
  13.     Private Declare Function ReadMemoryByte Lib "kernel32" Alias "ReadProcessMemory" (ByVal Handle As Integer, ByVal Address As Integer, ByRef Value As Byte, Optional ByVal Size As Integer = 2, Optional ByRef Bytes As Integer = 0) As Byte
  14.     Private Declare Function ReadMemoryInteger Lib "kernel32" Alias "ReadProcessMemory" (ByVal Handle As Integer, ByVal Address As Integer, ByRef Value As Integer, Optional ByVal Size As Integer = 4, Optional ByRef Bytes As Integer = 0) As Integer
  15.     Private Declare Function ReadMemoryFloat Lib "kernel32" Alias "ReadProcessMemory" (ByVal Handle As Integer, ByVal Address As Integer, ByRef Value As Single, Optional ByVal Size As Integer = 4, Optional ByRef Bytes As Integer = 0) As Single
  16.     Private Declare Function ReadMemoryDouble Lib "kernel32" Alias "ReadProcessMemory" (ByVal Handle As Integer, ByVal Address As Integer, ByRef Value As Double, Optional ByVal Size As Integer = 8, Optional ByRef Bytes As Integer = 0) As Double
  17.     Private Declare Function ReadMemoryString Lib "kernel32" Alias "ReadProcessMemory" (ByVal Handle As Integer, ByVal Address As Integer, ByRef Value As IntPtr, Optional ByVal Size As Integer = 8, Optional ByRef Bytes As Integer = 0) As IntPtr
  18.  
  19.     Private Declare Function WriteMemoryByteArray Lib "kernel32" Alias "WriteProcessMemory" (ByVal Handle As Integer, ByVal Address As Integer, ByRef Value As Byte(), Optional ByVal Size As Integer = 2, Optional ByRef Bytes As Integer = 0) As Byte()
  20.     Private Declare Function WriteMemoryByte Lib "kernel32" Alias "WriteProcessMemory" (ByVal Handle As Integer, ByVal Address As Integer, ByRef Value As Byte, Optional ByVal Size As Integer = 2, Optional ByRef Bytes As Integer = 0) As Byte
  21.     Private Declare Function WriteMemoryInteger Lib "kernel32" Alias "WriteProcessMemory" (ByVal Handle As Integer, ByVal Address As Integer, ByRef Value As Integer, Optional ByVal Size As Integer = 4, Optional ByRef Bytes As Integer = 0) As Integer
  22.     Private Declare Function WriteMemoryFloat Lib "kernel32" Alias "WriteProcessMemory" (ByVal Handle As Integer, ByVal Address As Integer, ByRef Value As Single, Optional ByVal Size As Integer = 2, Optional ByRef Bytes As Integer = 0) As Single
  23.     Private Declare Function WriteMemoryDouble Lib "kernel32" Alias "WriteProcessMemory" (ByVal Handle As Integer, ByVal Address As Integer, ByRef Value As Double, Optional ByVal Size As Integer = 2, Optional ByRef Bytes As Integer = 0) As Double
  24.     Public Function ReadText(ByVal EXENAME As String, ByVal Address As Integer) As IntPtr
  25.         Dim Value As String
  26.         If Process.GetProcessesByName(EXENAME).Length <> 0 Then
  27.             Dim Handle As Integer = Process.GetProcessesByName(EXENAME)(0).Handle
  28.             If Handle <> 0 Then
  29.                 ReadMemoryString(Handle, Address, Value)
  30.             End If
  31.         End If
  32.         Return Value
  33.     End Function
  34.  
  35.     Public Function ReadByte(ByVal EXENAME As String, ByVal Address As Integer) As Byte
  36.         Dim Value As Byte
  37.         If Process.GetProcessesByName(EXENAME).Length <> 0 Then
  38.             Dim Handle As Integer = Process.GetProcessesByName(EXENAME)(0).Handle
  39.             If Handle <> 0 Then
  40.                 ReadMemoryByte(Handle, Address, Value)
  41.             End If
  42.         End If
  43.         Return Value
  44.     End Function
  45.  
  46.     Public Function ReadInteger(ByVal EXENAME As String, ByVal Address As Integer) As Integer
  47.         Dim Value As Integer
  48.         If Process.GetProcessesByName(EXENAME).Length <> 0 Then
  49.             Dim Handle As Integer = Process.GetProcessesByName(EXENAME)(0).Handle
  50.             If Handle <> 0 Then
  51.                 ReadMemoryInteger(Handle, Address, Value)
  52.             End If
  53.         End If
  54.         Return Value
  55.     End Function
  56.  
  57.     Public Function ReadFloat(ByVal EXENAME As String, ByVal Address As Integer) As Single
  58.         Dim Value As Single
  59.         If Process.GetProcessesByName(EXENAME).Length <> 0 Then
  60.             Dim Handle As Integer = Process.GetProcessesByName(EXENAME)(0).Handle
  61.             If Handle <> 0 Then
  62.                 ReadMemoryFloat(Handle, Address, Value)
  63.             End If
  64.         End If
  65.         Return Value
  66.     End Function
  67.  
  68.     Public Function ReadDouble(ByVal EXENAME As String, ByVal Address As Integer) As Double
  69.         Dim Value As Double
  70.         If Process.GetProcessesByName(EXENAME).Length <> 0 Then
  71.             Dim Handle As Integer = Process.GetProcessesByName(EXENAME)(0).Handle
  72.             If Handle <> 0 Then
  73.                 ReadMemoryByte(Handle, Address, Value)
  74.             End If
  75.         End If
  76.         Return Value
  77.     End Function
  78.  
  79.     Public Function ReadPointerByte(ByVal EXENAME As String, ByVal Pointer As Integer, ByVal ParamArray Offset As Integer()) As Byte
  80.         Dim Value As Byte
  81.         If Process.GetProcessesByName(EXENAME).Length <> 0 Then
  82.             Dim Handle As Integer = Process.GetProcessesByName(EXENAME)(0).Handle
  83.             If Handle <> 0 Then
  84.                 For Each I As Integer In Offset
  85.                     ReadMemoryInteger(Handle, Pointer, Pointer)
  86.                     Pointer += I
  87.                 Next
  88.                 ReadMemoryByte(Handle, Pointer, Value)
  89.             End If
  90.         End If
  91.         Return Value
  92.     End Function
  93.  
  94.     Public Function ReadPointerInteger(ByVal EXENAME As String, ByVal Pointer As Integer, ByVal ParamArray Offset As Integer()) As Integer
  95.         Dim Value As Integer
  96.         If Process.GetProcessesByName(EXENAME).Length <> 0 Then
  97.             Dim Handle As Integer = Process.GetProcessesByName(EXENAME)(0).Handle
  98.             If Handle <> 0 Then
  99.                 For Each I As Integer In Offset
  100.                     ReadMemoryInteger(Handle, Pointer, Pointer)
  101.                     Pointer += I
  102.                 Next
  103.                 ReadMemoryInteger(Handle, Pointer, Value)
  104.             End If
  105.         End If
  106.         Return Value
  107.     End Function
  108.  
  109.     Public Function ReadPointerFloat(ByVal EXENAME As String, ByVal Pointer As Integer, ByVal ParamArray Offset As Integer()) As Single
  110.         Dim Value As Single
  111.         If Process.GetProcessesByName(EXENAME).Length <> 0 Then
  112.             Dim Handle As Integer = Process.GetProcessesByName(EXENAME)(0).Handle
  113.             If Handle <> 0 Then
  114.                 For Each I As Integer In Offset
  115.                     ReadMemoryInteger(Handle, Pointer, Pointer)
  116.                     Pointer += I
  117.                 Next
  118.                 ReadMemoryFloat(Handle, Pointer, Value)
  119.             End If
  120.         End If
  121.         Return Value
  122.     End Function
  123.  
  124.     Public Function ReadPointerDouble(ByVal EXENAME As String, ByVal Pointer As Integer, ByVal ParamArray Offset As Integer()) As Double
  125.         Dim Value As Double
  126.         If Process.GetProcessesByName(EXENAME).Length <> 0 Then
  127.             Dim Handle As Integer = Process.GetProcessesByName(EXENAME)(0).Handle
  128.             If Handle <> 0 Then
  129.                 For Each I As Integer In Offset
  130.                     ReadMemoryInteger(Handle, Pointer, Pointer)
  131.                     Pointer += I
  132.                 Next
  133.                 ReadMemoryDouble(Handle, Pointer, Value)
  134.             End If
  135.         End If
  136.         Return Value
  137.     End Function
  138.  
  139.     Public Sub WriteByte(ByVal EXENAME As String, ByVal Address As Integer, ByVal Value As Byte)
  140.         If Process.GetProcessesByName(EXENAME).Length <> 0 Then
  141.             Dim Handle As Integer = Process.GetProcessesByName(EXENAME)(0).Handle
  142.             If Handle <> 0 Then
  143.                 WriteMemoryByte(Handle, Address, Value)
  144.             End If
  145.         End If
  146.     End Sub
  147.     Public Sub WriteByteArray(ByVal EXENAME As String, ByVal Address As Integer, ByVal Value As Byte())
  148.         If Process.GetProcessesByName(EXENAME).Length <> 0 Then
  149.             Dim Handle As Integer = Process.GetProcessesByName(EXENAME)(0).Handle
  150.             If Handle <> 0 Then
  151.                 WriteMemoryByteArray(Handle, Address, Value)
  152.             End If
  153.         End If
  154.     End Sub
  155.  
  156.     Public Sub WriteInteger(ByVal EXENAME As String, ByVal Address As Integer, ByVal Value As Integer)
  157.         If Process.GetProcessesByName(EXENAME).Length <> 0 Then
  158.             Dim Handle As Integer = Process.GetProcessesByName(EXENAME)(0).Handle
  159.             If Handle <> 0 Then
  160.                 WriteMemoryInteger(Handle, Address, Value)
  161.             End If
  162.         End If
  163.     End Sub
  164.  
  165.     Public Sub WriteFloat(ByVal EXENAME As String, ByVal Address As Integer, ByVal Value As Single)
  166.         If Process.GetProcessesByName(EXENAME).Length <> 0 Then
  167.             Dim Handle As Integer = Process.GetProcessesByName(EXENAME)(0).Handle
  168.             If Handle <> 0 Then
  169.                 WriteMemoryFloat(Handle, Address, Value)
  170.             End If
  171.         End If
  172.     End Sub
  173.  
  174.     Public Sub WriteDouble(ByVal EXENAME As String, ByVal Address As Integer, ByVal Value As Double)
  175.         If Process.GetProcessesByName(EXENAME).Length <> 0 Then
  176.             Dim Handle As Integer = Process.GetProcessesByName(EXENAME)(0).Handle
  177.             If Handle <> 0 Then
  178.                 WriteMemoryDouble(Handle, Address, Value)
  179.             End If
  180.         End If
  181.     End Sub
  182.  
  183.     Public Sub WritePointerByte(ByVal EXENAME As String, ByVal Pointer As Integer, ByVal Value As Byte, ByVal ParamArray Offset As Integer())
  184.         If Process.GetProcessesByName(EXENAME).Length <> 0 Then
  185.             Dim Handle As Integer = Process.GetProcessesByName(EXENAME)(0).Handle
  186.             If Handle <> 0 Then
  187.                 For Each I As Integer In Offset
  188.                     ReadMemoryInteger(Handle, Pointer, Pointer)
  189.                     Pointer += I
  190.                 Next
  191.                 WriteMemoryByte(Handle, Pointer, Value)
  192.             End If
  193.         End If
  194.     End Sub
  195.  
  196.     Public Sub WritePointerInteger(ByVal EXENAME As String, ByVal Pointer As Integer, ByVal Value As Integer, ByVal ParamArray Offset As Integer())
  197.         If Process.GetProcessesByName(EXENAME).Length <> 0 Then
  198.             Dim Handle As Integer = Process.GetProcessesByName(EXENAME)(0).Handle
  199.             If Handle <> 0 Then
  200.                 For Each I As Integer In Offset
  201.                     ReadMemoryInteger(Handle, Pointer, Pointer)
  202.                     Pointer += I
  203.                 Next
  204.                 WriteMemoryInteger(Handle, Pointer, Value)
  205.             End If
  206.         End If
  207.     End Sub
  208.  
  209.     Public Sub WritePointerFloat(ByVal EXENAME As String, ByVal Pointer As Integer, ByVal Value As Single, ByVal ParamArray Offset As Integer())
  210.         If Process.GetProcessesByName(EXENAME).Length <> 0 Then
  211.             Dim Handle As Integer = Process.GetProcessesByName(EXENAME)(0).Handle
  212.             If Handle <> 0 Then
  213.                 For Each I As Integer In Offset
  214.                     ReadMemoryInteger(Handle, Pointer, Pointer)
  215.                     Pointer += I
  216.                 Next
  217.                 WriteMemoryFloat(Handle, Pointer, Value)
  218.             End If
  219.         End If
  220.     End Sub
  221.     Public Sub WritePointerDouble(ByVal EXENAME As String, ByVal Pointer As Integer, ByVal Value As Double, ByVal ParamArray Offset As Integer())
  222.         If Process.GetProcessesByName(EXENAME).Length <> 0 Then
  223.             Dim Handle As Integer = Process.GetProcessesByName(EXENAME)(0).Handle
  224.             If Handle <> 0 Then
  225.                 For Each I As Integer In Offset
  226.                     ReadMemoryInteger(Handle, Pointer, Pointer)
  227.                     Pointer += I
  228.                 Next
  229.                 WriteMemoryDouble(Handle, Pointer, Value)
  230.             End If
  231.         End If
  232.  
  233.     End Sub
  234. End Module
Advertisement
Add Comment
Please, Sign In to add comment