|
-
Mar 31st, 2002, 07:49 PM
#1
Thread Starter
Frenzied Member
Changing program memory
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??
-
Apr 1st, 2002, 12:01 PM
#2
Monday Morning Lunatic
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?
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Apr 1st, 2002, 12:24 PM
#3
Thread Starter
Frenzied Member
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 =)
-
Apr 1st, 2002, 12:50 PM
#4
Monday Morning Lunatic
Hmmm.
*looks carefully*
PROCESS_ALL_ACCESS -- this may not be granted so you'll have to check....but if it works, great
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|