library Project1;
{ Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }
uses
windows, Winapi.ShellAPI, System.IOUtils, System.Types,
HookUtils,
HookIntfs,
messages,
sysutils,
tlhelp32;
{$R *.res}
var
old_DragQueryFileW: function(hDrop: hDrop; iFile: UINT; lpszFile: LPWSTR;
cch: UINT): UINT; stdcall;
type
Tfilename = record
filename: array [0 .. 255] of WideChar;
end;
var
g_files: array [0 .. 9999] of Tfilename;
function _DragQueryFileW(hDrop: hDrop; iFile: UINT; lpszFile: LPWSTR; cch: UINT)
: UINT; stdcall;
var
res: UINT;
i, k: Integer;
tmp: array [0 .. 255] of WideChar;
LList: TStringDynArray;
str: string;
begin
if iFile = $FFFFFFFF then
begin
res := old_DragQueryFileW(hDrop, iFile, lpszFile, cch);
k := 0;
for i := 0 to res - 1 do
begin
// ZeroMemory(@tmp,Length(tmp)*SizeOf(WideChar));
old_DragQueryFileW(hDrop, i, @tmp, Length(tmp) * SizeOf(WideChar));
if DirectoryExists(string(tmp)) then
begin
LList := TDirectory.GetFiles(tmp, '*.*',
TSearchOption.soAllDirectories);
for str in LList do
begin
ZeroMemory(@g_files[k].filename, 256 * SizeOf(WideChar));
CopyMemory(@g_files[k].filename, PWideChar(str),
Length(str) * SizeOf(WideChar));
inc(k);
if k > 9999 then
begin
MessageBoxW(0, '文件数量不能超过10000个', '错误', MB_OK + MB_ICONSTOP +
MB_TOPMOST);
Exit;
end;
end;
end
else
begin
ZeroMemory(@g_files[k].filename, 256 * SizeOf(WideChar));
CopyMemory(@g_files[k].filename, @tmp, Length(tmp) * SizeOf(WideChar));
inc(k);
if k > 9999 then
begin
MessageBoxW(0, '文件数量不能超过10000个', '错误', MB_OK + MB_ICONSTOP +
MB_TOPMOST);
Exit;
end;
end;
end;
end
else
begin
CopyMemory(lpszFile, @g_files[iFile].filename, 256 * SizeOf(WideChar));
end;
Result := k;
end;
procedure hook();
begin
if not Assigned(old_DragQueryFileW) then
begin
HookProc(shell32, 'DragQueryFileW', @_DragQueryFileW, @old_DragQueryFileW);
end
else
begin
if Assigned(old_DragQueryFileW) then
begin
UnHookProc(@old_DragQueryFileW);
end;
@old_DragQueryFileW := nil;
end;
end;
procedure DllEntryPoint(fdwReason: DWORD);
begin
case fdwReason of
DLL_THREAD_ATTACH:
hook;
DLL_THREAD_DETACH:
hook;
DLL_PROCESS_DETACH:
hook;
DLL_PROCESS_ATTACH:
hook;
end;
end;
begin
DLLProc := @DllEntryPoint;
end.