-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathcrash_filter.cpp
66 lines (56 loc) · 1.66 KB
/
crash_filter.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include "syslib.h"
#include "srvmgr.h"
int exc = 0;
char awarn[]="Warning: recursive exception, characters unsaved!\n";
char asavi[]="Saving characters...\n";
void _declspec(naked) exc_handler(void)
{
__asm
{ //6081F0
push offset asavi
call log_format
call upd_all
retn
}
}
bool exception_already = false;
bool exception_secondary = false;
DWORD exc_handler_run(struct _EXCEPTION_POINTERS *info)
{
__try
{
// dump info
log_format("EXCEPTION DUMP:\neax=%08Xh,ebx=%08Xh,ecx=%08Xh,edx=%08Xh,\nesp=%08Xh,ebp=%08Xh,esi=%08Xh,edi=%08Xh;\neip=%08Xh;\naddr=%08Xh,code=%08Xh,flags=%08Xh\n",
info->ContextRecord->Eax,
info->ContextRecord->Ebx,
info->ContextRecord->Ecx,
info->ContextRecord->Edx,
info->ContextRecord->Esp,
info->ContextRecord->Ebp,
info->ContextRecord->Esi,
info->ContextRecord->Edi,
info->ContextRecord->Eip,
info->ExceptionRecord->ExceptionAddress,
info->ExceptionRecord->ExceptionCode,
info->ExceptionRecord->ExceptionFlags);
log_format("BEGIN STACK TRACE: 0x%08Xh <= ", info->ExceptionRecord->ExceptionAddress);
unsigned long stebp = *(unsigned long*)(info->ContextRecord->Ebp);
while(true)
{
bool bad_ebp = false;
if(stebp & 3) bad_ebp = true;
if(!bad_ebp && IsBadReadPtr((void*)stebp, 8)) bad_ebp = true;
if(bad_ebp) /* ? */ break;
log_format2("%08Xh <= ", *(unsigned long*)(stebp+4));
stebp = *(unsigned long*)(stebp); // o_O
}
log_format2("END STACK TRACE\n");
ExitProcess(1);
}
__except(EXCEPTION_EXECUTE_HANDLER) { /* empty */ }
return EXCEPTION_EXECUTE_HANDLER;
}
void SetExceptionFilter()
{
SetUnhandledExceptionFilter((LPTOP_LEVEL_EXCEPTION_FILTER)&exc_handler_run);
}