0

我有一个类似的链接列表:

class MemoryCell
{
protected:
    unsigned char* _address; // the address offset (in another process)
    unsigned int _size;  // the size of this memory block
    unsigned char* _buffer; // the data

    MemoryCell* _next; // points to next memory cell to form linked list
};

然后我有一个MemoryMapper班级将负责。我想把所有的记忆单元都放进去。

// void MemoryMapper::MapAllCells(unsigned int procId)//
unsigned int offset = 0x0;
while (true)
    {
        long memoryData = ptrace(PTRACE_PEEKDATA, procId, offset);
        if (memoryData == -1) break; // need to check for errno(3) too
       // add new MemoryCell w/ data to head of linked list
       // how to get next offset based on what was returned?

它在地址 0 处立即中断。我认为该过程可能从 0x0 开始,但我想我需要真正的偏移量。但是我怎样才能得到下一个偏移量(基于前一个的大小)?

希望很清楚,但如果需要我可以澄清谢谢

4

1 回答 1

0

您无法从ptrace(); 不过,您可以从/proc/PID/maps子进程中获取它。请注意,0通常不映射地址,以便捕获NULL指针引用,并且可能没有意义PTRACE_PEEKDATA(现在通常不使用单独的 I 和 D,并且在没有它的情况下,地址 0 通常是文本,而不是数据;内核是否麻烦区分,我不知道我的头)。

于 2012-04-14T22:21:18.583 回答