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

📄 bioshelp.pas

📁 del *.obj del *.dcu del *.~* del *.hpp del *.dcp del *.dpl del *.cesettings del *.log upx sy
💻 PAS
📖 第 1 页 / 共 2 页
字号:
unit BiosHelp;

{$ALIGN ON}
{$MINENUMSIZE 4}

interface

uses
 Windows;

type
 PRomBiosDump = ^TRomBiosDump;
 TRomBiosDump = array[$000F0000..$000FFFFF] of Byte;

type
 TReadRomBiosMethod = (
   rrbmAutomatic, { Autodetect OS type and use proper method }
   rrbmGeneric, { Use 16-bit COM program to dump the BIOS  }
   rrbmMemory, { Read from memory (Win9x)                 }
   rrbmPhysical { Read from physical memory object (WinNT) }
   );

function ReadRomBios(var Dump: TRomBiosDump; Method: TReadRomBiosMethod;
 Timeout: DWORD = INFINITE): Boolean;

function GetRomBiosBuffer(const Dump: TRomBiosDump; Address: Pointer;
 var Buffer; BufferSize: Cardinal): Cardinal;
function GetRomBiosString(const Dump: TRomBiosDump; Address: Pointer): string;
function GetRomBiosLongLong(const Dump: TRomBiosDump; Address: Pointer):
 LONGLONG;
function GetRomBiosDWord(const Dump: TRomBiosDump; Address: Pointer): DWORD;
function GetRomBiosWord(const Dump: TRomBiosDump; Address: Pointer): Word;
function GetRomBiosByte(const Dump: TRomBiosDump; Address: Pointer): Byte;
function GetmotherboradKey: string; //取得系统系列号
function Getmotherboradver: string; //BIOS 版本
function Getmotherboraddate: string; //BIOS日期
function Getmotherboradverxx: string; //BIOS 版权信息
function Getmotherboradname: string; //BIOS 名称

implementation

{##############################################################################
#
# #
#                             GENERIC METHOD #
# #
# Create an temporary folder, save an 16bit COM program (RomDump.com) into it,
#
# execute program redirected to an file (Rom.dmp, RomDump.com simply dumps the
#
# memory range F000:0000-F000:FFFF to STDOUT), read dump file into the buffer,
#
# and finally cleanup all temporary files and directories. #
# #
# (the function RomDumpCode is x86 specific, which i wrote to generate 16-bit #
#  code with the help of the 23-bit Delphi compiler, never try to execute the #
#  pseudo-code in your program! it will not work in 32-bit protected mode) #
# #
###############################################################################
}

{ *INTERNAL* - Pseudo 16-bit code }

type
 PRomDumpCodeInfo = ^TRomDumpCodeInfo;
 TRomDumpCodeInfo = (rdciStart, rdciEnd, rdciSize);

function _RomDumpCode(Info: TRomDumpCodeInfo): Pointer;
var
 CodeStart: Pointer;
 CodeEnd: Pointer;
begin
 asm
         JMP     @@End

         { *BEGIN* 16-bit code  }
         { -- never use it in your program! -- }
         { COM which writes ROM-BIOS to StdOut }
 @@Start:
         { Dump F000:0000-F000:FFFE }
         XOR     eDX, eDX  // DS = 0xF000   ; Data segment
         MOV     DH, 0F0h
         MOV     DS, eDX
         XOR     eDX, eDX  // DX = 0x0000   ; Data offset
         XOR     eCX, eCX  // CX = 0xFFFF   ; Data length
         DEC     eCX
         XOR     eBX, eBX  // BX = 0x0001   ; STDOUT (file handle)
         INC     eBX
         MOV     AH, 40h   // DosCall(0x40) ; INT21, DOS_WRITE_TO_HANDLE
         INT     21h
         JC      @@Exit    // On error exit ; AL = Error code
         { Dump F000:FFFF }
         XOR     eDX, eDX  // DS = 0xF000   ; Data segment
         MOV     DH, 0F0h
         MOV     DS, eDX
         XOR     eDX, eDX  // DX = 0xFFFF   ; Data offset
         DEC     eDX
         XOR     eCX, eCX  // CX = 0x0001   ; Data length
         INC     eCX
         MOV     eBX, eCX  // BX = 0x0001   ; STDOUT (file handle)
         MOV     AH, 40h   // DosCall(0x40) ; INT21, DOS_WRITE_TO_HANDLE
         INT     21h
         JC      @@Exit    // On error exit ; AL = Error code
         MOV     AL, 0     // no error      ; AL = 0
 @@Exit:
         MOV     AH, 4Ch   // DosCall(0x4C) ; INT21, DOS_TERMINATE_EXE
         INT     21h
 @@End:
         { *END* 16-bit code  }

         MOV     CodeStart, OFFSET @@Start
         MOV     CodeEnd, OFFSET @@End
 end;
 case Info of
   rdciStart:
     Result := CodeStart;
   rdciEnd:
     Result := CodeEnd;
   rdciSize:
     Result := Pointer(Cardinal(CodeEnd) - Cardinal(CodeStart));
 else
   Result := nil;
 end;
end;

{ *INTERNAL* - Save 16-bit code to file }

function _RomDumpCodeToFile(const Filename: string): Boolean;
var
 ComFile: THandle;
 Size: Cardinal;
begin
 Result := False;
 ComFile := CreateFile(PChar(Filename), GENERIC_WRITE, FILE_SHARE_READ, nil,
   CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
 if ComFile <> INVALID_HANDLE_VALUE then
 try
   Result := WriteFile(ComFile, _RomDumpCode(rdciStart)^,
     Cardinal(_RomDumpCode(rdciSize)), Size, nil) and
     (Size = Cardinal(_RomDumpCode(rdciSize)));
   if not Result then
     DeleteFile(PChar(Filename));
 finally
   CloseHandle(ComFile);
 end;
end;

{ *INTERNAL* - Execute 16-bit code redirected to file }

function _RomDumpCodeExecute(const Com, Dmp: string; Timeout: DWORD): Boolean;
var
 ComSpec: string;
 si: TStartupInfo;
 pi: TProcessInformation;
begin
 Result := False;
 SetLength(ComSpec, MAX_PATH);
 SetLength(ComSpec,
   GetEnvironmentVariable('ComSpec', PChar(@ComSpec[1]), MAX_PATH));
 if Length(ComSpec) > 0 then
 begin
   FillChar(si, SizeOf(TStartupInfo), 0);
   si.cb := SizeOf(TStartupInfo);
   si.dwFlags := STARTF_USESHOWWINDOW;
   si.wShowWindow := SW_HIDE;
   if CreateProcess(nil, PChar(ComSpec + ' /C ' + Com + ' > ' + Dmp),
     nil, nil, False, CREATE_NEW_CONSOLE or CREATE_NEW_PROCESS_GROUP, nil,
     nil, si, pi) then
   try
     Result := WaitForSingleObject(pi.hProcess, Timeout) <> WAIT_TIMEOUT;
   finally
     CloseHandle(pi.hProcess);
     CloseHandle(pi.hThread);
   end;
 end;
end;

function DirectoryExists(const Dir: string): Boolean;
var
 Attr: DWORD;
begin
 Attr := GetFileAttributes(PChar(Dir));
 Result := (Attr <> $FFFFFFFF) and
   (Attr and FILE_ATTRIBUTE_DIRECTORY = FILE_ATTRIBUTE_DIRECTORY);
end;

{ Get BIOS dump the generic way }

function ReadRomBios16(var Buffer: TRomBiosDump; Timeout: DWORD): Boolean;
const
 TempSub = '~RomDmp';
 ComName = 'RomDump.com';
 DmpName = 'Rom.dmp';
var
 TempPath: string;
 TempDir: string;
 TempIdx: Integer;
 TempIdxStr: string;
 ComFile: string;
 DmpFile: string;
 DmpHandle: THandle;
 Written: DWORD;
begin
 Result := False;
 SetLength(TempPath, MAX_PATH);
 SetLength(TempPath, GetTempPath(MAX_PATH, PChar(@TempPath[1])));
 if Length(TempPath) > 0 then
 begin
   if (TempPath[Length(TempPath)] <> '\') then
     TempPath := TempPath + '\';
   TempIdx := 0;
   repeat
     Inc(TempIdx);
     Str(TempIdx, TempIdxStr);
     TempDir := TempPath + TempSub + TempIdxStr;
   until not DirectoryExists(TempDir);
   if CreateDirectory(PChar(TempDir), nil) then
   try
     TempDir := TempDir + '\';
     ComFile := TempDir + ComName;
     DmpFile := TempDir + DmpName;
     if _RomDumpCodeToFile(ComFile) then
     try
       if _RomDumpCodeExecute(ComFile, DmpFile, Timeout) then
       begin
         DmpHandle := CreateFile(PChar(DmpFile), GENERIC_READ,
           FILE_SHARE_READ or FILE_SHARE_WRITE, nil, OPEN_EXISTING, 0, 0);
         if DmpHandle <> INVALID_HANDLE_VALUE then
         try
           FillChar(Buffer, SizeOf(TRomBiosDump), 0);
           Result := ReadFile(DmpHandle, Buffer, SizeOf(TRomBiosDump),
             Written, nil) and (Written = SizeOf(TRomBiosDump));
         finally
           CloseHandle(DmpHandle);
         end;
       end;
     finally
       DeleteFile(PChar(DmpFile));
       DeleteFile(PChar(ComFile));
     end;
   finally
     RemoveDirectory(PChar(TempDir));
   end;
 end;
end;

{##############################################################################
#
# #
#                           DIRECT METHOD (Win9x) #
# #
# Due to the fact that Windows 95/98/ME maps the BIOS into every Win32 process
#
# for read access it is very simple to fill the buffer from memory. #
# #
###############################################################################
}

function ReadRomBios9x(var Buffer: TRomBiosDump): Boolean;
begin
 Result := False;
 try
   FillChar(Buffer, SizeOf(TRomBiosDump), 0);
   Move(Pointer(Low(TRomBiosDump))^, Buffer, SizeOf(TRomBiosDump));
   Result := True;
 except
   // ignore exceptions
 end
end;

{##############################################################################
#
# #
#                       PHYSICAL MEMORY METHOD (WinNT) #
# #
# On Windows NT the ROM BIOS is only available through the named kernel object
#
# '\Device\PhysicalMemory'. Because it is impossible to open kernel objects in
#
# user mode with standard Win32 API functions we make use of NT's nativeAPI in
#
# NtDll.dll ("NT-Layer") namely ZwOpenSection. #
# #
# (note: mostly there are two versions of every function ZwXxx and NtXxx. The #
#  only difference in kernel mode is that the NtXxx version works in conside- #
#  ration to security while ZwXxx not. But in user mode both work like NtXxx.)
#
# #
# At first the section is opened with ZwOpenSection. Normally we would proceed
#
# ZwMapViewOfSection, ZwUnmapViewOfSection, and NtClose. But the functions are
#

⌨️ 快捷键说明

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