How to read pointer+offset from other process (like Cheat Engine)?

Just starting out? Need help? Post your questions and find answers here.
User avatar
Mijikai
Addict
Addict
Posts: 1517
Joined: Sun Sep 11, 2016 2:17 pm

Re: How to read pointer+offset from other process (like Cheat Engine)?

Post by Mijikai »

Are you sure the first address is static?
U can also try ro read it without the base added and see if it works.

Some other things:
Where does $885D64 come from?
I saw that you use PeekI() on the result which i dont understand.
When trying to get the base its best to iterate through all modules even thought
the first one is probably always the executable base.

Some code i threw together:

Code: Select all

EnableExplicit

Procedure.i memBase(ProcessId.i,Name.s)
  Protected handle.i
  Protected me32.MODULEENTRY32
  Protected base.i
  handle = CreateToolhelp32Snapshot_(#TH32CS_SNAPMODULE32|#TH32CS_SNAPMODULE,ProcessId)
  If Not handle = #INVALID_HANDLE_VALUE
    me32\dwSize = SizeOf(MODULEENTRY32)
    If Module32First_(handle,@me32)
      Name = LCase(Name)
      Repeat
        If LCase(PeekS(@me32\szModule)) = Name
          base = me32\modBaseAddr
          Break
        EndIf
      Until Module32Next_(handle,@me32) = #False
    EndIf
    CloseHandle_(handle)
  EndIf
  ProcedureReturn base
EndProcedure

Procedure.i Main()
  Protected hwnd.i
  Protected pid.i
  Protected hproc.i
  Protected base.i
  Protected address.i
  hwnd = FindWindow_(#Null,"Barony")
  If hwnd
    GetWindowThreadProcessId_(hwnd,@pid)
    Debug "hwnd:  0x" + Hex(hwnd)
    Debug "pid:   " + pid
    hproc = OpenProcess_(#PROCESS_ALL_ACCESS,#False,pid)
    If hproc
      Debug "hproc: 0x" + Hex(hproc)
      base = memBase(pid,"Barony.exe");<-not sure what the exe name is!
      Debug "base:  0x" + Hex(base)
      ReadProcessMemory_(hproc,base + $A55D64,@address,4,#Null);<- a pointer is 4 bytes according to CE
      If address
        Debug "addr1: 0x" + Hex(address)
        ReadProcessMemory_(hproc,address + $110,@address,4,#Null)
         If address
           Debug "addr2: 0x" + Hex(address)
           ReadProcessMemory_(hproc,address,@address,4,#Null)
           If address
             Debug "health: " + Str(address)
           EndIf
         EndIf
      EndIf
      CloseHandle_(hproc)
    EndIf
  EndIf
  ProcedureReturn #Null
EndProcedure

Main()

End
rotacak
User
User
Posts: 77
Joined: Tue Feb 14, 2006 2:00 pm

Re: How to read pointer+offset from other process (like Cheat Engine)?

Post by rotacak »

Perfect, it works, thanks!
SeregaZ
Enthusiast
Enthusiast
Posts: 628
Joined: Fri Feb 20, 2009 9:24 am
Location: Almaty (Kazakhstan. not Borat, but Triple G)
Contact:

Re: How to read pointer+offset from other process (like Cheat Engine)?

Post by SeregaZ »

How to get size of memory of that process? I want to make full dump as file and watch what it have, to know where to dig later...
Post Reply