-
Notifications
You must be signed in to change notification settings - Fork 7
/
main.cpp
181 lines (159 loc) · 5.94 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
/*
This file is part of the Pattern scanner for OSX
Copyright (C) 2016 Gabriel Romon <[email protected]>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation. You may not use, modify
or distribute this program under any other version of the
GNU Affero General Public License.
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 Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program.
*/
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <mach/mach_traps.h>
#include <mach/mach_init.h>
#include <mach/mach_error.h>
#include <mach/mach.h>
#include <mach-o/dyld_images.h>
#include <mach-o/loader.h>
#include <libproc.h>
#include <sys/stat.h>
#include <string>
#include <sstream>
using namespace std;
mach_port_t task;
uint64_t Client, SizeClient;
uint8_t * buffer;
////
// define global patterns
////
string LocalPlayer = "4839DF74??4885FF74??4889DEE8????????EB??";
string EntityList = "554889E54156534889FBBE??000000E8????????8B??????????83F8FF";
string Glow = "488D3D??????05E8????????85C00F84????????48C7??????????????????488D??????????";
////
// copy client.dylib to our program memory
////
int GetCSpid() {
int csgopid ;
int numberOfProcesses = proc_listpids(PROC_ALL_PIDS, 0, NULL, 0);
pid_t pids[numberOfProcesses];
bzero(pids, sizeof(pids));
proc_listpids(PROC_ALL_PIDS, 0, pids, sizeof(pids));
for (int i = 0; i < numberOfProcesses; ++i) {
if (pids[i] == 0) { continue; }
char pathBuffer[PROC_PIDPATHINFO_MAXSIZE];
bzero(pathBuffer, PROC_PIDPATHINFO_MAXSIZE);
proc_pidpath(pids[i], pathBuffer, sizeof(pathBuffer));
char nameBuffer[256];
int position = strlen(pathBuffer);
while(position >= 0 && pathBuffer[position] != '/')
{
position--;
}
strcpy(nameBuffer, pathBuffer + position + 1);
if (strcmp(nameBuffer, "csgo_osx64")==0) {
return pids[i];
}
}
return 0;
}
void ClientToBuffer() {
kern_return_t kret;
mach_vm_address_t address;
int csgopid = GetCSpid();
kret = task_for_pid(mach_task_self(), csgopid, &task);
if (kret!=KERN_SUCCESS)
{
printf("task_for_pid() failed with message %s!\n",mach_error_string(kret));
exit(0);
}
struct task_dyld_info dyld_info;
mach_msg_type_number_t count = TASK_DYLD_INFO_COUNT;
if (task_info(task, TASK_DYLD_INFO, (task_info_t)&dyld_info, &count) == KERN_SUCCESS)
{
address = dyld_info.all_image_info_addr;
}
mach_msg_type_number_t size = sizeof(struct dyld_all_image_infos);
vm_offset_t readMem;
vm_read(task,address,size,&readMem,&size);
struct dyld_all_image_infos* infos = (struct dyld_all_image_infos *) readMem;
size = sizeof(struct dyld_image_info) * infos->infoArrayCount;
vm_read(task,(mach_vm_address_t) infos->infoArray,size,&readMem,&size);
struct dyld_image_info* info = (struct dyld_image_info*) readMem;
mach_msg_type_number_t sizeMax=512;
for (int i=0; i < infos->infoArrayCount; i++) {
vm_read(task,(mach_vm_address_t) info[i].imageFilePath,sizeMax,&readMem,&sizeMax);
char *path = (char *) readMem ;
if(strstr(path, "/client.dylib") != NULL){
Client = (mach_vm_address_t)info[i].imageLoadAddress ;
struct stat st;
stat(path, &st);
printf("client: 0x%llx %lld\n", Client, st.st_size);
uint8_t * m_data;
m_data = new uint8_t[st.st_size];
sizeMax = st.st_size;
vm_read(task,(vm_address_t)Client,sizeMax,&readMem,&sizeMax);
uint64_t address = (uint64_t)readMem;
buffer = (uint8_t *)address;
SizeClient = st.st_size;
}
}
}
uint64_t Scan(string s){
stringstream ss;
bool flag = true;
for (int j=0;j<(SizeClient-(s.size())/2 + 1);j++){
flag = true;
for (int i=0; i<(s.size())/2; i++){
string bytechar = s.substr(2*i,2);
if (bytechar.compare("??") != 0){
if (bytechar.substr(1,1).compare("?") == 0){
char byte[2];
int out;
out = sprintf(byte, "%x",buffer[i+j]);
string bytebuffer (byte);
if (bytebuffer.length()==1){
bytebuffer = "0"+bytebuffer;
}
if (bytechar.substr(0,1).compare(bytebuffer.substr(0,1))!=0){
flag=false;
break;
}
continue;
}
uint8_t byte = std::stoi(bytechar, NULL,16);
if (byte != buffer[j+i]){
flag = false;
break;
}
}
}
if (flag){
return (Client+j);
}
}
return 0;
}
int main(int argc, const char * argv[]) {
ClientToBuffer();
uint64_t LocalPlayerArr=Scan(LocalPlayer);
uint64_t EntityArr=Scan(EntityList);
uint64_t GlowArr=Scan(Glow);
uint32_t int1 = (int)*((int*)(LocalPlayerArr-Client+buffer + 0x17));
LocalPlayerArr = LocalPlayerArr + 0x1F + int1 - Client;
printf("LocalPlayer: %llx\n",LocalPlayerArr);
uint32_t int2 = (int)*((int*)(EntityArr-Client+buffer + 0x22));
uint64_t int3 = (uint64_t) *(uint64_t *)(EntityArr-Client+buffer + 0x26 + int2);
EntityArr = int3 + 0x8 + 0x20 -Client;
printf("EntityList : %llx\n",EntityArr);
uint32_t int4 = (int)*((int*)(GlowArr-Client+buffer + 0x22));
GlowArr = GlowArr + 0x26 + int4 - Client;
printf("Glow: %llx\n",GlowArr);
return 0;
}