-
Notifications
You must be signed in to change notification settings - Fork 0
/
ExceptionThrow.cpp
59 lines (55 loc) · 2.86 KB
/
ExceptionThrow.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
#include "ExceptionThrow.h"
#include "LogObject.h"
#include "utils.h"
#include "Debugger.h"
#include <ehdata.h>
namespace cchips {
int CExceptionObject::m_reference_count = 0;
cchips::exception_throw g_exception_msg("this is sample");
LONG WINAPI CExceptionObject::VehHandler(struct _EXCEPTION_POINTERS *ep)
{
if (!ep) return EXCEPTION_CONTINUE_SEARCH;
if (!ep->ExceptionRecord) return EXCEPTION_CONTINUE_SEARCH;
//DWORD e_code = ep->ExceptionRecord->ExceptionCode;
//std::cout << "VehHandler e_code: " << std::hex << e_code << " addr: " << ep->ExceptionRecord->ExceptionAddress << std::endl;
if(IsCplusplusException(ep)) {
ClearThreadTls();
static ULONG_PTR* exception_vtbl = (reinterpret_cast<ULONG_PTR*>(*reinterpret_cast<ULONG_PTR*>(&g_exception_msg)));
std::exception* p = reinterpret_cast<std::exception*>(ep->ExceptionRecord->ExceptionInformation[1]);
ThrowInfo* throw_info = reinterpret_cast<ThrowInfo*>(ep->ExceptionRecord->ExceptionInformation[2]);
if (p && throw_info)
{
if(throw_info->pmfnUnwind)
{
ULONG_PTR* p_vtbl = (reinterpret_cast<ULONG_PTR*>(*reinterpret_cast<ULONG_PTR*>(p)));
if (p_vtbl && exception_vtbl && (*p_vtbl == *exception_vtbl))
{
std::string msg = p->what();
exception_throw* q = reinterpret_cast<exception_throw*>(p);
std::error_code err_code = q->GetErrCode();
int code = err_code.value();
const std::error_category& category = err_code.category();
std::string msg2 = category.message(code);
std::string name = category.name();
//{
// std::unique_ptr<CLogHandle> assert_handle = std::make_unique<CLogHandle>(ASSERT_FEATURE, CLogObject::logtype::log_exception, true);
// if (assert_handle) (*assert_handle).AddLog(LOGPAIR("exit process", p->what()));
//}
//DISABLE_LOG();
// waiting all log output and terminate self.
// waiting for 1 second.
//int count = 0;
//do {
// if (IS_LOGS_NULL()) break;
// std::this_thread::sleep_for(std::chrono::milliseconds(exception_sleep_wait_timeout));
// if ((count++) > exception_try_loop_count) break;
//} while (1);
return EXCEPTION_CONTINUE_EXECUTION;
}
}
}
check_return();
}
return GetDebugger().Dispatch(ep);
}
} // namespace cchips