{*******************************************************} { } { ApiHookEtc } { } { Copyright (C) 2023 kku } { } {*******************************************************} unit ApiHookEtc; interface uses Winapi.Windows, Winapi.ShellAPI; type TFun_DragQueryFileA = function(Drop: HDROP; FileIndex: UINT; FileName: LPSTR; cb: UINT): UINT; stdcall; TFun_DragQueryFileW = function(Drop: HDROP; FileIndex: UINT; FileName: LPWSTR; cb: UINT): UINT; stdcall; TFun_DragQueryPoint = function(Drop: HDROP; var Point: TPoint): BOOL; stdcall; function DragQueryFileAHook(Drop: HDROP; FileIndex: UINT; FileName: LPSTR; cb: UINT): UINT; stdcall; function DragQueryFileWHook(Drop: HDROP; FileIndex: UINT; FileName: LPWSTR; cb: UINT): UINT; stdcall; function DragQueryPointHook(Drop: HDROP; var Point: TPoint): BOOL; stdcall; var ozDragQueryFileA: TFun_DragQueryFileA = nil; ozDragQueryFileW: TFun_DragQueryFileW = nil; ozDragQueryPoint: TFun_DragQueryPoint = nil; implementation function DragQueryFileAHook(Drop: HDROP; FileIndex: UINT; FileName: LPSTR; cb: UINT): UINT; stdcall; begin { if (_AppHook <> nil) and _AppHook.Active then begin // _AppHook.Log('DragQueryFileAHook()'); // 차단 if (_AppHook.RcvWnd <> 0) and (FileIndex = DWORD(-1)) then // (FileIndex <> DWORD(-1)) and (FileName <> nil) then begin Result := 0; //ozDragQueryFileA(Drop, FileIndex, FileName, cb); var i, nCnt, nLen: Integer; nCnt := ozDragQueryFileA(Drop, DWORD(-1), nil, 0); if nCnt > 0 then begin var FList: TStringList; Guard(FList, TStringList.Create); FList.Add(_AppHook.ModuleName); if _AppHook.hProcWnd_ <> 0 then FList.Add(GetWindowCaption(_AppHook.hProcWnd_)) else FList.Add(''); var sPath: AnsiString; for i := 0 to nCnt - 1 do begin nLen := ozDragQueryFileA(Drop, i, nil, 0) + 1; SetLength(sPath, nLen); ozDragQueryFileA(Drop, i, PAnsiChar(sPath), nLen); // if FileExists(sPath) then begin SetLength(sPath, nLen - 1); // 끝에 #0 제거 FList.Add(sPath); end; end; if FList.Count > 1 then begin FList.SaveToFile(ExtractFilePath(_AppHook.sLogPath_) + TXT_DROPINFO, TEncoding.UTF8); PostMessage(_AppHook.RcvWnd, WM_CATCH_DROPFILES, 0, 0); end; end; end; // Result := 0; end else } Result := ozDragQueryFileA(Drop, FileIndex, FileName, cb); end; function DragQueryFileWHook(Drop: HDROP; FileIndex: UINT; FileName: LPWSTR; cb: UINT): UINT; stdcall; begin { if (_AppHook <> nil) and _AppHook.Active then begin // _AppHook.Log('DragQueryFileAHook()'); // 차단 if (_AppHook.RcvWnd <> 0) and (FileIndex = DWORD(-1)) then // (FileIndex <> DWORD(-1)) and (FileName <> nil) then begin Result := 0; //ozDragQueryFileA(Drop, FileIndex, FileName, cb); var i, nCnt, nLen: Integer; nCnt := ozDragQueryFileW(Drop, DWORD(-1), nil, 0); if nCnt > 0 then begin var FList: TStringList; Guard(FList, TStringList.Create); FList.Add(_AppHook.ModuleName); if _AppHook.hProcWnd_ <> 0 then FList.Add(GetWindowCaption(_AppHook.hProcWnd_)) else FList.Add(''); var sPath: String; for i := 0 to nCnt - 1 do begin nLen := ozDragQueryFileW(Drop, i, nil, 0) + 1; SetLength(sPath, nLen); ozDragQueryFileW(Drop, i, PChar(sPath), nLen); // if FileExists(sPath) then begin SetLength(sPath, nLen - 1); // 끝에 #0 제거 FList.Add(sPath); end; end; if FList.Count > 1 then begin FList.SaveToFile(ExtractFilePath(_AppHook.sLogPath_) + '$DrpFle.txt', TEncoding.UTF8); PostMessage(_AppHook.RcvWnd, WM_CATCH_DROPFILES, 0, 0); end; end; end; end else } Result := ozDragQueryFileW(Drop, FileIndex, FileName, cb); end; function DragQueryPointHook(Drop: HDROP; var Point: TPoint): BOOL; stdcall; begin { if (_AppHook <> nil) and _AppHook.Active then Result := FALSE else } ozDragQueryPoint(Drop, Point); end; end.