yeputons

Untitled

Feb 5th, 2014
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <windows.h>
  3. #include <assert.h>
  4.  
  5. int main(int argc, char* argv[]) {
  6. if (argc != 2) {
  7. printf("Usage: textexe <executable-to-test>\n");
  8. return 1;
  9. }
  10.  
  11. STARTUPINFO sinf;
  12. PROCESS_INFORMATION pinf;
  13. memset(&sinf, 0, sizeof sinf);
  14. sinf.cb = sizeof(sinf);
  15.  
  16. printf("Trying to run '%s'...\n", argv[1]);
  17. if (!CreateProcess(argv[1], argv[1], NULL, NULL, FALSE, CREATE_SUSPENDED, NULL, NULL, &sinf, &pinf)) {
  18. DWORD error = GetLastError();
  19. printf("Got system error code %u\n", (int)error);
  20.  
  21. LPSTR msg;
  22. DWORD msg_len = FormatMessage(
  23. FORMAT_MESSAGE_ALLOCATE_BUFFER
  24. | FORMAT_MESSAGE_FROM_SYSTEM
  25. | FORMAT_MESSAGE_IGNORE_INSERTS,
  26. NULL,
  27. error,
  28. MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),
  29. (LPSTR)&msg,
  30. 32,
  31. NULL
  32. );
  33. if (!msg_len) {
  34. printf("Unable to get description (FormatMessage failed with error code %u)\n", (unsigned)GetLastError());
  35. } else {
  36. printf("%s\n", msg);
  37. LocalFree(msg);
  38. }
  39. return error;
  40. }
  41. TerminateProcess(pinf.hProcess, -1);
  42. WaitForSingleObject(pinf.hProcess, INFINITE);
  43. printf("Success\n");
  44. return 0;
  45. }
Add Comment
Please, Sign In to add comment