i am currently writing a trainer (or trying to) that will access another program and write to it's memory addresses. at any rate, i have accomplished findind the thread process ID for a program, but i am having trouble reading the memory addresses of the program. for now, i am using the calculator program as a test just to see if i am reading the addresses correctly. i am lost. take a look at the code and see if you can tell what i am trying to accomplish and what i am doing wrong! any help would be appreciated.
best,
mike
[CODE]
; -----------------------------------------------------------------------------
; Create or open existing kernel32.decls file in userlibs folder and place
; these lines in it (uncommented!)...
; -----------------------------------------------------------------------------
;
;.lib "kernel32.dll"
;
;CreateToolhelp32Snapshot% (flags, th32processid)
;Process32First% (snapshot, entry*)
;Process32Next% (snapshot, entry*)
;CloseHandle% (object)
;OpenProcess% (dwDesiredAccess%, Null, dwProcessId%) : "OpenProcess"
;ReadProcessMemory% (hProcess%, lpBaseAddress*, lpBuffer*, nSize%, Null)
;WriteProcessMemory% (hProcess%, lpBaseAddress*, lpBuffer*, nSize%, lpNumberOfBytesWritten%)
;
; -----------------------------------------------------------------------------
; -----------------------------------------------------------------------------
; Create or open existing user32.decls file in userlibs folder and place
; these lines in it (uncommented!)...
; -----------------------------------------------------------------------------
;
;.lib "user32.dll"
;
;FindWindow% (Null, Caption$) : "FindWindowA"
;SetWindowState(hwnd,command):"ShowWindow"
;ShowWindow% (hwnd%, nCmdShow%) : "ShowWindow"
;GetWindowThreadProcessId% (hwnd%, ProcessId%) : "GetWindowThreadProcessId"
;
; -----------------------------------------------------------------------------
; -----------------------------------------------------------------------------
;Make sure that the calculator program included with windows is running so that this will identify it
; -----------------------------------------------------------------------------
Const MAX_PATH = 264
Const TH32CS_SNAPHEAPLIST = $1
Const TH32CS_SNAPPROCESS = $2
Const TH32CS_SNAPTHREAD = $4
Const TH32CS_SNAPMODULE = $8
Const TH32CS_SNAPALL = TH32CS_SNAPHEAPLIST Or TH32CS_SNAPPROCESS Or TH32CS_SNAPTHREAD Or TH32CS_SNAPMODULE
Const TH32CS_INHERIT = $80000000
Const INVALID_HANDLE_VALUE = -1
Const SizeOf_PE32 = 296
Const STANDARD_RIGHTS_REQUIRED = $F0000
Const SYNCHRONIZE = $100000
Const PROCESS_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED Or SYNCHRONIZE Or $FFF)
;x = NULL in most instances
Type PROCESSENTRY32
Field dwSize
Field cntUsage
Field th32ProcessID
Field th32DefaultHeapID
Field th32ModuleID
Field cntThreads
Field th32ParentProcessID
Field pcPriClassBase
Field dwFlags
Field szExeFile$ [MAX_PATH]
End Type
snap = CreateToolhelp32Snapshot (TH32CS_SNAPPROCESS, 0)
If snap
Proc32=CreateBank(SizeOf_PE32)
PokeInt(Proc32, 0, BankSize(Proc32)) ; dwSize
If Process32First (snap, Proc32) ;<--- read first running process
Print "Process ID: " + th32ProcessID
Print
While Process32Next (snap, Proc32) ;<--- read each running process
dwSize=PeekInt(Proc32,0)
cntUsage=PeekInt(Proc32,4)
th32ProcessID=PeekInt(Proc32,8)
th32DefaultHeapID=PeekInt(Proc32,12)
th32ModuleID=PeekInt(Proc32,16)
cntThreads=PeekInt(Proc32,20)
th32ParentProcessID=PeekInt(Proc32,24)
pcPriClassBase=PeekInt(Proc32,28)
dwFlags=PeekInt(Proc32,32)
offset = 36
Repeat
char = PeekByte(Proc32, offset)
offset = offset + 1
szExeFile$ = szExeFile$ + Chr$(char)
Until char = 0
szExeFile$=Left$(szExeFile$,Len(szExeFile$)-1)
Print
Print szExeFile$ ;<--- process name
Print "Process ID: " + th32ProcessID
If szExeFile$="calc.exe" Then program=th32ProcessID;<--- program = processID of calculator
szExeFile$=""
Wend
EndIf
CloseHandle (snap)
EndIf
Print
Print "Calculator program is thread process " + program + "."
; <--- from here down is where i don't know what i am doing right
app=openprocess(PROCESS_ALL_ACCESS,x,program)
Print "Value for app is " + app + "." ;<--- just to see what it contains
pip=CreateBank(3) ; <-- is bank the way to go here? how big?
zap=readprocessmemory(app,$77d43999,pip,4,x) ;<--- Not sure what To put here at all...
tip=PeekByte (pip,0) ;<--- just want to see what one address contains.
Print "the address $77d43999 contains the number " + tip + "." ; always zero or not what really is at that address
;obviously i am doing something wrong because i can look at address $77d43999 with tsearch and it is not what tip says
;i am not even sure where the addresses for the calculator program begins?? i thought that
;app would point at that or something. anyways, HELP!
Input ()
End
;code below is what we are trying to accomplish, but it is in purebasic format (!?$)
;app = OpenProcess_(#PROCESS_ALL_ACCESS,Null,pid)
; Buffer For storing stuff, in bytes
;pip = AllocateMemory(1,3)
; To read from process
;zap = ReadProcessMemory_(app,4987153,pip,3,Null)
;tip = PeekL(pip)
; To write to process
;zing = PokeL(pip,9474192)
;zip = WriteProcessMemory_(app,4987153,pip,3,Null)
[/CODE]
you must have the calculator program (calc.exe) running in the background when you run this. i am not sure how to accesses the addresses that the calc program is residing in memory. that's what i am trying to accomplish. this code requires two .decls (one for user32.dll and one for kernel32.dll) the .decls are included at the top of the code after the ";"'s. just uncomment them and save them in the userlibs directory. I hope someone can help!
best,
mike
[CODE]
; -----------------------------------------------------------------------------
; Create or open existing kernel32.decls file in userlibs folder and place
; these lines in it (uncommented!)...
; -----------------------------------------------------------------------------
;
;.lib "kernel32.dll"
;
;CreateToolhelp32Snapshot% (flags, th32processid)
;Process32First% (snapshot, entry*)
;Process32Next% (snapshot, entry*)
;CloseHandle% (object)
;OpenProcess% (dwDesiredAccess%, Null, dwProcessId%) : "OpenProcess"
;ReadProcessMemory% (hProcess%, lpBaseAddress*, lpBuffer*, nSize%, Null)
;WriteProcessMemory% (hProcess%, lpBaseAddress*, lpBuffer*, nSize%, lpNumberOfBytesWritten%)
;
; -----------------------------------------------------------------------------
; -----------------------------------------------------------------------------
; Create or open existing user32.decls file in userlibs folder and place
; these lines in it (uncommented!)...
; -----------------------------------------------------------------------------
;
;.lib "user32.dll"
;
;FindWindow% (Null, Caption$) : "FindWindowA"
;SetWindowState(hwnd,command):"ShowWindow"
;ShowWindow% (hwnd%, nCmdShow%) : "ShowWindow"
;GetWindowThreadProcessId% (hwnd%, ProcessId%) : "GetWindowThreadProcessId"
;
; -----------------------------------------------------------------------------
; -----------------------------------------------------------------------------
;Make sure that the calculator program included with windows is running so that this will identify it
; -----------------------------------------------------------------------------
Const MAX_PATH = 264
Const TH32CS_SNAPHEAPLIST = $1
Const TH32CS_SNAPPROCESS = $2
Const TH32CS_SNAPTHREAD = $4
Const TH32CS_SNAPMODULE = $8
Const TH32CS_SNAPALL = TH32CS_SNAPHEAPLIST Or TH32CS_SNAPPROCESS Or TH32CS_SNAPTHREAD Or TH32CS_SNAPMODULE
Const TH32CS_INHERIT = $80000000
Const INVALID_HANDLE_VALUE = -1
Const SizeOf_PE32 = 296
Const STANDARD_RIGHTS_REQUIRED = $F0000
Const SYNCHRONIZE = $100000
Const PROCESS_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED Or SYNCHRONIZE Or $FFF)
;x = NULL in most instances
Type PROCESSENTRY32
Field dwSize
Field cntUsage
Field th32ProcessID
Field th32DefaultHeapID
Field th32ModuleID
Field cntThreads
Field th32ParentProcessID
Field pcPriClassBase
Field dwFlags
Field szExeFile$ [MAX_PATH]
End Type
snap = CreateToolhelp32Snapshot (TH32CS_SNAPPROCESS, 0)
If snap
Proc32=CreateBank(SizeOf_PE32)
PokeInt(Proc32, 0, BankSize(Proc32)) ; dwSize
If Process32First (snap, Proc32) ;<--- read first running process
Print "Process ID: " + th32ProcessID
While Process32Next (snap, Proc32) ;<--- read each running process
dwSize=PeekInt(Proc32,0)
cntUsage=PeekInt(Proc32,4)
th32ProcessID=PeekInt(Proc32,8)
th32DefaultHeapID=PeekInt(Proc32,12)
th32ModuleID=PeekInt(Proc32,16)
cntThreads=PeekInt(Proc32,20)
th32ParentProcessID=PeekInt(Proc32,24)
pcPriClassBase=PeekInt(Proc32,28)
dwFlags=PeekInt(Proc32,32)
offset = 36
Repeat
char = PeekByte(Proc32, offset)
offset = offset + 1
szExeFile$ = szExeFile$ + Chr$(char)
Until char = 0
szExeFile$=Left$(szExeFile$,Len(szExeFile$)-1)
Print szExeFile$ ;<--- process name
Print "Process ID: " + th32ProcessID
If szExeFile$="calc.exe" Then program=th32ProcessID;<--- program = processID of calculator
szExeFile$=""
Wend
EndIf
CloseHandle (snap)
EndIf
Print "Calculator program is thread process " + program + "."
; <--- from here down is where i don't know what i am doing right
app=openprocess(PROCESS_ALL_ACCESS,x,program)
Print "Value for app is " + app + "." ;<--- just to see what it contains
pip=CreateBank(3) ; <-- is bank the way to go here? how big?
zap=readprocessmemory(app,$77d43999,pip,4,x) ;<--- Not sure what To put here at all...
tip=PeekByte (pip,0) ;<--- just want to see what one address contains.
Print "the address $77d43999 contains the number " + tip + "." ; always zero or not what really is at that address
;obviously i am doing something wrong because i can look at address $77d43999 with tsearch and it is not what tip says
;i am not even sure where the addresses for the calculator program begins?? i thought that
;app would point at that or something. anyways, HELP!
Input ()
End
;code below is what we are trying to accomplish, but it is in purebasic format (!?$)
;app = OpenProcess_(#PROCESS_ALL_ACCESS,Null,pid)
; Buffer For storing stuff, in bytes
;pip = AllocateMemory(1,3)
; To read from process
;zap = ReadProcessMemory_(app,4987153,pip,3,Null)
;tip = PeekL(pip)
; To write to process
;zing = PokeL(pip,9474192)
;zip = WriteProcessMemory_(app,4987153,pip,3,Null)
[/CODE]
you must have the calculator program (calc.exe) running in the background when you run this. i am not sure how to accesses the addresses that the calc program is residing in memory. that's what i am trying to accomplish. this code requires two .decls (one for user32.dll and one for kernel32.dll) the .decls are included at the top of the code after the ";"'s. just uncomment them and save them in the userlibs directory. I hope someone can help!