Skip to content

Instantly share code, notes, and snippets.

@olliencc
Last active January 6, 2022 15:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save olliencc/a17bb1e3b5aea320e8b9c69526fd3bed to your computer and use it in GitHub Desktop.
Save olliencc/a17bb1e3b5aea320e8b9c69526fd3bed to your computer and use it in GitHub Desktop.
Toy code to demonstrate a malhandler
void InstallHandlers()
{
AddVectoredExceptionHandler(true, (PVECTORED_EXCEPTION_HANDLER)MyUnhandledExceptionFilter);
_tprintf(TEXT("[i] Registered exception handler %p\n"), &MyUnhandledExceptionFilter);
AddVectoredExceptionHandler(false, (PVECTORED_EXCEPTION_HANDLER)MyUnhandledExceptionFilter2);
_tprintf(TEXT("[i] Registered second exception handler %p\n"), &MyUnhandledExceptionFilter2);
// Register the third
AddVectoredExceptionHandler(false, (PVECTORED_EXCEPTION_HANDLER)MyUnhandledExceptionFilter3);
_tprintf(TEXT("[i] Registered third exception handler %p\n"), &MyUnhandledExceptionFilter3);
// Register the fourth
AddVectoredExceptionHandler(false, (PVECTORED_EXCEPTION_HANDLER)MyUnhandledExceptionFilter4);
_tprintf(TEXT("[i] Registered fourth exception handler %p\n"), &MyUnhandledExceptionFilter4);
// Register the fourth lots
AddVectoredExceptionHandler(false, (PVECTORED_EXCEPTION_HANDLER)MyUnhandledExceptionFilter4);
_tprintf(TEXT("[i] Registered fourth exception handler %p\n"), &MyUnhandledExceptionFilter4);
AddVectoredExceptionHandler(false, (PVECTORED_EXCEPTION_HANDLER)MyUnhandledExceptionFilter4);
_tprintf(TEXT("[i] Registered fourth exception handler %p\n"), &MyUnhandledExceptionFilter4);
AddVectoredExceptionHandler(false, (PVECTORED_EXCEPTION_HANDLER)MyUnhandledExceptionFilter4);
_tprintf(TEXT("[i] Registered fourth exception handler %p\n"), &MyUnhandledExceptionFilter4);
AddVectoredExceptionHandler(false, (PVECTORED_EXCEPTION_HANDLER)MyUnhandledExceptionFilter4);
_tprintf(TEXT("[i] Registered fourth exception handler %p\n"), &MyUnhandledExceptionFilter4);
LPVOID myMalHandler = NULL;
// Allocate some memory
myMalHandler = VirtualAlloc(NULL, 1000, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE);
AddVectoredExceptionHandler(false, (PVECTORED_EXCEPTION_HANDLER)myMalHandler);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment