| 597 | |
| 598 | template< class T > |
| 599 | static BOOL |
| 600 | patchFunction(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 |
no test coverage detected