Rizin
unix-like reverse engineering framework and cli tools
|
#include <rz_debug.h>
#include <rz_reg.h>
#include <rz_lib.h>
#include <rz_analysis.h>
#include <string.h>
#include <mach/mach_host.h>
#include <mach/host_priv.h>
#include <mach/mach_vm.h>
#include <mach/thread_status.h>
#include <mach/vm_statistics.h>
#include <TargetConditionals.h>
#include "xnu_debug.h"
#include "xnu_threads.h"
#include <sys/sysctl.h>
Go to the source code of this file.
Classes | |
struct | DyldAllImageInfos32 |
struct | DyldImageInfo32 |
struct | DyldAllImageInfos64 |
struct | DyldImageInfo64 |
Macros | |
#define | MAX_MACH_HEADER_SIZE (64 * 1024) |
#define | DYLD_INFO_COUNT 5 |
#define | DYLD_INFO_LEGACY_COUNT 1 |
#define | DYLD_INFO_32_COUNT 3 |
#define | DYLD_INFO_64_COUNT 5 |
#define | DYLD_IMAGE_INFO_32_SIZE 12 |
#define | DYLD_IMAGE_INFO_64_SIZE 24 |
#define | DEBUG_MAP_TAG_ID 239 /* anonymous page id monitorable (e.g. vmmap) */ |
#define | xwrz_testwx(x) ((x & 1) << 2) | (x & 2) | ((x & 4) >> 2) |
#define | xwrz_testwx(x) ((x & 1) << 2) | (x & 2) | ((x & 4) >> 2) |
#define | COMMAND_SIZE(segment_count, segment_command_sz, thread_count, tstate_size) segment_count *segment_command_sz + thread_count * sizeof(struct thread_command) + tstate_size *thread_count |
#define | CAST_DOWN(type, addr) (((type)((uintptr_t)(addr)))) |
#define | CORE_ALL_SECT 0 |
Variables | |
static task_t | task_dbg = 0 |
#define COMMAND_SIZE | ( | segment_count, | |
segment_command_sz, | |||
thread_count, | |||
tstate_size | |||
) | segment_count *segment_command_sz + thread_count * sizeof(struct thread_command) + tstate_size *thread_count |
Definition at line 572 of file xnu_debug.c.
#define CORE_ALL_SECT 0 |
Definition at line 806 of file xnu_debug.c.
#define DEBUG_MAP_TAG_ID 239 /* anonymous page id monitorable (e.g. vmmap) */ |
Definition at line 31 of file xnu_debug.c.
#define DYLD_IMAGE_INFO_32_SIZE 12 |
Definition at line 29 of file xnu_debug.c.
#define DYLD_IMAGE_INFO_64_SIZE 24 |
Definition at line 30 of file xnu_debug.c.
#define DYLD_INFO_32_COUNT 3 |
Definition at line 27 of file xnu_debug.c.
#define DYLD_INFO_64_COUNT 5 |
Definition at line 28 of file xnu_debug.c.
#define DYLD_INFO_COUNT 5 |
Definition at line 25 of file xnu_debug.c.
#define DYLD_INFO_LEGACY_COUNT 1 |
Definition at line 26 of file xnu_debug.c.
#define MAX_MACH_HEADER_SIZE (64 * 1024) |
Definition at line 24 of file xnu_debug.c.
Definition at line 571 of file xnu_debug.c.
Definition at line 571 of file xnu_debug.c.
Definition at line 1201 of file xnu_debug.c.
Referenced by xnu_dbg_maps().
vm_address_t get_kernel_base | ( | task_t | ___task | ) |
Definition at line 1037 of file xnu_debug.c.
References addr, count, eprintf, IMAGE_OFFSET, info(), KERNEL_LOWER, PFMT64x, and ut64().
Referenced by xnu_dbg_maps().
Definition at line 576 of file xnu_debug.c.
Referenced by xnu_generate_corefile().
Definition at line 1085 of file xnu_debug.c.
Referenced by xnu_dbg_modules().
kern_return_t mach_vm_region_recurse | ( | vm_map_t | target_task, |
mach_vm_address_t * | address, | ||
mach_vm_size_t * | size, | ||
natural_t * | nesting_depth, | ||
vm_region_recurse_info_t | info, | ||
mach_msg_type_number_t * | infoCnt | ||
) |
Referenced by xnu_dbg_maps().
|
static |
Definition at line 1190 of file xnu_debug.c.
References addr, list(), map(), NULL, and RZ_BETWEEN.
Referenced by xnu_dbg_maps().
task_t pid_to_task | ( | int | pid | ) |
Definition at line 498 of file xnu_debug.c.
References eprintf, err, pid, RZ_LOG_ERROR, rz_str_get_null(), task_dbg, task_for_pid_ios9pangu(), and task_for_pid_workaround().
Referenced by rz_xnu_get_cur_thread(), rz_xnu_update_thread_list(), validate_mach_message(), xnu_continue(), xnu_create_exception_thread(), xnu_dbg_maps(), xnu_dbg_modules(), xnu_generate_corefile(), xnu_get_vmmap_entries_for_pid(), xnu_map_protect(), xnu_restore_exception_ports(), xnu_step(), and xnu_stop().
Referenced by xnu_dbg_maps().
|
static |
Definition at line 1213 of file xnu_debug.c.
References regress::m, map(), RZ_NEWCOPY, and strdup().
Referenced by xnu_dbg_maps().
|
static |
|
static |
Definition at line 57 of file xnu_debug.c.
References eprintf, i, NULL, and pid.
Referenced by pid_to_task().
|
static |
Definition at line 182 of file xnu_debug.c.
References count, eprintf, and info().
Referenced by xnu_stop().
Definition at line 810 of file xnu_debug.c.
References NULL, path, pid, and process().
Referenced by xnu_get_pid().
|
static |
Definition at line 133 of file xnu_debug.c.
References dbg, rz_debug_t::pid, pid, r, rz_debug_t::reason, RZ_DEBUG_REASON_SIGNAL, RZ_LOG_ERROR, rz_debug_reason_t::signum, xnu_create_exception_thread(), xnu_stop(), and xnu_wait_for_exception().
|
static |
Definition at line 620 of file xnu_debug.c.
References mach_header::cpusubtype, mach_header_64::cpusubtype, mach_header::cputype, mach_header_64::cputype, mach_header::filetype, mach_header_64::filetype, header, mach_header::magic, mach_header_64::magic, MH_CORE, MH_MAGIC, MH_MAGIC_64, mach_header::ncmds, mach_header_64::ncmds, pid, mach_header_64::reserved, mach_header::sizeofcmds, mach_header_64::sizeofcmds, xnu_get_cpu_subtype(), and xnu_get_cpu_type().
Referenced by xnu_generate_corefile().
|
static |
Definition at line 777 of file xnu_debug.c.
References thread_command::cmd, thread_command::cmdsize, coredump_thread_state_flavor_t::count, count, eprintf, tir_t::flavors, tir_t::header, header, tir_t::hoffset, i, int, LC_THREAD, PFMT64x, ut64(), and xnu_get_thread_status().
Referenced by xnu_generate_corefile().
Definition at line 227 of file xnu_debug.c.
References dbg, eprintf, pid, pid_to_task(), rz_xnu_get_cur_thread(), rz_xnu_get_thread(), _xnu_thread::stepping, and xnu_clear_trace_bit().
Definition at line 1225 of file xnu_debug.c.
References cmp(), dbg, eprintf, rz_debug_map_t::file, get_kernel_base(), i, info(), list(), regress::m, mach_vm_region_recurse(), moduleAt(), regress::modules, mr(), rz_debug_map_t::name, NULL, PFMT64x, rz_debug_t::pid, pid_to_task(), proc_regionfilename(), rz_debug_map_clone(), rz_debug_map_new(), rz_list_append(), rz_list_free(), rz_list_new(), rz_list_sort(), rz_str_lchr(), rz_str_rwx_i(), snprintf, strdup(), unparse_inheritance(), ut64(), xnu_dbg_modules(), xnu_map_free(), and xwrz_testwx.
Definition at line 1097 of file xnu_debug.c.
References addr, calloc(), count, dbg, DYLD_IMAGE_INFO_32_SIZE, DYLD_IMAGE_INFO_64_SIZE, eprintf, free(), i, info(), DyldAllImageInfos32::info_array, DyldAllImageInfos64::info_array, DyldAllImageInfos32::info_array_count, DyldAllImageInfos64::info_array_count, rz_io_bind_t::io, rz_debug_t::iob, list(), mach0_size(), memset(), mr(), NULL, pid_to_task(), rz_io_bind_t::read_at, RZ_ABS, rz_debug_map_new(), rz_list_append(), rz_list_free(), rz_list_newf(), strdup(), rz_debug_t::tid, ut64(), and xnu_map_free().
Referenced by xnu_dbg_maps().
Definition at line 644 of file xnu_debug.c.
References LOG_MACH_ERROR, _xnu_thread::port, task_dbg, and threads.
Referenced by xnu_generate_corefile().
Definition at line 160 of file xnu_debug.c.
References dbg, eprintf, NULL, pid, PT_DETACH, r, rz_list_free(), task_dbg, rz_debug_t::threads, and xnu_restore_exception_ports().
Definition at line 827 of file xnu_debug.c.
References calloc(), cleanup(), COMMAND_SIZE, count, dbg, dest, eprintf, error(), tir_t::flavors, free(), get_mach_header_sizes(), tir_t::header, header, tir_t::hoffset, i, rz_debug_t::maps, MAX_TSTATE_FLAVORS, memcpy(), NULL, rz_debug_t::pid, pid_to_task(), _xnu_thread::port, rz_buf_append_buf(), rz_buf_append_bytes(), rz_buf_free(), rz_buf_new_with_bytes(), rz_list_free(), rz_list_length(), rz_list_new(), tir_t::tstate_size, xnu_build_corefile_header(), xnu_collect_thread_state(), xnu_dealloc_threads(), xnu_get_vmmap_entries_for_pid(), xnu_thread_list(), and xnu_write_mem_maps_to_buffer().
|
static |
Definition at line 610 of file xnu_debug.c.
References NULL.
Referenced by xnu_build_corefile_header().
|
static |
Definition at line 590 of file xnu_debug.c.
References cpu_type, len, NULL, and pid.
Referenced by xnu_build_corefile_header().
Definition at line 381 of file xnu_debug.c.
References len, NULL, and pid.
Referenced by xnu_info().
RzDebugPid* xnu_get_pid | ( | int | pid | ) |
Definition at line 907 of file xnu_debug.c.
References EINVAL, eprintf, foo, free(), malloc(), memcpy(), cmd_descs_generate::nargs, NULL, pid, rz_debug_pid_new(), and uidFromPid().
|
static |
Definition at line 772 of file xnu_debug.c.
References count.
Referenced by xnu_collect_thread_state().
Definition at line 538 of file xnu_debug.c.
References count, info(), n, pid, and pid_to_task().
Referenced by xnu_generate_corefile().
RzDebugInfo* xnu_info | ( | RzDebug * | dbg, |
const char * | arg | ||
) |
Definition at line 397 of file xnu_debug.c.
References dbg, eprintf, NULL, rz_debug_t::pid, proc, rdi, RZ_DBG_PROC_RUN, RZ_DBG_PROC_SLEEP, RZ_DBG_PROC_STOP, RZ_NEW0, strdup(), rz_debug_t::tid, and xnu_get_kinfo_proc().
RzDebugMap* xnu_map_alloc | ( | RzDebug * | dbg, |
ut64 | addr, | ||
int | size | ||
) |
Definition at line 346 of file xnu_debug.c.
References addr, dbg, DEBUG_MAP_TAG_ID, eprintf, NULL, _xnu_thread::port, rz_debug_map_get(), rz_debug_map_sync(), rz_xnu_get_thread(), rz_debug_t::tid, and ut64().
Definition at line 368 of file xnu_debug.c.
References addr, dbg, LOG_MACH_ERROR, _xnu_thread::port, rz_xnu_get_thread(), and rz_debug_t::tid.
|
static |
Definition at line 1089 of file xnu_debug.c.
Referenced by xnu_dbg_maps(), and xnu_dbg_modules().
Definition at line 486 of file xnu_debug.c.
References addr, dbg, LOG_MACH_ERROR, pid_to_task(), rz_debug_t::tid, and xwrz_testwx.
char* xnu_reg_profile | ( | RzDebug * | dbg | ) |
Definition at line 252 of file xnu_debug.c.
References rz_debug_t::bits, dbg, eprintf, NULL, RZ_SYS_BITS_32, and RZ_SYS_BITS_64.
Definition at line 315 of file xnu_debug.c.
References dbg, memcpy(), RZ_MIN, RZ_REG_TYPE_DRX, RZ_REG_TYPE_FLG, RZ_REG_TYPE_GPR, RZ_REG_TYPE_SEG, rz_xnu_get_cur_thread(), rz_xnu_get_thread(), rz_xnu_thread_get_drx(), rz_xnu_thread_get_gpr(), _xnu_thread::state, _xnu_thread::state_size, and type.
Definition at line 279 of file xnu_debug.c.
References rz_debug_t::bits, dbg, _xnu_thread::gpr, memcpy(), RZ_MIN, RZ_REG_TYPE_DRX, RZ_SYS_BITS_64, rz_xnu_get_cur_thread(), rz_xnu_get_thread(), rz_xnu_thread_set_drx(), rz_xnu_thread_set_gpr(), and type.
Definition at line 112 of file xnu_debug.c.
References dbg, eprintf, rz_debug_t::pid, pid_to_task(), rz_xnu_get_cur_thread(), rz_xnu_get_thread(), _xnu_thread::stepping, rz_debug_t::tid, and xnu_set_trace_bit().
Definition at line 194 of file xnu_debug.c.
References eprintf, pid, pid_to_task(), and task_suspend_count().
Referenced by xnu_attach().
Definition at line 453 of file xnu_debug.c.
References dbg, eprintf, _xnu_thread::gpr, list(), memcpy(), _xnu_thread::name, _xnu_thread::port, rz_debug_pid_free(), rz_debug_pid_new(), rz_list_append(), rz_xnu_thread_get_gpr(), rz_xnu_update_thread_list(), _xnu_thread::state_size, and rz_debug_t::threads.
Referenced by xnu_generate_corefile().
Definition at line 108 of file xnu_debug.c.
References dbg, pid, and xnu_wait_for_exception().
|
static |
Definition at line 668 of file xnu_debug.c.
References rz_debug_map_t::addr, rz_debug_map_t::addr_end, CAST_DOWN, cleanup(), segment_command_64::cmd, segment_command_64::cmdsize, eprintf, error(), FALSE, header, segment_command_64::initprot, INT_MAX, LC_SEGMENT, LC_SEGMENT_64, segment_command::maxprot, segment_command_64::maxprot, segment_command_64::nsects, rz_debug_map_t::perm, PFMT64d, PFMT64x, rz_buf_append_bytes(), sc, segment_command_64::segname, rz_debug_map_t::size, task_dbg, rz_debug_map_t::user, ut64(), VM_PROT_READ, segment_command_64::vmaddr, segment_command_64::vmsize, and xwrz_testwx.
Referenced by xnu_generate_corefile().
|
static |
Definition at line 18 of file xnu_debug.c.
Referenced by pid_to_task(), xnu_dealloc_threads(), xnu_detach(), and xnu_write_mem_maps_to_buffer().