gpt4 book ai didi

delphi - 如何让文件真正隐藏在目录中?

转载 作者:行者123 更新时间:2023-12-03 15:23:36 25 4
gpt4 key购买 nike

我昨天下载了一个程序,它是为了加密和安全。除非有人要求,否则我不会在这里命名它,但它有一个功能可以使指定文件夹内的文件完全不可见。

我有隐藏文件和文件夹 - 已选择,还有隐藏 protected 操作系统文件 - 未选择,但这些文件已完全从 View 中消失,也不会显示在搜索中。我将文件夹从 VMware Workstation 复制到我的主机上,但文件仍然是 super 隐藏的!根据Windows,该文件夹中有零个文件。

这个巫术魔法是怎么可能的?我想在我自己的加密程序中使用 Delphi 来模拟这一点。我在这里和通过 Google 没有找到任何方法来表明这是如何可能的,但实际的程序帮助文件说它们仍在该文件夹中,但不向大多数处理文件的普通 Windows 软件注册。

这是其中一个问题,我无法提供任何代码来显示我所尝试过的内容,而是接受我可以尝试的建议,或者也许这里有人确切地知道它是如何完成的?

最佳答案

由于信息较少一种可能性是使用 NTFS 上的替代文件流,可以将其添加到文件和文件夹中。您可以通过在命令行输入“notepad C:\temp:hidden1.txt”来尝试此操作,如果您回答"is",将创建新的文件流。保存后,您可以以完全相同的方式重新打开它。这也可以从 delphi 完成(加载/保存)。仅当使用 NTFS 时才有效。我不知道这种方法是否用于所描述的情况,找到ADS可以通过以下代码完成:

unit u_ListADS;

// 20120928 by Thomas Wassermann
// www.devworx.de
interface

uses
Windows, Messages, SysUtils, Variants, Classes, StrUtils;

Procedure GetADS(List: TStrings; const Path, WildCard: String; Recursiv: Boolean = false);

function NtQueryInformationFile(FileHandle: Cardinal; IoStatusBlock: Pointer; FileInformation: Pointer; FileInformationLength: Cardinal;
FileInformationClass: Cardinal): Cardinal; stdcall; external 'ntdll.dll';

implementation

type
_FILE_STREAM_INFORMATION = record
NextEntryOffset: Cardinal;
StreamNameLength: Cardinal;
StreamSize: int64;
StreamAllocationSize: int64;
StreamName: array [0 .. MAX_PATH] of WideChar;
end;

PFILE_STREAM_INFORMATION = ^_FILE_STREAM_INFORMATION;

function GetStreams(aFilename: String): TStringList;
var
FileHandle: Integer;
FileName: array [0 .. MAX_PATH] of WideChar;
StreamName: String;
InfoBlock: _FILE_STREAM_INFORMATION;
StatusBlock: record Status: Cardinal;
Information: PDWORD;
end;

Procedure Analyze;
begin
CopyMemory(@FileName, @InfoBlock.StreamName, InfoBlock.StreamNameLength);
StreamName := Copy(Filename, 1, PosEx(':', Filename, 2) - 1);
if StreamName <> ':' then Result.Add(StreamName);
end;
begin
Result := TStringList.Create;
FileHandle := FileOpen(aFilename, GENERIC_READ);
NtQueryInformationFile(FileHandle, @StatusBlock, @InfoBlock, SizeOf(InfoBlock), 22);
FileClose(FileHandle);
if InfoBlock.StreamNameLength <> 0 then
Repeat

if (InfoBlock.NextEntryOffset <> 0) then
begin
InfoBlock := PFILE_STREAM_INFORMATION(PByte(@InfoBlock) + InfoBlock.NextEntryOffset)^;
Analyze;
end;
until InfoBlock.NextEntryOffset = 0
end;

Procedure GetADS(List: TStrings; const Path, WildCard: String; Recursiv: Boolean = false);
Var
SR: SysUtils.TSearchRec;
RES: Integer;
SP: String;
StreamList: TStringList;
i: Integer;
begin
if length(Path) = 0 then
exit;
if length(WildCard) = 0 then
exit;
SP := IncludeTrailingBackSlash(Path) + WildCard;
RES := FindFirst(IncludeTrailingBackSlash(Path) + '*.*', faDirectory, SR);
While RES = 0 Do
Begin
If (SR.attr And faDirectory) <> 0 Then
If SR.Name[1] <> '.' Then
if Recursiv then
GetADS(List, IncludeTrailingBackSlash(Path) + SR.Name, WildCard, Recursiv);
RES := FindNext(SR);
End;
SysUtils.FindClose(SR);
RES := FindFirst(SP, $27, SR);
While RES = 0 Do
Begin
StreamList := GetStreams(IncludeTrailingBackSlash(Path) + SR.Name);
for i := 0 to StreamList.Count - 1 do
List.Add(IncludeTrailingBackSlash(Path) + SR.Name + StreamList[i]);
StreamList.Free;
RES := FindNext(SR);
End;
SysUtils.FindClose(SR);
end;

end.

调用可以是例如

  GetADS(Listbox1.Items,Directory.Text, WildCards.Text,rekursiv.checked);

关于delphi - 如何让文件真正隐藏在目录中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13506986/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com