Imports System.Runtime.InteropServices
Public Class form1
'API ReadProcessMemory
<DllImport("kernel32.dll", SetLastError:=True)> _
Private Shared Function ReadProcessMemory( _
ByVal hProcess As IntPtr, _
ByVal lpBaseAddress As IntPtr, _
<Out()> ByVal lpBuffer() As Byte, _
ByVal dwSize As Integer, _
ByRef lpNumberOfBytesRead As Integer) As Boolean
End Function
Private Function FindAddress(ByVal pHandle As IntPtr, ByVal BaseAddress As IntPtr, ByVal StaticPointer As IntPtr, ByVal Offsets() As IntPtr) As IntPtr
' Create a buffer that is 4 bytes on a 32-bit system or 8 bytes on a 64-bit system.
Dim tmp(IntPtr.Size - 1) As Byte
Dim Address As IntPtr = BaseAddress
' We must check for 32-bit vs 64-bit.
If IntPtr.Size = 4 Then
Address = New IntPtr(Address.ToInt32 + StaticPointer.ToInt32)
Else
Address = New IntPtr(Address.ToInt64 + StaticPointer.ToInt64)
End If
' Loop through each offset to find the address
For i As Integer = 0 To Offsets.Length - 1
ReadProcessMemory(pHandle, Address, tmp, IntPtr.Size, 0)
If IntPtr.Size = 4 Then
Address = BitConverter.ToInt32(tmp, 0) + Offsets(i).ToInt32()
Else
Address = BitConverter.ToInt64(tmp, 0) + Offsets(i).ToInt64()
End If
Next
Return Address
End Function
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim p As Process() = Process.GetProcessesByName("Tutorial-i386")
' I'm assuming p is a Process object that represents the game process.
Dim pID As IntPtr = p(0).Handle
Dim base As IntPtr = p(0).MainModule.BaseAddress
' Our static pointer...
Dim sptr As IntPtr = &H2903B0
' And our offsets...
Dim offsets() As IntPtr = {&HC, &H14, &H0, &H18}
Dim addr As IntPtr = FindAddress(pID, base, sptr, offsets)
Dim f As String
f = addr.ToString
MessageBox.Show(f)
End Sub
End Class
For i As Integer = 0 To Offsets.Length - 1
ReadProcessMemory(pHandle, Address, tmp, IntPtr.Size, 0)
If IntPtr.Size = 4 Then
Address = BitConverter.ToInt32(tmp, 0) + Offsets(i).ToInt32() '' BREAK-POINT ON THIS LINE
Else
Address = BitConverter.ToInt64(tmp, 0) + Offsets(i).ToInt64() '' BREAK-POINT ON THIS LINE
End If
Next
Dim f As String
f = addr.ToString("X") '' display the number as hex
MessageBox.Show(f)
'replace with MessageBox.Show(addr.ToString("X")) and get rid of 'f' : un-needed.
Private Function FindAddress(ByVal pHandle As IntPtr, ByVal BaseAddress As IntPtr, ByVal StaticPointer As IntPtr, ByVal Offsets() As IntPtr) As IntPtr
' Create a buffer that is 4 bytes on a 32-bit system or 8 bytes on a 64-bit system.
Dim tmp(IntPtr.Size - 1) As Byte
Dim _ListOfAllAddressAsHexString As New System.Text.StringBuilder '' AB -used for debugging output
_ListOfAllAddressAsHexString.AppendLine("procHandle: " & pHandle.ToString)
_ListOfAllAddressAsHexString.AppendLine("MainModuleBase: &H" & BaseAddress.ToString("X"))
_ListOfAllAddressAsHexString.AppendLine("StaticOffset: &H" & StaticPointer.ToString("X"))
Dim Address As IntPtr = BaseAddress
If IntPtr.Size = 4 Then ' We must check for 32-bit vs 64-bit.
Address = New IntPtr(Address.ToInt32 + StaticPointer.ToInt32)
Else
Address = New IntPtr(Address.ToInt64 + StaticPointer.ToInt64)
End If
_ListOfAllAddressAsHexString.AppendLine("MainModuleBase + staticOffset: &H" & Address.ToString("X"))
_ListOfAllAddressAsHexString.AppendLine("---------------------------")
' Loop through each offset to find the address
For i As Integer = 0 To Offsets.Length - 1
ReadProcessMemory(pHandle, Address, tmp, IntPtr.Size, 0)
If IntPtr.Size = 4 Then
Address = BitConverter.ToInt32(tmp, 0) + Offsets(i).ToInt32()
Else
Address = BitConverter.ToInt64(tmp, 0) + Offsets(i).ToInt64()
End If
_ListOfAllAddressAsHexString.AppendLine("ptr#" & i & ": &H" & Address.ToString("X"))
Next
''display the msg box containing all the addr
MessageBox.Show(_ListOfAllAddressAsHexString.ToArray,"debugging list -ab")
Return Address
End Function
