您需要使用自定义 CreateFile 创建注入 DLL,如下所示:
/** We'll create a custom version of the CreateFile (WinAPI).
*
*
*/
HANDLE WINAPI __CreateFile(LPCWSTR fileName,
DWORD desiredAccess,
DWORD shareMode,
LPSECURITY_ATTRIBUTES securityAttributes,
DWORD createDisp,
DWORD flags,
HANDLE tmp)
{
// At very first, we shall call the original CreateFile.
HANDLE file = Real_CreateFile(fileName,
desiredAccess,
shareMode,
securityAttributes,
createDisp,
flags,
tmp);
/** Here, you can do whatever you wish with fileName and the handle, file.
*
* ...
*/
return file;
}
然而,这还不够。您还需要从 Detours 中受益:
BOOL APIENTRY DllMain(HANDLE module, DWORD reasonForCall, LPVOID reserved)
{
switch (reasonForCall) {
case DLL_PROCESS_ATTACH: {
if (::GetModuleHandle(L"blablabla.exe") == NULL) {
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourAttach(&(PVOID &)Real_CreateFile, __CreateFile);
DetourTransactionCommit();
}
break;
case DLL_THREAD_ATTACH: {
}
break;
case DLL_THREAD_DETACH: {
}
break;
case DLL_PROCESS_DETACH: {
if (::GetModuleHandle(L"blablabla.exe") == NULL) {
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourDetach(&(PVOID&)Real_CreateFile, __CreateFile);
DetourTransactionCommit();
}
}
}
return TRUE;
}
我把剩下的留给你练习。这只是一个方向。您还需要找到合适的 IPC 方法来进行数据传输。