X
xawangting
Unregistered / Unconfirmed
GUEST, unregistred user!
这是原函数声明:<br>type<br> TZwQueryDirectoryFileNextHook = function(FileHandle: THANDLE; Event: THANDLE;<br> ApcRoutine: PIO_APC_ROUTINE; ApcContext: pointer; IoStatusBlock:<br> PIO_STATUS_BLOCK;<br> FileInformation: PVOID; FileInformationLength: ULONG; FileInformationClass:<br> FILE_INFORMATION_CLASS;<br> ReturnSingleEntry: BOOLEAN; FileName: PUNICODE_STRING; RestartScan:<br> BOOLEAN): DWORD; stdcall;<br><br>替换的函数<br>function SundyNtQueryDirectoryFile(FileHandle: THANDLE; Event: THANDLE;<br> ApcRoutine: PIO_APC_ROUTINE; ApcContext: pointer; IoStatusBlock:<br> PIO_STATUS_BLOCK;<br> FileInformation: PVOID; FileInformationLength: ULONG; FileInformationClass:<br> FILE_INFORMATION_CLASS;<br> ReturnSingleEntry: BOOLEAN; FileName: PUNICODE_STRING; RestartScan: BOOLEAN):<br> DWORD; stdcall;<br>var<br> P: Pointer;<br> Curr, Prev: PFILE_BOTH_DIRECTORY_INFORMATION;<br> i: integer;<br> PW: PWideChar;<br> FNI: PFILE_NAME_INFORMATION;<br>begin<br> try<br> WriteLog('c:/debug.txt', 'SundyNtQueryDirectoryFile执行了');<br> P := RestoreApiProc(1);<br> result := TZwQueryDirectoryFileNextHook(P)(FileHandle, Event, ApcRoutine,<br> ApcContext,<br> IoStatusBlock, FileInformation, FileInformationLength,<br> FileInformationClass, ReturnSingleEntry, FileName, RestartScan);<br> if FileBothDirectoryInformation = FileInformationClass then<br> begin<br> Prev := nil;<br> Curr := PFILE_BOTH_DIRECTORY_INFORMATION(FileInformation);<br> while Curr^.NextEntryOffset > 0 do<br> begin<br> if isHideFile(<br> PWideChar(DWORD(@PFILE_BOTH_DIRECTORY_INFORMATION(Curr)^.FileName[0])<br> + 1)<br>   and (Curr^.FileAttributes = 16) then<br> begin<br> if Curr^.NextEntryOffset = 0 then<br> begin<br> if Prev = nil then<br> exit;<br> Prev^.NextEntryOffset := 0;<br> break;<br> end<br> else<br> begin<br> Prev^.NextEntryOffset := Prev^.NextEntryOffset +<br> Curr^.NextEntryOffset;<br> DWORD(Curr) := DWORD(Curr) + Curr^.NextEntryOffset;<br> end;<br> end<br> else<br> begin<br> Prev := Curr;<br> DWORD(Curr) := DWORD(Curr) + Curr^.NextEntryOffset;<br> end;<br> end;<br> end;<br> SundyTools.ReplaceApiProc(PID, P, @SundyNtQueryDirectoryFile, 1);<br> FDHooked := TRUE;<br> except<br> if FDHooked then<br> SundyTools.RestoreApiProc(1);<br> FDHooked := FALSE;<br> end;<br> WriteLog('c:/debug.txt', 'SundyNtQueryDirectoryFile执行了');<br><br>end;<br> SundyTools.RestoreApiProc函数:<br>function ReplaceApiProc(ProcessId: DWORD; OldP: Pointer; NewP: Pointer; index: integer): Pointer;<br>var<br> R: DWORD;<br> old,Newointer;<br>begin<br> try<br> Result := OldP;<br> ss.JmpCode :=$B8;<br> ss.Address :=NewP;<br> ss.MovEAX[0] := $FF;<br> ss.MovEAX[1] := $E0;<br> ss.MovEAX[2] := 0;<br> //保存原函数地址<br> OldAdd[index]:=dword(oldp);<br>//读取缓存区<br> old:=Pointer(@ReplaceCode[index][0]);<br> new:=@ss;<br> WriteLog('c:/SundyTools.txt','old: '+inttostr(dword(old))+'New: '+inttostr(dword(New)));<br> WriteLog('c:/SundyTools.txt','oldp: '+inttostr(dword(oldp))+'Newp: '+inttostr(dword(Newp)));<br><br> WriteLog('c:/SundyTools.txt','ReadProcessMemory开始执行');<br><br> ReadProcessMemory(ProcessId , OldP, old, 8, R);<br> WriteLog('c:/SundyTools.txt','ReadProcessMemory执行了');<br> WriteLog('c:/SundyTools.txt','WriteProcessMemory开始执行');<br><br> WriteProcessMemory(ProcessId , OldP,New,8, R);<br> WriteLog('c:/SundyTools.txt','WriteProcessMemory执行了');<br><br> PReplaceEx(@ReplaceCode[index][0])^.processId := ProcessId;<br> except<br> OutputDebugString(pchar('ReplaceApiProc Function Error'));<br> end;<br>end;<br>在网上找不到相关的资料,请高手帮忙解决一下吧