我不知道從偏移.text段,但在調試器中查看您想要的地址並從中減去模塊加載偏移量。即使基地址是明確設置的,它也可能每次都在不同的地址加載。
替代運行時修補可能只是簡單地修補dll本身。 OllyDbg是一款優秀的免費彙編級調試器和代碼分析工具,可讓您輕鬆修補二進制文件。
編輯:
只是爲了好玩這是我用來使用擴展二進制補丁了一些功能我沒有在一個應用程序像一些示例代碼 - 在運行時。我做了一些簡化,沒有重新編譯和測試,但你應該明白。
(我有二進制被週期性地更新的複雜化,因此,附加的工作模式匹配的小範圍從已知偏移之內。)
void MyCrazyPatch()
{
static bool patched = false;
if (!patched)
{
patched = true;
DWORD dwPatchOffsetStart = 0x5310;
DWORD dwPatchLength = 22;
BYTE rgPatchMatch[] = { 0xab, 0x07, 0x37, 0x56, 0x50, 0xe8, 0x92, 0xfb, 0xff, 0xff, 0x83,
0xf8, 0x01, 0x89, 0xb5, 0xfc, 0x0f, 0x85, 0xb2, 0xaa, 0x00, 0x00, 0x8b };
HMODULE hmod = GetModuleHandle(L"mybinary.dll");
if (hmod != NULL
{
MODULEINFO modInfo;
if (GetModuleInformation(GetCurrentProcess(),
hmod,
&modInfo,
sizeof(modInfo)))
{
DWORD dwIncrement = 0;
dwPatchOffsetStart += (DWORD)modInfo.lpBaseOfDll;
while (dwIncrement < 0x200 &&
memcmp((void*)(dwPatchOffsetStart + dwIncrement),
rgPatchMatch,
sizeof(rgPatchMatch)) != 0)
{
dwIncrement++;
}
// Sanity check then add nop's to stomp out the offending code.
if (dwIncrement < 0x200 &&
memcmp((void*)(dwPatchOffsetStart + dwIncrement),
rgPatchMatch,
sizeof(rgPatchMatch)) == 0)
{
DWORD dwOldProtect = 0;
VirtualProtect((void*)(dwPatchOffsetStart + dwIncrement),
dwPatchLength,
PAGE_EXECUTE_READWRITE,
&dwOldProtect);
memset((void*)(dwPatchOffsetStart + dwIncrement), 0x90, dwPatchLength);
VirtualProtect((void*)(dwPatchOffsetStart + dwIncrement),
dwPatchLength,
dwOldProtect,
NULL);
}
}
}
}
}
沒有,這將工作。更改可執行頁面將觸發寫入時複製,因此運行過程將永久使用修補後的代碼。 – 2009-08-06 02:19:57