Back to index

enigmail  1.4.3
crashinjectdll.cpp
Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <windows.h>
00003 
00004 // make sure we only ever spawn one thread
00005 DWORD tid = -1;
00006 
00007 DWORD WINAPI CrashingThread(
00008   LPVOID lpParameter
00009 )
00010 {
00011   // not a very friendly DLL
00012   volatile int* x = (int *)0x0;
00013   *x = 1;
00014   return 0;
00015 }
00016 
00017 BOOL WINAPI DllMain(
00018   HANDLE hinstDLL,
00019   DWORD dwReason,
00020   LPVOID lpvReserved
00021 )
00022 {
00023   if (tid == -1)
00024     // we have to crash on another thread because LoadLibrary() will
00025     // catch memory access errors and return failure to the calling process
00026     CreateThread(
00027                  NULL,                   // default security attributes
00028                  0,                      // use default stack size
00029                  CrashingThread  ,       // thread function name
00030                  NULL,                   // argument to thread function
00031                  0,                      // use default creation flags
00032                  &tid);                  // returns the thread identifier
00033   return TRUE;
00034 }