Skip to content

Commit

Permalink
Merge pull request #86 from dillonfranke/master
Browse files Browse the repository at this point in the history
Set Default Behavior to Skip Re-Instrumentation of Duplicate Modules
  • Loading branch information
ifratric authored Dec 17, 2024
2 parents ed07784 + 521ec50 commit c0aeb2b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion hook.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ It is expected that most hooking operations can be performed just using the brea

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.

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.
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.

### Example

Expand Down
11 changes: 6 additions & 5 deletions tinyinst.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -846,10 +846,12 @@ void TinyInst::OnModuleInstrumented(ModuleInfo* module) {
} else if(hook->GetFunctionOffset()) {
address = (size_t)(module->module_header) + hook->GetFunctionOffset();
} else {
FATAL("Hook specifies neithr function name nor offset");
FATAL("Hook specifies neither function name nor offset");
}
if(address) {
resolved_hooks[address] = hook;
} else if (hook->GetModuleName() != std::string("*")) {
WARN("Could not resolve function %s in module %s", hook->GetFunctionName().c_str(), hook->GetModuleName().c_str());
}
}
}
Expand Down Expand Up @@ -1075,9 +1077,8 @@ void TinyInst::OnInstrumentModuleLoaded(void *module, ModuleInfo *target_module)
target_module->module_header &&
(target_module->module_header != (void *)module))
{
WARN("Instrumented module loaded on a different address than seen previously\n"
"Module will need to be re-instrumented. Expect a drop in performance.");
ClearInstrumentation(target_module);
WARN("Skipping re-instrumentation of duplicate module %s.", target_module->module_name.c_str());
return;
}

target_module->module_header = (void *)module;
Expand All @@ -1095,7 +1096,7 @@ void TinyInst::OnInstrumentModuleLoaded(void *module, ModuleInfo *target_module)
}
}

// called when a potentialy interesting module gets loaded
// called when a potentially interesting module gets loaded
void TinyInst::OnModuleLoaded(void *module, char *module_name) {
Debugger::OnModuleLoaded(module, module_name);

Expand Down

0 comments on commit c0aeb2b

Please sign in to comment.