HI,
Im looking for some example code to change a programs memory by an offset. Like it would search for 'Notepad.exe' and edit an offset in that memory.
Can anyone help me out??
Printable View
HI,
Im looking for some example code to change a programs memory by an offset. Like it would search for 'Notepad.exe' and edit an offset in that memory.
Can anyone help me out??
You can't do that unless you're a device driver, not even under 98.
NT is even stricter I think.
The 32-bit protected (note that bit ;)) memory model restricts memory values, and the same pointer may be usable in two different programs because they both have their own 4gb memory address space.
Why do you need to access its memory?
Cheating at a game.. Its all and good fun =)
After searching all last night.. I found out you can
access another processes memory AND edit it
WITH VB. I didnt know that was possible..
VB Code:
Option Explicit Private Const PROCESS_ALL_ACCESS = &H1F0FFF Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long Private Declare Function WriteProcessMemory Lib "kernel32" (ByVal hProcess As Long, ByVal lpBaseAddress As Any, lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal Classname As String, ByVal WindowName As String) As Long Private Declare Function ReadProcessMem Lib "kernel32" Alias "ReadProcessMemory" (ByVal hProcess As Long, ByVal lpBaseAddress As Any, ByRef lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long Public GameHwnd As Long 'stores hwnd for read/write Public Sub SetGameHwnd(GameName As String) 'assigns hwnd to Public GameHwnd GameHwnd = FindWindow(vbNullString, GameName) End Sub Public Function ReadAByte(Address As Long, ValBuffer As Byte) Dim pid&, PHandle& If GameHwnd& = 0 Then ReadAByte = -1 'if no hwnd found, returns a negative value Exit Function End If GetWindowThreadProcessId GameHwnd, pid PHandle = OpenProcess(PROCESS_ALL_ACCESS, False, pid) If PHandle = 0 Then ReadAByte = -1 'if no process found, returns a negative value Exit Function End If ReadProcessMem PHandle, Address, ValBuffer, 1, 0& CloseHandle PHandle End Function Public Sub WriteAByte(Address As Long, Value As Byte) Dim pid&, PHandle& If GameHwnd = 0 Then Exit Sub 'if no hwnd found, exit without writing GetWindowThreadProcessId GameHwnd, pid PHandle = OpenProcess(PROCESS_ALL_ACCESS, False, pid) If PHandle = 0 Then Exit Sub 'if no process found, exit without writing WriteProcessMemory PHandle, Address, Value, 1, 0& CloseHandle PHandle End Sub
Thanks for your support =)
Hmmm.
*looks carefully*
PROCESS_ALL_ACCESS -- this may not be granted so you'll have to check....but if it works, great :D