MCPcopy Create free account
hub / github.com/apitrace/apitrace / patchModule

Function patchModule

inject/injectee_iat.cpp:726–819  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

724
725
726static void
727patchModule(HMODULE hModule,
728 const char *szModule,
729 Action action)
730{
731 /* Never patch this module */
732 if (hModule == g_hThisModule) {
733 return;
734 }
735
736 /* Never patch our hook module */
737 if (hModule == g_hHookModule) {
738 return;
739 }
740
741 /* Hook modules only once */
742 if (action == ACTION_HOOK) {
743 std::pair< std::set<HMODULE>::iterator, bool > ret;
744 EnterCriticalSection(&g_Mutex);
745 ret = g_hHookedModules.insert(hModule);
746 LeaveCriticalSection(&g_Mutex);
747 if (!ret.second) {
748 return;
749 }
750 }
751
752 const char *szBaseName = getBaseName(szModule);
753
754 /* Don't hook our replacement modules to avoid tracing internal APIs */
755 /* XXX: is this really a good idea? */
756 if (isMatchModuleName(szBaseName)) {
757 return;
758 }
759
760 /* Leave these modules alone.
761 *
762 * Hooking other injection DLLs easily leads to infinite recursion (and
763 * stack overflow), especially when those libraries use techniques like
764 * modifying the hooked functions prolog (instead of patching IAT like we
765 * do).
766 *
767 * See also:
768 * - http://www.nynaeve.net/?p=62
769 */
770 if (stricmp(szBaseName, "kernel32.dll") == 0 ||
771 stricmp(szBaseName, "AcLayers.dll") == 0 ||
772 stricmp(szBaseName, "ConEmuHk.dll") == 0 ||
773 stricmp(szBaseName, "gameoverlayrenderer.dll") == 0 ||
774 stricmp(szBaseName, "gameoverlayrenderer64.dll") == 0 ||
775 stricmp(szBaseName, "nvoglv32.dll") == 0 ||
776 stricmp(szBaseName, "nvoglv64.dll") == 0) {
777 return;
778 }
779
780 if (VERBOSITY > 0) {
781 debugPrintf("inject: found module %s\n", szModule);
782 }
783

Callers 1

patchAllModulesFunction · 0.70

Calls 8

getBaseNameFunction · 0.85
isMatchModuleNameFunction · 0.85
getFirstImportDescriptorFunction · 0.85
patchDescriptorFunction · 0.85
getDelayImportDescriptorFunction · 0.85
getDescriptorNameFunction · 0.85
debugPrintfFunction · 0.70
insertMethod · 0.45

Tested by

no test coverage detected