Eh bien, basead dans ma dernière question:api indigène: RtlInitUnicodeString réaccorder personnages étranges
How build a path to file using Native Api and open with NtOpenFile api?
comme @Remy Lebeau a suggéré RtlInitUnicodeString()
fonctionne très bien quand SourceString est de type:
'\??\c:\test.txt'
.
Déjà dans ce cas-ci, après RtlInitUnicodeString()
valeur tampon est toujours:
'dfᄸɟ\Device\HarddiskVolume2\Windows\SysWOW64\gdi32.dll'
, voir:
avec des personnages étranges au démarrage. Et de cette façon est clair que NtOpenFile()
échouera.
Quelqu'un sait quelque chose pour résoudre ce problème, s'il vous plaît?
Voici ma dernière tentative:
uses
Winapi.Windows,
System.SysUtils,
System.Classes,
NtDll,
ntdll_;
var
hmod: HMODULE = 0
type
{ .: MEMORY_INFORMATION_CLASS :. }
_MEMORY_INFORMATION_CLASS = (MemoryBasicInformation, MemoryWorkingSetList,
MemoryMappedFilenameInformation, MemorySectionName,
MemoryBasicVlmInformation);
MEMORY_INFORMATION_CLASS = _MEMORY_INFORMATION_CLASS;
TMemoryInformationClass = MEMORY_INFORMATION_CLASS;
PMemoryInformationClass = ^TMemoryInformationClass;
{ .: UNICODE STRING:. }
PUnicodeString = ^TUnicodeString;
TUnicodeString = packed record
Length: Word;
MaximumLength: Word;
Buffer: PWideChar;
end;
///////////////////////////////////////////////////////////////////////////////
procedure UnhookPfn(pfn: Pointer);
const
OBJ_CASE_INSENSITIVE = $00000040;
NtCurrentProcess = THandle(-1);
var
pinth: PImageNtHeaders32;
StrUnicode : TNtUnicodeString
Name: PUnicodeString;
oa: TNtObjectAttributes;
rcb: SIZE_T;
begin
if ((RtlPcToFileHeader(pfn, @hmod)) <> (NtNotImplementedPointer)) then
begin
pinth := RtlImageNtHeader(hmod);
GetMem(Name, SizeOf(Name));
FillChar(Name^,SizeOf(Name),#0);
if (0 <= NtQueryVirtualMemory(NtCurrentProcess, Pointer(hmod),
Integer(MemoryMappedFilenameInformation), Pointer(Name), MAX_PATH * SizeOf(WCHAR),
@rcb)) then
begin
RtlInitUnicodeString(@StrUnicode, PWideChar(Name));
InitializeObjectAttributes(@oa, @StrUnicode, OBJ_CASE_INSENSITIVE, 0, nil);
end;
FreeMem(Name);
end;
{ ::: Usage ::: }
/// /////////////////////////////////////////////////////////////////////////////
var
BitBltAddr: Pointer;
begin
try
hmod := GetModuleHandle('Gdi32.dll');
BitBltAddr := GetProcAddress(hmod, 'BitBlt');
UnhookPfn(BitBltAddr);
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
Readln;
end.
EDITION 1:(suggestion @RbMm)
procedure UnhookPfn(pfn: Pointer);
const
OBJ_CASE_INSENSITIVE = $00000040;
NtCurrentProcess = THandle(-1);
var
pinth: PImageNtHeaders32;
Name: PUnicodeString;
rcb: SIZE_T;
iosb: TIoStatusBlock;
oa: TNtObjectAttributes;
StrPath : TNtUnicodeString;
begin
if ((RtlPcToFileHeader(pfn, @hmod)) <> (NtNotImplementedPointer)) then
begin
pinth := RtlImageNtHeader(hmod);
GetMem(Name, SizeOf(Name));
FillChar(Name^,SizeOf(Name),#0);
if (0 <= NtQueryVirtualMemory(NtCurrentProcess, Pointer(hmod),
Integer(MemoryMappedFilenameInformation), Pointer(Name), MAX_PATH * SizeOf(WCHAR), // Name buffer = '\Device\HarddiskVolume2\Windows\SysWOW64\gdi32.dll'
@rcb)) then
begin
InitializeObjectAttributes(@oa, @Name, OBJ_CASE_INSENSITIVE, 0, nil); // buffer of ObjectName = 'strange character'
end;
EDITION 2:
La solution finale à ce trouble comme l'a dit @RbMm était:
InitializeObjectAttributes(@oa, Name, OBJ_CASE_INSENSITIVE, 0, nil);
Extrayez ce qui est nécessaire et incluez-le dans la question. J'ai posté ce lien plusieurs fois: [mcve]. Pouvez-vous confirmer si vous l'avez lu ou non? Lisez aussi ceci: http://sscce.org/ –
Enfin, pour la N-ième fois, pourquoi utilisez-vous l'API native? –
@DavidHeffernan, [parce que a été suggéré à cet utilisateur Luiz Eduardo] (http://stackoverflow.com/questions/41928081/how-restore-inline-hook) utiliser native api pour cette tâche. –