Skip to content

Commit

Permalink
Remove some...really unnecessary functions
Browse files Browse the repository at this point in the history
This stuff..idk..i don't think anyone EVER gonna need this
  • Loading branch information
voron00 committed Oct 14, 2017
1 parent 431e4ff commit eec2e57
Show file tree
Hide file tree
Showing 5 changed files with 0 additions and 189 deletions.
64 changes: 0 additions & 64 deletions cracking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
2 changes: 0 additions & 2 deletions cracking.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 0 additions & 5 deletions gsc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -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},
Expand Down
109 changes: 0 additions & 109 deletions gsc_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
9 changes: 0 additions & 9 deletions gsc_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -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();

Expand Down

0 comments on commit eec2e57

Please sign in to comment.