Skip to content

Commit fa4fbab

Browse files
committed
feat(main): Added startup arguments
No arguments auto mode 2 arguments target process and dll file
1 parent 320140e commit fa4fbab

1 file changed

Lines changed: 41 additions & 9 deletions

File tree

Injector/src/main.cpp

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,39 @@
33
#include "injector.hpp"
44
#include "util/downloader.hpp"
55

6-
int main()
6+
int main(int argc, const char** args)
77
{
88
using namespace injector;
9-
const char* dll_name = "./YimMenu.dll";
109

11-
g_log->verbose("MAIN", "Loading settings");
10+
const char* target_app;
11+
const char* dll_name;
1212

13-
g_settings.load();
13+
if (argc == 1)
14+
{
15+
g_log->verbose("MAIN", "Loading settings");
16+
g_settings.load();
17+
18+
target_app = g_settings.target_application.c_str();
19+
dll_name = "./latest.dll";
20+
}
21+
else if (argc == 3)
22+
{
23+
target_app = args[1];
24+
dll_name = args[2];
25+
26+
if (Injector::inject(target_app, dll_name))
27+
g_log->verbose("MAIN", "Successfully injected...");
28+
else
29+
g_log->error("MAIN", "Failed to inject into target process.");
30+
31+
return 0;
32+
}
33+
else
34+
{
35+
g_log->error("MAIN", "Invalid argument count.");
36+
37+
return 1;
38+
}
1439

1540
if (g_settings.dll_provider.empty())
1641
{
@@ -31,7 +56,10 @@ int main()
3156
else
3257
g_log->info("MAIN", "No DLL present, downloading from server.");
3358

34-
std::string url = g_settings.dll_provider + "/YimMenu.dll";
59+
std::string url = g_settings.dll_provider + "/" + json["file"].get<std::string>();
60+
61+
g_log->verbose("MAIN", "Downloading file from %s", url.c_str());
62+
3563
download::file(url.c_str(), dll_name);
3664

3765
g_log->info("MAIN", "Downloaded DLL, new version %s", json["version"].get<std::string>().c_str());
@@ -40,12 +68,16 @@ int main()
4068
g_settings.attempt_save();
4169
}
4270

43-
if (Injector::inject(g_settings.target_application.c_str(), dll_name))
71+
if (Injector::inject(target_app, dll_name))
72+
{
4473
g_log->verbose("MAIN", "Successfully injected...");
45-
else
46-
g_log->error("MAIN", "Failed to inject into target process.");
74+
75+
return 0;
76+
}
77+
78+
g_log->error("MAIN", "Failed to inject into target process.");
4779

4880
system("timeout 10");
4981

50-
return 0;
82+
return 1;
5183
}

0 commit comments

Comments
 (0)