function myNtDeviceIoControlFile(FileHandle:THANDLE;Event:THANDLE;ApcRoutine:PIO_APC_ROUTINE;ApcContext:PVOID;IoStatusBlock:PIO_STATUS_BLOCK;IoControlCode:ULONG;InputBuffer:PVOID;InputBufferLength:ULONG;OutputBuffer:PVOID;OutputBufferLength:ULONG):NTSTATUS;stdcall;
var
AfdInfo: PAFD_INFO;
Buff: PAnsiChar;
Len: DWORD;
sid,Url,reStr,reVal:String;
begin
Result := OldNtDeviceIoControlFile(FileHandle,Event,ApcRoutine,ApcContext,IoStatusBlock,IoControlCode,InputBuffer,InputBufferLength,OutputBuffer,OutputBufferLength);
if Result <> 0) then Exit; // 原始函数返回失败 则退出
OutputDebugString(Pchar(IntToHex(FileHandle,8)));
//就这么简单,Hook后,直接调用源函数,然后输出句柄。都经常崩溃。。。马丹
end;
function myNtDeviceIoControlFile(FileHandle:THANDLE;Event:THANDLE;ApcRoutine:PIO_APC_ROUTINE;ApcContext:PVOID;IoStatusBlock:PIO_STATUS_BLOCK;IoControlCode:ULONG;InputBuffer:PVOID;InputBufferLength:ULONG;OutputBuffer:PVOID;OutputBufferLength:ULONG):NTSTATUS;stdcall;
var
sid:String;
isHttp:Bool;
myeid,nteid:Dword;
begin
isHttp := False;myeid := 0;nteid := 0;
if ((IoControlCode = AFD_SEND) or (IoControlCode = AFD_RECV)) and (Event <> 0) then
begin
myeid := CreateEvent(nil,False,False,nil);
nteid := Event;
Event := myeid;
isHttp := True;
end;
//执行源函数
Result := OldNtDeviceIoControlFile(FileHandle,Event,ApcRoutine,ApcContext,IoStatusBlock,IoControlCode,InputBuffer,InputBufferLength,OutputBuffer,OutputBufferLength);
if not isHttp then Exit;
if Result <> 0 then
begin
SetEvent(nteid);
CloseHandle(myeid);
Exit;
end;
WaitForSingleObject(myeid,INFINITE);
//sid := 'ddddddddddddddddddddd';
sid := InttoStr(FileHandle);
//dbg(sid);
SetEvent(nteid);
closeHandle(myeid);
end;