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

📄 smbiosinformation.cpp

📁 Windows下Hardware直接读写
💻 CPP
字号:
#include "StdAfx.h"
#include ".\smbiosinformation.h"
#include ".\HwReadWrite.h"


CSMBiosInformation::CSMBiosInformation(void)
: m_pStartAddress(0)
{
}

CSMBiosInformation::~CSMBiosInformation(void)
{
}

const char sm_anchor_string[5] = {"_SM_"};

bool CSMBiosInformation::getSMStartAddress(void)
{
	int MemLength = 0x1000;
	BYTE pBuffer[0x1000+1];
	for(PBYTE dwBase = (PBYTE)0xF0000; dwBase < (PBYTE)0xFFFFF; dwBase += MemLength)
	{
		gpHwRw->GetMemoryData((PBYTE)dwBase, MemLength, pBuffer);
		for(int i = 0; i < (int)(MemLength - strlen(sm_anchor_string)); i++)
		{
			if(strncmp((char*)&pBuffer[i], sm_anchor_string, strlen(sm_anchor_string)) == 0 )
			{
				//dwFindOffset = i;
				m_pStartAddress = dwBase + i;
				return true;
			}
		}		
	}//end of for the MemLength
	return false;
}

// get the all the data of type nType, dump to buffer
int CSMBiosInformation::getInfoTypeBytes()
{
	BYTE tmpBuffer[0x1000 + 1];
	DWORD iIndex;
	BOOL bRead;
	BOOL get_string = false;
	DMITYPEINFO dmiInfo;
	DWORD tableAddress;

	if(m_pStartAddress == 0)
	{
		bRead = getSMStartAddress();
	}
////
	DWORD dwBaseAddress = (DWORD)m_pStartAddress & 0xFFFFF000;
	//get type 0 binary data
	gpHwRw->GetMemoryData((PBYTE)dwBaseAddress, 0x1000, tmpBuffer);	
	iIndex = (DWORD)m_pStartAddress - dwBaseAddress;
	tableAddress = *((DWORD*)&tmpBuffer[iIndex + 18]); // 05h is entry table length

	tableAddress = 0xf3abf;
	dwBaseAddress = tableAddress & 0xFFFFF000;
	gpHwRw->GetMemoryData((PBYTE)dwBaseAddress, 0x1000, tmpBuffer);
	iIndex = tableAddress - dwBaseAddress;
	//get the string table data 
	for(; iIndex < 0x1000; iIndex++)
	{
		
		if(get_string == false)
		{
			//tmpBuffer[iIndex + 1] is the header length
			if(tmpBuffer[iIndex] == 127)
			{
				break;
			}
			memcpy(&dmiInfo.dmiHeader, &tmpBuffer[iIndex], sizeof(DMIHEADER));
			dmiInfo.startAddr = (PBYTE)(dwBaseAddress + iIndex);
			iIndex += (tmpBuffer[iIndex + 1]); //iIndex + 1 is length
			if(tmpBuffer[iIndex] == 0)
			{
				//no string referenced
				get_string = false;
				//add this informatin to list
				dmiInfo.endAddr = (PBYTE)dwBaseAddress + iIndex;
				dmiInfo.pBuffer = new BYTE[iIndex];
				memcpy(dmiInfo.pBuffer, &tmpBuffer[(DWORD)dmiInfo.startAddr - dwBaseAddress], dmiInfo.endAddr - dmiInfo.startAddr);
				this->listDMITypeInfo.push_back(dmiInfo);
				if(tmpBuffer[iIndex+1] == 0)
				{
					iIndex ++;
				}
			}
			else
			{
				get_string = true;
			}
		}
		else
		{
			//get the string
			if(tmpBuffer[iIndex] == 0 && tmpBuffer[iIndex + 1] == 0)
			{
				iIndex += 1;
				//add this informatin to list
				dmiInfo.endAddr = (PBYTE)dwBaseAddress + iIndex;
				dmiInfo.pBuffer = new BYTE[iIndex];
				memcpy(dmiInfo.pBuffer, &tmpBuffer[(DWORD)dmiInfo.startAddr - dwBaseAddress], dmiInfo.endAddr - dmiInfo.startAddr);
				this->listDMITypeInfo.push_back(dmiInfo);
				get_string = false;
			}
		}
	}
	return 0;
}

int CSMBiosInformation::getInfoEntryTable(PBYTE pStartAddr , PBYTE pEndAddr, SM_STRUCT_TABLE_ENTRY* pEntryTable  )
{
	if(!pEntryTable || !pStartAddr)
	{
		return -1;
	}
	gpHwRw->GetMemoryData((PBYTE)pStartAddr, sizeof(SM_STRUCT_TABLE_ENTRY), (PBYTE)pEntryTable);	
	pEndAddr = pStartAddr + sizeof(SM_STRUCT_TABLE_ENTRY);
	return 0;
}


int CSMBiosInformation::dumpDMIInformation(void)
{
	
	return 0;
}

int CSMBiosInformation::GetSMTypeName(int type, char* typeName)
{
	CString strLine;
	CString strOffset;
	CString strDes;
	CStdioFile fileTypeName;
	if(typeName == NULL)
	{
		return -1;
	}
	if(!fileTypeName.Open("SMType.txt", CFile::modeRead))
	{
		return -1;
	}
	while(fileTypeName.ReadString(strLine))
	{
		 if(strLine.GetAt(0) == '#' || strLine.GetAt(0) == ';')
		{
			//comments, continue
			continue;
		}
		strOffset = strLine.Left(2);
		if(type == _tcstoul(strOffset, 0, 16))
		{
			strncpy(typeName, strLine.GetBuffer(0) + 3, 128);
			fileTypeName.Close();
			return 0;
		}
		
	}
	strncpy(typeName, "Unknown Type", 16);
	fileTypeName.Close();
	return 0;
}

⌨️ 快捷键说明

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