static void darwin_debug_regions_recurse (task_t task) { mach_vm_address_t r_addr; mach_vm_address_t r_start; mach_vm_size_t r_size; natural_t r_depth; mach_msg_type_number_t r_info_size; vm_region_submap_short_info_data_64_t r_info; kern_return_t kret; int ret; struct cleanup *table_chain; struct ui_out *uiout = current_uiout; table_chain = make_cleanup_ui_out_table_begin_end (uiout, 9, -1, "regions"); if (gdbarch_addr_bit (target_gdbarch ()) <= 32) { ui_out_table_header (uiout, 10, ui_left, "start", "Start"); ui_out_table_header (uiout, 10, ui_left, "end", "End"); } else { ui_out_table_header (uiout, 18, ui_left, "start", "Start"); ui_out_table_header (uiout, 18, ui_left, "end", "End"); } ui_out_table_header (uiout, 3, ui_left, "min-prot", "Min"); ui_out_table_header (uiout, 3, ui_left, "max-prot", "Max"); ui_out_table_header (uiout, 5, ui_left, "inheritence", "Inh"); ui_out_table_header (uiout, 9, ui_left, "share-mode", "Shr"); ui_out_table_header (uiout, 1, ui_left, "depth", "D"); ui_out_table_header (uiout, 3, ui_left, "submap", "Sm"); ui_out_table_header (uiout, 0, ui_noalign, "tag", "Tag"); ui_out_table_body (uiout); r_start = 0; r_depth = 0; while (1) { const char *tag; struct cleanup *row_chain; r_info_size = VM_REGION_SUBMAP_SHORT_INFO_COUNT_64; r_size = -1; kret = mach_vm_region_recurse (task, &r_start, &r_size, &r_depth, (vm_region_recurse_info_t) &r_info, &r_info_size); if (kret != KERN_SUCCESS) break; row_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "regions-row"); ui_out_field_core_addr (uiout, "start", target_gdbarch (), r_start); ui_out_field_core_addr (uiout, "end", target_gdbarch (), r_start + r_size); ui_out_field_string (uiout, "min-prot", unparse_protection (r_info.protection)); ui_out_field_string (uiout, "max-prot", unparse_protection (r_info.max_protection)); ui_out_field_string (uiout, "inheritence", unparse_inheritance (r_info.inheritance)); ui_out_field_string (uiout, "share-mode", unparse_share_mode (r_info.share_mode)); ui_out_field_int (uiout, "depth", r_depth); ui_out_field_string (uiout, "submap", r_info.is_submap ? _("sm ") : _("obj")); tag = unparse_user_tag (r_info.user_tag); if (tag) ui_out_field_string (uiout, "tag", tag); else ui_out_field_int (uiout, "tag", r_info.user_tag); do_cleanups (row_chain); if (!ui_out_is_mi_like_p (uiout)) ui_out_text (uiout, "\n"); if (r_info.is_submap) r_depth++; else r_start += r_size; } do_cleanups (table_chain); }
static RList *ios_dbg_maps(RDebug *dbg, int only_modules) { boolt contiguous = R_FALSE; ut32 oldprot = UT32_MAX; ut32 oldmaxprot = UT32_MAX; char buf[1024]; char module_name[MAXPATHLEN]; mach_vm_address_t address = MACH_VM_MIN_ADDRESS; mach_vm_size_t size = (mach_vm_size_t) 0; mach_vm_size_t osize = (mach_vm_size_t) 0; natural_t depth = 0; int tid = dbg->pid; task_t task = pid_to_task (tid); RDebugMap *mr = NULL; RList *list = NULL; int i = 0; if (only_modules) { return xnu_dbg_modules (dbg); } #if __arm64__ || __aarch64__ size = osize = 16384; // acording to frida #else size = osize = 4096; #endif #if 0 if (dbg->pid == 0) { vm_address_t base = get_kernel_base (task); eprintf ("Kernel Base Address: 0x%"PFMT64x"\n", (ut64)base); return NULL; } #endif kern_return_t kr; for (;;) { struct vm_region_submap_info_64 info; mach_msg_type_number_t info_count; info_count = VM_REGION_SUBMAP_INFO_COUNT_64; memset (&info, 0, sizeof (info)); kr = mach_vm_region_recurse (task, &address, &size, &depth, (vm_region_recurse_info_t) &info, &info_count); if (kr != KERN_SUCCESS) { //eprintf ("Cannot kern succ recurse\n"); break; } if (info.is_submap) { depth++; continue; } if (!list) { list = r_list_new (); //list->free = (RListFree*)r_debug_map_free; } { module_name[0] = 0; int ret = proc_regionfilename (tid, address, module_name, sizeof (module_name)); module_name[ret] = 0; } #if 0 oldprot = info.protection; oldmaxprot = info.max_protection; // contiguous pages seems to hide some map names if (mr) { if (address == mr->addr + mr->size) { if (oldmaxprot == info.max_protection) { contiguous = R_FALSE; } else if (oldprot != UT32_MAX && oldprot == info.protection) { /* expand region */ mr->size += size; contiguous = R_TRUE; } else { contiguous = R_FALSE; } } else { contiguous = R_FALSE; } } else contiguous = R_FALSE; //if (info.max_protection == oldprot && !contiguous) { #endif if (1) { #define xwr2rwx(x) ((x&1)<<2) | (x&2) | ((x&4)>>2) // XXX: if its shared, it cannot be read? snprintf (buf, sizeof (buf), "%s %02x %s%s%s%s%s %s depth=%d", r_str_rwx_i (xwr2rwx (info.max_protection)), i, unparse_inheritance (info.inheritance), info.user_tag? " user": "", info.is_submap? " sub": "", info.inheritance? " inherit": "", info.is_submap ? " submap": "", module_name, depth); //info.shared ? "shar" : "priv", //info.reserved ? "reserved" : "not-reserved", //""); //module_name); mr = r_debug_map_new (buf, address, address+size, xwr2rwx (info.protection), 0); if (mr == NULL) { eprintf ("Cannot create r_debug_map_new\n"); break; } mr->file = strdup (module_name); i++; r_list_append (list, mr); } if (size<1) { eprintf ("EFUCK\n"); size = osize; // f**k } address += size; size = 0; } return list; }
static void darwin_debug_regions (task_t task, mach_vm_address_t address, int max) { kern_return_t kret; vm_region_basic_info_data_64_t info, prev_info; mach_vm_address_t prev_address; mach_vm_size_t size, prev_size; mach_port_t object_name; mach_msg_type_number_t count; int nsubregions = 0; int num_printed = 0; count = VM_REGION_BASIC_INFO_COUNT_64; kret = mach_vm_region (task, &address, &size, VM_REGION_BASIC_INFO_64, (vm_region_info_t) &info, &count, &object_name); if (kret != KERN_SUCCESS) { printf_filtered (_("No memory regions.")); return; } memcpy (&prev_info, &info, sizeof (vm_region_basic_info_data_64_t)); prev_address = address; prev_size = size; nsubregions = 1; for (;;) { int print = 0; int done = 0; address = prev_address + prev_size; /* Check to see if address space has wrapped around. */ if (address == 0) print = done = 1; if (!done) { count = VM_REGION_BASIC_INFO_COUNT_64; kret = mach_vm_region (task, &address, &size, VM_REGION_BASIC_INFO_64, (vm_region_info_t) &info, &count, &object_name); if (kret != KERN_SUCCESS) { size = 0; print = done = 1; } } if (address != prev_address + prev_size) print = 1; if ((info.protection != prev_info.protection) || (info.max_protection != prev_info.max_protection) || (info.inheritance != prev_info.inheritance) || (info.shared != prev_info.reserved) || (info.reserved != prev_info.reserved)) print = 1; if (print) { printf_filtered (_("%s-%s %s/%s %s %s %s"), paddress (target_gdbarch (), prev_address), paddress (target_gdbarch (), prev_address + prev_size), unparse_protection (prev_info.protection), unparse_protection (prev_info.max_protection), unparse_inheritance (prev_info.inheritance), prev_info.shared ? _("shrd") : _("priv"), prev_info.reserved ? _("reserved") : _("not-rsvd")); if (nsubregions > 1) printf_filtered (_(" (%d sub-rgn)"), nsubregions); printf_filtered (_("\n")); prev_address = address; prev_size = size; memcpy (&prev_info, &info, sizeof (vm_region_basic_info_data_64_t)); nsubregions = 1; num_printed++; } else { prev_size += size; nsubregions++; } if ((max > 0) && (num_printed >= max)) done = 1; if (done) break; } }