Windows で IAT のフックを実行するコードを書いています。IAT (Kernel32!GetCurrentProcessId) でターゲット関数のアドレスを変更することはできますが、プログラムの後半で、フックされた関数が呼び出されると、フックの代わりに Kernel32!GetCurrentProcessId が呼び出されます。
プロセスをデバッグすると、Kernel!GetCurrentProcessId の元の IAT アドレスを確認できます。
GetCurrentProcessId アドレス: 7C8099C0
スワップインしたい関数は次のとおりです。
MyGetCurrentProcessId アドレス: 100118BB
thunkIAT->u1.Function のアドレスをフックし、7C8099C0 から 100118BB に変更しますが、前述のように、プログラム内から GetCurrentProcessId() が呼び出されると、Kernel32 関数が呼び出されます (私が注入したものではありません)。
フックを実行するコードの一部は次のとおりです。
if(strcmp(apiName,(char*)(*nameData).Name)==0)
{
DBG_PRINT2("[processImportDescriptor]: found match for %s\n", apiName);
VirtualProtect(
&thunkIAT->u1.Function, // start addres of the zone to "unlock"
0x010, // size to protect
PAGE_EXECUTE_READWRITE, // new permission
&dwOldProtect // old permission
);
procPtr = MyGetCurrentProcessId;
thunkIAT->u1.Function = (DWORD)procPtr;
DBG_PRINT2("MyGetCurrentProcessId() address: %08X\n", MyGetCurrentProcessId);
DBG_PRINT2("procPtr address: %08X\n", procPtr);
DBG_PRINT2("thunkIAT->u1.Function address: %08X\n", thunkIAT->u1.Function);
VirtualProtect(
&thunkIAT->u1.Function, // start addres of the zone to "relock"
0x0010, // size to protect
dwOldProtect, // new permission
&dwOldProtect2 // old permission
);
}
何かご意見は?ありがとうございました。