-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
77 lines (53 loc) · 1.68 KB
/
main.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
72
73
74
75
76
77
#include "global.h"
#include "credman.h"
HANDLE hHeap = NULL;
HANDLE StdHandle = NULL;
extern HeapCreate_ pHeapCreate;
extern HeapDestroy_ pHeapDestroy;
extern ExitProcess_ pExitProcess;
#define ws_stdout L"stdout"
int __cdecl main()
{
WCHAR ws_Message[MAX_PATH * sizeof(WCHAR)];
LPWSTR* szArglist = NULL;
LPWSTR lpAppName, lpSaveTo;
DWORD dwCharsWritten;
int nArgs;
do {
szArglist = CommandLineToArgvW(GetCommandLineW(), &nArgs);
if (!szArglist)
break;
StdHandle = GetStdHandle(STD_OUTPUT_HANDLE);
if (!StdHandle)
break;
SetConsoleOutputCP(CP_UTF8);
lpAppName = szArglist[0];
if (nArgs != 2) {
wcscpy(ws_Message, L"Usage:\n");
wcscat(ws_Message, lpAppName);
wcscat(ws_Message, L" stdout/file\n\nExample:\n");
wcscat(ws_Message, lpAppName);
wcscat(ws_Message, L" stdout\n");
wcscat(ws_Message, lpAppName);
wcscat(ws_Message, L" log.txt");
WriteConsoleW(StdHandle, ws_Message, wcslen(ws_Message), &dwCharsWritten, NULL);
break;
}
lpSaveTo = szArglist[1];
if (wcsncmp(lpSaveTo, ws_stdout, wcslen(ws_stdout)) == 0)
lpSaveTo = NULL;
if (!bResolveFunctions())
break;
hHeap = pHeapCreate(0, 0x10000, 0);
if (!hHeap)
break;
doBackup(lpSaveTo);
} while (FALSE);
if (szArglist)
LocalFree(szArglist);
if (hHeap) {
pHeapDestroy(hHeap);
pExitProcess(0);
}
return 0;
}