Results 1 to 4 of 4

Thread: Changing program memory

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Sep 1999
    Location
    Phoenix, az
    Posts
    1,517

    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??

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Sep 1999
    Location
    Phoenix, az
    Posts
    1,517
    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:
    1. Option Explicit
    2.  
    3. Private Const PROCESS_ALL_ACCESS = &H1F0FFF
    4. Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
    5. Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
    6. 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
    7. Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
    8. Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal Classname As String, ByVal WindowName As String) As Long
    9. 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
    10. Public GameHwnd As Long 'stores hwnd for read/write
    11.  
    12. Public Sub SetGameHwnd(GameName As String) 'assigns hwnd to Public GameHwnd
    13.     GameHwnd = FindWindow(vbNullString, GameName)
    14. End Sub
    15.  
    16. Public Function ReadAByte(Address As Long, ValBuffer As Byte)
    17.     Dim pid&, PHandle&
    18.    
    19.     If GameHwnd& = 0 Then
    20.         ReadAByte = -1 'if no hwnd found, returns a negative value
    21.         Exit Function
    22.     End If
    23.    
    24.     GetWindowThreadProcessId GameHwnd, pid
    25.     PHandle = OpenProcess(PROCESS_ALL_ACCESS, False, pid)
    26.    
    27.     If PHandle = 0 Then
    28.         ReadAByte = -1 'if no process found, returns a negative value
    29.         Exit Function
    30.     End If
    31.    
    32.     ReadProcessMem PHandle, Address, ValBuffer, 1, 0&
    33.     CloseHandle PHandle
    34.  
    35. End Function
    36.  
    37. Public Sub WriteAByte(Address As Long, Value As Byte)
    38.     Dim pid&, PHandle&
    39.    
    40.     If GameHwnd = 0 Then Exit Sub 'if no hwnd found, exit without writing
    41.    
    42.     GetWindowThreadProcessId GameHwnd, pid
    43.     PHandle = OpenProcess(PROCESS_ALL_ACCESS, False, pid)
    44.    
    45.     If PHandle = 0 Then Exit Sub 'if no process found, exit without writing
    46.    
    47.     WriteProcessMemory PHandle, Address, Value, 1, 0&
    48.     CloseHandle PHandle
    49.  
    50. End Sub


    Thanks for your support =)

  4. #4
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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
  •  



Click Here to Expand Forum to Full Width