crashinjectdll.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. #include <stdio.h>
  5. #include <windows.h>
  6. // make sure we only ever spawn one thread
  7. DWORD tid = -1;
  8. DWORD WINAPI CrashingThread(
  9. LPVOID lpParameter
  10. )
  11. {
  12. // not a very friendly DLL
  13. volatile int* x = (int *)0x0;
  14. *x = 1;
  15. return 0;
  16. }
  17. BOOL WINAPI DllMain(
  18. HANDLE hinstDLL,
  19. DWORD dwReason,
  20. LPVOID lpvReserved
  21. )
  22. {
  23. if (tid == -1)
  24. // we have to crash on another thread because LoadLibrary() will
  25. // catch memory access errors and return failure to the calling process
  26. CreateThread(
  27. nullptr, // default security attributes
  28. 0, // use default stack size
  29. CrashingThread, // thread function name
  30. nullptr, // argument to thread function
  31. 0, // use default creation flags
  32. &tid); // returns the thread identifier
  33. return TRUE;
  34. }