1. 获取进程的所有PTE表项,从而得到所有物理地址
参考:https://www.cnblogs.com/pengdonglin137/p/6802108.html
通过/proc/pid/pagemap
1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <unistd.h> 4 #include <assert.h> 5 #include <errno.h> 6 #include <stdint.h> 7 #include <string.h> 8 9 #define PAGEMAP_ENTRY 8 10 #define GET_BIT(X,Y) (X & ((uint64_t)1<<Y)) >> Y 11 #define GET_PFN(X) X & 0x7FFFFFFFFFFFFF 12 13 const int __endian_bit = 1; 14 #define is_bigendian() ( (*(char*)&__endian_bit) == 0 ) 15 16 int i, c, pid, status; 17 unsigned long virt_addr; 18 uint64_t read_val, file_offset, page_size; 19 char path_buf [0x100] = {}; 20 FILE * f; 21 char *end; 22 23 int read_pagemap(char * path_buf, unsigned long virt_addr); 24 25 int main(int argc, char ** argv){ 26 if(argc!=3){ 27 printf("Argument number is not correct! pagemap PID VIRTUAL_ADDRESS "); 28 return -1; 29 } 30 if(!memcmp(argv[1],"self",sizeof("self"))){ 31 sprintf(path_buf, "/proc/self/pagemap"); 32 pid = -1; 33 } 34 else{ 35 pid = strtol(argv[1],&end, 10); 36 if (end == argv[1] || *end != '