About Monkey 2 › Forums › Monkey 2 Programming Help › ReadProcessMemory
This topic contains 2 replies, has 2 voices, and was last updated by
Mark Sibly
1 year, 8 months ago.
-
AuthorPosts
-
August 16, 2017 at 10:37 pm #9876
I’m trying to read memory from another process but I’m having a hard time wrapping the Windows API function for it.
https://msdn.microsoft.com/en-us/library/ms680553(v=VS.85).aspx
Anyone got any hints?
August 17, 2017 at 10:43 pm #9892I’ve had some progress, but the problem is that the data I get from ReadProcessMemory does not match with what other memory readers show.
For example, the memory address for me at the time of testing $0CC7E8E8 was how far I’ve scrolled in Ted2Go.
That value when read via this example remains unchanged no matter how much I scroll, but I can see the value change in other memory readers just fine.
And restarting the example below displays another value the next time, even though I have NOT scrolled.
So I’m not sure what kind of data I’m getting back…This may be hard for others to test since the address probably won’t be the same twice, and your Process ID for Ted2Go will be different…
But really, all you have to do is have Ted2Go running, find the PID for Ted2Go and enter that into the example and run it a few times without doing anything in Ted2Go, and you’ll see that the value is different each time.
If you have a memory reader, you can check the address 0CC7E8E8 for Ted2Go and you’ll see that it doesn’t match with what this example shows.I’m honestly not even sure if I’m wrapping the Win32 functions correctly…
At line 27 – OpenProcess https://msdn.microsoft.com/en-us/library/windows/desktop/ms684320(v=vs.85).aspx
At line 30 – CloseHandle https://msdn.microsoft.com/en-us/library/windows/desktop/ms724211(v=vs.85).aspx
At line 33 – ReadProcessMemory https://msdn.microsoft.com/en-us/library/windows/desktop/ms680553(v=vs.85).aspxMonkey12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182#Import "<std>"#Import "<mojo>"Using std..Using mojo..#Import "<windows.h>"'===IMPORTANT CHANGE THIS TO YOUR TED2 PROCESS ID/PID===Global Ted2Id:UInt=5392'Things like Process Explorer for Windows shows you your Ted2 PID'https://cdn.portableapps.com/ProcessExplorerPortable.png'Ideally you'd want to search for a window name and get the PID that way'But I haven't figured that outGlobal MemoryAddr:=$0CC7E8E8ExternStruct HANDLEEnd'Get a HANDLE via a process IDFunction OpenProcess:HANDLE( dwDesiredAccess:UInt, bInheritHandle:Bool, dwProcessId:UInt )'Close a HANDLEFunction CloseHandle:Bool( hObject:HANDLE )'Read memory from a HANDLEFunction ReadProcessMemory:Bool( hProcess:HANDLE, lpBaseAddress:UInt Ptr, lpBuffer:Byte Ptr, nSize:Int, lpNumberOfBytesRead:Int )PublicFunction ReadMemory:Byte[]( addr:UInt, bytes:Byte )'Prepare buffer to store our bytes inLocal buff:=New Byte[bytes]'Open the process to get HANDLE'Open with PROCESS_VM_READ rightsLocal process:=OpenProcess( $0010 , False, Ted2Id )'Use HANDLE to read memoryIf Not ReadProcessMemory( process, Varptr addr, Varptr buff[0], bytes, 0 ) ThenPrint "Unable to read memory!"Endif'Close the HANDLEIf Not CloseHandle( process ) Then Print "Unable to close handle"'Return memory readReturn buffEndClass MyWindow Extends WindowMethod New( title:String="Simple mojo app",width:Int=640,height:Int=480,flags:WindowFlags=Null )Super.New( title,width,height,flags )EndMethod OnRender( canvas:Canvas ) OverrideApp.RequestRender()'Display our memory stuffLocal x:Int=8Local v:=ReadMemory( MemoryAddr, 4 )For Local i:=0 Until v.Lengthcanvas.DrawText( v[i], x, 8 )x+=canvas.Font.TextWidth( v[i] )x+=canvas.Font.TextWidth( " " )NextEndEndFunction Main()New AppInstanceNew MyWindowApp.Run()EndAugust 17, 2017 at 10:58 pm #9893HANDLE should be:
Alias HANDLE:Void Ptr
-
AuthorPosts
You must be logged in to reply to this topic.