線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:2698
推到 Plurk!
推到 Facebook!

在WINDOWS EXPLORER中拷贝、删除、移动文件和文件夹到底用的是什么API函数;

答題得分者是:wameng
popmailzjw
一般會員


發表:7
回覆:18
積分:5
註冊:2002-05-11

發送簡訊給我
#1 引用回覆 回覆 發表時間:2004-10-06 18:36:10 IP:218.18.xxx.xxx 未訂閱
我HOOK了所有API中相似的函数:copyFile(A,W), CopyFileEx(A,W),SHFileOperation(A,W)怎么都不对呀, 大家在做监视和控制文件操作时是怎么做的呀,说是有一个COPYHOOK的东西,可是它只能对文件夹有用,听说也能对文件有用,不知道怎么改 还有一个这个东西SHChangeNotifyRegister,可是它却只能监视,不能控制。 还有其它好方法吗,要求用DELPHI能实现的??
wameng
版主


發表:31
回覆:1336
積分:1188
註冊:2004-09-16

發送簡訊給我
#2 引用回覆 回覆 發表時間:2004-10-06 20:25:16 IP:61.31.xxx.xxx 未訂閱
確實 COPYHOOK 只能針對 Folder 文件夾進行監視及控制。 不能對文件(檔案)進行監視及控制。 >我HOOK了所有API中相似的函数:copyFile(A,W), CopyFileEx(A,W),SHFileOperation(A,W)怎么都不对呀, 您確定 HOOK 成功嗎!應該就這些了..... 您的HOOK,是全域嗎!
wameng
版主


發表:31
回覆:1336
積分:1188
註冊:2004-09-16

發送簡訊給我
#3 引用回覆 回覆 發表時間:2004-10-06 20:49:15 IP:61.31.xxx.xxx 未訂閱
或者是寫成 HOOK.VXD 方式
popmailzjw
一般會員


發表:7
回覆:18
積分:5
註冊:2002-05-11

發送簡訊給我
#4 引用回覆 回覆 發表時間:2004-10-07 13:31:04 IP:218.18.xxx.xxx 未訂閱
我試過了,我自己用程序寫一下copyFile之類的函數操作文件,它能HOOK到,說明應該不是這些了
wameng
版主


發表:31
回覆:1336
積分:1188
註冊:2004-09-16

發送簡訊給我
#5 引用回覆 回覆 發表時間:2004-10-07 15:58:41 IP:61.222.xxx.xxx 未訂閱
有試過用 HOOK SHFileOperation >我試過了,我自己用程序寫一下copyFile之類的函數操作文件,它能HOOK到,說明應該不是這些了 是和 HOOK 在同一個 Process 嗎! 全域(系統級) HOOK 必須為 DLL
wameng
版主


發表:31
回覆:1336
積分:1188
註冊:2004-09-16

發送簡訊給我
#6 引用回覆 回覆 發表時間:2004-10-07 18:41:15 IP:61.222.xxx.xxx 未訂閱
popmailzjw 您好! 經過我測試結果。 如果 要監視及控制檔案 不被系統給 COPY ,Delete, Rename,Move....等等 是可以的,直接 HOOK shell32.dll 的 SHFileOperationA 及 SHFileOperationW 兩個函數。 HOOP COPYFILEA/W 是無效的。 主要作業系統是透過 SHELL 處理的。 我已經測試通過了。可以強制讓某個檔案不准刪除或搬移等等。
popmailzjw
一般會員


發表:7
回覆:18
積分:5
註冊:2002-05-11

發送簡訊給我
#7 引用回覆 回覆 發表時間:2004-10-08 10:05:36 IP:218.18.xxx.xxx 未訂閱
真的吗,我怎么没有HOOK到,能把你的HOOK方法给我看一下吗,谢谢了 我研究了好久了,也没有实现呀 可以的话发到我的邮箱:popmailzjw@163.com QQ:77144122
popmailzjw
一般會員


發表:7
回覆:18
積分:5
註冊:2002-05-11

發送簡訊給我
#8 引用回覆 回覆 發表時間:2004-10-08 10:12:37 IP:218.18.xxx.xxx 未訂閱
以下是我的原码 library HookAPIDLL; uses HookAPI in '..\HookAPI.pas', Windows, shellApi, SysUtils, Dialogs; type //TOpenProcess = function(dwDesiredAccess: DWORD; bInheritHandle: BOOL; dwProcessId: DWORD): THandle; stdcall; //TSHFileOperation = function(const lpFileOp: TSHFileOpStruct): Integer; stdcall; TCopyFile = function(lpExistingFileName, lpNewFileName: PChar; bFailIfExists: BOOL): BOOL; {function (lpExistingFileName, lpNewFileName: PChar; lpProgressRoutine: TFNProgressRoutine; lpData: Pointer; pbCancel: PBool; dwCopyFlags: DWORD): BOOL; stdcall; } var //APIOpenProcess: TOpenProcess; //APISHFileOperation: TSHFileOperation; APICopyFile: TCopyFile; iHook: HHook; hMapObject: THandle; fMapFile: Pointer; procedure CreateMapFile; begin // create map file if hMapObject = 0 then begin hMapObject := CreateFileMapping($FFFFFFFF, nil, page_ReadWrite, 0, 18, 'ProtectProcess'); if hMapObject > 0 then begin fMapFile := MapViewOfFile(hMapObject, File_Map_All_Access, 0, 0, 0); StrCopy(PChar(fMapFile), PChar(IntToStr(GetCurrentProcessID))); end; end; end; procedure FreeMapFile; begin if fMapFile <> nil then UnMapViewOfFile(fMapFile); if hMapObject > 0 then CloseHandle(hMapObject); end; // hook proc function HookProc(nCode: Integer; WPARAM: wParam; LPARAM: lParam): LResult; stdcall; begin Result := 0; // do onthing if nCode < 0 then Result := CallNextHookEx(iHook, nCode, wParam, lParam); end; // our EXE calls this method to setup the hook procedure SetHook; stdcall; begin CreateMapFile; iHook := SetWindowsHookEx(WH_SYSMSGFILTER, @HookProc, hInstance, 0); end; // our EXE calls this method to unset the hook procedure UnSetHook; stdcall; begin UnHookWindowsHookEx(iHook); iHook := 0; FreeMapFile; end; function MySHFileOperation(const lpFileOp: TSHFileOpStruct): Integer; stdcall; begin case lpFileOp.wFunc of FO_MOVE: showmessage('move file'); FO_COPY: showmessage('copy file'); FO_DELETE: showmessage('delete file'); FO_RENAME: showmessage('rename file'); end; Result := 0 //APISHFileOperation(lpFileOp); end; function MyCopyFile(lpExistingFileName, lpNewFileName: PChar; bFailIfExists: BOOL): BOOL; stdcall; {function CopyFileEx (lpExistingFileName, lpNewFileName: PChar; lpProgressRoutine: TFNProgressRoutine; lpData: Pointer; pbCancel: PBool; dwCopyFlags: DWORD): BOOL; stdcall; } begin showmessage(lpExistingFileName '-->' lpNewFileName); result := true; end; procedure SetAPIHook; stdcall; begin if @APICopyFile = nil then begin //SHFileOperation //deletefile @APICopyFile := LocateFunctionAddress(@CopyFile); RepointFunction(@APICopyFile, @MyCopyFile); end; //CopyCallback() end; procedure UnSetAPIHook; stdcall; begin {if @APISHFileOperation <> nil then begin RepointFunction(@MySHFileOperation, @APISHFileOperation); @APISHFileOperation := nil; end;} if @APICopyFile <> nil then begin RepointFunction(@MyCopyFile, @APICopyFile); @APICopyFile := nil; end; end; function IsHooking: bool; stdcall; begin Result := (@APICopyFile <> nil) and (iHook <> 0); end; procedure EntryPointProc(Reason: Integer); begin case reason of DLL_PROCESS_ATTACH: begin hMapObject := OpenFileMapping(File_Map_All_Access, true, 'ProtectProcess'); if hMapObject > 0 then fMapFile := MapViewOfFile(hMapObject, File_Map_All_Access, 0, 0, 0); SetAPIHook; //showmessage('loadOK'); end; DLL_PROCESS_DETACH: begin UnSetAPIHook; FreeMapFile; //showmessage('FreeOK'); end; end; end; exports SetHook, UnSetHook, SetAPIHook, UnSetAPIHook, IsHooking; begin fMapFile := nil; iHook := 0; DllProc := @EntryPointProc; EntryPointProc(DLL_PROCESS_ATTACH); end.
popmailzjw
一般會員


發表:7
回覆:18
積分:5
註冊:2002-05-11

發送簡訊給我
#9 引用回覆 回覆 發表時間:2004-10-08 10:13:41 IP:218.18.xxx.xxx 未訂閱
unit HookAPI; interface uses Windows, Classes; function LocateFunctionAddress(Code: Pointer): Pointer; function RepointFunction(OldFunc, NewFunc: Pointer): Integer; type //定义一个入口结构 PImage_Import_Entry = ^Image_Import_Entry; Image_Import_Entry = record Characteristics: DWORD; TimeDateStamp: DWORD; MajorVersion: Word; MinorVersion: Word; Name: DWORD; LookupTable: DWORD; end; type //定义一个跳转的结构 TImportCode = packed record JumpInstruction: Word; //定义跳转指令jmp AddressOfPointerToFunction: ^Pointer; //定义要跳转到的函数 end; PImportCode = ^TImportCode; implementation function LocateFunctionAddress(Code: Pointer): Pointer; var func: PImportCode; begin Result := Code; if Code = nil then exit; try func := code; if (func.JumpInstruction = $25FF) then begin Result := func.AddressOfPointerToFunction^; end; except Result := nil; end; end; function RepointFunction(OldFunc, NewFunc: Pointer): Integer; var IsDone: TList; function RepointAddrInModule(hModule: THandle; OldFunc, NewFunc: Pointer): Integer; var Dos: PImageDosHeader; NT: PImageNTHeaders; ImportDesc: PImage_Import_Entry; RVA: DWORD; Func: ^Pointer; DLL: string; f: Pointer; written: DWORD; begin Result := 0; Dos := Pointer(hModule); if IsDone.IndexOf(Dos) >= 0 then exit; IsDone.Add(Dos); OldFunc := LocateFunctionAddress(OldFunc); if IsBadReadPtr(Dos, SizeOf(TImageDosHeader)) then exit; if Dos.e_magic <> IMAGE_DOS_SIGNATURE then exit; NT := Pointer(Integer(Dos) dos._lfanew); RVA := NT^.OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT] .VirtualAddress; if RVA = 0 then exit; ImportDesc := pointer(integer(Dos) RVA); while (ImportDesc^.Name <> 0) do begin DLL := PChar(Integer(Dos) ImportDesc^.Name); RepointAddrInModule(GetModuleHandle(PChar(DLL)), OldFunc, NewFunc); Func := Pointer(Integer(DOS) ImportDesc.LookupTable); while Func^ <> nil do begin f := LocateFunctionAddress(Func^); if f = OldFunc then begin WriteProcessMemory(GetCurrentProcess, Func, @NewFunc, 4, written); if Written > 0 then Inc(Result); end; Inc(Func); end; Inc(ImportDesc); end; end; begin IsDone := TList.Create; try Result := RepointAddrInModule(GetModuleHandle(nil), OldFunc, NewFunc); finally IsDone.Free; end; end; end.
wameng
版主


發表:31
回覆:1336
積分:1188
註冊:2004-09-16

發送簡訊給我
#10 引用回覆 回覆 發表時間:2004-10-08 11:03:43 IP:61.222.xxx.xxx 未訂閱
我看您的源碼 並沒有 HOOK SHFileOperationA/W 這個函數 我是用 C 寫的,用Delphi 寫的HOOK 相當不穩定(非常)。 如果您能 HOOK COPYFILEA/W 那麼表示您的方法正常的。
popmailzjw
一般會員


發表:7
回覆:18
積分:5
註冊:2002-05-11

發送簡訊給我
#11 引用回覆 回覆 發表時間:2004-10-08 11:16:09 IP:218.18.xxx.xxx 未訂閱
C的也给我参考一下行不,这个问题真的困我太久了,一直没有找到方法解决 發表人 - popmailzjw 於 2004/10/08 11:18:10
wameng
版主


發表:31
回覆:1336
積分:1188
註冊:2004-09-16

發送簡訊給我
#12 引用回覆 回覆 發表時間:2004-10-08 12:00:15 IP:61.222.xxx.xxx 未訂閱
Delphi 您可以用現成的 MadCodeHOOK http://www.madshi.net/ 很簡單的。 後來我覺得 HOOK SHFileOperationA/W 還是不夠 因為使用 COPY.EXE 仍然有效。 PS. 源碼放在家裡,我現在用的是公司的電腦。
popmailzjw
一般會員


發表:7
回覆:18
積分:5
註冊:2002-05-11

發送簡訊給我
#13 引用回覆 回覆 發表時間:2004-10-08 12:21:16 IP:218.18.xxx.xxx 未訂閱
我只考虑浏览器中COPY,MOVE,DELETE,其它条件下的我不考虑
popmailzjw
一般會員


發表:7
回覆:18
積分:5
註冊:2002-05-11

發送簡訊給我
#14 引用回覆 回覆 發表時間:2004-10-08 14:54:08 IP:218.18.xxx.xxx 未訂閱
上面的地址我进不去,没办法了
favinc
一般會員


發表:22
回覆:19
積分:8
註冊:2003-03-11

發送簡訊給我
#15 引用回覆 回覆 發表時間:2004-10-29 23:57:24 IP:211.147.xxx.xxx 未訂閱
Open、Edit、Print又如何Hook得到? 兵临城下,快活如故。
------
兵临城下,快活如故。
dg822
一般會員


發表:14
回覆:38
積分:10
註冊:2004-12-16

發送簡訊給我
#16 引用回覆 回覆 發表時間:2005-01-22 01:24:20 IP:210.100.xxx.xxx 未訂閱
wameng 大大,你是不是有madshi suit?能email给我吗? 我想看看源码。。。。小弟在此先谢过了………
系統時間:2024-05-08 21:03:09
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!