全
全文检索
Unregistered / Unconfirmed
GUEST, unregistred user!
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
type
IMAGE_FIXUP_ENTRY = packed record
offset:WORD;
types:WORD;
end;
PIMAGE_FIXUP_ENTRY = ^IMAGE_FIXUP_ENTRY;
NTSTATUS = LongWord;
type
_SYSTEM_MODULE_INFORMATION = packed record
Reserved:Array[0..1] of LongWord;
Baseointer;
Size:LongWord;
Flags:LongWord;
Index:WORD;
Unknown:WORD;
LoadCount:WORD;
ModuleNameOffset:WORD;
ImageName:Array[0..255] of char;
end;
type
MODULES = packed record
dwNumberOfModulesWORD;
smi:_SYSTEM_MODULE_INFORMATION;
end;
TPMODULES = ^MODULES;
SYSTEM_MODULE_INFORMATION = _SYSTEM_MODULE_INFORMATION;
PSYSTEM_MODULE_INFORMATION = ^SYSTEM_MODULE_INFORMATION;
type
TPDWord = ^DWORD;
TSystem_Basic_Information = packed record
dwUnknown1: DWORD;
uKeMaximumIncrement: ULONG;
uPageSize: ULONG;
uMmNumberOfPhysicalPages: ULONG;
uMmLowestPhysicalPage: ULONG;
uMmHighestPhysicalPage: ULONG;
uAllocationGranularity: ULONG;
pLowestUserAddress: Pointer;
pMmHighestUserAddress: Pointer;
uKeActiveProcessors: ULONG;
bKeNumberProcessors: byte;
bUnknown2: byte;
wUnknown3: word;
end;
var
Form1: TForm1;
NtQuerySystemInformation: function(infoClass: DWORD;
buffer: Pointer;
bufSize: DWORD;
returnSize: TPDword): DWORD
stdcall = nil;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
pModules: TPMODULES;
pointer;
STATUS_INFO_LENGTH_MISMATCH:dword;
rc,dwNeededSizeword;
dwKernelBase:dword;
pKernelName:string;
hKernel:HMODULE;
begin
STATUS_INFO_LENGTH_MISMATCH:=$C0000004;
if @NtQuerySystemInformation = nil then
NtQuerySystemInformation := GetProcAddress(GetModuleHandle('ntdll.dll'),'NtQuerySystemInformation');
if @NtQuerySystemInformation = nil then exit;
rc:=NtQuerySystemInformation(11,@pModules, 4,@dwNeededSize);
if rc = STATUS_INFO_LENGTH_MISMATCH then
begin
pModules:=TPMODULES(GlobalAlloc(GPTR,dwNeededSize));
rc:=NtQuerySystemInformation(11,@pModules,dwNeededSize,nil);
end;
if rc=0 then exit;
dwKernelBase:=dword(pModules.smi.Base)
//这里的 pModules.smi.Base 数据为 0
pKernelName:=pModules.smi.ModuleNameOffset+pModules.smi.ImageName
//这里 pKernelName = '' 所以下面那句不会成功
hKernel:=LoadLibraryEx(pchar(pKernelName),0,DONT_RESOLVE_DLL_REFERENCES);
end;
end.
//下面是 VC 的原文
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
type
IMAGE_FIXUP_ENTRY = packed record
offset:WORD;
types:WORD;
end;
PIMAGE_FIXUP_ENTRY = ^IMAGE_FIXUP_ENTRY;
NTSTATUS = LongWord;
type
_SYSTEM_MODULE_INFORMATION = packed record
Reserved:Array[0..1] of LongWord;
Baseointer;
Size:LongWord;
Flags:LongWord;
Index:WORD;
Unknown:WORD;
LoadCount:WORD;
ModuleNameOffset:WORD;
ImageName:Array[0..255] of char;
end;
type
MODULES = packed record
dwNumberOfModulesWORD;
smi:_SYSTEM_MODULE_INFORMATION;
end;
TPMODULES = ^MODULES;
SYSTEM_MODULE_INFORMATION = _SYSTEM_MODULE_INFORMATION;
PSYSTEM_MODULE_INFORMATION = ^SYSTEM_MODULE_INFORMATION;
type
TPDWord = ^DWORD;
TSystem_Basic_Information = packed record
dwUnknown1: DWORD;
uKeMaximumIncrement: ULONG;
uPageSize: ULONG;
uMmNumberOfPhysicalPages: ULONG;
uMmLowestPhysicalPage: ULONG;
uMmHighestPhysicalPage: ULONG;
uAllocationGranularity: ULONG;
pLowestUserAddress: Pointer;
pMmHighestUserAddress: Pointer;
uKeActiveProcessors: ULONG;
bKeNumberProcessors: byte;
bUnknown2: byte;
wUnknown3: word;
end;
var
Form1: TForm1;
NtQuerySystemInformation: function(infoClass: DWORD;
buffer: Pointer;
bufSize: DWORD;
returnSize: TPDword): DWORD
stdcall = nil;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
pModules: TPMODULES;
pointer;
STATUS_INFO_LENGTH_MISMATCH:dword;
rc,dwNeededSizeword;
dwKernelBase:dword;
pKernelName:string;
hKernel:HMODULE;
begin
STATUS_INFO_LENGTH_MISMATCH:=$C0000004;
if @NtQuerySystemInformation = nil then
NtQuerySystemInformation := GetProcAddress(GetModuleHandle('ntdll.dll'),'NtQuerySystemInformation');
if @NtQuerySystemInformation = nil then exit;
rc:=NtQuerySystemInformation(11,@pModules, 4,@dwNeededSize);
if rc = STATUS_INFO_LENGTH_MISMATCH then
begin
pModules:=TPMODULES(GlobalAlloc(GPTR,dwNeededSize));
rc:=NtQuerySystemInformation(11,@pModules,dwNeededSize,nil);
end;
if rc=0 then exit;
dwKernelBase:=dword(pModules.smi.Base)
//这里的 pModules.smi.Base 数据为 0
pKernelName:=pModules.smi.ModuleNameOffset+pModules.smi.ImageName
//这里 pKernelName = '' 所以下面那句不会成功
hKernel:=LoadLibraryEx(pchar(pKernelName),0,DONT_RESOLVE_DLL_REFERENCES);
end;
end.
//下面是 VC 的原文