Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- http://bayfiles.com/file/1dTh/ymkZXT/systembug.exe
- C:\Documents and Settings\Anders\Local Settings\Temp\t5>call systembug
- main: argc=1 OS=5.1
- ModeA: starting self as child:"C:\Documents and Settings\Anders\Local Settings\T
- emp\t5\systembug.exe" Dummy
- main: argc=2 OS=5.1
- ModeB: calling system(IF 1==1 echo !foo bar > "C:\DOCUME~1\Anders\LOCALS~1\Temp\
- systembugoutput.txt")
- ModeB: system return: 0, outfile attr: 0x2020
- ModeA: returning 0
- C:\Documents and Settings\Anders\Local Settings\Temp\t5>call systembug|more
- main: argc=1 OS=5.1
- ModeA: starting self as child:"C:\Documents and Settings\Anders\Local Settings\T
- emp\t5\systembug.exe" Dummy
- main: argc=2 OS=5.1
- ModeB: calling system(IF 1==1 echo !foo bar > "C:\DOCUME~1\Anders\LOCALS~1\Temp\
- systembugoutput.txt")
- The handle could not be opened
- during redirection of handle 1.
- The handle could not be opened
- during redirection of handle 1.
- The handle could not be opened
- during redirection of handle 1.
- ModeB: system return: 1, outfile attr: 0xffffffff
- ModeA: returning 1
- C:\Documents and Settings\Anders\Local Settings\Temp\t5>
- */
- #include <stdlib.h>
- #include <stdio.h>
- #include <windows.h>
- int ModeA()
- {
- STARTUPINFO si;
- ZeroMemory(&si, sizeof(si));
- si.cb = sizeof(si);
- PROCESS_INFORMATION pi;
- int sysret = -1;
- char cmdline[MAX_PATH+100];
- *cmdline = '\"';
- GetModuleFileName(NULL,cmdline+1,MAX_PATH);
- lstrcat(cmdline,"\" Dummy");
- printf("ModeA: starting self as child:%s\n",cmdline);
- fflush(stdout);
- if (CreateProcess(0, cmdline, 0, 0, FALSE, 0, 0, 0, &si, &pi))
- {
- WaitForSingleObject( pi.hProcess, INFINITE );
- GetExitCodeProcess( pi.hProcess, (DWORD*)&sysret );
- CloseHandle( pi.hProcess );
- CloseHandle( pi.hThread );
- }
- printf("ModeA: returning %d\n",sysret);
- fflush(stdout);
- return sysret;
- }
- int ModeB()
- {
- char cmdline[MAX_PATH+100],outfile[MAX_PATH];
- //lstrcpy(cmdline,"if 1==1 \"C:\\Program Files\\DevTools\\NSIS\\NSISA\\makensis.exe\" /? > \"");
- lstrcpy(cmdline,"IF 1==1 echo !foo bar > \"");
- GetTempPath(MAX_PATH,outfile);
- lstrcat(outfile,"systembugoutput.txt");
- lstrcat(cmdline,outfile);
- lstrcat(cmdline,"\"");
- DeleteFile(outfile);
- printf("ModeB: calling system(%s)\n",cmdline);
- fflush(stdout);
- int sysret = system(cmdline);
- DWORD attr = GetFileAttributes(outfile);
- printf("ModeB: system return: %d, outfile attr: %#x\n",sysret,attr);
- fflush(stdout);
- return sysret;
- }
- int main(int argc, char *argv[])
- {
- OSVERSIONINFO ovi;
- ovi.dwOSVersionInfoSize = sizeof(ovi);
- GetVersionEx(&ovi);
- printf("main: argc=%d OS=%d.%d\n",argc,ovi.dwMajorVersion,ovi.dwMinorVersion);
- if (argc < 2)
- {
- return ModeA();
- }
- else
- {
- return ModeB();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement