?? 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 + -