Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifdef _WIN32
- #define psa_execve(psa, childPidVarName, nPidVarName, statusVarName) \
- PROCESS_INFORMATION pProcInfo; \
- ZeroMemory(&pProcInfo, sizeof(pProcInfo)); \
- unsigned int psa##_i, psa##_j; \
- for (psa##_i = 0; psa##_i < 1024; psa##_i++) { \
- if (!psa[psa##_i]) { \
- psa##_i++; \
- break; \
- } \
- } \
- char psa##_buffer[2048]; \
- strcat(psa[0], ".exe"); \
- psa_get_cmdline(psa, psa##_i, psa##_j, psa##_buffer); \
- STARTUPINFO si; \
- ZeroMemory(&si, sizeof(si)); /* how is this any different from memset 0? */ \
- printf("buffer = '%s'\n", psa##_buffer); \
- CreateProcess( \
- psa[0], /* application name */ \
- psa##_buffer, /* command line */ \
- NULL, /* process attributes */ \
- NULL, /* thread attributes */ \
- FALSE, /* inherit handles */ \
- 0, /* creation flags, whatever that means */ \
- NULL, /* the environment; NULL means copy the parent process's environment */ \
- NULL, /* lpCurrentDirectory; NULL means copy */ \
- &si, /* startupinfo, whatever it is */ \
- &pProcInfo /* process information, which is the actual fucking result of this fucktion */ \
- ); \
- WaitForSingleObject(pProcInfo.hProcess, INFINITE); \
- DWORD dwExitCode; \
- GetExitCodeProcess(pProcInfo.hProcess, &dwExitCode); \
- int statusVarName = (int)dwExitCode; \
- \
- CloseHandle(pProcInfo.hProcess); \
- CloseHandle(pProcInfo.hThread)
- #else
- #define psa_execve(psa, childPidVarName, nPidVarName, statusVarName) \
- pid_t childPidVarName = fork(); \
- pid_t nPidVarName = 0; \
- int statusVarName = 0; \
- if (!childPidVarName) { \
- execv(psa[0], psa); \
- } \
- while ((nPidVarName = waitpid(childPidVarName, &statusVarName, 0)) > 0)
- #endif
Add Comment
Please, Sign In to add comment