Fixed a few bugs, debugging

This commit is contained in:
Berserker 2019-05-25 15:43:28 +03:00
parent 8beefb97c3
commit f62819869e
4 changed files with 39 additions and 16 deletions

View File

@ -279,9 +279,9 @@ end; // .function Hook_NtCreateFile
function Hook_NtClose (OrigFunc: WinNative.TNtClose; hData: HANDLE): NTSTATUS; stdcall; function Hook_NtClose (OrigFunc: WinNative.TNtClose; hData: HANDLE): NTSTATUS; stdcall;
begin begin
// if VfsDebug.LoggingEnabled then begin if VfsDebug.LoggingEnabled then begin
// WriteLog('[ENTER] NtClose', Format('Handle: %x', [integer(hData)])); WriteLog('[ENTER] NtClose', Format('Handle: %x', [integer(hData)]));
// end; end;
with VfsOpenFiles.OpenFilesCritSection do begin with VfsOpenFiles.OpenFilesCritSection do begin
Enter; Enter;
@ -295,9 +295,9 @@ begin
Leave; Leave;
end; end;
// if VfsDebug.LoggingEnabled then begin if VfsDebug.LoggingEnabled then begin
// WriteLog('[LEAVE] NtClose', Format('Status: %x', [integer(result)])); WriteLog('[LEAVE] NtClose', Format('Status: %x', [integer(result)]));
// end; end;
end; // .function Hook_NtClose end; // .function Hook_NtClose
function IsSupportedFileInformationClass (FileInformationClass: integer): boolean; function IsSupportedFileInformationClass (FileInformationClass: integer): boolean;

View File

@ -117,7 +117,7 @@ begin
end; end;
// No real items added, maybe there is a need to add '.' and/or '..' manually // No real items added, maybe there is a need to add '.' and/or '..' manually
if VfsItemFound and (Self.DirListing.Count = NumVfsChildren) then begin if VfsItemFound and (Self.DirListing.Count = NumVfsChildren) and not VfsUtils.IsRootDriveAbsPath(Self.AbsPath) then begin
if VfsMatching.MatchPattern('.', Mask) then begin if VfsMatching.MatchPattern('.', Mask) then begin
Self.DirListing.AddItem(@DirInfo, '.'); Self.DirListing.AddItem(@DirInfo, '.');
end; end;

View File

@ -39,8 +39,6 @@
<Excluded_Packages Name="$(BDS)\bin\dcloffice2k100.bpl">Microsoft Office 2000 Sample Automation Server Wrapper Components</Excluded_Packages> <Excluded_Packages Name="$(BDS)\bin\dcloffice2k100.bpl">Microsoft Office 2000 Sample Automation Server Wrapper Components</Excluded_Packages>
<Excluded_Packages Name="$(BDS)\bin\dclofficexp100.bpl">Microsoft Office XP Sample Automation Server Wrapper Components</Excluded_Packages> <Excluded_Packages Name="$(BDS)\bin\dclofficexp100.bpl">Microsoft Office XP Sample Automation Server Wrapper Components</Excluded_Packages>
</Excluded_Packages></Delphi.Personality></BorlandProject></BorlandProject> </Excluded_Packages></Delphi.Personality></BorlandProject></BorlandProject>

View File

@ -121,7 +121,10 @@ function NormalizePath (const Path: WideString; {n} HadTrailingDelim: pboolean =
Optionally returns flag, whether path had trailing delim or not. *) Optionally returns flag, whether path had trailing delim or not. *)
function ToNtAbsPath (const Path: WideString; {n} HadTrailingDelim: pboolean = nil): WideString; function ToNtAbsPath (const Path: WideString; {n} HadTrailingDelim: pboolean = nil): WideString;
(* Return true if path is valid absolute path to root drive like '\??\X:' with any/zero number of trailing slashes *) (* Return true if path is valid absolute path to root drive like 'X:' with any/zero number of trailing slashes *)
function IsRootDriveAbsPath (const Path: WideString): boolean;
(* Return true if path is valid absolute NT path to root drive like '\??\X:' with any/zero number of trailing slashes *)
function IsNtRootDriveAbsPath (const Path: WideString): boolean; function IsNtRootDriveAbsPath (const Path: WideString): boolean;
(* Adds backslash to path end, unless there is already existing one *) (* Adds backslash to path end, unless there is already existing one *)
@ -138,7 +141,7 @@ function StripNtAbsPathPrefix (const Path: WideString): WideString;
function SaveAndRet (Res: integer; out ResCopy): integer; function SaveAndRet (Res: integer; out ResCopy): integer;
(* Opens file/directory using absolute NT path and returns success flag *) (* Opens file/directory using absolute NT path and returns success flag *)
function SysOpenFile (const NtAbsPath: WideString; {OUT} var Res: Windows.THandle; const OpenMode: TSysOpenFileMode = OPEN_AS_ANY; const AccessMode: ACCESS_MASK = GENERIC_READ or SYNCHRONIZE): boolean; function SysOpenFile (const NtAbsPath: WideString; {OUT} var Res: Windows.THandle; const OpenMode: TSysOpenFileMode = OPEN_AS_ANY; const AccessMode: ACCESS_MASK = FILE_GENERIC_READ): boolean;
(* Returns TNativeFileInfo record for single file/directory. Short names and files indexes/ids in the result are always empty. *) (* Returns TNativeFileInfo record for single file/directory. Short names and files indexes/ids in the result are always empty. *)
function GetFileInfo (const FilePath: WideString; {OUT} var Res: TNativeFileInfo): boolean; function GetFileInfo (const FilePath: WideString; {OUT} var Res: TNativeFileInfo): boolean;
@ -217,7 +220,7 @@ function NormalizeAbsPath (const Path: WideString; {n} HadTrailingDelim: pboolea
begin begin
result := StrLib.ExcludeTrailingBackslashW(Path, HadTrailingDelim); result := StrLib.ExcludeTrailingBackslashW(Path, HadTrailingDelim);
if (Length(result) = 2) and (result[1] = ':') then begin if (Length(result) = 2) and (result[2] = ':') then begin
result := result + '\'; result := result + '\';
if HadTrailingDelim <> nil then begin if HadTrailingDelim <> nil then begin
@ -240,6 +243,26 @@ begin
end; end;
end; end;
function IsRootDriveAbsPath (const Path: WideString): boolean;
const
MIN_VALID_LEN = Length('X:');
var
i: integer;
begin
result := (Length(Path) >= MIN_VALID_LEN) and (ord(Path[1]) < 256) and (char(Path[1]) in ['A'..'Z']) and (Path[2] = ':');
if result then begin
for i := MIN_VALID_LEN + 1 to Length(Path) do begin
if Path[i] <> '\' then begin
result := false;
exit;
end;
end;
end;
end; // .function IsRootDriveAbsPath
function IsNtRootDriveAbsPath (const Path: WideString): boolean; function IsNtRootDriveAbsPath (const Path: WideString): boolean;
const const
MIN_VALID_LEN = Length('\??\X:'); MIN_VALID_LEN = Length('\??\X:');
@ -455,7 +478,7 @@ begin
result := StrLib.Join(FileNames, #13#10); result := StrLib.Join(FileNames, #13#10);
end; end;
function SysOpenFile (const NtAbsPath: WideString; {OUT} var Res: Windows.THandle; const OpenMode: TSysOpenFileMode = OPEN_AS_ANY; const AccessMode: ACCESS_MASK = GENERIC_READ or SYNCHRONIZE): boolean; function SysOpenFile (const NtAbsPath: WideString; {OUT} var Res: Windows.THandle; const OpenMode: TSysOpenFileMode = OPEN_AS_ANY; const AccessMode: ACCESS_MASK = FILE_GENERIC_READ): boolean;
var var
FilePathU: WinNative.UNICODE_STRING; FilePathU: WinNative.UNICODE_STRING;
hFile: Windows.THandle; hFile: Windows.THandle;
@ -466,7 +489,9 @@ begin
FilePathU.AssignExistingStr(NtAbsPath); FilePathU.AssignExistingStr(NtAbsPath);
ObjAttrs.Init(@FilePathU); ObjAttrs.Init(@FilePathU);
result := WinNative.NtOpenFile(@hFile, AccessMode, @ObjAttrs, @IoStatusBlock, FILE_SHARE_READ or FILE_SHARE_WRITE, ord(OpenMode) or FILE_SYNCHRONOUS_IO_NONALERT) = WinNative.STATUS_SUCCESS;
result := WinNative.NtOpenFile(@hFile, AccessMode, @ObjAttrs, @IoStatusBlock, FILE_SHARE_READ or FILE_SHARE_WRITE or FILE_SHARE_DELETE,
ord(OpenMode) or FILE_SYNCHRONOUS_IO_NONALERT or FILE_OPEN_FOR_BACKUP_INTENT) = WinNative.STATUS_SUCCESS;
if result then begin if result then begin
Res := hFile; Res := hFile;
@ -488,7 +513,7 @@ begin
FileAllInfo := @Buf; FileAllInfo := @Buf;
// * * * * * // // * * * * * //
NtAbsPath := ToNtAbsPath(FilePath); NtAbsPath := ToNtAbsPath(FilePath);
result := SysOpenFile(NtAbsPath, hFile, OPEN_AS_ANY); result := SysOpenFile(NtAbsPath, hFile, OPEN_AS_ANY, STANDARD_RIGHTS_READ or FILE_READ_ATTRIBUTES or FILE_READ_EA or SYNCHRONIZE);
if not result then begin if not result then begin
exit; exit;
@ -549,7 +574,7 @@ var
begin begin
hDir := Windows.INVALID_HANDLE_VALUE; hDir := Windows.INVALID_HANDLE_VALUE;
SysOpenFile(ToNtAbsPath(DirPath), hDir, OPEN_AS_DIR); SysOpenFile(ToNtAbsPath(DirPath), hDir, OPEN_AS_DIR, FILE_LIST_DIRECTORY or SYNCHRONIZE);
Self.Create(hDir, Mask); Self.Create(hDir, Mask);