-
Notifications
You must be signed in to change notification settings - Fork 9
/
hidec.c
71 lines (59 loc) · 1.95 KB
/
hidec.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <process.h>
#include <windows.h>
#pragma optimize("gy", on)
#pragma comment(lib,"kernel32")
#pragma comment(lib,"user32")
#pragma comment(linker, "/ALIGN:16")
#pragma comment(linker, "/MERGE:.rdata=.data")
#pragma comment(linker, "/MERGE:.text=.data")
#pragma comment(linker,"/SUBSYSTEM:WINDOWS")
void WinMainCRTStartup(void)
{
STARTUPINFO si;
PROCESS_INFORMATION pi;
int bWait = 0;
DWORD exitcode = 0;
char stopchar = ' ';
char* lpszCmd = GetCommandLine();
if (lpszCmd[0] == '"') stopchar = '"';
do {
lpszCmd++;
}
while ((lpszCmd[0] != stopchar) && (lpszCmd[0] != 0));
if (lpszCmd[0] != 0)
{
do {
lpszCmd++;
}
while ((lpszCmd[0] != 0) && ((lpszCmd[0] == ' ') || (lpszCmd[0] == 't')));
};
if (lpszCmd[0] == 0)
{
MessageBox(0, "About:\n\nhidec hides console window of started program & waits (opt.) for its termination\n\nUsage:\n\n\thidec [/w] <filename>\n\nWhere:\n\n/w\twait for program termination\nfilename\texecutable file name", "Error: Incorrect usage", 0);
ExitProcess(0);
};
if ((lpszCmd[0] == '/')&&(((lpszCmd[1])|0x20) == 'w')&&(lpszCmd[2] == ' '))
{
bWait = 1;
lpszCmd += 3;
};
while ((lpszCmd[0] != 0) && ((lpszCmd[0] == ' ') || (lpszCmd[0] == 't'))) lpszCmd++;
/* create process with new console */
unsigned char *ps = (unsigned char*)&si;
for (unsigned int i = 0; i < sizeof(si); i++) ps[ i ] = 0x00;
si.cb = sizeof(si);
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_HIDE;
if( CreateProcess( NULL, lpszCmd,
NULL, NULL, FALSE, CREATE_NEW_CONSOLE,
NULL, NULL, & si, & pi ) )
{
if (bWait) WaitForSingleObject(pi.hProcess, INFINITE);
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
}
else
exitcode = GetLastError();
/* terminate this */
ExitProcess(exitcode);
}