Advertisement
Guest User

GetFileNameFormHandle: nt api

a guest
Dec 17th, 2017
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.10 KB | None | 0 0
  1. uses
  2.  Windows, SysUtils;
  3.  
  4. type
  5.  NTStatus = cardinal;
  6.  
  7.  PIO_STATUS_BLOCK = ^IO_STATUS_BLOCK;
  8.  
  9.   IO_STATUS_BLOCK = packed record
  10.     Status: NTStatus;
  11.     Information: dword;
  12.   end;
  13.  
  14.   PFILE_NAME_INFORMATION = ^FILE_NAME_INFORMATION;
  15.  
  16.   FILE_NAME_INFORMATION = packed record
  17.     FileNameLength: ULONG;
  18.     FileName: array [0 .. MAX_PATH - 1] of WideChar;
  19.   end;
  20.  
  21. function NtQueryInformationFile(FileHandle: THandle;
  22.   IoStatusBlock: PIO_STATUS_BLOCK; FileInformation: pointer; Length: dword;
  23.   FileInformationClass: dword): NTStatus; stdcall; external 'ntdll.dll';
  24.  
  25. function GetFileNameFromHandle(const hFile: THandle): string; // This "hFile" i get from of: de.LoadDll.hFile
  26. var
  27.   IO_STATUSBLOCK: IO_STATUS_BLOCK;
  28.   FileNameInfo: FILE_NAME_INFORMATION;
  29.   szFile: String;
  30. begin
  31.   FillChar(FileNameInfo.FileName, SizeOf(FileNameInfo.FileName), 0);
  32.   NtQueryInformationFile(hFile, @IO_STATUSBLOCK, @FileNameInfo, 500, 9);
  33.   szFile := WideCharToString(FileNameInfo.FileName);
  34.   Result := szFile; // This returns for example with notepad.exe: \Windows\SysWOW64\notepad.exe, without the C:
  35.  
  36. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement