Skip to content

Commit 489aa59

Browse files
committed
add plugin_name as parameter to hook loading functions
This is mainly for the sake of better logging
1 parent d3ba3b8 commit 489aa59

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

src/core/PIUTools_Filesystem.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ void PIUTools_Filesystem_Redirect_Init(void){
115115
PHookEntry fsredirect_entry = filesystem_redirect_entries;
116116
if (fsredirect_entry != NULL) {
117117
while (fsredirect_entry->hook_type != HOOK_ENTRY_END) {
118-
PIUTools_Plugin_LoadHook(fsredirect_entry);
118+
PIUTools_Plugin_LoadHook(fsredirect_entry, "filesystem_redirect");
119119
// Move to the next entry
120120
fsredirect_entry++;
121121
}

src/core/PIUTools_Hook.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@ static int piutools_hook_init(void){
3737
return 1;
3838
}
3939

40-
static void print_hook_status(const char* hook_type, const char* module_name, const char* library_name, const char* function_name, int hook_status){
40+
static void print_hook_status(const char* hook_type, const char* plugin_name, const char* module_name, const char* library_name, const char* function_name, int hook_status){
4141
const char* hook_fail_msg = "\033[1;31mHook Fail:\033[0m";
4242
const char* hook_ok_msg = "\033[1;32mHook OK:\033[0m";
4343
const char* hook_status_msg = (hook_status) ? hook_ok_msg:hook_fail_msg;
4444
if(module_name == NULL){
4545
module_name = "Main Executable";
4646
}
4747

48-
DBG_printf("[%s]: %s -- %s %s %s",hook_type,hook_status_msg, module_name, library_name, function_name);
48+
DBG_printf("[plugin:%s][%s]: %s -- %s %s %s", plugin_name, hook_type, hook_status_msg, module_name, library_name, function_name);
4949
}
5050

5151
int PIUTools_Hook_GetFunctionAddress(const char* library_name, const char* function_name, void** pfunction_address){
@@ -78,16 +78,16 @@ int PIUTools_Hook_GetFunctionAddress(const char* library_name, const char* funct
7878

7979

8080

81-
void* PIUTools_Hook_Inline(const char* module_name, const char* function_name, void* hook_addr){
81+
void* PIUTools_Hook_Inline(const char* module_name, const char* function_name, void* hook_addr, const char *plugin_name){
8282
if(!module_initialized){if(!piutools_hook_init()){exit(-1);}}
8383
void* res = hook_function_byname(module_name,function_name, hook_addr);
84-
print_hook_status("HOOK_INLINE",module_name,"",function_name,(res != NULL));
84+
print_hook_status("HOOK_INLINE",plugin_name,module_name,"",function_name,(res != NULL));
8585
return res;
8686
}
8787

88-
void* PIUTools_Hook_Import(const char* module_name, const char* library_name, const char* function_name, void* hook_addr){
88+
void* PIUTools_Hook_Import(const char* module_name, const char* library_name, const char* function_name, void* hook_addr, const char *plugin_name){
8989
if(!module_initialized){if(!piutools_hook_init()){exit(-1);}}
9090
void* res = hook_import_byname(module_name,library_name,function_name,hook_addr);
91-
print_hook_status("HOOK_IMPORT",module_name,library_name,function_name,(res != NULL));
91+
print_hook_status("HOOK_IMPORT",plugin_name,module_name,library_name,function_name,(res != NULL));
9292
return res;
9393
}

src/core/PIUTools_Plugin.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ static void load_plugin(const char* plugin_name){
2828

2929
if (cur_entry != NULL) {
3030
while (cur_entry->hook_type != HOOK_ENTRY_END) {
31-
PIUTools_Plugin_LoadHook((void*)cur_entry);
31+
PIUTools_Plugin_LoadHook((void*)cur_entry, plugin_name);
3232
// Move to the next entry
3333
cur_entry++;
3434
}
@@ -58,17 +58,17 @@ void PIUTools_Plugin_Init(void){
5858
ini_parse(plugin_config_path,parse_loader_config,NULL);
5959
}
6060

61-
void PIUTools_Plugin_LoadHook(void* ventry){
61+
void PIUTools_Plugin_LoadHook(void* ventry, const char *plugin_name){
6262
PHookEntry entry = (PHookEntry)ventry;
6363
if(!module_initialized){PIUTools_Plugin_Init();}
6464
if(entry->hook_enabled){
6565
void* rfa;
6666
switch(entry->hook_type){
6767
case HOOK_TYPE_INLINE:
68-
rfa = PIUTools_Hook_Inline(entry->source_library_name,entry->target_function_name, entry->hook_function_addr);
68+
rfa = PIUTools_Hook_Inline(entry->source_library_name,entry->target_function_name, entry->hook_function_addr, plugin_name);
6969
break;
7070
case HOOK_TYPE_IMPORT:
71-
rfa = PIUTools_Hook_Import(entry->target_binary_name,entry->source_library_name,entry->target_function_name, entry->hook_function_addr);
71+
rfa = PIUTools_Hook_Import(entry->target_binary_name,entry->source_library_name,entry->target_function_name, entry->hook_function_addr, plugin_name);
7272
break;
7373
default:
7474
break;
@@ -77,4 +77,4 @@ void PIUTools_Plugin_LoadHook(void* ventry){
7777
*entry->original_function_addr_ptr = rfa;
7878
}
7979
}
80-
}
80+
}

0 commit comments

Comments
 (0)