Rizin
unix-like reverse engineering framework and cli tools
|
#include <stdio.h>
#include <stdarg.h>
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include <rz_util.h>
#include <rz_cons.h>
#include <rz_list.h>
#include <rz_debug.h>
#include "transport.h"
#include "winkd.h"
#include "kd.h"
#include "profiles.h"
Go to the source code of this file.
Macros | |
#define | O_FLAG_XPVAD 1 |
#define | O_(n) ctx->profile->f[n] |
#define | KOBJECT_PROCESS 3 |
#define | KOBJECT_THREAD 6 |
#define | PKT_REQ(p) ((kd_req_t *)(((kd_packet_t *)p)->data)) |
#define | PKT_STC(p) ((kd_stc_64 *)(((kd_packet_t *)p)->data)) |
#define | PKT_IO(p) ((kd_ioc_t *)(((kd_packet_t *)p)->data)) |
#define | PTE_VALID 0x0001 |
#define | PTE_LARGEPAGE 0x0080 |
#define | PTE_PROTOTYPE 0x0400 |
#define | ARM_DESCRIPTOR 0x0002 |
|
static |
Definition at line 225 of file winkd.c.
References error(), KD_E_OK, KD_PACKET_TYPE_ACKNOWLEDGE, KD_PACKET_TYPE_FILE_IO, KD_RET_ENOENT, kd_send_data_packet(), NULL, PKT_IO, kd_ioc_t::req, kd_ioc_t::ret, RZ_LOG_DEBUG, winkd_lock_enter(), winkd_lock_leave(), and winkd_wait_packet().
Referenced by winkd_wait_packet().
|
inlinestatic |
Definition at line 850 of file winkd.c.
References ARM_DESCRIPTOR, and PTE_LARGEPAGE.
Referenced by winkd_va_to_pa().
|
inlinestatic |
Definition at line 252 of file winkd.c.
References PKT_STC, and rz_offsetof.
Referenced by winkd_wait_packet().
Definition at line 604 of file winkd.c.
References rz_debug_map_t::addr.
Referenced by winkd_list_modules().
|
static |
Definition at line 1344 of file winkd.c.
References count, free(), KD_MAX_PAYLOAD, memcpy(), NULL, PKT_REQ, req, RZ_MIN, type, and winkd_send_state_manipulate_req().
Referenced by winkd_read_at(), and winkd_read_at_phys().
|
static |
Definition at line 617 of file winkd.c.
References count, is_target_kernel(), and winkd_read_at_uva().
Referenced by winkd_list_modules().
int winkd_bkpt | ( | RZ_BORROW RZ_NONNULL KdCtx * | ctx, |
const ut64 | addr, | ||
const int | set, | ||
const int | hw, | ||
RZ_BORROW RZ_NONNULL int * | handle | ||
) |
Definition at line 1312 of file winkd.c.
References addr, DbgKdRestoreBreakPointApi, DbgKdWriteBreakPointApi, free(), handle, NULL, PKT_REQ, req, and winkd_send_state_manipulate_req().
Referenced by rz_debug_winkd_breakpoint().
void winkd_break | ( | void * | arg | ) |
Definition at line 1442 of file winkd.c.
References iob_write().
Referenced by winkd_lock_enter().
int winkd_continue | ( | RZ_BORROW RZ_NONNULL KdCtx * | ctx, |
bool | handled | ||
) |
Definition at line 1141 of file winkd.c.
References DbgKdContinueApi, KD_E_MALFORMED, KD_E_OK, KD_E_TIMEOUT, KD_PACKET_TYPE_ACKNOWLEDGE, KD_PACKET_TYPE_STATE_MANIPULATE, kd_send_data_packet(), NULL, req, rz_list_free(), winkd_lock_enter(), winkd_lock_leave(), and winkd_wait_packet().
Referenced by rz_debug_winkd_continue().
int winkd_get_bits | ( | RZ_BORROW RZ_NONNULL WindCtx * | ctx | ) |
Definition at line 80 of file winkd.c.
References RZ_SYS_BITS_32, and RZ_SYS_BITS_64.
Referenced by rz_debug_winkd_attach().
int winkd_get_cpu | ( | RZ_BORROW RZ_NONNULL KdCtx * | ctx | ) |
int winkd_get_cpus | ( | RZ_BORROW RZ_NONNULL KdCtx * | ctx | ) |
WindProc* winkd_get_process_at | ( | RZ_BORROW RZ_NONNULL WindCtx * | ctx, |
ut64 | address | ||
) |
Definition at line 488 of file winkd.c.
References E_ImageFileName, E_Peb, E_UniqueProcessId, E_VadRoot, K_DirectoryTableBase, KOBJECT_PROCESS, Proc::name, NULL, O_, PFMT64x, proc, RZ_LOG_WARN, RZ_NEW0, type, and winkd_read_ptr_at().
Referenced by get_current_process_and_thread(), rz_debug_dmp_attach(), rz_debug_dmp_init(), and winkd_list_process().
Definition at line 58 of file winkd.c.
References bits(), build(), i, NULL, p, p_table, RZ_NEW0, and sp.
Referenced by rz_debug_dmp_init(), and winkd_read_ver().
int winkd_get_sp | ( | RZ_BORROW RZ_NONNULL WindCtx * | ctx | ) |
Definition at line 40 of file winkd.c.
References K_CmNtCSDVersion, PFMT64x, RZ_LOG_DEBUG, ut64(), and UT64_MAX.
Referenced by rz_debug_dmp_init(), and winkd_read_ver().
ut32 winkd_get_target | ( | RZ_BORROW RZ_NONNULL WindCtx * | ctx | ) |
ut64 winkd_get_target_base | ( | RZ_BORROW RZ_NONNULL WindCtx * | ctx | ) |
Definition at line 166 of file winkd.c.
References O_, P_ImageBaseAddress, ut64(), and winkd_read_at_uva().
Referenced by rz_debug_winkd_select().
ut32 winkd_get_target_thread | ( | RZ_BORROW RZ_NONNULL WindCtx * | ctx | ) |
Definition at line 162 of file winkd.c.
Referenced by rz_debug_winkd_select().
WindThread* winkd_get_thread_at | ( | RZ_BORROW RZ_NONNULL WindCtx * | ctx, |
ut64 | address | ||
) |
Definition at line 739 of file winkd.c.
References C_UniqueThread, calloc(), WindThread::entrypoint, ET_Cid, ET_Win32StartAddress, WindThread::ethread, KOBJECT_THREAD, NULL, O_, PFMT64x, WindThread::runnable, RZ_LOG_WARN, WindThread::status, type, WindThread::uniqueid, and ut64().
Referenced by get_current_process_and_thread(), rz_debug_dmp_attach(), rz_debug_dmp_init(), and winkd_list_threads().
Definition at line 187 of file winkd.c.
References desc, free(), RZ_FREE, rz_list_free(), rz_th_lock_free(), and winkd_ctx_fini().
Referenced by __close().
KdCtx* winkd_kdctx_new | ( | RZ_BORROW RZ_NONNULL io_desc_t * | desc | ) |
Definition at line 177 of file winkd.c.
References desc, NULL, RZ_NEW0, and rz_th_lock_new().
Referenced by __open().
RzList* winkd_list_maps | ( | RZ_BORROW RZ_NONNULL WindCtx * | ctx | ) |
Definition at line 476 of file winkd.c.
References free(), maps(), NULL, rz_list_newf(), UT64_MAX, and winkd_walk_vadtree().
Referenced by rz_debug_dmp_maps(), and rz_debug_winkd_maps().
RzList* winkd_list_modules | ( | RZ_BORROW RZ_NONNULL WindCtx * | ctx | ) |
Definition at line 625 of file winkd.c.
References calloc(), free(), is_target_kernel(), length, map_comparator(), mod(), NULL, PFMT64x, read_at_uva_or_kernel(), rz_list_add_sorted(), rz_list_free(), rz_list_join(), rz_list_newf(), RZ_LOG_DEBUG, RZ_LOG_ERROR, RZ_LOG_WARN, RZ_NEW0, rz_str_utf16_to_utf8(), ut64(), UT64_MAX, winkd_read_at_uva(), and winkd_windmodule_free().
Referenced by dmp_get_modules(), rz_debug_dmp_init(), and rz_debug_winkd_modules().
RzList* winkd_list_process | ( | RZ_BORROW RZ_NONNULL WindCtx * | ctx | ) |
Definition at line 513 of file winkd.c.
References E_ActiveProcessLinks, free(), K_PsActiveProcessHead, NULL, O_, PFMT64x, proc, rz_list_append(), rz_list_newf(), RZ_LOG_ERROR, RZ_LOG_WARN, ut64(), UT64_MAX, winkd_get_process_at(), and winkd_read_ptr_at().
Referenced by rz_debug_dmp_pids(), rz_debug_winkd_pids(), and winkd_set_target().
RzList* winkd_list_threads | ( | RZ_BORROW RZ_NONNULL WindCtx * | ctx | ) |
Definition at line 782 of file winkd.c.
References E_ThreadListHead, ET_ThreadListEntry, WindThread::ethread, free(), NULL, O_, PFMT64x, rz_list_append(), rz_list_newf(), RZ_LOG_ERROR, RZ_LOG_WARN, ut64(), UT64_MAX, and winkd_get_thread_at().
Referenced by rz_debug_dmp_threads(), rz_debug_winkd_threads(), and winkd_set_target().
bool winkd_lock_enter | ( | RZ_BORROW RZ_NONNULL KdCtx * | ctx | ) |
Definition at line 23 of file winkd.c.
References rz_cons_break_pop(), rz_cons_break_push(), rz_cons_is_breaked(), rz_th_lock_tryenter(), and winkd_break().
Referenced by do_io_reply(), rz_debug_winkd_wait(), winkd_continue(), winkd_send_state_manipulate_req(), and winkd_sync().
bool winkd_lock_leave | ( | RZ_BORROW RZ_NONNULL KdCtx * | ctx | ) |
Definition at line 34 of file winkd.c.
References rz_cons_break_pop(), and rz_th_lock_leave().
Referenced by do_io_reply(), rz_debug_winkd_wait(), winkd_continue(), winkd_send_state_manipulate_req(), and winkd_sync().
int winkd_op_at_uva | ( | RZ_BORROW RZ_NONNULL WindCtx * | ctx, |
ut64 | address, | ||
ut8 * | buf, | ||
int | count, | ||
bool | write | ||
) |
Definition at line 567 of file winkd.c.
References count, test_evm::end, PFMT64x, RZ_LOG_VERBOSE, RZ_MIN, ut64(), UT64_ADD_OVFCHK, winkd_va_to_pa(), and write.
Referenced by winkd_read_at_uva(), and winkd_write_at_uva().
int winkd_query_mem | ( | RZ_BORROW RZ_NONNULL KdCtx * | ctx, |
const ut64 | addr, | ||
int * | address_space, | ||
int * | flags | ||
) |
Definition at line 1276 of file winkd.c.
References addr, DbgKdQueryMemoryApi, flags, free(), NULL, PKT_REQ, req, and winkd_send_state_manipulate_req().
int winkd_read_at | ( | RZ_BORROW RZ_NONNULL KdCtx * | ctx, |
const ut64 | offset, | ||
RZ_BORROW RZ_NONNULL RZ_OUT ut8 * | buf, | ||
const int | count | ||
) |
Definition at line 1377 of file winkd.c.
References count, DbgKdReadVirtualMemoryApi, and read_at().
Referenced by __read(), read_at_kernel_virtual(), rz_debug_winkd_attach(), and winkd_read_ver().
int winkd_read_at_phys | ( | RZ_BORROW RZ_NONNULL KdCtx * | ctx, |
const ut64 | offset, | ||
RZ_BORROW RZ_NONNULL RZ_OUT ut8 * | buf, | ||
const int | count | ||
) |
Definition at line 1370 of file winkd.c.
References count, DbgKdReadPhysicalMemoryApi, and read_at().
Referenced by op_at_phys().
int winkd_read_at_uva | ( | RZ_BORROW RZ_NONNULL WindCtx * | ctx, |
ut64 | address, | ||
RZ_BORROW RZ_NONNULL RZ_OUT ut8 * | buf, | ||
int | count | ||
) |
Definition at line 596 of file winkd.c.
References count, and winkd_op_at_uva().
Referenced by __read(), dmp_read(), read_at_uva_or_kernel(), winkd_get_target_base(), and winkd_list_modules().
int winkd_read_reg | ( | RZ_BORROW RZ_NONNULL KdCtx * | ctx, |
RZ_BORROW RZ_NONNULL RZ_OUT ut8 * | buf, | ||
int | size | ||
) |
Definition at line 1231 of file winkd.c.
References DbgKdGetContextApi, free(), memcpy(), NULL, PKT_REQ, realloc(), req, RZ_MIN, autogen_x86imm::tmp, and winkd_send_state_manipulate_req().
Referenced by rz_debug_winkd_reg_read().
bool winkd_read_ver | ( | RZ_BORROW RZ_NONNULL KdCtx * | ctx | ) |
Definition at line 997 of file winkd.c.
References DBGKD_VERS_FLAG_DATA, DBGKD_VERS_FLAG_PTR64, free(), K_PaeEnabled, KD_MACH_AMD64, KD_MACH_I386, NULL, PFMT64x, PKT_REQ, req, RZ_LOG_DEBUG, RZ_LOG_ERROR, RZ_LOG_WARN, ut64(), winkd_get_profile(), winkd_get_sp(), winkd_read_at(), and winkd_send_state_manipulate_req().
Referenced by rz_debug_winkd_attach().
|
static |
Definition at line 940 of file winkd.c.
References buf_len, KD_E_MALFORMED, KD_E_OK, KD_PACKET_TYPE_ACKNOWLEDGE, KD_PACKET_TYPE_STATE_MANIPULATE, kd_send_data_packet(), NULL, PKT_REQ, req, rz_cons_is_breaked(), RZ_FREE, RZ_LOG_DEBUG, winkd_lock_enter(), winkd_lock_leave(), and winkd_wait_packet().
Referenced by read_at(), winkd_bkpt(), winkd_query_mem(), winkd_read_reg(), winkd_read_ver(), winkd_write_at(), winkd_write_at_phys(), and winkd_write_reg().
bool winkd_set_cpu | ( | RZ_BORROW RZ_NONNULL KdCtx * | ctx, |
int | cpu | ||
) |
Definition at line 106 of file winkd.c.
References found, p, pid, rz_list_first(), rz_list_free(), WindThread::uniqueid, winkd_list_process(), and winkd_list_threads().
Referenced by rz_debug_dmp_select(), and rz_debug_winkd_select().
int winkd_sync | ( | RZ_BORROW RZ_NONNULL KdCtx * | ctx | ) |
Definition at line 1065 of file winkd.c.
References test_evm::end, free(), iob_write(), KD_E_IOERR, KD_E_OK, KD_INITIAL_PACKET_ID, KD_IO_NET, KD_IO_PIPE, KD_PACKET_TYPE_RESET, KD_PACKET_TYPE_STATE_CHANGE64, kd_read_packet(), kd_send_ctrl_packet(), NULL, PKT_STC, rz_list_free(), RZ_LOG_INFO, s, winkd_lock_enter(), winkd_lock_leave(), and winkd_wait_packet().
Referenced by rz_debug_winkd_attach().
bool winkd_va_to_pa | ( | RZ_BORROW RZ_NONNULL WindCtx * | ctx, |
ut64 | directory_table, | ||
ut64 | va, | ||
RZ_BORROW RZ_NONNULL RZ_OUT ut64 * | pa | ||
) |
Definition at line 860 of file winkd.c.
References is_page_large(), mask, PTE_PROTOTYPE, PTE_VALID, RZ_LOG_ERROR, autogen_x86imm::tmp, and ut64().
Referenced by winkd_op_at_uva().
int winkd_wait_packet | ( | RZ_BORROW RZ_NONNULL KdCtx * | ctx, |
const ut32 | type, | ||
RZ_NULLABLE RZ_OUT kd_packet_t ** | p | ||
) |
Definition at line 258 of file winkd.c.
References cpu, DbgKdCommandStringStateChange, DbgKdExceptionStateChange, DbgKdLoadSymbolsStateChange, do_io_reply(), free(), KD_E_BREAK, KD_E_MALFORMED, KD_E_OK, KD_INITIAL_PACKET_ID, KD_PACKET_CTRL, KD_PACKET_DATA, KD_PACKET_TYPE_ACKNOWLEDGE, KD_PACKET_TYPE_FILE_IO, KD_PACKET_TYPE_RESEND, KD_PACKET_TYPE_RESET, KD_PACKET_TYPE_STATE_CHANGE64, KD_PACKET_TYPE_STATE_MANIPULATE, KD_PACKET_TYPE_UNUSED, kd_read_packet(), load_symbol_path_is_valid(), NULL, p, path, PFMT32x, PFMT64x, PKT_IO, PKT_REQ, PKT_STC, req, RZ_LOG_DEBUG, RZ_LOG_VERBOSE, RZ_LOG_WARN, rz_str_endswith(), rz_sys_backtrace(), strdup(), and type.
Referenced by do_io_reply(), rz_debug_winkd_wait(), winkd_continue(), winkd_send_state_manipulate_req(), and winkd_sync().
void winkd_walk_vadtree | ( | RZ_BORROW RZ_NONNULL WindCtx * | ctx, |
ut64 | address, | ||
ut64 | parent, | ||
RzList * | out | ||
) |
Definition at line 390 of file winkd.c.
References test_evm::end, map(), out, rz_list_append(), RZ_LOG_DEBUG, RZ_NEW0, RZ_PERM_RWX, rz_read_le32(), start, ut64(), UT64_MAX, and winkd_read_ptr_at().
Referenced by winkd_list_maps().
void winkd_windmodule_free | ( | void * | ptr | ) |
Definition at line 611 of file winkd.c.
Referenced by dmp_get_modules(), and winkd_list_modules().
int winkd_write_at | ( | RZ_BORROW RZ_NONNULL KdCtx * | ctx, |
const ut64 | offset, | ||
RZ_BORROW RZ_NONNULL RZ_IN const ut8 * | buf, | ||
const int | count | ||
) |
Definition at line 1384 of file winkd.c.
References count, DbgKdWriteVirtualMemoryApi, free(), KD_MAX_PAYLOAD, NULL, PKT_REQ, req, RZ_MIN, and winkd_send_state_manipulate_req().
Referenced by __write().
int winkd_write_at_phys | ( | RZ_BORROW RZ_NONNULL KdCtx * | ctx, |
const ut64 | offset, | ||
RZ_BORROW RZ_NONNULL RZ_IN const ut8 * | buf, | ||
const int | count | ||
) |
Definition at line 1408 of file winkd.c.
References count, DbgKdWritePhysicalMemoryApi, free(), KD_MAX_PAYLOAD, memset(), PKT_REQ, req, RZ_MIN, and winkd_send_state_manipulate_req().
Referenced by op_at_phys().
int winkd_write_at_uva | ( | RZ_BORROW RZ_NONNULL WindCtx * | ctx, |
ut64 | address, | ||
RZ_BORROW RZ_NONNULL RZ_IN const ut8 * | buf, | ||
int | count | ||
) |
Definition at line 600 of file winkd.c.
References count, and winkd_op_at_uva().
Referenced by __write(), and dmp_write().
bool winkd_write_reg | ( | RZ_BORROW RZ_NONNULL KdCtx * | ctx, |
ut32 | flags, | ||
RZ_BORROW RZ_NONNULL RZ_IN const ut8 * | buf, | ||
int | size | ||
) |
Definition at line 1179 of file winkd.c.
References DbgKdSetContextApi, DbgKdSetContextEx, flags, free(), KD_MAX_PAYLOAD, malloc(), memcpy(), NULL, PKT_REQ, req, RZ_FREE, RZ_LOG_DEBUG, RZ_MIN, ut64(), and winkd_send_state_manipulate_req().
Referenced by rz_debug_winkd_reg_write().