From bf05bd32769d10450473e769c470d384f0ae6485 Mon Sep 17 00:00:00 2001 From: midipix Date: Mon, 27 May 2019 23:10:05 +0000 Subject: debug helpers: __ntapi_tt_debug_execution_flow(): initial implementation. --- src/debug/ntapi_tt_debug_execution_flow.c | 95 +++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 src/debug/ntapi_tt_debug_execution_flow.c (limited to 'src/debug') diff --git a/src/debug/ntapi_tt_debug_execution_flow.c b/src/debug/ntapi_tt_debug_execution_flow.c new file mode 100644 index 0000000..5bf4e6c --- /dev/null +++ b/src/debug/ntapi_tt_debug_execution_flow.c @@ -0,0 +1,95 @@ +#include +#include +#include +#include +#include +#include +#include "ntapi_impl.h" + +static int32_t __log_exception_to_server( + nt_dbg_wait_state_change * dbgstate, + void * hserver) +{ + int32_t status; + nt_tty_log_msg msg; + + if (!hserver) + return NT_STATUS_SUCCESS; + + __ntapi->tt_aligned_block_memset( + &msg,0,sizeof(msg)); + + msg.header.msg_type = NT_LPC_NEW_MESSAGE; + msg.header.data_size = sizeof(msg.data); + msg.header.msg_size = sizeof(msg); + msg.data.ttyinfo.opcode = NT_TTY_LOG_ENTRY; + msg.data.loginfo.type = NT_TTY_LOG_INFO_EXCEPTION_RECORD; + msg.data.loginfo.reserved = 0; + msg.data.loginfo.cid.process_id = dbgstate->cid.process_id; + msg.data.loginfo.cid.thread_id = dbgstate->cid.thread_id; + + __ntapi->tt_generic_memcpy( + &msg.data.loginfo.data, + &dbgstate->_u.exception_info.exception_record, + sizeof(nt_exception_record)); + + if ((status = __ntapi->zw_request_wait_reply_port(hserver,&msg,&msg))) + return status; + else if (msg.data.ttyinfo.status) + return msg.data.ttyinfo.status; + + return NT_STATUS_SUCCESS; +} + +int32_t __stdcall __ntapi_tt_debug_execution_flow( + __in void * hdbgobj, + __in void * hserver, + __in void * hlogfile, + __in uint32_t evtmask, + __in uint64_t * nevents) +{ + int32_t status; + int32_t response; + int floop; + uint64_t nevts; + uint64_t necap; + nt_dbg_wait_state_change dbgstate; + + (void)hlogfile; + + necap = (nevents && *nevents) ? *nevents : (uint64_t)(-1); + + for (nevts=0, floop=1; floop && (nevts < necap); nevts++) { + if ((status = __ntapi->zw_wait_for_debug_event( + hdbgobj, + NT_SYNC_NON_ALERTABLE, + 0,&dbgstate))) + return status; + + switch (dbgstate.state) { + case NT_DBG_STATE_EXCEPTION: + if (evtmask & NT_DBG_FLOW_MASK_EXCEPTION) { + __log_exception_to_server(&dbgstate,hserver); + } + + response = NT_DBG_EXCEPTION_NOT_HANDLED; + break; + + case NT_DBG_STATE_EXIT_PROCESS: + response = NT_DBG_CONTINUE; + floop = 0; + break; + + default: + response = NT_DBG_CONTINUE; + break; + } + + __ntapi->zw_debug_continue( + hdbgobj, + &dbgstate.cid, + response); + } + + return NT_STATUS_SUCCESS; +} -- cgit v1.2.3