-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.cpp
409 lines (315 loc) · 12.6 KB
/
main.cpp
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
#include <stdio.h>
#include <string>
#include <thread>
#include <iostream>
#include <dirent.h>
#include <fstream>
#include <climits>
#include <unistd.h>
#include <sstream>
#include <iomanip>
#include <X11/Xos.h>
#include <X11/X.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xatom.h>
#include <X11/extensions/shape.h>
#include <X11/extensions/Xfixes.h>
#include <X11/extensions/Xcomposite.h>
#include <vector>
#include <cstring>
#include <cstddef>
#include <algorithm>
#include <cctype>
#include <linux/uinput.h>
#include "hacks/bhop.hpp"
#include "hacks/aimbot.hpp"
#include "hacks/playerInfo.hpp"
#include "hacks/ESP.hpp"
#include "hacks/draw.hpp"
#include "client/client.hpp"
#include "engine/engine.hpp"
#include "GUI/GUI.hpp"
#include "memory.hpp"
#include "xutil.hpp"
//Reads the data of a file
std::string readFile(std::string filePath, bool firstLine=true) {
std::ifstream file;
file.open(filePath, std::ifstream::in);
char currentChar;
std::string concat = "";
while (file.get(currentChar)) {
if (firstLine == true && currentChar == '\n') {break;}
concat += currentChar;
}
file.close();
return concat;
}
//https://www.unknowncheats.me/forum/general-programming-and-reversing/147140-linux-accessing-process-memory.html
pid_t getProcessByName(std::string strName) {
if (strName.length() == 0)
return -1;
//Try to open the /proc/ directory
DIR *pDir = opendir("/proc/");
if (pDir == nullptr) { return -1; } // if that fails then exit
dirent* pDirent = nullptr;
//basically loop through all the processes
while (pDirent = readdir(pDir), pDirent != nullptr) {
//Skip non processes
if (pDirent->d_type != DT_DIR) {
continue;
}
//Basically contains the process ID
std::string strProcID(pDirent->d_name);
//Get the name of the processes
std::string strComm{ readFile("/proc/" + strProcID + "/comm") };
//Check if the currently iterated processes is the one we want
if (strComm == strName) {
pid_t pid = (pid_t) atoi(strProcID.c_str());
return pid;
}
}
return -1;
}
//Returns Address of the Signature
//Unfinished, doesn't work, would like some help.
/*
unsigned int findPattern(pid_t procId, std::string moduleName, std::string Pattern) {
const unsigned int start = Memory::getModuleBaseAddress(procId, moduleName);
const unsigned int end = (start + Memory::getModuleSize(procId, moduleName));
int howManyBytes = 0;
std::string concatTemp = "";
for (int i = 0; i < Pattern.length(); i++) {
if (Pattern[i] == ' ') {
howManyBytes++;
continue;
}
concatTemp += Pattern[i];
}
Pattern = concatTemp;
bool found = true;
unsigned int patternIter = 0;
std::byte currentByte;
std::byte currentByteFromPattern;
for (unsigned int i = start; i <= end; i++) {
found = true;
patternIter = 0;
for (unsigned int h = 0; h <= howManyBytes; h++) {
Memory::Read(procId, i, ¤tByte, sizeof(currentByte));
std::string byte = "";
byte += Pattern[patternIter];
byte += Pattern[patternIter+1];
if (byte == "??") {
patternIter++;
continue;
}
currentByteFromPattern = (std::byte) Memory::hexToInt( byte );
std::cout << "currentByte: ";
std::cout << std::hex << (int) currentByte << '\n';
std::cout << "currentByteFromPattern: ";
std::cout << std::hex << (int) currentByteFromPattern << '\n';
std::cout << "patternIterator: " << patternIter << '\n';
if (currentByte != currentByteFromPattern) {
found = false;
break;
}
patternIter++;
}
if (found == true) {
return i;
}
}
return 0; //failed, cant return negative numbers due to signed-ness
}
*/
int main() {
if (getuid()) { //check if we are root or not
printf("cs-source-hack: Please run as root\ncs-source-hack: Example: \"sudo ./cs-source-hack\"\n");
return 1;
}
pid_t gamePid = getProcessByName("hl2_linux");
if (gamePid == -1) { // check if we successfully got the game processes id
printf("cs-source-hack: Please open the game\n");
return 1;
}
//Get memory addresses/offsets
const uintptr_t ClientObject = Memory::getModuleBaseAddress(gamePid, "bin/client.so");
const uintptr_t EngineObject = Memory::getModuleBaseAddress(gamePid, "bin/engine.so");
const uintptr_t hl2_linux = Memory::getModuleBaseAddress(gamePid, "hl2_linux");
//some address inside of window struct: engine.so + 0xD20008
Memory::Read(gamePid, EngineObject + 0xD20014, &ENGINE::screenX, sizeof(int));
Memory::Read(gamePid, EngineObject + 0xD20018, &ENGINE::screenY, sizeof(int));
Memory::Read(gamePid, ClientObject + 0xBE9380, &CLIENT::radarList, sizeof(uintptr_t));
CLIENT::playerList = ClientObject + 0xBA5FB4;
CLIENT::localPlayer = ClientObject + 0xBD0750;
ENGINE::viewMatrix = EngineObject + 0xC9B160;
CLIENT::dwForceJump = ClientObject + 0xBEE4E8;
CLIENT::dwForceAttack1 = ClientObject + 0xBEE578;
CLIENT::dwForceAttack2 = ClientObject + 0xBEE4C8;
CLIENT::onGround = ClientObject + 0xB9E650;
CLIENT::cameraLocation = ClientObject + 0xBC3E08;
ENGINE::pLocalYaw = EngineObject + 0xB3349C;
ENGINE::pLocalPitch = EngineObject + 0xB33498;
std::cout << "Client.so: " << std::hex << ClientObject << '\n';
std::cout << "Engine.so: " << std::hex << EngineObject << '\n';
std::cout << "hl2_linux: " << std::hex << hl2_linux << '\n';
std::cout << "viewMatrix: " << std::hex << ENGINE::viewMatrix << '\n';
std::cout << "playerList: " << std::hex << CLIENT::playerList << '\n';
std::cout << "radarList: " << std::hex << CLIENT::radarList << '\n';
std::cout << "cameraLocation: " << std::hex << CLIENT::cameraLocation << '\n';
std::cout << "pLocalYaw: " << std::hex << ENGINE::pLocalYaw << '\n';
std::cout << "pLocalPitch: " << std::hex << ENGINE::pLocalPitch << '\n';
std::cout << "localPlayer: " << std::hex << CLIENT::localPlayer << '\n';
printf("screenX: %d\n", ENGINE::screenX);
printf("screenY: %d\n", ENGINE::screenY);
//https://gist.github.com/ericek111/774a1661be69387de846f5f5a5977a46 great piece of black magic.
/* beginning of X initiation*/
Display* d = XOpenDisplay(NULL);
Display* bhopDisplay = XOpenDisplay(NULL);
Display* aimDisplay = XOpenDisplay(NULL);
Display* drawDisplay = XOpenDisplay(NULL);
if (!d) {
printf("cs-source-hack: Please run startx/xinit\nIf you are running this program from SSH, it won't work.\n");
return 1;
}
Screen* s = DefaultScreenOfDisplay(d);
if (s == NULL) return 1;
int default_display_resolution[2];
getDefaultDisplayResolution(default_display_resolution);
XWindowAttributes gameAttr = getWindowAttributesFromPid(d, gamePid);
printf("gameAttr.x %d\n", gameAttr.x);
printf("gameAttr.y %d\n", gameAttr.y);
// ENGINE::screenXpos = gameAttr.x;
// ENGINE::screenYpos = gameAttr.y;
ENGINE::screenXpos = 0;
ENGINE::screenYpos = 0;
if ((gameAttr.x > s->width || gameAttr.x < 0) || (gameAttr.y > s->height || gameAttr.y < 0)) {
printf("gameAttr is corrupted, assuming the game is full screen.\n");
ENGINE::screenXpos = 0;
ENGINE::screenYpos = 0;
}
printf("s->width %d\n", s->width);
printf("s->height %d\n", s->height);
if (default_display_resolution[0] < ENGINE::screenX && default_display_resolution[1] < ENGINE::screenY) {
ENGINE::screenX = s->width;
ENGINE::screenY = s->height;
}
printf("Final screen width and height:\nx: %d\ny: %d\n", ENGINE::screenX, ENGINE::screenY);
int screen = DefaultScreen(d);
int shape_event_base;
int shape_error_base;
if (!XShapeQueryExtension(d, &shape_event_base, &shape_error_base)) {
printf("cs-source-hack: NO shape extension in your system !\n");
return 1;
}
XColor bgcolor = createXColorFromRGBA(0, 0, 0, 0, d, screen);
Window root = DefaultRootWindow(d);
Visual* visual = DefaultVisual(d, screen);
XVisualInfo vinfo;
XMatchVisualInfo(d, DefaultScreen(d), 32, TrueColor, &vinfo);
Colormap colormap = XCreateColormap(d, DefaultRootWindow(d), vinfo.visual, AllocNone);
XSetWindowAttributes attr;
attr.background_pixmap = None;
attr.background_pixel = bgcolor.pixel;
attr.border_pixel=0;
attr.win_gravity=NorthWestGravity;
attr.bit_gravity=ForgetGravity;
attr.save_under=1;
attr.event_mask=BASIC_EVENT_MASK;
attr.do_not_propagate_mask=NOT_PROPAGATE_MASK;
attr.override_redirect=1; // OpenGL > 0
attr.colormap = colormap;
unsigned long mask = CWColormap | CWBorderPixel | CWBackPixel | CWEventMask | CWWinGravity|CWBitGravity | CWSaveUnder | CWDontPropagate | CWOverrideRedirect;
Window window = XCreateWindow(d, root, ENGINE::screenXpos, ENGINE::screenYpos, ENGINE::screenX, ENGINE::screenY, 0, vinfo.depth, InputOutput, vinfo.visual, mask, &attr);
XShapeCombineMask(d, window, ShapeInput, 0, 0, None, ShapeSet);
XShapeSelectInput(d, window, ShapeNotifyMask);
//wattr.override_redirect = 1;
//XChangeWindowAttributes(d, window, CWOverrideRedirect, &wattr);
XserverRegion region = XFixesCreateRegion (d, NULL, 0);
XFixesSetWindowShapeRegion (d, window, ShapeInput, 0, 0, region);
XFixesDestroyRegion (d, region);
XdbeBackBuffer back_buffer = XdbeAllocateBackBufferName(d, window, 0);
XMapWindow(d, window);
DRAW::shadowfont = XLoadQueryFont(d, "6x13bold");
DRAW::font = XLoadQueryFont(d, "6x13");
if (!DRAW::font || !DRAW::shadowfont) {
std::cout << "cs-source-hack: One or more fonts are missing, aborting." << std::endl;
return 1;
}
//some color constants
DRAW::red = createXColorFromRGB(255, 0, 0, d, DefaultScreen(d));
DRAW::orange = createXColorFromRGB(255, 170, 0, d, DefaultScreen(d));
DRAW::black = createXColorFromRGB(0, 0, 0, d, DefaultScreen(d));
DRAW::white = createXColorFromRGB(255, 255, 255, d, DefaultScreen(d));
DRAW::green = createXColorFromRGB(0, 255, 0, d, DefaultScreen(d));
DRAW::yellow = createXColorFromRGB(255, 255, 0, d, DefaultScreen(d));
DRAW::tColor = createXColorFromRGB(230, 35, 35, d, DefaultScreen(d));
DRAW::ctColor = createXColorFromRGB(148, 196, 248, d, DefaultScreen(d));
DRAW::cyan = createXColorFromRGB(0, 255, 240, d, DefaultScreen(d));
DRAW::gray = createXColorFromRGBA(90, 90, 90, -1, d, DefaultScreen(d));
DRAW::blue = createXColorFromRGB(38, 113, 252, d, DefaultScreen(d));
/* end of X initiation */
/* uinput initiation */
//file handle
int dev_uinput = open("/dev/uinput", O_WRONLY | O_NONBLOCK);
//make a pretend USB input device
struct uinput_setup usetup;
ioctl(dev_uinput, UI_SET_EVBIT, EV_KEY);
ioctl(dev_uinput, UI_SET_KEYBIT, KEY_SPACE);
memset(&usetup, 0, sizeof(usetup));
usetup.id.bustype = BUS_USB;
usetup.id.vendor = 0x1234; /* sample vendor */
usetup.id.product = 0x5678; /* sample product */
strcpy(usetup.name, "input device CSS");
ioctl(dev_uinput, UI_DEV_SETUP, &usetup);
ioctl(dev_uinput, UI_DEV_CREATE);
//configuration GUI thread
pthread_t pGUI;
pthread_create(&pGUI, NULL, guiThread, NULL);
pthread_setname_np(pGUI, "guiThread");
//bhop thread
std::thread bhopThread(bhop, gamePid, bhopDisplay, dev_uinput);
pthread_setname_np(bhopThread.native_handle(), "bhopThread");
//aimbot thread
std::thread aimbotThread(aimbot, gamePid, aimDisplay);
pthread_setname_np(aimbotThread.native_handle(), "aimbotThread");
//draw thread for esp and such
std::thread drawThread(draw, gamePid, back_buffer, drawDisplay, window);
pthread_setname_np(drawThread.native_handle(), "drawThread");
/* Fun Stuff */
printf("Ready\n");
printf("The Free and Open Source no-name GNU CS:S cheat, made with GNU Emacs, for your GNU operating system.\n");
printf(" , , \n");
printf(" / \\ \n");
printf(" ((__-^^-,-^^-__)) \n");
printf(" `-_---\' `---_-\' \n");
printf(" `--|o` \'o|--\' \n"); //GNU ascii :D
printf(" \\ ` / \n");
printf(" ): :( \n");
printf(" :o_o: \n");
printf(" \"-\" \n");
/* End Of Fun Stuff */
//player iterator thread
for (;;) {
if (isKeyDown(d, XK_Delete)) {
printf("Closing now");
ioctl(dev_uinput, UI_DEV_DESTROY);
close(dev_uinput);
exit(0);
}
//move and resize drawing window if needed
/*
gameAttr = getWindowAttributesFromPid(d, gamePid);
if (ENGINE::screenXpos != gameAttr.x || ENGINE::screenYpos != gameAttr.y ||
ENGINE::screenX != gameAttr.width || ENGINE::screenY != gameAttr.height) {
XMoveResizeWindow(d, window, gameAttr.x, gameAttr.y, gameAttr.width, gameAttr.height);
ENGINE::screenXpos = gameAttr.x;
ENGINE::screenYpos = gameAttr.y;
ENGINE::screenX = gameAttr.width;
ENGINE::screenY = gameAttr.height;
}
*/
players(gamePid);
}
return 0;
}