Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <windows.h>
- #include <assert.h>
- int main(int argc, char* argv[]) {
- if (argc != 2) {
- printf("Usage: textexe <executable-to-test>\n");
- return 1;
- }
- STARTUPINFO sinf;
- PROCESS_INFORMATION pinf;
- memset(&sinf, 0, sizeof sinf);
- sinf.cb = sizeof(sinf);
- if (!CreateProcess(argv[1], argv[1], NULL, NULL, FALSE, CREATE_SUSPENDED, NULL, NULL, &sinf, &pinf)) {
- DWORD error = GetLastError();
- printf("Got system error code %u while trying to execute '%s'\n", (int)error, argv[1]);
- LPSTR msg;
- DWORD msg_len = FormatMessage(
- FORMAT_MESSAGE_ALLOCATE_BUFFER
- | FORMAT_MESSAGE_FROM_SYSTEM
- | FORMAT_MESSAGE_IGNORE_INSERTS,
- NULL,
- error,
- MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),
- (LPSTR)&msg,
- 32,
- NULL
- );
- if (!msg_len) {
- printf("Unable to get description (FormatMessage failed with error code %u)\n", (unsigned)GetLastError());
- } else {
- printf("%s", msg);
- LocalFree(msg);
- }
- return error;
- }
- TerminateProcess(pinf.hProcess, -1);
- WaitForSingleObject(pinf.hProcess, INFINITE);
- return 0;
- }
Add Comment
Please, Sign In to add comment