请尝试使用easyhook,因为我手边除了Windows机器之外没有其他设备。
以下只是调用流程(类似于我多年前所做的事情,通过Detours将软件的套接字绑定端口更改为不同的端口)
关于Hook the CreateFileW:
在easyhook维基中的示例正是我们想要的。
CreateFileHook = LocalHook.Create(
LocalHook.GetProcAddress("kernel32.dll", "CreateFileW"),
new DCreateFile(CreateFile_Hooked),
this);
CreateFile_Hooked
函数中,您可以更改参数InFileName
,然后调用真正的CreateFileW
函数。static IntPtr CreateFile_Hooked(
String InFileName,
UInt32 InDesiredAccess,
UInt32 InShareMode,
IntPtr InSecurityAttributes,
UInt32 InCreationDisposition,
UInt32 InFlagsAndAttributes,
IntPtr InTemplateFile)
{
// FIGURE OUT THE FILE NAME THAT YOU WANT HERE
// IF the InFileName is not your Document name "My.doc", then call orignal CreateFile
// with all the parameter unchanged.
// call original API...
return CreateFile(
YOUR_CHANGED_FILE_NAME_HERE,
InDesiredAccess,
InShareMode,
InSecurityAttributes,
InCreationDisposition,
InFlagsAndAttributes,
InTemplateFile);
}
呼叫流程:
在您将标题更改为“My_Document_2012_11_29”之后,钩取Word进程的CreateFileW。例如,当InFileName为“My.doc”时, 则应将其更改为“My_Document_2012_11_29”。
由于这是在Word进程中完成的,因此Detoured函数不知道“My.doc”映射到“My_Document_2012_11_29”。 有很多方法可以获取此映射信息,其中一种方法是将此映射信息保存到应用程序中的已知文件中,并在Detoured函数中读取该文件。