📄 ctrlcmos.cpp
字号:
#include "StdAfx.h"
#include "ctrlcmos.h"
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <conio.h>
CCtrlCMOS::CCtrlCMOS(void)
{
CMOSRecord = new BYTE[128];
memset(CMOSRecord,0,0x80);
}
CCtrlCMOS::~CCtrlCMOS(void)
{
if (CMOSRecord!=NULL)
delete CMOSRecord;
}
/* 从CMOS内存中读信息 */
void CCtrlCMOS::ReadCMOSWIN98(void)
{
int t=0;
for(int i=0;i<128;i++)
{
_outp(0x70,t);
*(CMOSRecord+i) = (BYTE)t;
}
/*
BYTE *temp=CMOSRecord;
__asm
{
mov esi, dword ptr temp
mov cx,0x80
mov ah,0
mov ebx,0
mov dx,0x70 // CMOS口地址
l1:
mov al,ah
out dx,al
inc dx
in al,dx
mov BYTE PTR [esi+ebx],al
inc ah
inc ebx
dec dx
loop l1
}
*/
/*
; CMOSRead
;
; On call: AL = CMOS-register to read
;
; Returns: AH = contents of the CMOS-register read
__asm
{
or al, 80h // disable NMI
cli // disable interrupts
out 70h, al // write to indexport 70h
jmp short $+2 // short I/O delay
in al, 71h // read from dataport 71h
mov ah, al // store in AH
xor al, al // AL = 0
out 70h, al // enable NMI
sti // enable interrupts
}*/
}
/* 向CMOS内存写入信息 */
void CCtrlCMOS::WriteCMOSWIN98(void)
{
BYTE *temp = CMOSRecord;
__asm
{
mov esi,dword ptr temp
mov cx,0x80
mov ah,0
mov ebx,0
mov dx,0x70
_L1:
mov al,ah
out dx,al
mov al,byte ptr [esi+ebx]
inc dx
out dx,al
inc ah
inc ebx
dec dx
loop _L1
}
/*
; CMOSWrite
;
; On call: AH = value to be written
; AL = CMOS-register to write to
;
; Returns: nothing
CMOSWrite PROC NEAR
or al, 80h ; disable NMI
cli ; disable interrupts
out 70h, al ; write to indexport 70h
mov al, ah ; value in AL
jmp short $+2 ; short I/O delay
out 71h, al ; write to dataport 71h
xor al, al ; AL = 0
jmp short $+2 ; short I/O delay
out 70h, al ; enable NMI
sti ; enable interrupts
ret ; return
CMOSWrite ENDP
*/
}
void CCtrlCMOS::WriteFileWIN98(void)
{
CString sPath;
GetModuleFileName(NULL,sPath.GetBufferSetLength(MAX_PATH+1),MAX_PATH);
sPath.ReleaseBuffer ();
int nPos;
nPos=sPath.ReverseFind ('\\');
sPath=sPath.Left (nPos);
CString lpszFile = sPath + "\\CMOS.MEM";
FILE *f1;
char flnm[255];
strcpy(flnm,lpszFile);
if ((f1 = fopen(flnm,"wb"))==NULL) { /* 建立一个二进制文件 */
printf("File does not opened !");
}
fwrite(CMOSRecord,128,1,f1); /* 写CMOS内存信息记录到文件 */
fclose(f1);
}
void CCtrlCMOS::ReadBIOSWINNT(void)
{
UNICODE_STRING struniph;
OBJECT_ATTRIBUTES obj_ar;
ZWOS ZWopenS;
ZWMV ZWmapV;
ZWUMV ZWunmapV;
HANDLE hSection;
HMODULE hinstLib;
DWORD ba;
LARGE_INTEGER so;
SIZE_T ssize;
so.LowPart=0x000f0000;//物理内存的基址,就是f000:0000
so.HighPart=0x00000000;
ssize=0xffff;
wchar_t strPH[30]=L"\\device\\physicalmemory";
FILE *f1;
// 初始化全局字符串
//变量初始化
ba=0;//联系后的基址将在这里返回
struniph.Buffer=strPH;
struniph.Length=0x2c;//注意大小是按字节算
struniph.MaximumLength =0x2e;//也是字节
obj_ar.Attributes =64;//属性
obj_ar.Length =24;//OBJECT_ATTRIBUTES类型的长度
obj_ar.ObjectName=&struniph;//指向对象的指针
obj_ar.RootDirectory=0;
obj_ar.SecurityDescriptor=0;
obj_ar.SecurityQualityOfService =0;
//读入ntdll.dll,得到函数地址
hinstLib = LoadLibrary("ntdll.dll");
ZWopenS=(ZWOS)GetProcAddress(hinstLib,"ZwOpenSection");
ZWmapV=(ZWMV)GetProcAddress(hinstLib,"ZwMapViewOfSection");
ZWunmapV=(ZWUMV)GetProcAddress(hinstLib,"ZwUnmapViewOfSection");
//调用函数,对物理内存进行映射
ZWopenS(&hSection,4,&obj_ar);
ZWmapV((HANDLE)hSection,(HANDLE)0xffffffff,&ba,0,0xffff,&so,&ssize,1,0,2);
CString sPath;
GetModuleFileName(NULL,sPath.GetBufferSetLength(MAX_PATH+1),MAX_PATH);
sPath.ReleaseBuffer ();
int nPos;
nPos=sPath.ReverseFind ('\\');
sPath=sPath.Left (nPos);
CString lpszFile = sPath + "\\BIOS.MEM";
char flnm[255];
strcpy(flnm,lpszFile);
f1=fopen(flnm,"wb+");
fwrite((void*)ba,65536,1,f1);
fclose(f1);
MessageBox(NULL,"Bios saved to"+lpszFile,"Save OK",MB_OK);
}
void CCtrlCMOS::ReadFileWin98(void)
{
static char BASED_CODE szFilter[] = "CMOS Data Files (*.MEM)|*.MEM||";
CFileDialog dlg(TRUE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, szFilter, NULL );
dlg.m_ofn.lpstrTitle = "Open CMOS Data File";
if( IDOK != dlg.DoModal() )
return;
CString szFileName = dlg.m_ofn.lpstrFile;
CFile frecord;
if (!frecord.Open(szFileName,CFile::modeRead))
{ /* 打开一个二进制文件 */
AfxMessageBox("Open File Failed!");
return;
}
frecord.Read(CMOSRecord,128); /* 从文件中读CMOS内存信息 */
frecord.Close();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -