Update CS:GO team score gamedata.
6 extern "C" char * cplus_demangle(const char *, int);
7 #define DMGL_PARAMS (1 << 0)
15 static bool FindVFunc(void *handle, void **vtable, const char* vtable_end, const char *class_function, const char *params, VOffset *offsets);
17 int main(int argc, char **argv)
28 fprintf(stderr, "Usage: <binary> <vtable start symbol> <function> <optional: params> <optional: vtable end symbol>\n");
32 handle = dlopen(argv[1], RTLD_NOW);
36 fprintf(stderr, "Failed to open server image, error [%s]\n", dlerror());
40 pVtable = (void **)dlsym(handle, argv[2]);
45 snprintf(startSym, sizeof(startSym), "_ZTV%d%s", strlen(argv[2]), argv[2]);
46 pVtable = (void **)dlsym(handle, startSym);
51 fprintf(stderr, "Invalid vtable symbol \"%s\"\n", argv[2]);
65 int len = strlen(params)-1;
67 if (params[len] == '"')
80 ret = FindVFunc(handle, pVtable, argv[5], argv[3], params, &offsets);
84 ret = FindVFunc(handle, pVtable, "_ZTI", argv[3], params, &offsets);
91 printf("%s%s - Win: %i Linux : %i\n", argv[3], params, offsets.windows_offset, offsets.linux_offset);
95 printf("%s - Win: %i Linux : %i\n", argv[3], offsets.windows_offset, offsets.linux_offset);
102 fprintf(stderr, "Failed to find function!");
107 static bool FindVFunc(void *handle, void **vtable, const char* vtable_end, const char *class_function, const char *params, VOffset *offsets)
111 int linux_offset = -1;
112 int windows_offset = -1;
116 int start_offset = -1;
118 for (int i=0; i< 1000; i++)
120 void *FuncPtr = vtable[i];
122 int status = dladdr(FuncPtr, &d);
129 if (i > 1 && strncmp(d.dli_sname, vtable_end, strlen(vtable_end)) == 0)
134 char *name = cplus_demangle(d.dli_sname, DMGL_PARAMS);
138 printf("Demangling failed\n");
142 char *foundfunction = strpbrk(name, ":");
144 if (foundfunction == NULL)
146 //printf("Couldnt split function\n");
151 //Skip both ':' chars
155 if (strncmp(foundfunction, class_function, strlen(class_function)) == 0 && foundfunction[strlen(class_function)] == '(')
157 //printf("Symbol: %s Demangled: %s Offset: %i\n", d.dli_sname, name, i);
159 //We have a pointer to a function, but it may be overloaded.
162 if (start_offset == -1)
167 char *foundparams = strpbrk(foundfunction, "(");
169 if (foundparams == NULL)
176 if(params == NULL || strcmp(foundparams, params) == 0)
178 //This is actually our function - So this is the linux offset
180 location = overloads;
187 windows_offset = (overloads-location) + start_offset;
189 offsets->linux_offset = linux_offset - 2;
190 offsets->windows_offset = windows_offset - 2;