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

📄 biosinformation.cpp

📁 取计算机硬件信息的算法、包括CPU、BIOS、HARDID、MAC
💻 CPP
字号:
// BiosInformation.cpp: implementation of the CBiosInformation class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "BiosInformation.h"

typedef struct _UNICODE_STRING {
  USHORT  Length;//长度
  USHORT  MaximumLength;//最大长度
  PWSTR  Buffer;//缓存指针,访问物理内存时,此处指向UNICODE字符串"\device\physicalmemory"
} UNICODE_STRING,*PUNICODE_STRING;

typedef struct _OBJECT_ATTRIBUTES {
    ULONG Length;//长度 18h
    HANDLE RootDirectory;//00000000
    PUNICODE_STRING ObjectName;//指向对象名的指针
    ULONG Attributes;//对象属性00000040h
    PVOID SecurityDescriptor;        //Points to type SECURITY_DESCRIPTOR,0
    PVOID SecurityQualityOfService;  //Points to type SECURITY_QUALITY_OF_SERVICE,0
} OBJECT_ATTRIBUTES,*POBJECT_ATTRIBUTES;

typedef DWORD  (__stdcall *ZWOS)(PHANDLE,ACCESS_MASK,POBJECT_ATTRIBUTES);
typedef DWORD  (__stdcall *ZWMV)(HANDLE,HANDLE,PVOID,ULONG,ULONG,PLARGE_INTEGER,PSIZE_T,DWORD,ULONG,ULONG);

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CBiosInformation::CBiosInformation()
{
	m_lpBiosInfo=NULL;
}

CBiosInformation::~CBiosInformation()
{

}

BOOL CBiosInformation::Init()
{
	if(NULL!=m_lpBiosInfo)
		return TRUE;

	//读入ntdll.dll,得到函数地址
	HMODULE hinstLib;
	ZWOS ZWopenS;
	ZWMV ZWmapV;
    hinstLib=LoadLibrary("ntdll.dll");
	if(NULL==hinstLib)
		return FALSE;
	ZWopenS=(ZWOS)GetProcAddress(hinstLib,"ZwOpenSection");
    ZWmapV=(ZWMV)GetProcAddress(hinstLib,"ZwMapViewOfSection");
	if(NULL==ZWopenS || NULL==ZWmapV)
		return FALSE;
	
	//调用函数,对物理内存进行映射
	wchar_t strPH[]=L"\\device\\physicalmemory";//*
	UNICODE_STRING struniph;
    struniph.Buffer=strPH;
	struniph.Length=0x2c;//*注意大小是按字节算,双字节一个字符
	struniph.MaximumLength =0x2e;//也是字节
	OBJECT_ATTRIBUTES obj_ar;
    obj_ar.Attributes=64;//属性40h
	obj_ar.Length=24;//OBJECT_ATTRIBUTES类型的长度18h
	obj_ar.ObjectName=&struniph;//指向对象的指针
	obj_ar.RootDirectory=0;
	obj_ar.SecurityDescriptor=0;
    obj_ar.SecurityQualityOfService=0;
	HANDLE hSection;
    if(0!=ZWopenS(&hSection,4,&obj_ar))
		return FALSE;

	DWORD ba;
	LARGE_INTEGER so;
	SIZE_T ssize;
    ba=0;//联系后的基址将在这里返回
	so.LowPart=0x000f0000;//物理内存的基址,就是f000:0000
	so.HighPart=0x00000000;
	ssize=0xffff;
	if(0!=ZWmapV((HANDLE)hSection,(HANDLE)0xffffffff,&ba,0,0xffff,&so,&ssize,1,0,2))
		return FALSE;

	m_lpBiosInfo=(LPSTR)ba;
	
	return TRUE;
}

BOOL CBiosInformation::GetBiosDate(LPSTR szDate)
{
	if(0==isalnum(*(m_lpBiosInfo+0xfff5)))
		return FALSE;
	
	strcpy(szDate,m_lpBiosInfo+0xfff5);

	return TRUE;
}

BOOL CBiosInformation::GetAwardBiosID(LPSTR szBiosID)
{
//	if(strstr(m_lpBiosInfo+0xe061,"Award")==NULL)
//		return FALSE;

	if(0==isalnum(*(m_lpBiosInfo+0xe061)) || 0==isalnum(*(m_lpBiosInfo+0xec71)))
		return FALSE;

	strcpy(szBiosID,m_lpBiosInfo+0xec71);

	return TRUE;
}

BOOL CBiosInformation::GetAMIBiosID(LPSTR szBiosID)
{
//	if(strnicmp(m_lpBiosInfo+0xf400,"AMIBIOS",7)!=0)
//		return FALSE;

	if(0==isalnum(*(m_lpBiosInfo+0xf400)) || 0==isalnum(*(m_lpBiosInfo+0xf478)))
		return FALSE;

	strcpy(szBiosID,m_lpBiosInfo+0xf478);

	return TRUE;
}

BOOL CBiosInformation::GetBiosID(LPSTR szBiosID)
{
	if(!Init())
	{
		*szBiosID='\0';
		return FALSE;
	}

	if(!GetAwardBiosID(szBiosID))
	{
		if(!GetAMIBiosID(szBiosID))
		{
			if(!GetBiosDate(szBiosID))
			{
				*szBiosID='\0';
				return FALSE;
			}
		}
	}

	return TRUE;
}

⌨️ 快捷键说明

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