-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli_main.cpp
More file actions
161 lines (155 loc) · 5.41 KB
/
Copy pathcli_main.cpp
File metadata and controls
161 lines (155 loc) · 5.41 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
155
156
157
158
159
160
161
#include "proximo_core.h"
#include <iostream>
#include <string>
#include <fstream>
#include <sstream>
#include <filesystem>
#include <LIEF/logging.hpp>
int main(int argc, char **argv)
{
LIEF::logging::disable();
EnableDebugPrivilege();
if (argc < 2)
{
json errorPayload;
errorPayload["isSuccessful"] = false;
errorPayload["status"] = "error";
errorPayload["errorMessage"] = "No command specified. Available commands: list-processes, get-process-details, list-modules, get-exports, analyze-candidates, generate-proxy, build-proxy";
std::cout << errorPayload.dump() << std::endl;
return 1;
}
std::string commandName = argv[1];
if (commandName == "list-processes")
{
std::string filterQuery = (argc >= 3) ? argv[2] : "";
json resultPayload = GetRunningProcesses(filterQuery);
std::cout << resultPayload.dump() << std::endl;
return 0;
}
else if (commandName == "get-process-details")
{
if (argc < 3)
{
json errorPayload;
errorPayload["isSuccessful"] = false;
errorPayload["status"] = "error";
errorPayload["errorMessage"] = "Missing target process identifier or name";
std::cout << errorPayload.dump() << std::endl;
return 1;
}
DWORD processIdentifier = FindProcessIdentifierByNameOrString(argv[2]);
json resultPayload = GetProcessDetails(processIdentifier);
std::cout << resultPayload.dump() << std::endl;
return 0;
}
else if (commandName == "list-modules")
{
if (argc < 3)
{
json errorPayload;
errorPayload["isSuccessful"] = false;
errorPayload["status"] = "error";
errorPayload["errorMessage"] = "Missing target process identifier or name";
std::cout << errorPayload.dump() << std::endl;
return 1;
}
DWORD processIdentifier = FindProcessIdentifierByNameOrString(argv[2]);
json resultPayload = GetProcessModules(processIdentifier);
std::cout << resultPayload.dump() << std::endl;
return 0;
}
else if (commandName == "get-exports")
{
if (argc < 3)
{
json errorPayload;
errorPayload["isSuccessful"] = false;
errorPayload["status"] = "error";
errorPayload["errorMessage"] = "Missing target DLL file path";
std::cout << errorPayload.dump() << std::endl;
return 1;
}
json resultPayload = GetDllExports(argv[2]);
std::cout << resultPayload.dump() << std::endl;
return 0;
}
else if (commandName == "analyze-candidates")
{
if (argc < 3)
{
json errorPayload;
errorPayload["isSuccessful"] = false;
errorPayload["status"] = "error";
errorPayload["errorMessage"] = "Missing target process identifier or name";
std::cout << errorPayload.dump() << std::endl;
return 1;
}
DWORD processIdentifier = FindProcessIdentifierByNameOrString(argv[2]);
json resultPayload = AnalyzeProxyCandidates(processIdentifier);
std::cout << resultPayload.dump() << std::endl;
return 0;
}
else if (commandName == "generate-proxy")
{
if (argc < 3)
{
json errorPayload;
errorPayload["isSuccessful"] = false;
errorPayload["status"] = "error";
errorPayload["errorMessage"] = "Missing project options JSON string or file path";
std::cout << errorPayload.dump() << std::endl;
return 1;
}
std::string rawArgument = argv[2];
json parsedOptions;
try
{
if (std::filesystem::exists(rawArgument))
{
std::ifstream fileStream(rawArgument);
fileStream >> parsedOptions;
}
else
{
parsedOptions = json::parse(rawArgument);
}
}
catch (const std::exception &exceptionDetails)
{
json errorPayload;
errorPayload["isSuccessful"] = false;
errorPayload["status"] = "error";
errorPayload["errorMessage"] = std::string("JSON parse error: ") + exceptionDetails.what();
std::cout << errorPayload.dump() << std::endl;
return 1;
}
json resultPayload = GenerateProxyProject(parsedOptions);
std::cout << resultPayload.dump() << std::endl;
return 0;
}
else if (commandName == "build-proxy")
{
if (argc < 3)
{
json errorPayload;
errorPayload["isSuccessful"] = false;
errorPayload["status"] = "error";
errorPayload["errorMessage"] = "Missing target project directory path";
std::cout << errorPayload.dump() << std::endl;
return 1;
}
std::string buildConfiguration = (argc >= 4) ? argv[3] : "Release";
json resultPayload = BuildProxyProject(argv[2], buildConfiguration);
std::cout << resultPayload.dump() << std::endl;
return 0;
}
else
{
json errorPayload;
errorPayload["isSuccessful"] = false;
errorPayload["status"] = "error";
errorPayload["errorMessage"] = "Unknown command: " + commandName;
std::cout << errorPayload.dump() << std::endl;
return 1;
}
}