- Код: Выделить всё
const
DRIVER_INFORMATION = 11;
type
TPDWord = ^DWORD;
TDriverInfo = packed record
Address: Pointer;
Unknown1: DWORD;
Unknown2: DWORD;
EntryIndex: DWORD;
Unknown4: DWORD;
Name: array [0..MAX_PATH + 3] of Char;
end;
var
NtQuerySystemInformation: function (infoClass: DWORD;
buffer: Pointer;
bufSize: DWORD;
returnSize: TPDword): DWORD; stdcall = nil;
function GetDriverInfo: string;
var
temp, Index, numBytes, numEntries: DWORD;
buf: TPDword;
driverInfo: ^TDriverInfo;
begin
if @NtQuerySystemInformation = nil then
NtQuerySystemInformation := GetProcAddress(GetModuleHandle('ntdll.dll'),
'NtQuerySystemInformation');
// Obtain required buffer size
NtQuerySystemInformation(DRIVER_INFORMATION, @temp, 0, @numBytes);
// Allocate buffer
buf := AllocMem(numBytes * 2);
NtQuerySystemInformation(DRIVER_INFORMATION, buf, numBytes * 2, @numBytes);
numEntries := buf^;
driverInfo := Pointer(DWORD(buf) + 12);
Result := '';
for Index := 1 to numEntries do
begin
Result := Result + #0$D#0$A+'Address: $' + IntToHex(DWORD(driverInfo^.Address), 8) +
'Name: "' + (driverInfo^.Name) + '"';
Inc(driverInfo);
end;
Delete(Result, 1, 2);
FreeMem(buf);
end;
Перевожу код на VB.
Путем копирования из буфера 4 байтов, получаю число драйверов( все работает), но последующие копирования "летят к черту..."
- Код: Выделить всё
Option Explicit
Private Declare Function NtQuerySystemInformation Lib "ntdll.dll" (ByVal infoClass As Long, ByVal Buffer As Long, ByVal BufferSize As Long, ByVal Ret As Long) As Long
Private Declare Function VirtualAlloc Lib "kernel32.dll" (ByVal Address As Long, ByVal dwSize As Long, ByVal AllocationType As Long, ByVal Protect As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDst As Any, pSrc As Any, ByVal ByteLen As Long)
Private Const DRIVER_INFORMATION = 11
Private Const PAGE_READWRITE = &H4
Private Const MEM_RELEASE = &H8000
Private Const MEM_COMMIT = &H1000
Private Type DriverInfo
dwAddress As Long
dwUnknown1 As Long
dwUnknown2 As Long
dwEntryIndex As Long
dwUnknown4 As Long
sName As String
End Type
Private Sub Command1_Click()
Dim Ret As Long
Dim Buffer As Long
Dim NumDrivers As Long
Dim DI As DriverInfo
Dim Temp As Long
NtQuerySystemInformation DRIVER_INFORMATION, 0, 0, VarPtr(Ret)
Buffer = VirtualAlloc(0, Ret * 2, MEM_COMMIT, PAGE_READWRITE)
NtQuerySystemInformation DRIVER_INFORMATION, Buffer, Ret * 2, VarPtr(Ret)
CopyMemory NumDrivers, ByVal Buffer, 4
MsgBox NumDrivers 'Показываем число драйверов
Buffer = Buffer + 12 'Задаем смещение
CopyMemory Temp, ByVal Buffer, 4 'Пытаюсь копировать, но VB стреляется...
MsgBox Temp
End Sub
Пожалуйста, подскажите что не так...
Заранее благодарен...