-
Notifications
You must be signed in to change notification settings - Fork 0
/
csgo_run.c
121 lines (99 loc) · 3.01 KB
/
csgo_run.c
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
/*
csgo_run.c - Custom imeplementation of csgo runner
Copyright (C) 2023 kotleni
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <unistd.h>
#include <stdbool.h>
#include <string.h>
#include <dlfcn.h>
#if defined(__APPLE__)
#include <malloc/malloc.h>
#define LAUNCHER_PATH "bin/osx64/launcher.dylib"
#elif defined(__linux__)
#include <malloc.h>
#define LAUNCHER_PATH "bin/linux64/launcher_client.so"
#endif
typedef struct {
char* injectLib;
int injectDelay;
} Arguments;
typedef struct {
char* libpath;
int delay;
} InjectConfig;
FILE* logFile;
void* inject(InjectConfig* cfg) {
sleep(cfg->delay);
printf("Injecting %s\n", cfg->libpath);
// load lib
void* handle = dlopen(cfg->libpath, 10);
if(!handle) {
// fail to load the library
printf("Injecting error: %s\n", dlerror());
return NULL;
}
return NULL;
}
void parse_arguments(int argc, char *argv[], Arguments* arguments) {
for(int i = 0; i < argc; i += 1) {
if(strcmp(argv[i], "-inj") == 0) {
arguments->injectLib = argv[i + 1];
} else if(strcmp(argv[i], "-injdelay") == 0) {
arguments->injectDelay = atoi(argv[i + 1]);
}
}
}
int main(int argc, char *argv[]) {
logFile = fopen("csgo_run.log", "w");
// Dump args to file
for (int i = 0; i < argc; i++) {
fprintf(logFile, "Argument %d: %s\n", i, argv[i]);
}
// Dump env vars to file
FILE* envProc = popen("env", "r");
char output[128];
while (fgets(output, sizeof(output), envProc) != NULL) {
fprintf(logFile, "%s", output);
}
fclose(logFile);
Arguments* arguments = (Arguments*) malloc(sizeof(Arguments));
arguments->injectLib = NULL; // -inj <lib>
arguments->injectDelay = 0; // -injdelay <secs>
parse_arguments(argc, argv, arguments);
long (*LauncherMain)(unsigned int, long);
// load lib
void* dl = dlopen(LAUNCHER_PATH, 2);
if(!dl) {
char* err = dlerror();
printf("Failed to load the launcher (%s)\n", err);
while(1);
}
// get launchermain function
LauncherMain = (long (*)(unsigned int, long))dlsym(dl, "LauncherMain");
if(!LauncherMain) {
puts("Failed to load the launcher entry proc");
while(1);
}
// -inj <lib>
if(arguments->injectLib != NULL) {
pthread_t tid;
InjectConfig* inj_cfg = (InjectConfig*) malloc(sizeof(InjectConfig));
inj_cfg->libpath = arguments->injectLib;
inj_cfg->delay = arguments->injectDelay;
pthread_create(&tid, NULL, &inject, inj_cfg);
pthread_detach(tid);
}
// invoke launchermain
return LauncherMain(argc, (long)argv);
}