简体   繁体   English

如何使用 pymem 读取内存?

[英]How do i read memory using pymem?

this code writes and reads memory from a program.此代码从程序中写入和读取内存。 the program is built in 64bit.该程序内置于 64 位。 i have no problem using mem.write_float but when using mem.read, an error occurs我使用 mem.write_float 没有问题,但是使用 mem.read 时出现错误

pymem.exception.MemoryReadError: Could not read memory at: 16, length: 8 - GetLastError: 29

does anyone have idea?有人知道吗?

from pymem import *
from pymem.process import *


mem = Pymem("###.exe")
game_module = module_from_name(mem.process_handle, "###.exe").lpBaseOfDll


def getPtrAddr(address, offsets):
    addr = mem.read_longlong(address)
    for offset in offsets:
        if offset != offsets[-1]:
            addr = mem.read_longlong(addr + offset)
    addr = addr + offsets[-1]
    return addr

while True:

    mem.write_float(getPtrAddr(game_module + 0x06D26780, [0x28, 0x20, 0X08, 0x08, 0x170, 0x10, 0xE8]), 1000.233)
    
    mem.read_longlong(getPtrAddr(game_module + 0x06D26780, [0x28, 0x20, 0X08, 0x08, 0x170,0x10, 0xE8]))

In your function, read_longlong is reading integer.在您的函数中, read_longlong 正在读取整数。 To jump from pointer to pointer you need to read pointer value.要从指针跳转到指针,您需要读取指针值。 Instead of reading int, you can use "ptypes" see: https://pymem.readthedocs.io/en/latest/api.html#module-pymem.ptypes您可以使用“ptypes”代替阅读 int,参见: https ://pymem.readthedocs.io/en/latest/api.html#module-pymem.ptypes

You can use ptypes like this;您可以像这样使用 ptypes;

from pymem import Pymem
from pymem.ptypes import RemotePointer

pm = Pymem("###.exe")

def getPointerAddress(base, offsets):
    remote_pointer = RemotePointer(pm.process_handle, base)
    for offset in offsets:
        if offset != offsets[-1]:
            remote_pointer = RemotePointer(pm.process_handle, remote_pointer.value + offset)
        else:
            return remote_pointer.value + offset

pm.write_int(getPointerAddress(pm.base_address + 0x123ABC, offsets=[offset1, offset2, offset3]), 123456)

in your code;在您的代码中;

game_module = module_from_name(mem.process_handle, "###.exe").lpBaseOfDll

and

pm.base_address

are basically the same thing基本上是一样的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM