|
1 | 1 | #include <string> |
2 | 2 | #include <windows.h> |
3 | 3 | using namespace std; |
| 4 | + |
| 5 | +bool hijackCmdline = false; |
4 | 6 | char* sz_masqCmd_Ansi = NULL, *sz_masqCmd_ArgvAnsi[100] = { }; |
5 | 7 | wchar_t* sz_masqCmd_Widh = NULL, *sz_masqCmd_ArgvWidh[100] = { }; |
6 | 8 | int int_masqCmd_Argc = 0; |
7 | 9 | LPWSTR hookGetCommandLineW() { return sz_masqCmd_Widh; } |
8 | 10 | LPSTR hookGetCommandLineA() { return sz_masqCmd_Ansi; } |
| 11 | + |
9 | 12 | int __wgetmainargs(int* _Argc, wchar_t*** _Argv, wchar_t*** _Env, int _useless_, void* _useless) { |
10 | 13 | *_Argc = int_masqCmd_Argc; |
11 | 14 | *_Argv = (wchar_t **)sz_masqCmd_ArgvWidh; |
@@ -39,6 +42,8 @@ void masqueradeCmdline(const wchar_t* cmdline) { |
39 | 42 | sz_masqCmd_ArgvAnsi[i] = new char[b.size() + 1]; |
40 | 43 | lstrcpyA(sz_masqCmd_ArgvAnsi[i], b.c_str()); |
41 | 44 | } |
| 45 | + |
| 46 | + hijackCmdline = true; |
42 | 47 | } |
43 | 48 |
|
44 | 49 |
|
@@ -91,19 +96,15 @@ bool fixIAT(PVOID modulePtr) |
91 | 96 | LPSTR func_name = (LPSTR)by_name->Name; |
92 | 97 | size_t addr = (size_t)GetProcAddress(LoadLibraryA(lib_name), func_name); |
93 | 98 | printf(" [V] API %s at %x\n", func_name, addr); |
94 | | - if (strcmpi(func_name, "GetCommandLineA") == 0) |
| 99 | + |
| 100 | + if (hijackCmdline && strcmpi(func_name, "GetCommandLineA") == 0) |
95 | 101 | fieldThunk->u1.Function = (size_t)hookGetCommandLineA; |
96 | | - else if (strcmpi(func_name, "GetCommandLineW") == 0) |
| 102 | + else if (hijackCmdline && strcmpi(func_name, "GetCommandLineW") == 0) |
97 | 103 | fieldThunk->u1.Function = (size_t)hookGetCommandLineW; |
98 | | - else if (strcmpi(func_name, "__wgetmainargs") == 0) { |
99 | | - |
| 104 | + else if (hijackCmdline && strcmpi(func_name, "__wgetmainargs") == 0) |
100 | 105 | fieldThunk->u1.Function = (size_t)__wgetmainargs; |
101 | | - } |
102 | | - else if (strcmpi(func_name, "__getmainargs") == 0) { |
| 106 | + else if (hijackCmdline && strcmpi(func_name, "__getmainargs") == 0) |
103 | 107 | fieldThunk->u1.Function = (size_t)__getmainargs; |
104 | | - |
105 | | - } |
106 | | - |
107 | 108 | else |
108 | 109 | fieldThunk->u1.Function = addr; |
109 | 110 |
|
|
0 commit comments