Created
October 9, 2025 22:36
-
-
Save patryk4815/ffe57131682480549346f3e84f2cbc10 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <stdlib.h> | |
| #include <mach/mach.h> | |
| #include <mach/mach_vm.h> | |
| void print_protection(vm_prot_t prot) { | |
| printf("%c%c%c", | |
| (prot & VM_PROT_READ) ? 'r' : '-', | |
| (prot & VM_PROT_WRITE) ? 'w' : '-', | |
| (prot & VM_PROT_EXECUTE) ? 'x' : '-'); | |
| } | |
| int main(int argc, char *argv[]) { | |
| if (argc != 2) { | |
| fprintf(stderr, "Usage: %s <pid>\n", argv[0]); | |
| return 1; | |
| } | |
| pid_t pid = atoi(argv[1]); | |
| task_t task; | |
| kern_return_t kr = task_for_pid(mach_task_self(), pid, &task); | |
| if (kr != KERN_SUCCESS) { | |
| fprintf(stderr, "task_for_pid failed: %s\n", mach_error_string(kr)); | |
| return 1; | |
| } | |
| mach_vm_address_t address = 0; | |
| while (1) { | |
| mach_vm_size_t size; | |
| vm_region_basic_info_data_64_t basic_info; | |
| mach_port_t object_name; | |
| mach_msg_type_number_t count = VM_REGION_BASIC_INFO_COUNT_64; | |
| kr = mach_vm_region(task, &address, &size, VM_REGION_BASIC_INFO, | |
| (vm_region_info_t)&basic_info, &count, &object_name); | |
| if (kr != KERN_SUCCESS) break; | |
| vm_region_extended_info_data_t ext_info; | |
| mach_msg_type_number_t ext_count = VM_REGION_EXTENDED_INFO_COUNT; | |
| kr = mach_vm_region(task, &address, &size, VM_REGION_EXTENDED_INFO, | |
| (vm_region_info_t)&ext_info, &ext_count, &object_name); | |
| int user_tag = -1, share_mode = -1; | |
| if (kr == KERN_SUCCESS) { | |
| user_tag = ext_info.user_tag; | |
| share_mode = ext_info.share_mode; | |
| } | |
| printf("Region: 0x%llx - 0x%llx, size: 0x%llx, prot: ", | |
| address, address + size, size); | |
| print_protection(basic_info.protection); | |
| printf(", user_tag: %d, share_mode: %d, shared: %d\n", user_tag, share_mode, basic_info.shared); | |
| address += size; | |
| } | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment