-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtool_dispatch.cpp
More file actions
154 lines (138 loc) · 5.87 KB
/
tool_dispatch.cpp
File metadata and controls
154 lines (138 loc) · 5.87 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#include "common.h"
#include "whoami.h"
/*
This file is reached via main.cpp.
Essentually the plan is loop thru the command line until we get one we know, then branch to the right one.
All commands follow the same protocol typedef bool (*ToolFunction)(int* result, const char** message_result, const char* argv[]); localed in tool_dipatch.h
They should return true on sucess and false on fail.
They shouldn't assume result is not null and play defensive BUT if it's not null, main.cpp uses that as the exit code passed to ExitProcess().
They will get a pointer to a char* that they can set for a message to send. Note if the tool returns false, stderr. If the tool returns true, stdout.
argv[] is yep that argv[] from main.cpp. It's free to inspect and determine how it will read and be effected by it. Note it's const and and should be treated as such..
*/
struct ToolEntry
{
const char* flag_name;
ToolFunction FunctionPointer;
const char* description;
};
const char* feature_disabled = "This Feature is Disabled or not supported.";
bool Disabled(int* result, const char** message_result, const char* argv[], int argc)
{
*result = -1;
*message_result = feature_disabled;
return true;
}
bool NoSupport(int* result, const char** message_result, const char* argv[], int argc)
{
*result = -1;
*message_result = feature_disabled;
return true;
}
bool ShowHelp_(int* result, const char** message_result, const char* argv[], int argc);
ToolEntry Entries[22] =
{
{ "-EmptyRecyling", EmptyBin, "Empty the Recylling bin"},
{ "-OsVer", ReportVersionStdout, "Report what version of Windows is running to stdout."},
{ "-osMajor", ReportVersionMajorViaExit , "Report the major version of Windows as exit code. "},
{ "-osMinor", ReportVersionMinorViaExit , "Report the minor version of Windows as exit code. "},
{ "-osBuild", ReportVersionBuildViaExit , "Report the build verison Windows as exit code. "},
{ "-osPlatform", ReportVersionPlatformIDViaExit , "Report if Windows ix NT based or older."},
{ "-killprocess", KillProcess , "Terminate the target process. Tries playing nice 1st"},
{ "-upTime", ReportUpTimeToStdout , "How long has this system been up for."},
{ "-upTimeExitCode", ReportUpTimeAsExitCode , "Report length of time system running as exit code cap to 32-bit"},
{ "-whoami", WhoAmI_WriteStdout, "Short for decoding current token of this application (and user)"},
{ "-whoami_priv", WhoAmi_WriteStdout_Priv, "What privlidges does this application have?"},
{ "-?", ShowHelp_, "Show a quick help of all available commands"},
{ "-elevated", WhoAmi_Writestdout_TokenElevatedQuestion, "Check if this app is running full admin or not."},
#ifdef EXPERIMENT
{ "-whoami_priv_system", WhoAmi_WriteStdout_PrivSystemToken , "Open hard coded winlogon.exe target and use as target of whoami."},
{ "-whoami_user_group", WhoAmi_WriteStdout_UserGroups , "Output Group info of the user."},
{ "-which", SearchPath_EntryPoint, "When given a file/folder, asks windows where it's at."},
{ "-whichdll", whichdll_entrypoint, "Using a helper, get the path of the dll you set that is loaded"},
{ "-ShowPendingDeletes", ShowPendingDeletes, "(CURRENTLY NT ONLY) Show Pending file operations for the session (including deletes) that will trigger next reboot"},
#else
{ "-whoami_priv_system", Disabled , feature_disabled },
{ "-whoami_user_group", WhoAmi_WriteStdout_UserGroups , "Output Group info of the user."},
{ "-which", SearchPath_EntryPoint, "Find out where in the path a series on names is"},
{ "-whichdll", whichdll_entrypoint, "Using a helper, get the path of the dll you set that is loaded"},
{ "-ShowPendingDeletes", 0, feature_disabled},
#endif
{ "-processprofile", ProcessProfileEntryPoint, "Run Process Profile on self"},
{ "-checkSafeLoadPath", CheckSafeLoadPath_PipeStdout, "Check if SafeDllSearchMode is active or available and report to stdout."},
{ "-deleteonreboot", DeleteOnReboot, "Register a file or folder to be deleted on reboot. Folders should be empty "},
{0, 0, feature_disabled}
};
bool ShowHelp_(int* result, const char** message_result, const char* argv[], int argc)
{
LWAnsiString* output = LWAnsiString_CreateFromString("Available Commands For more info, consult help file:\r\n");
if (output == nullptr)
{
if (message_result != nullptr)
{
*message_result = "Failed to create output string";
}
if (result != nullptr)
{
*result = -1;
}
return false;
}
for (int i = 0; ; i++)
{
if (Entries[i].flag_name != 0)
{
if ((Entries[i].description != 0) && ((Entries[i].FunctionPointer != 0) && (Entries[i].FunctionPointer != Disabled) && (Entries[i].FunctionPointer != NoSupport)))
{
LWAnsiString_PadNewLine(output, '=', 20); // pad the flag name to 20 chars
LWAnsiString_AppendWithNewLine(output, Entries[i].flag_name);
LWAnsiString_PadNewLine(output, '=', 20); // pad the flag name to 20 chars
LWAnsiString_AppendWithNewLine(output, Entries[i].description);
LWAnsiString_PadNewLine(output, '=', 20); // pad the flag name to 20 chars
LWAnsiString_AppendNewLine(output);
}
LWAnsiString_Append(output, "\r\n");
}
else
{
break;
}
}
WriteStdout(LWAnsiString_ToCStr(output));
if (output != 0) LWAnsiString_FreeString(output);
return true;
}
/// <summary>
/// lookup the function pointer for the given flag name
/// </summary>
/// <param name="flag_name"></param>
/// <returns></returns>
/// <remarks> ai generated but seems to work</remarks>
ToolFunction GetFunctionPointer(const char* flag_name)
{
for (int i = 0; ; i++)
{
if (Entries[i].flag_name != 0)
{
if (lstrcmpiA(flag_name, Entries[i].flag_name) == 0)
{
return Entries[i].FunctionPointer;
}
}
else
{
break;
}
}
return nullptr;
}
const char* GetFunctionHelp(const char* flag_name)
{
for (int i = 0; i < sizeof(Entries) / sizeof(Entries[0]); i++)
{
if (lstrcmpiA(flag_name, Entries[i].flag_name) == 0)
{
return Entries[i].description;
}
}
return nullptr;
}