-
Notifications
You must be signed in to change notification settings - Fork 0
/
syscalls.cpp
64 lines (47 loc) · 1.75 KB
/
syscalls.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
//
// syscalls.cpp
// IdleSow
//
// Created by IX on 12-08-04.
// Copyright 2012 __MyCompanyName__. All rights reserved.
//
#include "globals.h"
void* dlopen(const char *path, int mode)
{
void* ret = (*orig_dlopen)(path, mode);
if( path != NULL && strstr(path, "/cgame_mac.dylib") != NULL)
{
// enumerate loaded images
int images = _dyld_image_count();
if(!images)
die("Couldn't find any images.\n");
for(int i = 0; i < images; i++)
{
const char *img_name = _dyld_get_image_name(i);
unsigned int img_base = 0;
if(!img_name)
printf("Couldn't read image %d\n", i);
img_base = (unsigned int) _dyld_get_image_header(i);
if(!img_base)
die("Couldn't get image address.");
if(i == 0) // Main module
{
printf("Main module!\n");
pCl = (client_state_t*)(img_base + OFFSET_CLIENT);
}
if(strstr(img_name, "/cgame_mac.dylib") != NULL)
{
printf("Found cgame at 0x%X\n", img_base);
pCg = (cg_state_t*)(img_base + OFFSET_STATE);
pCgs = (cg_static_t*)(img_base + OFFSET_STATIC);
pEnts = (centity_t*)(img_base + OFFSET_ENT);
oImport = (cgame_import_t*)(img_base + OFFSET_IMP);
oExport = ((cgame_export_t*)(img_base + OFFSET_EXP));
}
else if(strstr(img_name, "/game_mac.dylib") != NULL)
printf("Found client at 0x%X\n", img_base);
}
fflush(stdout);
}
return ret;
}