Skip to content

Instantly share code, notes, and snippets.

@wiggin15
Created July 29, 2018 12:08
Show Gist options
  • Save wiggin15/0a4c51b5bc6c52e6e31e2234f88558ab to your computer and use it in GitHub Desktop.
Save wiggin15/0a4c51b5bc6c52e6e31e2234f88558ab to your computer and use it in GitHub Desktop.
vm_region_recurse_64 / proc_regionfilename
#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
#include <libproc.h>
#include <mach/mach.h>
#include <CoreFoundation/CoreFoundation.h>
int main(void)
{
kern_return_t kr = KERN_SUCCESS;
vm_address_t address = 0;
vm_size_t size = 0;
uint32_t depth = 0;
mach_port_t task = MACH_PORT_NULL;
char buf[PATH_MAX];
int ret;
pid_t pid = getpid();
task_for_pid(mach_task_self(), pid, &task);
while (1) {
mach_msg_type_number_t count = VM_REGION_SUBMAP_INFO_COUNT_64;
struct vm_region_submap_info_64 info;
kr = vm_region_recurse_64(task, &address, &size, &depth,
(vm_region_recurse_info_t)&info, &count);
if (kr) {
break;
}
if (info.is_submap) {
depth++;
printf("Recursing into %016lx-%016lx\n", address, address+size);
} else {
errno = 0;
ret = proc_regionfilename(pid, address, buf, sizeof(buf));
printf("%016lx-%016lx (depth=%d) %s (errno=%d ret=%d)\n", address, address+size, depth, buf, errno, ret);
address += size;
}
}
return 0;
}
~ ./a.out
000000010d89d000-000000010d89e000 (depth=0) /private/tmp/a.out (errno=0 ret=18)
000000010d89e000-000000010d89f000 (depth=0) /private/tmp/a.out (errno=0 ret=18)
000000010d89f000-000000010d8a0000 (depth=0) /private/tmp/a.out (errno=0 ret=18)
000000010d8a0000-000000010d8a2000 (depth=0) /usr/lib/dyld (errno=0 ret=13)
000000010d8a2000-000000010d8a3000 (depth=0) /usr/lib/dyld (errno=0 ret=13)
000000010d8a3000-000000010d8a4000 (depth=0) /usr/lib/dyld (errno=0 ret=13)
000000010d8a4000-000000010d8a5000 (depth=0) /usr/lib/dyld (errno=0 ret=13)
000000010d8a5000-000000010d8a9000 (depth=0) /usr/lib/dyld (errno=0 ret=13)
000000010d8a9000-000000010d8aa000 (depth=0) /usr/lib/dyld (errno=0 ret=13)
000000010d8aa000-000000010d8ab000 (depth=0) /usr/lib/dyld (errno=0 ret=13)
000000010d8ab000-000000010d8af000 (depth=0) /usr/lib/dyld (errno=0 ret=13)
000000010d8af000-000000010d8b0000 (depth=0) /usr/lib/dyld (errno=0 ret=13)
000000010d8b0000-000000010d8b1000 (depth=0) /usr/lib/dyld (errno=0 ret=13)
000000010ea88000-000000010ead3000 (depth=0) /usr/lib/dyld (errno=0 ret=13)
000000010ead3000-000000010ead6000 (depth=0) /usr/lib/dyld (errno=0 ret=13)
000000010ead6000-000000010eb0b000 (depth=0) /usr/lib/dyld (errno=0 ret=13)
000000010eb0b000-000000010eb26000 (depth=0) /usr/lib/dyld (errno=0 ret=13)
00007fe5a8c00000-00007fe5a8d00000 (depth=0) /private/var/db/dyld/dyld_shared_cache_x86_64h (errno=0 ret=46)
00007fe5a9000000-00007fe5a9800000 (depth=0) /private/var/db/dyld/dyld_shared_cache_x86_64h (errno=0 ret=46)
00007ffede363000-00007ffee1b63000 (depth=0) /private/var/db/dyld/dyld_shared_cache_x86_64h (errno=0 ret=46)
00007ffee1b63000-00007ffee2363000 (depth=0) /private/var/db/dyld/dyld_shared_cache_x86_64h (errno=0 ret=46)
Recursing into 00007fff00000000-00007fff80000000
00007fff49112000-00007fff50cdd000 (depth=1) /private/var/db/dyld/dyld_shared_cache_x86_64h (errno=0 ret=46)
00007fff50cdd000-00007fff50cde000 (depth=1) /private/var/db/dyld/dyld_shared_cache_x86_64h (errno=0 ret=46)
00007fff50cde000-00007fff78e6a000 (depth=1) /private/var/db/dyld/dyld_shared_cache_x86_64h (errno=0 ret=46)
00007fffa9112000-00007fffa9200000 (depth=1) /private/var/db/dyld/dyld_shared_cache_x86_64h (errno=0 ret=46)
00007fffa9200000-00007fffa9400000 (depth=1) /private/var/db/dyld/dyld_shared_cache_x86_64h (errno=0 ret=46)
00007fffa9400000-00007fffa9600000 (depth=1) /private/var/db/dyld/dyld_shared_cache_x86_64h (errno=0 ret=46)
00007fffa9600000-00007fffaa000000 (depth=1) /private/var/db/dyld/dyld_shared_cache_x86_64h (errno=0 ret=46)
00007fffaa000000-00007fffaa200000 (depth=1) /private/var/db/dyld/dyld_shared_cache_x86_64h (errno=0 ret=46)
00007fffaa200000-00007fffaa400000 (depth=1) /private/var/db/dyld/dyld_shared_cache_x86_64h (errno=0 ret=46)
00007fffaa400000-00007fffaa800000 (depth=1) /private/var/db/dyld/dyld_shared_cache_x86_64h (errno=0 ret=46)
00007fffaa800000-00007fffaaa00000 (depth=1) /private/var/db/dyld/dyld_shared_cache_x86_64h (errno=0 ret=46)
00007fffaaa00000-00007fffaac00000 (depth=1) /private/var/db/dyld/dyld_shared_cache_x86_64h (errno=0 ret=46)
00007fffaac00000-00007fffaae00000 (depth=1) /private/var/db/dyld/dyld_shared_cache_x86_64h (errno=0 ret=46)
00007fffaae00000-00007fffab000000 (depth=1) /private/var/db/dyld/dyld_shared_cache_x86_64h (errno=0 ret=46)
00007fffab000000-00007fffab200000 (depth=1) /private/var/db/dyld/dyld_shared_cache_x86_64h (errno=0 ret=46)
00007fffab200000-00007fffab400000 (depth=1) /private/var/db/dyld/dyld_shared_cache_x86_64h (errno=0 ret=46)
00007fffab400000-00007fffab600000 (depth=1) /private/var/db/dyld/dyld_shared_cache_x86_64h (errno=0 ret=46)
00007fffab600000-00007fffab800000 (depth=1) /private/var/db/dyld/dyld_shared_cache_x86_64h (errno=0 ret=46)
00007fffab800000-00007fffabe00000 (depth=1) /private/var/db/dyld/dyld_shared_cache_x86_64h (errno=0 ret=46)
00007fffabe00000-00007fffac000000 (depth=1) /private/var/db/dyld/dyld_shared_cache_x86_64h (errno=0 ret=46)
00007fffac000000-00007fffac200000 (depth=1) /private/var/db/dyld/dyld_shared_cache_x86_64h (errno=0 ret=46)
00007fffac200000-00007fffac400000 (depth=1) /private/var/db/dyld/dyld_shared_cache_x86_64h (errno=0 ret=46)
00007fffac400000-00007fffac600000 (depth=1) /private/var/db/dyld/dyld_shared_cache_x86_64h (errno=0 ret=46)
00007fffac600000-00007fffac800000 (depth=1) /private/var/db/dyld/dyld_shared_cache_x86_64h (errno=0 ret=46)
00007fffac800000-00007fffacc00000 (depth=1) /private/var/db/dyld/dyld_shared_cache_x86_64h (errno=0 ret=46)
00007fffacc00000-00007ffface00000 (depth=1) /private/var/db/dyld/dyld_shared_cache_x86_64h (errno=0 ret=46)
00007ffface00000-00007fffad000000 (depth=1) /private/var/db/dyld/dyld_shared_cache_x86_64h (errno=0 ret=46)
00007fffad000000-00007fffad200000 (depth=1) /private/var/db/dyld/dyld_shared_cache_x86_64h (errno=0 ret=46)
00007fffad200000-00007fffad400000 (depth=1) /private/var/db/dyld/dyld_shared_cache_x86_64h (errno=0 ret=46)
00007fffad400000-00007fffad600000 (depth=1) /private/var/db/dyld/dyld_shared_cache_x86_64h (errno=0 ret=46)
00007fffad600000-00007fffad800000 (depth=1) /private/var/db/dyld/dyld_shared_cache_x86_64h (errno=0 ret=46)
00007fffad800000-00007fffada00000 (depth=1) /private/var/db/dyld/dyld_shared_cache_x86_64h (errno=0 ret=46)
00007fffada00000-00007fffadc00000 (depth=1) /private/var/db/dyld/dyld_shared_cache_x86_64h (errno=0 ret=46)
00007fffadc00000-00007fffade00000 (depth=1) /private/var/db/dyld/dyld_shared_cache_x86_64h (errno=0 ret=46)
00007fffade00000-00007fffae000000 (depth=1) /private/var/db/dyld/dyld_shared_cache_x86_64h (errno=0 ret=46)
00007fffae000000-00007fffae800000 (depth=1) /private/var/db/dyld/dyld_shared_cache_x86_64h (errno=0 ret=46)
00007fffae800000-00007fffaec00000 (depth=1) /private/var/db/dyld/dyld_shared_cache_x86_64h (errno=0 ret=46)
00007fffaec00000-00007fffaee00000 (depth=1) /private/var/db/dyld/dyld_shared_cache_x86_64h (errno=0 ret=46)
00007fffaee00000-00007fffaf000000 (depth=1) /private/var/db/dyld/dyld_shared_cache_x86_64h (errno=0 ret=46)
00007fffaf000000-00007fffaf200000 (depth=1) /private/var/db/dyld/dyld_shared_cache_x86_64h (errno=0 ret=46)
00007fffaf200000-00007fffaf400000 (depth=1) /private/var/db/dyld/dyld_shared_cache_x86_64h (errno=0 ret=46)
00007fffaf400000-00007fffaf600000 (depth=1) /private/var/db/dyld/dyld_shared_cache_x86_64h (errno=0 ret=46)
00007fffaf600000-00007fffaf800000 (depth=1) /private/var/db/dyld/dyld_shared_cache_x86_64h (errno=0 ret=46)
00007fffaf800000-00007fffafa00000 (depth=1) /private/var/db/dyld/dyld_shared_cache_x86_64h (errno=0 ret=46)
00007fffafa00000-00007fffafc00000 (depth=1) /private/var/db/dyld/dyld_shared_cache_x86_64h (errno=0 ret=46)
00007fffafc00000-00007fffafe00000 (depth=1) /private/var/db/dyld/dyld_shared_cache_x86_64h (errno=0 ret=46)
00007fffafe00000-00007fffb0000000 (depth=1) /private/var/db/dyld/dyld_shared_cache_x86_64h (errno=0 ret=46)
00007fffb0000000-00007fffb0400000 (depth=1) /private/var/db/dyld/dyld_shared_cache_x86_64h (errno=0 ret=46)
00007fffb0400000-00007fffb0600000 (depth=1) /private/var/db/dyld/dyld_shared_cache_x86_64h (errno=0 ret=46)
00007fffb0600000-00007fffb0800000 (depth=1) /private/var/db/dyld/dyld_shared_cache_x86_64h (errno=0 ret=46)
00007fffb0800000-00007fffb0a00000 (depth=1) /private/var/db/dyld/dyld_shared_cache_x86_64h (errno=0 ret=46)
00007fffb0a00000-00007fffb0c00000 (depth=1) /private/var/db/dyld/dyld_shared_cache_x86_64h (errno=0 ret=46)
00007fffb0c00000-00007fffb0e00000 (depth=1) /private/var/db/dyld/dyld_shared_cache_x86_64h (errno=0 ret=46)
00007fffb0e00000-00007fffb1000000 (depth=0) /private/var/db/dyld/dyld_shared_cache_x86_64h (errno=0 ret=46)
Recursing into 00007fffb1000000-00007fffb1200000
00007fffb1000000-00007fffb1200000 (depth=1) /private/var/db/dyld/dyld_shared_cache_x86_64h (errno=0 ret=46)
00007fffb1200000-00007fffb1400000 (depth=0) /private/var/db/dyld/dyld_shared_cache_x86_64h (errno=0 ret=46)
00007fffb1400000-00007fffb1600000 (depth=0) /private/var/db/dyld/dyld_shared_cache_x86_64h (errno=0 ret=46)
00007fffb1600000-00007fffb1617000 (depth=0) /private/var/db/dyld/dyld_shared_cache_x86_64h (errno=0 ret=46)
Recursing into 00007fffb1617000-00007fffc0000000
00007fffe9112000-00007ffff6252000 (depth=1) /private/var� (errno=22 ret=13)
00007fffffe00000-00007fffffe01000 (depth=1) /private/var (errno=22 ret=12)
00007fffffe98000-00007fffffe99000 (depth=1) /private/var (errno=22 ret=12)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment