VB 2010 - Signature / Pattern scanning
Hey there,
>.<" uh, I feel embarrassed just for having to ask for help, but given I just wasted countless hours 'googleing' .. here I am.
Now then, I was hoping to implement the 'ReadProcessMemory' function into my bot, to grab certain info from the game. Right now, the bot uses OCR to grab the info as it is the only other method of getting it. Pointers / static addresses don't seem to exist in this game as I have wasted well over 20+ hours ( and 1TB~ of my precious disk space ) trying to scan for them. It was at this time that I stumbled upon a tutorial on Signature / Pattern scanning. Unfortunately it was a C++ tut, and having very little to no C++ knowledge ( or byte scanning knowledge for that matter ), I went with the next best thing and built the C++ project as a .DLL which I had hope to just reference in my project and use it's functions ( like I have done countless of times in the past ). For whatever reason it didn't work this time.. ( Perhaps because it wasn't a class but only a header, whatever the hell that is )
So, after countless tries I went back to google and after what seemed like an eternity I have managed to get my hands on what looked like a promising piece of code. (It was actually in this very section, http://www.mpgh.net/forum/showthread.php?t=259014)
However, being as lucky as I am today, this 'promising' piece of code turned into a major kick in the balls when it threw a PInvokeStackImbalance at me upon execution ( no idea as to why as it seemed to have worked for whoever wrote/requested it in the other thread ). I have read countless websites and threads, they all seem to point to incorrect PInvoke definition. I've been staring at it for quite a few hours now, and, apart from feeling stupider as this is supposedly a 'simple thing to do', haven't progressed in any way.
Here's the MDA message :
Module1.vb
Usage :
I've literally read tens of thousands of lines of code during my google spree, my brain is so full of fuck I couldn't code a 'Hello World' app right now. So please be considerate and spare me any 'ERMAGERD L2Program' comments.
I'd really appreciate if you guys could help me get this to work, so I can see it in action, mess around with it to learn how it works and ultimately implement it into my crappy bot. Also, I'd love you forever.
>.<" uh, I feel embarrassed just for having to ask for help, but given I just wasted countless hours 'googleing' .. here I am.
Now then, I was hoping to implement the 'ReadProcessMemory' function into my bot, to grab certain info from the game. Right now, the bot uses OCR to grab the info as it is the only other method of getting it. Pointers / static addresses don't seem to exist in this game as I have wasted well over 20+ hours ( and 1TB~ of my precious disk space ) trying to scan for them. It was at this time that I stumbled upon a tutorial on Signature / Pattern scanning. Unfortunately it was a C++ tut, and having very little to no C++ knowledge ( or byte scanning knowledge for that matter ), I went with the next best thing and built the C++ project as a .DLL which I had hope to just reference in my project and use it's functions ( like I have done countless of times in the past ). For whatever reason it didn't work this time.. ( Perhaps because it wasn't a class but only a header, whatever the hell that is )
So, after countless tries I went back to google and after what seemed like an eternity I have managed to get my hands on what looked like a promising piece of code. (It was actually in this very section, http://www.mpgh.net/forum/showthread.php?t=259014)
However, being as lucky as I am today, this 'promising' piece of code turned into a major kick in the balls when it threw a PInvokeStackImbalance at me upon execution ( no idea as to why as it seemed to have worked for whoever wrote/requested it in the other thread ). I have read countless websites and threads, they all seem to point to incorrect PInvoke definition. I've been staring at it for quite a few hours now, and, apart from feeling stupider as this is supposedly a 'simple thing to do', haven't progressed in any way.
Here's the MDA message :
Code:
PInvokeStackImbalance was detected Message: A call to PInvoke function 'WindowsApplication1!WindowsApplication1.Module1::ReadProcessMemory' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature.
Module
Code:
Module Module1
Public Declare Function OpenProcess Lib "KERNEL32" _
(ByVal DesiredAccess As Int32, _
ByVal InheritHandle As Boolean, _
ByVal ProcessId As Int32) _
As Int32
Private Declare Function ReadProcessMemory Lib "KERNEL32" _
(ByVal Handle As Int32, _
ByVal address As Int32, _
ByRef Value As Int32, _
Optional ByVal Size As Int32 = 4, _
Optional ByVal lpNumberOfBytesWritten As Int64 = 0) _
As Long
Public PROCESS_VM_OPERATION As Int32 = 8
Public PROCESS_VM_READ As Int32 = 16
Public PROCESS_VM_WRITE As Int32 = 32
Private process_id As Int32 = 0
Public pHandle As Integer = 0
Public Function GetProcessId(ByVal game_name As String) As Boolean
Dim Processes() As Process = Process.GetProcesses
Dim process_name As String
Dim i As Byte
For i = LBound(Processes) To UBound(Processes)
process_name = Processes(i).ProcessName
If process_name = game_name Then
process_id = Processes(i).Id
pHandle = OpenProcess(PROCESS_VM_OPERATION + PROCESS_VM_WRITE + PROCESS_VM_READ, False, process_id)
Return True
End If
Next
If process_id = 0 Then
Return False
End If
Return False
End Function
Public Function ReadByte(ByVal address As Int32) As Integer
Dim value As Integer
ReadProcessMemory(pHandle, address, value, 1, 0)
Return value
End Function
Public Function AOBSCAN(ByVal GameName As String, ByVal ModuleName As String, ByVal Signature As Byte(), ByVal Mask As Byte()) As Integer
Dim BaseAddress, EndAddress As Int32
For Each PM As ProcessModule In Process.GetProcessesByName(GameName)(0).Modules
If ModuleName = PM.ModuleName Then
BaseAddress = PM.BaseAddress
EndAddress = BaseAddress + PM.ModuleMemorySize
End If
Next
Dim curAddr As Int32 = BaseAddress
Do
For i As Integer = 0 To Signature.Length - 1
If ReadByte(curAddr + i) = Signature(i) Or Mask(i) = &H0 Then
If i = Signature.Length - 1 Then
MsgBox(curAddr.ToString("X"))
Return curAddr
End If
Continue For
End If
Exit For
Next
curAddr += 1
Loop While curAddr < EndAddress
Return 0
End Function
End Module
Usage :
Code:
Dim sigAddresses As Integer = AOBSCAN("ac_client", "ac_client.exe", New Byte() {&HFF, &H25, &HBC, &H30, &HF, &H1, &H75, &H2}, New Byte() {&HFF, &H0, &HFF, &H0, &HFF, &H0, &H0, &H0})
'Not an actual pattern and mask. Also, I'm currently just testing and trying to get it to work with a simple game ( Assault Cube )
I'd really appreciate if you guys could help me get this to work, so I can see it in action, mess around with it to learn how it works and ultimately implement it into my crappy bot. Also, I'd love you forever.
