您现在的位置: 捷凌网安 >> 编程语言 >> Delphi编程 >> 正文
获取主板BIOS的信息

作者:佚名 责任编辑:左决 点击数: 更新时间:2008-2-16 5:42:18

1、读取主板序列号
2、AWard Bios密码读取
3、读取BIOS信息
4、获取BIOS日期信息

=========================================
1、读取主板序列号

uses SHA1, Base64;

 function GetHashedBiosInfo: string;
 var
   SHA1Context: TSHA1Context;
   SHA1Digest: TSHA1Digest;
 begin
   // Get the BIOS data
   SetString(Result, PChar(Ptr($F0000)), $10000);
   // Hash the string
   SHA1InIT(SHA1Context);
   SHA1Update(SHA1Context, PChar(Result), Length(Result));
   SHA1Final(SHA1Context, SHA1Digest);
   SetString(Result, PChar(@SHA1Digest), sizeof(SHA1Digest));
   // Return the hash string encoded in printable characters
   Result := B64Encode(Result);
 end;


 function GetBiosInfoAsText: string;
 var
   p, q: pchar;
 begin
   q := nil;
   p := PChar(Ptr($FE000));
   repeat
     if q <> nil then begin
       if not (p^ in [#10, #13, #32..#126, #169, #184]) then begin
         if (p^ = #0) and (p - q >= 8) then begin
           Result := Result + TrimRight(String(q)) + #13#10;
         end;
         q := nil;
       end;
     end else
       if p^ in [#33..#126, #169, #184] then
         q := p;
     inc(p);
   until p > PChar(Ptr($FFFFF));
   Result := TrimRight(Result);
 end;

 procedure TForm1.FormCreate(Sender: TObject);
 begin
   Memo1.Lines.Text := GetBiosInfoAsText;
 end;

==========================================
2、AWard Bios密码读取(应该是jingtao的文章,但是ID没有记录)
UnIT AwardBiosPas;
//WrITe by lovejingtao
//http://www.138soft.com
interface
uses windows,SysUtils;

function My_GetBiosPassword:String;
implementation

function CalcPossiblePassword(PasswordValue: WORD): string;
var
 I: BYTE;
 C: CHAR;
 S: string[8];

begin
 I := 0;
 while PasswordValue <> 0 do
   begin
     Inc(I);
     if $263 > PasswordValue then
       begin
         if $80 > PasswordValue then
           S[I] := CHAR(PasswordValue)
         else if $B0 > PasswordValue then
           S[I] := CHAR(PasswordValue and $77)
         else if $11D > PasswordValue then
           S[I] := CHAR($30 or (PasswordValue and $0F))
         else if $114 > PasswordValue then
           begin
             S[I] := CHAR($64 or (PasswordValue and $0F));
             if '0' > S[I] then
               S[I] := CHAR(BYTE(S[I]) + 8);
           end
         else if $1C2 > PasswordValue then
           S[I] := CHAR($70 or (PasswordValue and $03))
         else if $1E4 > PasswordValue then
           S[I] := CHAR($30 or (PasswordValue and $03))
         else
           begin
             S[I] := CHAR($70 or (PasswordValue and $0F));
             if 'z' < S[I] then
               S[I] := CHAR(BYTE(S[I]) - 8);
           end;
       end
     else
       S[I] := CHAR($30 or (PasswordValue and $3));
     PasswordValue := (PasswordValue - BYTE(S[I])) shr 2;
   end;

 S[0] := CHAR(I);
 PasswordValue := I shr 1;
 while PasswordValue < I do
   begin {this is to do because award starts calculating wITh the last letter}

     C := S[BYTE(S[0]) - I + 1];
     S[BYTE(S[0]) - I + 1] := S[I];
     S[I] := C;
     Dec(I);
   end;
 CalcPossiblePassword := S;
end;

function readcmos(off: byte): byte;
var
 value: byte;
begin
 asm
     xor ax, ax
     mov al, off
     out 70h, al
     in  al, 71h
     mov value, al
 end;
 readcmos := value;
end;
function My_GetBiosPassword:String;
var
 superpw, userpw: word;
 S:String;
begin
if Win32Platform <> VER_PLATFORM_WIN32_NT then //不是NT
begin
 pchar(@superpw)[0] := char(readcmos($1C));
 pchar(@superpw)[1] := char(readcmos($1D));
 pchar(@userpw)[0] := char(readcmos($64));
 pchar(@userpw)[1] := char(readcmos($65));
 S:='超级用户密码为:'+CalcPossiblePassword(superpw)+#13+'用户密码为:'+CalcPossiblePassword(userpw);
 Result:=S;
 end
 else
 Result:='用户系统为NT,无法获取BISO密码!';
 end;
end.

==========================================
3、读取BIOS信息
{程序使用Windows 95/2000平台,自动检测系统类型,然后进行不同调用}
uses BiosHelp;

procedure TForm1.Button1Click(Sender: TObject);
var
 Dump: TRomBiosDump;
 i: Integer;
begin
 ReadRomBios(Dump, rrbmAutomatic);
 for i := 1 to $000FFFFF - $000F0000 - 1 do
   Memo1.Lines.Add(IntToHex(Dump[i + $000FFFFF], 2));
end;
(*******************************************************************************
*                                                                              *
* BIOS Help - read ROM BIOS on Windows 95/98/SE/ME/NT/2K/XP                    *
*                                                                              *
* Copyright (C) 2001, Nico Bendlin (nico@bendlin.de)                           *
*                                                                              *
* Compiler: Delphi 4.03/5.01/6.00                                              *
* Version: 1.03, 2001-09-02                                                    *
*                                                                              *
*******************************************************************************)

{ postum scriptum: sorry for the bad english, i wrote IT in a hurry }

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;

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

[1] [2] 下一页

  • 上一篇文章:

  • 下一篇文章:
  •  
    最进更新
    普通文章VC++设计超强仿QQ自动伸缩窗04-17
    推荐文章基于HOOK和MMF的Win密码渗透04-17
    推荐文章几种VC++数据库开发技术的相04-17
    普通文章多线程、Socket技术及委托技04-11
    推荐文章VB.Net连接各种数据库的几种04-11
    普通文章VB.NET中的多窗体编程:升级04-11
    普通文章用VB.NET定制Windows控件04-11
    普通文章VB.NET中监视文件夹的变化04-11
    普通文章VB.NET中对象的克隆04-11
    推荐文章VB.NET中的TextBox控件详解04-11
     
    推荐文章
    推荐文章基于HOOK和MMF的Win密码渗透04-17
    推荐文章几种VC++数据库开发技术的相04-17
    推荐文章VB.Net连接各种数据库的几种04-11
    推荐文章VB.NET中的TextBox控件详解04-11
    推荐文章在VB.NET中进行抓屏04-11
    推荐文章VB.Net开发的长内容自动分页04-11
    推荐文章VB.NET中快速访问注册表技巧04-11
    推荐文章PHP5手动最简安装方法03-07
    推荐文章完全讲解PHP+MySQL的分页显示03-07
    推荐文章Linux Shell元字符知识笔记02-21
     
    热点文章 
    普通文章VC++设计超强仿QQ自动伸缩窗04-17
    推荐文章基于HOOK和MMF的Win密码渗透04-17
    推荐文章几种VC++数据库开发技术的相04-17
    普通文章VB.NET中的多窗体编程:升级04-11
    普通文章用VB.NET定制Windows控件04-11
    普通文章VB.NET中对象的克隆04-11
    推荐文章VB.NET中的TextBox控件详解04-11
    普通文章VB/VB.NET/C#导出到Excel的方04-11
    普通文章如何通过VB.NET获取网卡地址04-11
    普通文章VB.NET中使用ListView控件的04-11

    | 设为首页 | 加入收藏 | 联系站长 | 广告服务 | 友情链接 | 版权申明 | 网站地图 |

    在线交流 捷凌网安主群:51649627
    Copyright 2007-2008 © 捷凌网安. All rights reserved.
    备案序号:蜀ICP备08001812号