Skip to content

Commit

Permalink
further refine the exception handler
Browse files Browse the repository at this point in the history
  • Loading branch information
tomysshadow committed Jul 17, 2022
1 parent 58bf659 commit a372d9f
Show file tree
Hide file tree
Showing 21 changed files with 18 additions and 13 deletions.
Binary file modified Debug/FlashpointProxy.dll
Binary file not shown.
Binary file modified Debug/FlashpointProxy.ilk
Binary file not shown.
Binary file modified Debug/FlashpointProxy.pdb
Binary file not shown.
4 changes: 2 additions & 2 deletions FlashpointProxy/Debug/FlashpointProxy.log
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
main.cpp
shared.cpp
Generating Code...
c:\users\anthony\documents\visual studio 2017\projects\flashpointproxy\flashpointproxy\shared.cpp(89): warning C4733: Inline asm assigning to 'FS:0': handler not registered as safe handler
c:\users\anthony\documents\visual studio 2017\projects\flashpointproxy\flashpointproxy\shared.cpp(98): warning C4733: Inline asm assigning to 'FS:0': handler not registered as safe handler
c:\users\anthony\documents\visual studio 2017\projects\flashpointproxy\flashpointproxy\shared.cpp(94): warning C4733: Inline asm assigning to 'FS:0': handler not registered as safe handler
c:\users\anthony\documents\visual studio 2017\projects\flashpointproxy\flashpointproxy\shared.cpp(103): warning C4733: Inline asm assigning to 'FS:0': handler not registered as safe handler
FlashpointProxy.obj : warning LNK4075: ignoring '/EDITANDCONTINUE' due to '/SAFESEH' specification
Creating library C:\Users\Anthony\Documents\Visual Studio 2017\Projects\FlashpointProxy\Debug\FlashpointProxy.lib and object C:\Users\Anthony\Documents\Visual Studio 2017\Projects\FlashpointProxy\Debug\FlashpointProxy.exp
FlashpointProxy.vcxproj -> C:\Users\Anthony\Documents\Visual Studio 2017\Projects\FlashpointProxy\Debug\FlashpointProxy.dll
Binary file modified FlashpointProxy/Debug/FlashpointProxy.obj
Binary file not shown.
Binary file modified FlashpointProxy/Debug/main.obj
Binary file not shown.
Binary file modified FlashpointProxy/Debug/safeseh.obj
Binary file not shown.
Binary file modified FlashpointProxy/Debug/shared.obj
Binary file not shown.
Binary file modified FlashpointProxy/Debug/vc141.idb
Binary file not shown.
Binary file modified FlashpointProxy/Debug/vc141.pdb
Binary file not shown.
8 changes: 4 additions & 4 deletions FlashpointProxy/Release/FlashpointProxy.log
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
shared.cpp
Creating library C:\Users\Anthony\Documents\Visual Studio 2017\Projects\FlashpointProxy\Release\FlashpointProxy.lib and object C:\Users\Anthony\Documents\Visual Studio 2017\Projects\FlashpointProxy\Release\FlashpointProxy.exp
Generating code
c:\users\anthony\documents\visual studio 2017\projects\flashpointproxy\flashpointproxy\shared.cpp(89): warning C4733: Inline asm assigning to 'FS:0': handler not registered as safe handler
c:\users\anthony\documents\visual studio 2017\projects\flashpointproxy\flashpointproxy\shared.cpp(98): warning C4733: Inline asm assigning to 'FS:0': handler not registered as safe handler
c:\users\anthony\documents\visual studio 2017\projects\flashpointproxy\flashpointproxy\shared.cpp(89): warning C4733: Inline asm assigning to 'FS:0': handler not registered as safe handler
c:\users\anthony\documents\visual studio 2017\projects\flashpointproxy\flashpointproxy\shared.cpp(98): warning C4733: Inline asm assigning to 'FS:0': handler not registered as safe handler
c:\users\anthony\documents\visual studio 2017\projects\flashpointproxy\flashpointproxy\shared.cpp(94): warning C4733: Inline asm assigning to 'FS:0': handler not registered as safe handler
c:\users\anthony\documents\visual studio 2017\projects\flashpointproxy\flashpointproxy\shared.cpp(103): warning C4733: Inline asm assigning to 'FS:0': handler not registered as safe handler
c:\users\anthony\documents\visual studio 2017\projects\flashpointproxy\flashpointproxy\shared.cpp(94): warning C4733: Inline asm assigning to 'FS:0': handler not registered as safe handler
c:\users\anthony\documents\visual studio 2017\projects\flashpointproxy\flashpointproxy\shared.cpp(103): warning C4733: Inline asm assigning to 'FS:0': handler not registered as safe handler
All 393 functions were compiled because no usable IPDB/IOBJ from previous compilation was found.
Finished generating code
FlashpointProxy.vcxproj -> C:\Users\Anthony\Documents\Visual Studio 2017\Projects\FlashpointProxy\Release\FlashpointProxy.dll
Binary file modified FlashpointProxy/Release/FlashpointProxy.obj
Binary file not shown.
Binary file modified FlashpointProxy/Release/main.obj
Binary file not shown.
Binary file modified FlashpointProxy/Release/safeseh.obj
Binary file not shown.
Binary file modified FlashpointProxy/Release/shared.obj
Binary file not shown.
Binary file modified FlashpointProxy/Release/vc141.pdb
Binary file not shown.
19 changes: 12 additions & 7 deletions FlashpointProxy/shared.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,20 @@ extern "C" EXCEPTION_DISPOSITION __cdecl _except_handler(struct _EXCEPTION_RECOR
return ExceptionContinueSearch;
}

if (!EstablisherFrame) {
return ExceptionContinueSearch;
}

DWORD record = *(PDWORD)EstablisherFrame;

// set the new thread context to the one passed in as an argument
*ContextRecord = *(PCONTEXT)ExceptionRecord->ExceptionInformation[0];

__asm {
// remove our EXCEPTION_REGISTRATION record
mov eax, [EstablisherFrame] // get establisher frame
mov eax, [eax] // get pointer to previous record
mov ecx, fs:[0] // get address of current handler
mov [ecx], eax // set pointer to previous record in the current handler
mov eax, record // address of previous record
mov ecx, fs:[0] // address of current record
mov [ecx], eax // set pointer to previous record at address of current record
}
return ExceptionContinueExecution;
}
Expand All @@ -76,16 +81,16 @@ void setCurrentThreadContext(CONTEXT &context) {
// intended Windows function for this purpose, 64-bit only :(
RtlRestoreContext(&context, NULL);
#else
ULONG_PTR setCurrentThreadContextArguments[SET_CURRENT_THREAD_CONTEXT_NUMBER_OF_ARGUMENTS] = { (ULONG_PTR)&context };

// use SEH to set the current thread's context
DWORD handler = (DWORD)_except_handler_safeseh;

// pass the new thread context as an argument
ULONG_PTR setCurrentThreadContextArguments[SET_CURRENT_THREAD_CONTEXT_NUMBER_OF_ARGUMENTS] = { (ULONG_PTR)&context };

__asm {
// build EXCEPTION_REGISTRATION record
push handler // address of handler function
push fs:[0] // address of previous handler
push fs:[0] // address of previous record
mov fs:[0], esp // install new EXCEPTION_REGISTRATION
}

Expand Down
Binary file modified Release/FlashpointProxy.dll
Binary file not shown.
Binary file modified Release/FlashpointProxy.iobj
Binary file not shown.
Binary file modified Release/FlashpointProxy.ipdb
Binary file not shown.
Binary file modified Release/FlashpointProxy.pdb
Binary file not shown.

0 comments on commit a372d9f

Please sign in to comment.