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

Function patchFunction

inject/injectee_iat.cpp:599–629  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

597
598template< class T >
599static BOOL
600patchFunction(HMODULE hModule,
601 const char *szModule,
602 const char *pszDllName,
603 T pImportDescriptor,
604 const char *pszFunctionName,
605 LPVOID lpOldAddress,
606 LPVOID lpNewAddress)
607{
608 LPVOID* lpPatchAddress = getPatchAddress(hModule, pImportDescriptor, pszFunctionName, lpOldAddress);
609 if (lpPatchAddress == NULL) {
610 return FALSE;
611 }
612
613 if (*lpPatchAddress == lpNewAddress) {
614 return TRUE;
615 }
616
617 DWORD Offset = (DWORD)(UINT_PTR)lpPatchAddress - (UINT_PTR)hModule;
618 if (VERBOSITY > 0) {
619 debugPrintf("inject: patching %s!0x%lx -> %s!%s\n", szModule, Offset, pszDllName, pszFunctionName);
620 }
621
622 BOOL bRet;
623 bRet = replaceAddress(lpPatchAddress, lpNewAddress);
624 if (!bRet) {
625 debugPrintf("inject: failed to patch %s!0x%lx -> %s!%s\n", szModule, Offset, pszDllName, pszFunctionName);
626 }
627
628 return bRet;
629}
630
631
632

Callers 1

patchDescriptorFunction · 0.85

Calls 3

getPatchAddressFunction · 0.85
replaceAddressFunction · 0.85
debugPrintfFunction · 0.70

Tested by

no test coverage detected