Search code examples
pythonwinapireverse-engineering

return a float value from ReadProcessMemory in python


I have an address containing the y-position in the game called Assault Cube (I'm learning about reverse engineering)

My problem is readprocessmemory's ReadBuffer.value returns an integer, and I'm looking for a way to receive the value as a float. Does anyone know how to do this in python?

In the picture I've tried to illustrate how an integer (1125777408) is returned, which itself is correct, but I'd like to find a way to have the float value returned (104).

enter image description here

def ReadProcessMemory(self, hProcess, lpBaseAddress):
    try:
        lpBaseAddress = lpBaseAddress
        ReadBuffer = ctypes.c_uint()
        lpBuffer = ctypes.byref(ReadBuffer)
        nSize = ctypes.sizeof(ReadBuffer)
        lpNumberOfBytesRead = ctypes.c_ulong(0)

        ctypes.windll.kernel32.ReadProcessMemory(
                                                hProcess,
                                                lpBaseAddress,
                                                lpBuffer,
                                                nSize,
                                                lpNumberOfBytesRead
                                                )
        return ReadBuffer.value
    except (BufferError, ValueError, TypeError):
        self.CloseHandle(hProcess)
        e = 'Handle Closed, Error', hProcess, self.GetLastError()
        return e

Solution

  • There is a ctypes method called c_float, so use ctypes.c_float() instead of ctypes.c_int().