Advertisement
Anders

system/crt/nt5

Nov 28th, 2011
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.73 KB | None | 0 0
  1. /*
  2. http://bayfiles.com/file/1dTh/ymkZXT/systembug.exe
  3.  
  4. C:\Documents and Settings\Anders\Local Settings\Temp\t5>call systembug
  5. main: argc=1 OS=5.1
  6. ModeA: starting self as child:"C:\Documents and Settings\Anders\Local Settings\T
  7. emp\t5\systembug.exe" Dummy
  8. main: argc=2 OS=5.1
  9. ModeB: calling system(IF 1==1 echo !foo bar > "C:\DOCUME~1\Anders\LOCALS~1\Temp\
  10. systembugoutput.txt")
  11. ModeB: system return: 0, outfile attr: 0x2020
  12. ModeA: returning 0
  13.  
  14. C:\Documents and Settings\Anders\Local Settings\Temp\t5>call systembug|more
  15. main: argc=1 OS=5.1
  16. ModeA: starting self as child:"C:\Documents and Settings\Anders\Local Settings\T
  17. emp\t5\systembug.exe" Dummy
  18. main: argc=2 OS=5.1
  19. ModeB: calling system(IF 1==1 echo !foo bar > "C:\DOCUME~1\Anders\LOCALS~1\Temp\
  20. systembugoutput.txt")
  21. The handle could not be opened
  22. during redirection of handle 1.
  23. The handle could not be opened
  24. during redirection of handle 1.
  25. The handle could not be opened
  26. during redirection of handle 1.
  27. ModeB: system return: 1, outfile attr: 0xffffffff
  28. ModeA: returning 1
  29.  
  30.  
  31. C:\Documents and Settings\Anders\Local Settings\Temp\t5>
  32.  
  33. */
  34.  
  35. #include <stdlib.h>
  36. #include <stdio.h>
  37. #include <windows.h>
  38.  
  39.  
  40. int ModeA()
  41. {
  42.   STARTUPINFO si;
  43.   ZeroMemory(&si, sizeof(si));
  44.   si.cb = sizeof(si);
  45.   PROCESS_INFORMATION pi;
  46.   int sysret = -1;
  47.   char cmdline[MAX_PATH+100];
  48.   *cmdline = '\"';
  49.   GetModuleFileName(NULL,cmdline+1,MAX_PATH);
  50.   lstrcat(cmdline,"\" Dummy");
  51.   printf("ModeA: starting self as child:%s\n",cmdline);
  52.   fflush(stdout);
  53.   if (CreateProcess(0, cmdline, 0, 0, FALSE, 0, 0, 0, &si, &pi))
  54.   {
  55.     WaitForSingleObject( pi.hProcess, INFINITE );
  56.     GetExitCodeProcess( pi.hProcess, (DWORD*)&sysret );
  57.     CloseHandle( pi.hProcess );
  58.     CloseHandle( pi.hThread );
  59.   }
  60.   printf("ModeA: returning %d\n",sysret);
  61.   fflush(stdout);
  62.   return sysret;
  63. }
  64.  
  65. int ModeB()
  66. {
  67.   char cmdline[MAX_PATH+100],outfile[MAX_PATH];
  68.   //lstrcpy(cmdline,"if 1==1 \"C:\\Program Files\\DevTools\\NSIS\\NSISA\\makensis.exe\" /? > \"");
  69.   lstrcpy(cmdline,"IF 1==1 echo !foo bar > \"");
  70.   GetTempPath(MAX_PATH,outfile);
  71.   lstrcat(outfile,"systembugoutput.txt");
  72.   lstrcat(cmdline,outfile);
  73.   lstrcat(cmdline,"\"");
  74.   DeleteFile(outfile);
  75.   printf("ModeB: calling system(%s)\n",cmdline);
  76.   fflush(stdout);
  77.   int sysret = system(cmdline);
  78.   DWORD attr = GetFileAttributes(outfile);
  79.   printf("ModeB: system return: %d, outfile attr: %#x\n",sysret,attr);
  80.   fflush(stdout);
  81.   return sysret;
  82. }
  83.  
  84. int main(int argc, char *argv[])
  85. {
  86.   OSVERSIONINFO ovi;
  87.   ovi.dwOSVersionInfoSize = sizeof(ovi);
  88.   GetVersionEx(&ovi);
  89.   printf("main: argc=%d OS=%d.%d\n",argc,ovi.dwMajorVersion,ovi.dwMinorVersion);
  90.   if (argc < 2)
  91.   {
  92.     return ModeA();
  93.   }
  94.   else
  95.   {
  96.     return ModeB();
  97.   }
  98. }
  99.  
  100.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement