⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bioshelp.pas

📁 del *.obj del *.dcu del *.~* del *.hpp del *.dcp del *.dpl del *.cesettings del *.log upx sy
💻 PAS
📖 第 1 页 / 共 2 页
字号:
# more complex and there is no needing for it. With the handle (because we are
#
# in the "very simple" user mode =) we now use MapViewOfFile, UnmapViewOfFile,
#
# and CloseHandle to map an memory window (the ROM BIOS) into our process. #
# #
# Due to the fact that ZwOpenSection returns NT error-codes in case of failure
#
# we have to translate it to an Win32 error-code (RtlNtStatusToDosError). #
# All NT specific functions are dynamically loaded -- because the applications
#
# should start on Win9x systems =) #
# #
###############################################################################
}

{ For more information see Windows 2000/XP DDK  }
{ It works on Windows NT 4.0 too, use NtDll.dll }

type
 NTSTATUS = Integer;

const
 STATUS_SUCCESS = NTSTATUS(0);
 STATUS_INVALID_HANDLE = NTSTATUS($C0000008);
 STATUS_ACCESS_DENIED = NTSTATUS($C0000022);

type
 PUnicodeString = ^TUnicodeString;
 TUnicodeString = packed record
   Length: Word;
   MaximumLength: Word;
   Buffer: PWideChar;
 end;

const
 OBJ_INHERIT = $00000002;
 OBJ_PERMANENT = $00000010;
 OBJ_EXCLUSIVE = $00000020;
 OBJ_CASE_INSENSITIVE = $00000040;
 OBJ_OPENIF = $00000080;
 OBJ_OPENLINK = $00000100;
 OBJ_KERNEL_HANDLE = $00000200;
 OBJ_VALID_ATTRIBUTES = $000003F2;

type
 PObjectAttributes = ^TObjectAttributes;
 TObjectAttributes = record
   Length: ULONG;
   RootDirectory: THandle;
   ObjectName: PUnicodeString;
   Attributes: ULONG;
   SecurityDescriptor: PSecurityDescriptor;
   SecurityQualityOfService: PSecurityQualityOfService;
 end;

const
 ObjectPhysicalMemoryDeviceName = '\Device\PhysicalMemory';
 ObjectPhysicalMemoryName: TUnicodeString = (
   Length: Length(ObjectPhysicalMemoryDeviceName) * 2;
   MaximumLength: Length(ObjectPhysicalMemoryDeviceName) * 2 + 2;
   Buffer: ObjectPhysicalMemoryDeviceName;
   );
 ObjectPhysicalMemoryAccessMask: ACCESS_MASK = SECTION_MAP_READ;
 ObjectPhysicalMemoryAttributes: TObjectAttributes = (
   Length: SizeOf(TObjectAttributes);
   RootDirectory: 0;
   ObjectName: @ObjectPhysicalMemoryName;
   Attributes: OBJ_CASE_INSENSITIVE;
   SecurityDescriptor: nil;
   SecurityQualityOfService: nil;
   );

type
 TFNZwOpenSection = function(out SectionHandle: THandle;
   DesiredAccess: ACCESS_MASK; ObjectAttributes: PObjectAttributes): NTSTATUS;
 stdcall;
 TFNRtlNtStatusToDosError = function(Status: NTSTATUS): DWORD; stdcall;

const
 ntdll = 'ntdll.dll';

var
 ZwOpenSection: TFNZwOpenSection;
 RtlNtStatusToDosError: TFNRtlNtStatusToDosError;

function ReadRomBiosNt(var Buffer: TRomBiosDump; Timeout: DWORD): Boolean;
var
 NtLayer: HMODULE;
 Status: NTSTATUS;
 Section: THandle;
 View: Pointer;
begin
 Result := False;
 NtLayer := GetModuleHandle(ntdll);
 if NtLayer = 0 then
   SetLastError(ERROR_CALL_NOT_IMPLEMENTED)
 else
 begin
   if not Assigned(ZwOpenSection) then
     ZwOpenSection := GetProcAddress(NtLayer, 'ZwOpenSection');
   if not Assigned(RtlNtStatusToDosError) then
     RtlNtStatusToDosError := GetProcAddress(NtLayer,
       'RtlNtStatusToDosError');
   if not (Assigned(ZwOpenSection) and Assigned(RtlNtStatusToDosError)) then
     SetLastError(ERROR_CALL_NOT_IMPLEMENTED)
   else
   begin
     Status := ZwOpenSection(Section, ObjectPhysicalMemoryAccessMask,
       @ObjectPhysicalMemoryAttributes);
     case Status of
       STATUS_SUCCESS:
         try
           View := MapViewOfFile(Section, ObjectPhysicalMemoryAccessMask, 0,
             Low(TRomBiosDump), SizeOf(TRomBiosDump));
           if Assigned(View) then
           try
             FillChar(Buffer, SizeOf(TRomBiosDump), 0);
             Move(View^, Buffer, SizeOf(TRomBiosDump));
             Result := True;
           finally
             UnmapViewOfFile(View);
           end;
         finally
           CloseHandle(Section);
         end;
       STATUS_ACCESS_DENIED:
         Result := ReadRomBios16(Buffer, Timeout);
     else
       SetLastError(RtlNtStatusToDosError(Status))
     end;
   end;
 end;
end;

{##############################################################################
#
# #
#                               ReadRomBios #
# #
###############################################################################
}

function ReadRomBios(var Dump: TRomBiosDump; Method: TReadRomBiosMethod;
 Timeout: DWORD = INFINITE): Boolean;
begin
 Result := False;
 case Method of
   rrbmAutomatic:
     if (Integer(GetVersion) < 0) then
     try
       Result := ReadRomBios9x(Dump);
     except
       Result := ReadRomBios16(Dump, Timeout);
     end
     else
       Result := ReadRomBiosNt(Dump, Timeout);
   rrbmGeneric:
     Result := ReadRomBios16(Dump, Timeout);
   rrbmMemory:
     Result := ReadRomBios9x(Dump);
   rrbmPhysical:
     Result := ReadRomBiosNt(Dump, Timeout);
 else
   SetLastError(ERROR_INVALID_PARAMETER);
 end;
end;

{##############################################################################
#
# #
#     Utilities to simplify the access to data as generic standard types #
# #
###############################################################################
}

function GetRomBiosBuffer(const Dump: TRomBiosDump; Address: Pointer;
 var Buffer; BufferSize: Cardinal): Cardinal;
//Dump就是 ReadRomBios 读出来的数组,
//Address就是起始的读取的地址,BufferSize就是你要读取的大小。
begin
 Result := 0;
 if (Cardinal(Address) >= Low(TRomBiosDump)) and
   (Cardinal(Address) <= High(TRomBiosDump)) then
 begin
   Result := BufferSize;
   if (Cardinal(Address) + BufferSize > High(TRomBiosDump)) then
     Result := High(TRomBiosDump) - Cardinal(Address) + 1;
   Move(Dump[Cardinal(Address)], Buffer, Result);
 end;
end;

function GetRomBiosString(const Dump: TRomBiosDump; Address: Pointer): string;
begin
 Result := '';
 if (Cardinal(Address) >= Low(TRomBiosDump)) and
   (Cardinal(Address) <= High(TRomBiosDump)) then
   Result := string(PChar(@Dump[Cardinal(Address)]));
end;

function GetRomBiosLongLong(const Dump: TRomBiosDump; Address: Pointer):
 LONGLONG;
type
 PLongLong = ^LONGLONG;
begin
 Result := 0;
 if (Cardinal(Address) >= Low(TRomBiosDump)) and
   (Cardinal(Address) <= High(TRomBiosDump) - SizeOf(LONGLONG) + 1) then
   Result := PLongLong(@Dump[Cardinal(Address)])^;
end;

function GetRomBiosDWord(const Dump: TRomBiosDump; Address: Pointer): DWORD;
begin
 Result := 0;
 if (Cardinal(Address) >= Low(TRomBiosDump)) and
   (Cardinal(Address) <= High(TRomBiosDump) - SizeOf(DWORD) + 1) then
   Result := PDWORD(@Dump[Cardinal(Address)])^;
end;

function GetRomBiosWord(const Dump: TRomBiosDump; Address: Pointer): Word;
begin
 Result := 0;
 if (Cardinal(Address) >= Low(TRomBiosDump)) and
   (Cardinal(Address) <= High(TRomBiosDump) - SizeOf(Word) + 1) then
   Result := PWord(@Dump[Cardinal(Address)])^;
end;

function GetRomBiosByte(const Dump: TRomBiosDump; Address: Pointer): Byte;
begin
 Result := 0;
 if (Cardinal(Address) >= Low(TRomBiosDump)) and
   (Cardinal(Address) <= High(TRomBiosDump) - SizeOf(Byte) + 1) then
   Result := PByte(@Dump[Cardinal(Address)])^;
end;
function GetmotherboradKey: string; //取得主办序列号
var
 RBD: TRomBiosDump;
begin
 if ReadRomBios(RBD, rrbmAutomatic) then
 begin
   result := GetRomBiosString(RBD, Ptr($FEC71));
 end
 else
   result := 'sadgf00net';
end;
function Getmotherboradver: string; //BIOS 版本
var
 RBD: TRomBiosDump;
begin
 if ReadRomBios(RBD, rrbmAutomatic) then
 begin
   result := GetRomBiosString(RBD, Ptr($FE061));
 end
 else
   result := 'sadgf00net';
end;
function Getmotherboradverxx: string; //BIOS 版权信息
var
 RBD: TRomBiosDump;
begin
 if ReadRomBios(RBD, rrbmAutomatic) then
 begin
   result := GetRomBiosString(RBD, Ptr($FE091));
 end
 else
   result := 'sadgf00net';
end;
function Getmotherboraddate: string; //BIOS日期
var
 RBD: TRomBiosDump;
begin
 if ReadRomBios(RBD, rrbmAutomatic) then
 begin
   result := GetRomBiosString(RBD, Ptr($FFFF5));
 end
 else
   result := 'sadgf00net';
end;
function Getmotherboradname: string; //BIOS 名称
var
 RBD: TRomBiosDump;
begin
 if ReadRomBios(RBD, rrbmAutomatic) then
 begin
   result := GetRomBiosString(RBD, Ptr($FE0C1));
 end
 else
   result := 'sadgf00net';
end;
end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -