Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update python version and give error message #6

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ using namespace std;
void (*DedicatedMain)(int argc, const char** argv);

// engine
void (*CModelLoader_GetModelForName)(void*, const char* name, int referencetype);
void (*CModelLoader_ReferenceModel)(void*, const char* name, int referencetype);
void** p_modelloader;

template <typename T> void ptr(T*& f, void* so, uint32_t offset) {
Expand All @@ -26,7 +26,6 @@ char *mappath;

void startpoint() {
fprintf(stderr, "startpoint()\n");

void* modelloader = *p_modelloader;
cout << "modelloader @ " << modelloader << endl;

Expand All @@ -36,10 +35,10 @@ void startpoint() {
cerr << "Press enter to continue" << endl;
getchar();
}

void *buf = alloca(0x10000);

CModelLoader_GetModelForName(modelloader, mappath, 2);
CModelLoader_ReferenceModel(modelloader, mappath, 2);
cout << "Done" << endl;

_exit(0);
Expand All @@ -57,11 +56,20 @@ int main(int argc, char** argv) {
}

struct link_map *lm = (struct link_map*)dlopen("dedicated.so", RTLD_NOW);
if(lm == NULL)
{
fprintf(stderr, dlerror());
}
void* dedicated = (void*)lm->l_addr;
assert(dedicated);
lm = (struct link_map*)dlopen("engine.so", RTLD_NOW);
if (lm == NULL)
{
fprintf(stderr, dlerror());
}
void* engine = (void*)lm->l_addr;
assert(engine);


cout << "dedicated.so loaded at " << dedicated << endl;
cout << "engine.so loaded at " << engine << endl;
Expand All @@ -77,11 +85,11 @@ int main(int argc, char** argv) {
cout << "Reading from " << mappath << endl;

// dedicated
ptr(DedicatedMain, dedicated, 0x1beb0);
ptr(DedicatedMain, dedicated, 0x1d000);

// engine
ptr(CModelLoader_GetModelForName, engine, 0x180460);
ptr(p_modelloader, engine, 0x6E3C80);
ptr(CModelLoader_ReferenceModel, engine, 0x18A400);
ptr(p_modelloader, engine, 0x70E2E0);

const char* args[] = {"x", "-game", "csgo", "-nominidumps", "-nobreakpad"};
DedicatedMain(sizeof args / sizeof *args, args);
Expand Down
22 changes: 11 additions & 11 deletions patch.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python2
#!/usr/bin/env python3
import shutil
import struct
import os
Expand All @@ -14,35 +14,35 @@ def patch(d, offset, s):
d[offset:offset+len(s)] = s

######### engine.so
dat = bytearray(open("bin/engine.orig.so").read())
dat = bytearray(open("bin/engine.orig.so", "rb").read())

# Jump to forkserver entry point after initialization.
# 0x286d20 is the NET_CloseAllSockets function.
patch(dat, 0x286D20,
(
'\xb8' + struct.pack('<I', startpoint) + # mov eax, startpoint
'\xff\xd0' # call eax
))
patch(dat, 0x29E6B0,
(
b'\xb8' + struct.pack('<I', startpoint) + # mov eax, startpoint
b'\xff\xd0' # call eax
))

# Patch out a function that is registered via atexit().
# You can find it by looking for the single xref to the string
# "Missing shutdown function for %s"
patch(dat, 0x2CCDB0, "\xc3")
patch(dat, 0x2E5900, b"\xc3")

# nop out a call to BeginWatchdogTimer in the initialization sequence, so that we
# don't get SIGABRT after a while
patch(dat, 0x263F5F, "\x90"*6)
patch(dat, 0x27459F, b"\x90"*6)

with open("bin/engine.so", "wb") as f:
f.write(dat)

######### libtier0.so
dat = bytearray(open("bin/libtier0.orig.so").read())
dat = bytearray(open("bin/libtier0.orig.so", "rb").read())

# Avoid Plat_ExitPlatform crash
# .text:000156E7 test ebx, ebx
# .text:000156E9 jz short loc_156F5
# .text:000156EB mov ds:dword_0, 1
patch(dat, 0x156E7, "\x90"*(0x156F5-0x156e7))
patch(dat, 0x15877, b"\x90"*(0x15885 - 0x15877))
with open("bin/libtier0.so", "wb") as f:
f.write(dat)