-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMain.cpp
More file actions
142 lines (111 loc) · 3.78 KB
/
Main.cpp
File metadata and controls
142 lines (111 loc) · 3.78 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
#include "Log.h"
#include "SyringeDebugger.h"
#include "Support.h"
#include <string>
#include <commctrl.h>
#include <iostream>
#include "ini-rw/include/IniFile.hpp"
int Run(std::string_view const arguments) {
constexpr auto const VersionString = "Syringe 0.7.3.8 - Custom";
InitCommonControls();
Log::Open("syringe.log");
inirw::IniFile iniFile("syringeconfig.ini");
Log::WriteLine(VersionString);
Log::WriteLine("===============");
Log::WriteLine();
Log::WriteLine("WinMain: arguments = \"%.*s\"", printable(arguments));
Log::WriteLine(
"WinMain: try to find syringeconfig");
if (iniFile) {
if (inirw::IniKey* iniKey = iniFile.get_key_and_name("General", "IgnorableDlls")) {
std::string nRes = iniKey->ValueCommentPair.get_value();
if (!nRes.empty()) {
char* context = nullptr;
for (char* cur = strtok_s(nRes.data(), ",", &context);
cur;
cur = strtok_s(nullptr, ",", &context))
{
SyringeDebugger::IgnoredDll.push_back(cur);
}
}
}
if(inirw::IniKey* iniKey_HookRemoved = iniFile.get_key_and_name("Logger", "LogHookRemoved")) {
const std::string nRes = iniKey_HookRemoved->ValueCommentPair.get_value();
if (!nRes.empty()) {
inirw::TryParse(nRes.c_str(), &SyringeDebugger::LoggerOptions::LogHookRemove);
}
}
if (inirw::IniKey* iniKey_LoadLib = iniFile.get_key_and_name("Logger", "LogLoadLib")) {
const std::string nRes = iniKey_LoadLib->ValueCommentPair.get_value();
if (!nRes.empty()){
inirw::TryParse(nRes.c_str(), &SyringeDebugger::LoggerOptions::LogLoadLibFunc);
}
}
}
else {
Log::WriteLine(
"WinMain: could not find syringeconfig.ini ");
}
Log::WriteLine(
"WinMain: find syringeconfig done");
auto failure = "Could not load executable.";
auto exit_code = ERROR_ERRORS_ENCOUNTERED;
try
{
auto const command = get_command_line(arguments);
if (!command.flags.empty()) {
// artificial limitation
throw invalid_command_arguments{};
}
Log::WriteLine(
"WinMain: Trying to load executable file \"%.*s\"...",
printable(command.executable));
Log::WriteLine();
auto Debugger = std::make_unique<SyringeDebugger>(command.executable);
failure = "Could not run executable.";
Log::WriteLine("WinMain: SyringeDebugger::FindDLLs();");
Log::WriteLine();
Debugger->FindDLLs();
Log::WriteLine(
"WinMain: SyringeDebugger::Run(\"%.*s\");",
printable(command.arguments));
Log::WriteLine();
//MessageBoxA(
// nullptr, "Syringe Halted",
// VersionString, MB_OK | MB_ICONINFORMATION);
Debugger->Run(command.arguments);
Log::WriteLine("WinMain: SyringeDebugger::Run finished.");
Log::WriteLine("WinMain: Exiting on success.");
return ERROR_SUCCESS;
}
catch (lasterror const& e)
{
auto const message = replace(e.message, "%1", e.insert);
Log::WriteLine("WinMain: %s (%d)", message.c_str(), e.error);
auto const msg = std::string(failure) + "\n\n" + message;
MessageBoxA(nullptr, msg.c_str(), VersionString, MB_OK | MB_ICONERROR);
exit_code = static_cast<long>(e.error);
}
catch (invalid_command_arguments const&)
{
MessageBoxA(
nullptr, "Syringe cannot be run just like that.\n\n"
"Usage:\nSyringe.exe \"<exe name>\" <arguments>",
VersionString, MB_OK | MB_ICONINFORMATION);
Log::WriteLine(
"WinMain: No or invalid command line arguments given, exiting...");
exit_code = ERROR_INVALID_PARAMETER;
}
Log::WriteLine("WinMain: Exiting on failure.");
return static_cast<int>(exit_code);
}
int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPSTR lpCmdLine, _In_ int nCmdShow)
{
UNREFERENCED_PARAMETER(hInstance);
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(nCmdShow);
//MessageBoxA(
// nullptr, "Syringe Is halted before run",
// reinterpret_cast<LPCSTR>("TEST"), MB_OK | MB_ICONINFORMATION);
return Run(lpCmdLine);
}