Skip to content

Commit

Permalink
exception: Move RVA + module printing into a separate function.
Browse files Browse the repository at this point in the history
  • Loading branch information
nmlgc committed Aug 27, 2017
1 parent e1218ac commit f41d2e0
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions thcrap/src/exception.cpp
Expand Up @@ -9,7 +9,7 @@

#include "thcrap.h"

void log_context_dump(PCONTEXT ctx)
void log_print_context(PCONTEXT ctx)
{
if(!ctx) {
return;
Expand All @@ -23,6 +23,24 @@ void log_context_dump(PCONTEXT ctx)
);
}

void log_print_rva_and_module(HMODULE mod, void *addr)
{
if(!mod) {
return;
}
size_t crash_fn_len = GetModuleFileNameU(mod, NULL, 0) + 1;
VLA(char, crash_fn, crash_fn_len);
if(GetModuleFileNameU(mod, crash_fn, crash_fn_len)) {
log_printf(
" (Rx%x) (%s)",
(uint8_t *)addr - (uint8_t *)mod,
PathFindFileNameA(crash_fn)
);
}
VLA_FREE(crash_fn);
log_print("\n");
}

LONG WINAPI exception_filter(LPEXCEPTION_POINTERS lpEI)
{
LPEXCEPTION_RECORD lpER = lpEI->ExceptionRecord;
Expand All @@ -34,20 +52,8 @@ LONG WINAPI exception_filter(LPEXCEPTION_POINTERS lpEI)
"Exception %x at 0x%p",
lpER->ExceptionCode, lpER->ExceptionAddress
);
if(crash_mod) {
size_t crash_fn_len = GetModuleFileNameU(crash_mod, NULL, 0) + 1;
VLA(char, crash_fn, crash_fn_len);
if(GetModuleFileNameU(crash_mod, crash_fn, crash_fn_len)) {
log_printf(
" (Rx%x) (%s)",
(uint8_t *)lpER->ExceptionAddress - (uint8_t *)crash_mod,
PathFindFileNameA(crash_fn)
);
}
VLA_FREE(crash_fn);
}
log_printf("\n");
log_context_dump(lpEI->ContextRecord);
log_print_rva_and_module(crash_mod, lpER->ExceptionAddress);
log_print_context(lpEI->ContextRecord);
log_printf(
"===\n"
"\n"
Expand Down

0 comments on commit f41d2e0

Please sign in to comment.