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

📄 bioshelp.pas

📁 安邦售楼系统单机版 (DELPHI格式源码),比较实用
💻 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 := 'No BIOS key';
End;

Function Getmotherboradver: String;     //BIOS 版本
Var
   RBD              : TRomBiosDump;
Begin
   If ReadRomBios(RBD, rrbmAutomatic) Then Begin
      result := GetRomBiosString(RBD, ptr($FE061));
   End
   Else
      result := 'No BIOS ver';
End;

Function Getmotherboradverxx: String;   //BIOS 版权信息
Var
   RBD              : TRomBiosDump;
Begin
   If ReadRomBios(RBD, rrbmAutomatic) Then Begin
      result := GetRomBiosString(RBD, ptr($FE091));
   End
   Else
      result := 'No BIOS Copyright';
End;

Function Getmotherboraddate: String;    //BIOS日期
Var
   RBD              : TRomBiosDump;
Begin
   If ReadRomBios(RBD, rrbmAutomatic) Then Begin
      result := GetRomBiosString(RBD, ptr($FFFF5));
   End
   Else
      result := 'No BIOS date';
End;

Function Getmotherboradname: String;    //BIOS 名称
Var
   RBD              : TRomBiosDump;
Begin
   If ReadRomBios(RBD, rrbmAutomatic) Then Begin
      result := GetRomBiosString(RBD, ptr($FE0C1));
   End
   Else
      result := 'No BIOS name';
End;
End.

⌨️ 快捷键说明

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