Skip to content

Commit c0aeb2b

Browse files
authored
Merge pull request #86 from dillonfranke/master
Set Default Behavior to Skip Re-Instrumentation of Duplicate Modules
2 parents ed07784 + 521ec50 commit c0aeb2b

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

hook.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ It is expected that most hooking operations can be performed just using the brea
2323

2424
If a hook needs to add additional assembly code, this can be done by implementing `WriteCodeBefore`/`WriteCodeAfter` methods of the hook class. Assembly code can be inserted by calling the `WriteCode` function with the buffer containing the assembly to be inserted. Note that both `WriteCodeBefore`/`WriteCodeAfter` get called during instrumentation time (before the function gets run) and, due to how `HookBeginEnd` is implemented, `WriteCodeAfter` can be called multiple times for a single hooked function.
2525

26-
Once the hook classes have been implemented for each function the user wants to hook, the user can register them by calling `RegisterHook` method inside their clien's constructor.
26+
Once the hook classes have been implemented for each function the user wants to hook, the user can register them by calling `RegisterHook` method inside their client's constructor.
2727

2828
### Example
2929

tinyinst.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -846,10 +846,12 @@ void TinyInst::OnModuleInstrumented(ModuleInfo* module) {
846846
} else if(hook->GetFunctionOffset()) {
847847
address = (size_t)(module->module_header) + hook->GetFunctionOffset();
848848
} else {
849-
FATAL("Hook specifies neithr function name nor offset");
849+
FATAL("Hook specifies neither function name nor offset");
850850
}
851851
if(address) {
852852
resolved_hooks[address] = hook;
853+
} else if (hook->GetModuleName() != std::string("*")) {
854+
WARN("Could not resolve function %s in module %s", hook->GetFunctionName().c_str(), hook->GetModuleName().c_str());
853855
}
854856
}
855857
}
@@ -1075,9 +1077,8 @@ void TinyInst::OnInstrumentModuleLoaded(void *module, ModuleInfo *target_module)
10751077
target_module->module_header &&
10761078
(target_module->module_header != (void *)module))
10771079
{
1078-
WARN("Instrumented module loaded on a different address than seen previously\n"
1079-
"Module will need to be re-instrumented. Expect a drop in performance.");
1080-
ClearInstrumentation(target_module);
1080+
WARN("Skipping re-instrumentation of duplicate module %s.", target_module->module_name.c_str());
1081+
return;
10811082
}
10821083

10831084
target_module->module_header = (void *)module;
@@ -1095,7 +1096,7 @@ void TinyInst::OnInstrumentModuleLoaded(void *module, ModuleInfo *target_module)
10951096
}
10961097
}
10971098

1098-
// called when a potentialy interesting module gets loaded
1099+
// called when a potentially interesting module gets loaded
10991100
void TinyInst::OnModuleLoaded(void *module, char *module_name) {
11001101
Debugger::OnModuleLoaded(module, module_name);
11011102

0 commit comments

Comments
 (0)