From eec2e57a05e8e05ea499007c1012469d57c71553 Mon Sep 17 00:00:00 2001 From: voron00 Date: Sat, 14 Oct 2017 11:45:30 +0300 Subject: [PATCH] Remove some...really unnecessary functions This stuff..idk..i don't think anyone EVER gonna need this --- cracking.cpp | 64 ----------------------------- cracking.hpp | 2 - gsc.cpp | 5 --- gsc_utils.cpp | 109 -------------------------------------------------- gsc_utils.hpp | 9 ----- 5 files changed, 189 deletions(-) diff --git a/cracking.cpp b/cracking.cpp index 8a07706..efc731e 100755 --- a/cracking.cpp +++ b/cracking.cpp @@ -28,68 +28,4 @@ void cHook::hook() void cHook::unhook() { memcpy((void *)from, (void *)oldCode, 5); -} - -int cracking_call_function(int func_address, char *args, unsigned char *data) -{ - int data_pos = 0; - unsigned char stack[128]; - int stack_pos = 0; - - int mode_varargs = 0; - int i; - for (i=0; args[i]; i++) - { - if (args[i] == '.') - { - mode_varargs = 1; - continue; - } - *(int *)(stack + stack_pos) = *(int*)(data + data_pos); - - if (args[i] == 'f' && mode_varargs) - { - double tmp_double = (double)*(float *)(data + data_pos); - memcpy(stack + stack_pos, &tmp_double, 8); - } - if (args[i] == 'd') - { - double tmp_double = *(double *)(data + data_pos); - memcpy(stack + stack_pos, &tmp_double, 8); - } - - stack_pos += 4; // even 1-byte-chars will be 4-byte-aligned on stack - if (args[i] == 'f' && mode_varargs) - stack_pos += 4; // use 8 bytes for varargs/float, aka double - if (args[i] == 'd') - stack_pos += 4; // use 8 bytes for normal double - - switch (args[i]) - { - case 'i': - case 's': - case 'f': - data_pos += 4; - break; - case 'c': - data_pos += 1; - break; - case 'd': - data_pos += 8; - break; - } - } - - // http://wiki.osdev.org/Inline_Assembly - unsigned char *sp; - asm("movl %%esp, %0" : "=g" (sp)); - - memcpy(sp, stack, stack_pos); - - asm("movl %0, %%eax" : : "g" (func_address)); - asm("call *%eax"); - - int ret; - asm("movl %%eax, %0" : "=g" (ret)); - return ret; } \ No newline at end of file diff --git a/cracking.hpp b/cracking.hpp index 26d3a92..a6761ab 100755 --- a/cracking.hpp +++ b/cracking.hpp @@ -10,8 +10,6 @@ extern "C" { void cracking_hook_function(int from, int to); void cracking_hook_call(int from, int to); -int cracking_call_function(int func_address, char *args, unsigned char *data); - #ifdef __cplusplus } #endif diff --git a/gsc.cpp b/gsc.cpp index c60e3cf..e436ef4 100644 --- a/gsc.cpp +++ b/gsc.cpp @@ -191,7 +191,6 @@ scr_function_t scriptFunctions[] = {"FS_LoadDir", gsc_utils_FS_LoadDir, 0}, {"getType", gsc_utils_getType, 0}, {"float", gsc_utils_float, 0}, - {"rundll", gsc_utils_rundll, 0}, {"Cmd_ExecuteString", gsc_utils_ExecuteString, 0}, {"sendGameServerCommand", gsc_utils_sendgameservercommand, 0}, {"scandir", gsc_utils_scandir, 0}, @@ -208,10 +207,6 @@ scr_function_t scriptFunctions[] = {"getconfigstring", gsc_get_configstring, 0}, {"setconfigstring", gsc_set_configstring, 0}, {"makelocalizedstring", gsc_make_localized_string, 0}, - {"call_function_raw", gsc_call_function_raw, 0}, - {"dlopen", gsc_dlopen, 0}, - {"dlsym", gsc_dlsym, 0}, - {"dlclose", gsc_dlclose, 0}, {"sqrt", gsc_utils_sqrt, 0}, {"sqrtInv", gsc_utils_sqrtInv, 0}, {"getlasttestclientnumber", gsc_utils_getlasttestclientnumber, 0}, diff --git a/gsc_utils.cpp b/gsc_utils.cpp index 8f4378b..e3c637b 100644 --- a/gsc_utils.cpp +++ b/gsc_utils.cpp @@ -453,43 +453,6 @@ void gsc_utils_float() } } -// rundll("print.so", "test_print") -void gsc_utils_rundll() -{ - char *arg_library, *arg_function; - if ( ! stackGetParams("ss", &arg_library, &arg_function)) - { - stackError("gsc_utils_rundll() one or more arguments is undefined or has a wrong type"); - stackPushUndefined(); - return; - } - Com_DPrintf("lib=%s func=%s\n", arg_library, arg_function); - //void *handle = dlopen(arg_library, RTLD_GLOBAL); // crashes - //void *handle = dlopen(arg_library, RTLD_LOCAL); // crashes - //void *handle = dlopen(arg_library, RTLD_NOW); // crashes - void *handle = dlopen(arg_library, RTLD_LAZY); - if ( ! handle) - { - stackError("dlopen(\"%s\") failed", arg_library); - stackPushInt(0); - return; - } - Com_DPrintf("dlopen(\"%s\") returned: %.8x\n", arg_library, (unsigned int)handle); - void (*func)(); - //*((void *)&func) = dlsym(handle, arg_function); - *(int *)&func = (int)dlsym(handle, arg_function); - if (!func) - { - stackError("dlsym(\"%s\") failed", arg_function); - stackPushInt(0); - return; - } - Com_DPrintf("function-name=%s -> address=%.8x\n", arg_function, (unsigned int)func); - func(); - dlclose(handle); - stackPushInt(1); -} - void gsc_utils_ExecuteString() { char *str; @@ -733,78 +696,6 @@ void gsc_set_configstring() stackPushInt(1); } -void gsc_call_function_raw() -{ - int func_address; - char *args; - unsigned char *data; - if ( ! stackGetParams("isi", &func_address, &args, &data)) - { - stackError("gsc_call_function_raw() one or more arguments is undefined or has a wrong type"); - stackPushUndefined(); - return; - } - stackPushInt(cracking_call_function(func_address, args, data)); -} - -void gsc_dlopen() -{ - char *arg_library; - if ( ! stackGetParams("s", &arg_library)) - { - stackError("gsc_dlopen() argument is undefined or has a wrong type"); - stackPushUndefined(); - return; - } - int handle = (int)dlopen(arg_library, RTLD_LAZY); - if ( ! handle) - { - stackError("dlopen(\"%s\") failed! Error: %s", arg_library, dlerror()); - stackPushInt(0); - return; - } - stackPushInt(handle); -} - -void gsc_dlsym() -{ - int handle; - char *arg_function; - if ( ! stackGetParams("is", &handle, &arg_function)) - { - stackError("gsc_dlsym() one or more arguments is undefined or has a wrong type"); - stackPushUndefined(); - return; - } - int func = (int)dlsym((void *)handle, arg_function); - if (!func) - { - stackError("dlsym(\"%s\") failed! Error: %s", arg_function, dlerror()); - stackPushInt(0); - return; - } - stackPushInt(func); -} - -void gsc_dlclose() -{ - int handle; - if ( ! stackGetParams("i", &handle)) - { - stackError("gsc_dlclose() argument is undefined or has a wrong type"); - stackPushUndefined(); - return; - } - int ret = dlclose((void *)handle); - if (ret != 0) - { - stackError("dlclose(%d) failed! Error: %s", handle, dlerror()); - stackPushInt(0); - return; - } - stackPushInt(ret); -} - void gsc_utils_sqrt() { float x; diff --git a/gsc_utils.hpp b/gsc_utils.hpp index 0e50810..c58781d 100644 --- a/gsc_utils.hpp +++ b/gsc_utils.hpp @@ -29,7 +29,6 @@ void gsc_utils_file_exists(); void gsc_utils_FS_LoadDir(); void gsc_utils_getType(); void gsc_utils_float(); -void gsc_utils_rundll(); void gsc_utils_ExecuteString(); void gsc_utils_sendgameservercommand(); void gsc_utils_scandir(); @@ -39,7 +38,6 @@ void gsc_get_configstring(); void gsc_set_configstring(); void gsc_make_localized_string(); void gsc_utils_getlasttestclientnumber(); - void gsc_utils_fopen(); void gsc_utils_fread(); void gsc_utils_fwrite(); @@ -48,13 +46,6 @@ void gsc_utils_fsize(); void gsc_utils_sprintf(); void gsc_utils_getsystemtime(); void gsc_utils_getlocaltime(); - -void gsc_call_function_raw(); - -void gsc_dlopen(); -void gsc_dlsym(); -void gsc_dlclose(); - void gsc_utils_sqrt(); void gsc_utils_sqrtInv();