Skip to content

Commit

Permalink
introduced configurable retaddr check
Browse files Browse the repository at this point in the history
  • Loading branch information
jbremer committed Jan 14, 2013
1 parent 56acbe5 commit 4264155
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 0 deletions.
3 changes: 3 additions & 0 deletions config.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ void read_config()
else if(!strcmp(key, "first-process")) {
g_config.first_process = value[0] == '1';
}
else if(!strcmp(key, "retaddr-check")) {
g_config.retaddr_check = value[0] == '1';
}
}
}
fclose(fp);
Expand Down
3 changes: 3 additions & 0 deletions config.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ struct {

// is this the first process or not?
int first_process;

// do we want to enable the retaddr check?
int retaddr_check;
} g_config;

void read_config();
5 changes: 5 additions & 0 deletions cuckoomon.c
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,11 @@ BOOL APIENTRY DllMain(HANDLE hModule, DWORD dwReason, LPVOID lpReserved)
// initialize the Sleep() skipping stuff
init_sleep_skip(g_config.first_process);

// disable the retaddr check if the user wants so
if(g_config.retaddr_check == 0) {
hook_disable_retaddr_check();
}

// initialize all hooks
set_hooks();

Expand Down
14 changes: 14 additions & 0 deletions hooking.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ typedef struct _hook_info_t {

static void ensure_valid_hook_info();

// by default we enable the retaddr check
static int g_enable_retaddr_check = 1;

// length disassembler engine
int lde(void *addr)
{
Expand Down Expand Up @@ -82,6 +85,12 @@ static inline void __writefsdword(unsigned int index, unsigned int value)

static int is_valid_backtrace(unsigned int ebp)
{
// only perform this function when the retaddr-check is enabled, otherwise
// return true in all cases
if(g_enable_retaddr_check == 0) {
return 1;
}

// http://en.wikipedia.org/wiki/Win32_Thread_Information_Block
unsigned int top = __readfsdword(0x04);
unsigned int bottom = __readfsdword(0x08);
Expand Down Expand Up @@ -780,3 +789,8 @@ void hook_set_last_error(unsigned int errcode)
ensure_valid_hook_info();
hook_info()->last_error = errcode;
}

void hook_disable_retaddr_check()
{
g_enable_retaddr_check = 0;
}
2 changes: 2 additions & 0 deletions hooking.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ int hook_is_inside();
unsigned int hook_get_last_error();
void hook_set_last_error(unsigned int errcode);

void hook_disable_retaddr_check();

#define HOOK_BACKTRACE_DEPTH 20

#define HOOK_ENABLE_FPU 0
Expand Down

0 comments on commit 4264155

Please sign in to comment.