我有一个与此类似的链接列表:
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 开始,但我想我需要真正的偏移量。但是我怎样才能获得下一个偏移量(基于前一个偏移量的大小)?
希望很清楚,但如果需要我可以澄清,谢谢
最佳答案
您无法从ptrace()
获取此信息;不过,您可以从子进程的 /proc/PID/maps
获取它。请注意,地址0
通常不会被映射,以便捕获NULL
指针引用,并且对于PTRACE_PEEKDATA
可能没有意义(现在通常不使用单独的I和D,并且在没有它的情况下,地址0通常是文本,而不是数据;内核是否费心去区分,我不知道)。
关于c++ - Linux C++ ptrace——映射子进程内存的所有单元,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10157752/