Cannot read float value

Question:

trying to read float value but it giving error it says address must be int even though I use read_float and it makes an error it cant read it says address must be int

from pymem import *
from pymem.process import *

pm = pymem.Pymem("game.exe")

module = module_from_name(pm.process_handle, "game.exe").lpBaseOfDll

def GetPtrAddr(base, offsets):
    addr = pm.read_float(base)
    for i in offsets:
        if i != offsets[-1]:
            addr = pm.read_float(addr + i)
    return addr + offsets[-1]
northsouth = GetPtrAddr(module + 0x01B20C50, [0x38, 0x60, 0x290, 0x68, 0x140, 0x0, 0x3C])
print(pm.read_float(northsouth))



Traceback (most recent call last):
  File "C:UsersuserDesktopprogram3erfwq.py", line 14, in <module>
    northsouth = GetPtrAddr(module + 0x01B20C50, [0x38, 0x60, 0x290, 0x68, 0x140, 0x0, 0x3C])
  File "C:UsersuserDesktopprogram3erfwq.py", line 12, in GetPtrAddr
    addr = pm.read_float(addr + i)
  File "C:UsersuserAppDataLocalProgramsPythonPython310libsite-packagespymem__init__.py", line 650, in read_float
    value = pymem.memory.read_float(self.process_handle, address)
  File "C:UsersuserAppDataLocalProgramsPythonPython310libsite-packagespymemmemory.py", line 377, in read_float
    bytes = read_bytes(handle, address, struct.calcsize('f'))
  File "C:UsersuserAppDataLocalProgramsPythonPython310libsite-packagespymemmemory.py", line 97, in read_bytes
    raise TypeError('Address must be int: {}'.format(address))
TypeError: Address must be int: 1994287160.0
Asked By: cool

||

Answers:

The read_float method tries to read a float from a memory address.
The address you specify must be an int – but you are passing a float.

Focus on the argument addr + i. Since you initialized addr = pm.read_float(base) it definitely is a float, and adding i does not change that.

So either initialize using addr = pm.read_int(base), or stay with reading a float but then you have to convert it to an int like so:

addr = pm.read_float( int(addr + i) )
Answered By: Hiran Chaudhuri
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.