diff --git a/a_1authrowhook.asm b/a_1authrowhook.asm index f65f076..fb421c2 100644 --- a/a_1authrowhook.asm +++ b/a_1authrowhook.asm @@ -3,8 +3,8 @@ ; A/B/C:\... < ntstc_msvcrt's d:\os\obj\... PUBLIC _CxxThrowException -EXTERN _CxxThrowExceptionHook : proc -EXTERN CXX_THROW_REFERENCE : qword +EXTERN _SEHReport : proc +EXTERN gGxxThrowRefDll : qword .code @@ -15,16 +15,15 @@ _CxxThrowException PROC push RDX SUB RSP, 24 ; yo wtf, we have [0, -8], [-8, -8], [-16, -8] writes in our stack?! stdcall compiler optimizer conflicting with the reality that stdcall does not exist under x64? - MOV RAX, [_CxxThrowExceptionHook] + MOV RAX, [_SEHReport] CALL RAX - add rsp, 24 - pop RDX - pop RCX + ADD RSP, 24 + POP RDX + POP RCX - xor rax, rax + XOR RAX, RAX - jmp CXX_THROW_REFERENCE - ret + JMP gGxxThrowRefDll _CxxThrowException ENDP END \ No newline at end of file diff --git a/demo.cpp b/demo.cpp index 5ff217a..5bb48de 100644 --- a/demo.cpp +++ b/demo.cpp @@ -2,7 +2,7 @@ #include #include -extern "C" size_t CXX_THROW_REFERENCE = 0xDEADBEEF; +extern "C" size_t gGxxThrowRefDll = 0xDEADBEEF; static std::string kStringRawName = typeid(std::string).raw_name(); @@ -24,9 +24,10 @@ static bool IsReadable(const void *address) } #pragma warning(suppress : 4996) -static bool DoMagic(void *exception, const ThrowInfo *throwInfo, void *caller) +extern "C" void __stdcall _SEHReport(void *exception, const ThrowInfo *throwInfo, void *caller) { - if (!throwInfo) return false; + if (!throwInfo) return; + if (!exception) return; auto attribs = throwInfo->attributes; @@ -91,27 +92,15 @@ static bool DoMagic(void *exception, const ThrowInfo *throwInfo, void *caller) { std::cout << message << std::endl; } - - return true; -} - -extern "C" void __stdcall _CxxThrowExceptionHook( - void *pExceptionObject, - void * pThrowInfo, - void *caller -) -{ - DoMagic(pExceptionObject, (ThrowInfo *)pThrowInfo, caller); } int main() { - CXX_THROW_REFERENCE = (size_t)GetProcAddress(LoadLibraryW(L"ucrtbase.dll"), "_CxxThrowException"); + gGxxThrowRefDll = (size_t)GetProcAddress(LoadLibraryW(L"ucrtbase.dll"), "_CxxThrowException"); try { throw std::exception("hello"); std::cout << "cont?!!\n"; - } catch (...) {