28 uintptr_t addr_int = (uintptr_t)addr;
30 FILE *maps = fopen(
"/proc/self/maps",
"r");
36 while (fgets(line,
sizeof(line), maps) && count < max_matches) {
37 uintptr_t start, end, offset;
43 int parsed = sscanf(line,
"%lx-%lx %4s %lx %9s %lu", &start, &end, perms, &offset, device, &inode);
50 if (perms[2] !=
'x') {
61 int line_len = strlen(line);
65 for (
int i = line_len - 1; i >= 0; i--) {
66 if (line[i] !=
' ' && line[i] !=
'\t' && line[i] !=
'\n' && line[i] !=
'\r') {
69 while (path_start > 0 && line[path_start - 1] !=
' ' && line[path_start - 1] !=
'\t') {
76 if (path_start > 0 && line[path_start - 1] !=
'\0') {
81 int path_len = strlen(path);
82 while (path_len > 0 && (path[path_len - 1] ==
'\n' || path[path_len - 1] ==
'\r')) {
83 path[--path_len] =
'\0';
88 if (perms[2] ==
'x' && path[0] ==
'/') {
89 if (addr_int >= start && addr_int < end) {
92 matches[count].file_offset = (addr_int - start) + offset;