📄 smstdfun.cpp
字号:
#include "StdAfx.h"
// Description: A sample to show how to get SMBios information
// Author : Hercules Zeng
// Emailto : HexTech@hotmail.com
// Note : I'm very happy if you like it and modify it.
//#include "General.h"
#include "SMStdStr.h"
//#include "PhyMemFu.h"
#include <memory.h>
#include <string.h>
#include <stdio.h>
#include ".\HwReadWrite.h"
#include "winio.h"
SM_STRUCT_TABLE_ENTRY g_TableEntry;
list<dmiType0> g_type0;
BYTE g_type0Remains[64] = "";
DWORD g_type0RemainsLen = 0;
DWORD g_type0PhyAddress = 0;
list<dmiType1> g_type1;
BYTE g_type1Remains[64] = "";
DWORD g_type1RemainsLen = 0;
DWORD g_type1PhyAddress = 0;
list<dmiType2> g_type2;
BYTE g_type2Remains[64] = "";
DWORD g_type2RemainsLen = 0;
DWORD g_type2PhyAddress = 0;
list<dmiType3> g_type3;
BYTE g_type3Remains[64] = "";
DWORD g_type3RemainsLen = 0;
DWORD g_type3PhyAddress = 0;
list<dmiType4> g_type4;
BYTE g_type4Remains[64] = "";
DWORD g_type4RemainsLen = 0;
DWORD g_type4PhyAddress = 0;
list<dmiType5> g_type5;
BYTE g_type5Remains[64] = "";
DWORD g_type5RemainsLen = 0;
DWORD g_type5PhyAddress = 0;
list<dmiType6> g_type6;
BYTE g_type6Remains[64] = "";
DWORD g_type6RemainsLen = 0;
DWORD g_type6PhyAddress = 0;
DWORD g_dwPhyAddress[60];
DWORD g_dwEntryPhyAddress;
#pragma pack(1)
char SM_ANCHOR_STRING[5] = "_SM_";
const DWORD BIOS_ADDRESS_START = 0xF0000;
const DWORD BIOS_ADDRESS_END = 0xFFFFF;
const DWORD MemLength = 0x1000;
//----------------------------------------------------------------------------
// Return value: 0 means succeed, otherwise fail.
int findAnchorStringInPhyArea(DWORD dwStartAddress,
DWORD dwEndAddress,
char* strAnchor,
BYTE* pBuffer,
DWORD& dwFindOffset,
DWORD& dwPhyAddress)
{
for(DWORD dwBase = dwStartAddress; dwBase < dwEndAddress; dwBase += MemLength)
{
gpHwRw->GetMemoryData((PBYTE)dwBase, MemLength, pBuffer);
for(int i = 0; i < MemLength - strlen(strAnchor); ++i)
{
if(strncmp((char*)&pBuffer[i], strAnchor, strlen(strAnchor)) == 0 )
{
dwFindOffset = i;
dwPhyAddress = dwBase + i;
return 0;
}
}
}//end of for the MemLength
return -1; //didn't find the string
}
//----------------------------------------------------------------------------
// GetSMTableEntryPoint
//get the table entry
int GetSMTableEntryPoint(SM_STRUCT_TABLE_ENTRY* pEntry, DWORD& dwPhyAddress)
{
DWORD dwFindOffset = 0;
BYTE Buffer[MemLength + 1];
if( 0 == findAnchorStringInPhyArea(BIOS_ADDRESS_START,
BIOS_ADDRESS_END,
SM_ANCHOR_STRING,
Buffer,
dwFindOffset,
dwPhyAddress))
{
memcpy(pEntry, &Buffer[dwFindOffset], sizeof(SM_STRUCT_TABLE_ENTRY));
return 0;
}
return -1;
}
int GetSMTableEntryPointDescription(SM_STRUCT_TABLE_ENTRY* pEntry, char* pBuffer)
{
strcpy(pBuffer, "\r\n\r\n====================Descripition====================\r\n");
char str[260];
memcpy(str, (char*)(pEntry->bAnchorStr), 4);
str[4] = 0;
strcat(pBuffer, "Anchor String : ");
strcat(pBuffer, str);
strcat(pBuffer, "\r\n");
strcat(pBuffer, "Entry Point Structure Checksum : ");
sprintf(str, "%02Xh\r\n", pEntry->bEntryChksum);
strcat(pBuffer, str);
strcat(pBuffer, "Entry Point Length : ");
sprintf(str, "%02Xh\r\n", pEntry->bEntryLen);
strcat(pBuffer, str);
strcat(pBuffer, "SMBIOS Major Version : ");
sprintf(str, "%02Xh\r\n", pEntry->bSMMajorVer);
strcat(pBuffer, str);
strcat(pBuffer, "SMBIOS Minor Version : ");
sprintf(str, "%02Xh\r\n", pEntry->bSMMinVer);
strcat(pBuffer, str);
strcat(pBuffer, "Maximum Structure Size : ");
sprintf(str, "%04Xh\r\n", pEntry->wMaxStructSize);
strcat(pBuffer, str);
strcat(pBuffer, "Entry Point Revision : ");
sprintf(str, "%02Xh\r\n", pEntry->bEntryRev);
strcat(pBuffer, str);
strcat(pBuffer, "Formatted Area : ");
sprintf(str, "%02X%02X%02X%02X%02Xh\r\n", pEntry->bFormattedArea[0],
pEntry->bFormattedArea[1],
pEntry->bFormattedArea[2],
pEntry->bFormattedArea[3],
pEntry->bFormattedArea[4]);
strcat(pBuffer, str);
strcat(pBuffer, "Intermediate anchor string : ");
memcpy(str, (char*)(pEntry->bIntermediateAnchorStr), 5);
str[5] = 0;
strcat(pBuffer, str);
strcat(pBuffer, "\r\n");
strcat(pBuffer, "Intermediate Checksum : ");
sprintf(str, "%02Xh\r\n", pEntry->bIntermediateChksum);
strcat(pBuffer, str);
strcat(pBuffer, "Structure Table Length : ");
sprintf(str, "%04Xh\r\n", pEntry->wStructTableLen);
strcat(pBuffer, str);
strcat(pBuffer, "Structure Table Address : ");
sprintf(str, "%08Xh\r\n", pEntry->dStructTableAddress);
strcat(pBuffer, str);
strcat(pBuffer, "Number of SMBIOS Structures : ");
sprintf(str, "%04Xh\r\n", pEntry->wNumOfSMStruct);
strcat(pBuffer, str);
strcat(pBuffer, "SMBIOS BCD Revision : ");
sprintf(str, "%02Xh\r\n", pEntry->bSMBCDRev);
strcat(pBuffer, str);
return 0;
}
//----------------------------------------------------------------------------
// GetType5
int GetType5(DWORD dwStartAddress, dmiType5* pType5, DWORD& dwPhyAddress)
{
DWORD dwBaseAddress = dwStartAddress & 0xFFFFF000;
BYTE* pBuffer = new BYTE[0x1001];
if( 0 == gpHwRw->GetMemoryData((PBYTE)dwBaseAddress, 0x1000, pBuffer))
{
for(int iIndex = dwStartAddress - dwBaseAddress; iIndex < 0x1000; ++iIndex)
{
if(pBuffer[iIndex] == 0x05)
{
memcpy(pType5, &pBuffer[iIndex], sizeof(dmiType5));
delete [] pBuffer;
return 0;
}
iIndex += pBuffer[iIndex + 1];
for(; iIndex < 0x1000; ++iIndex)
{
if(pBuffer[iIndex] == 0 && pBuffer[iIndex + 1] == 0)
{
iIndex += 1;
break;
}
}
}
}
delete [] pBuffer;
return -1;
}
//----------------------------------------------------------------------------
int GetAllType(DWORD dwStartAddress)
{
DWORD dwBaseAddress = dwStartAddress & 0xFFFFF000;
BYTE* pBuffer = new BYTE[0x1001];
if( 0 == gpHwRw->GetMemoryData((PBYTE)dwBaseAddress, 0x1000, pBuffer))
{
for(int iIndex = dwStartAddress - dwBaseAddress; iIndex < 0x1000; ++iIndex)
{
switch(pBuffer[iIndex])
{
case 0x00:
{
dmiType0 type0;
memcpy(&type0, &pBuffer[iIndex], sizeof(dmiType0));
g_type0.insert(g_type0.end(), type0);
// skip remain string
g_type0PhyAddress = dwBaseAddress + iIndex;
iIndex += sizeof(dmiType0);
int nOld = iIndex;
for(; iIndex < 0x1000; ++iIndex)
{
if(pBuffer[iIndex] == 0 && pBuffer[iIndex + 1] == 0)
{
iIndex += 1;
break;
}
}
memcpy(g_type0Remains, &pBuffer[nOld], iIndex - nOld + 1);
g_type0RemainsLen = iIndex - nOld + 1;
break;
}
case 0x01:
{
dmiType1 type1;
memcpy(&type1, &pBuffer[iIndex], sizeof(dmiType1));
g_type1.insert(g_type1.end(), type1);
// skip remain string
g_type1PhyAddress = dwBaseAddress + iIndex;
iIndex += sizeof(dmiType1);
int nOld = iIndex;
for(; iIndex < 0x1000; ++iIndex)
{
if(pBuffer[iIndex] == 0 && pBuffer[iIndex + 1] == 0)
{
iIndex += 1;
break;
}
}
memcpy(g_type1Remains, &pBuffer[nOld], iIndex - nOld + 1);
g_type1RemainsLen = iIndex - nOld + 1;
break;
}
case 0x02:
{
dmiType2 type2;
memcpy(&type2, &pBuffer[iIndex], sizeof(dmiType2));
g_type2.insert(g_type2.end(), type2);
// skip remain string
g_type2PhyAddress = dwBaseAddress + iIndex;
iIndex += sizeof(dmiType2);
int nOld = iIndex;
for(; iIndex < 0x1000; ++iIndex)
{
if(pBuffer[iIndex] == 0 && pBuffer[iIndex + 1] == 0)
{
iIndex += 1;
break;
}
}
memcpy(g_type2Remains, &pBuffer[nOld], iIndex - nOld + 1);
g_type2RemainsLen = iIndex - nOld + 1;
break;
}
case 0x03:
{
dmiType3 type3;
memcpy(&type3, &pBuffer[iIndex], sizeof(dmiType3));
g_type3.insert(g_type3.end(), type3);
// skip remain string
g_type3PhyAddress = dwBaseAddress + iIndex;
iIndex += sizeof(dmiType3);
int nOld = iIndex;
for(; iIndex < 0x1000; ++iIndex)
{
if(pBuffer[iIndex] == 0 && pBuffer[iIndex + 1] == 0)
{
iIndex += 1;
break;
}
}
memcpy(g_type3Remains, &pBuffer[nOld], iIndex - nOld + 1);
g_type3RemainsLen = iIndex - nOld + 1;
break;
}
case 0x04:
{
dmiType4 type4;
memcpy(&type4, &pBuffer[iIndex], sizeof(dmiType4));
g_type4.insert(g_type4.end(), type4);
// skip remain string
g_type4PhyAddress = dwBaseAddress + iIndex;
iIndex += sizeof(dmiType4);
int nOld = iIndex;
for(; iIndex < 0x1000; ++iIndex)
{
if(pBuffer[iIndex] == 0 && pBuffer[iIndex + 1] == 0)
{
iIndex += 1;
break;
}
}
memcpy(g_type4Remains, &pBuffer[nOld], iIndex - nOld + 1);
g_type4RemainsLen = iIndex - nOld + 1;
break;
}
case 0x05:
{
dmiType5 type5;
memcpy(&type5, &pBuffer[iIndex], sizeof(dmiType5));
g_type5.insert(g_type5.end(), type5);
// skip remain string
//iIndex += pBuffer[iIndex + 1];
g_type5PhyAddress = dwBaseAddress + iIndex;
iIndex += sizeof(dmiType5);
int nOld = iIndex;
for(; iIndex < 0x1000; ++iIndex)
{
if(pBuffer[iIndex] == 0 && pBuffer[iIndex + 1] == 0)
{
iIndex += 1;
break;
}
}
memcpy(g_type5Remains, &pBuffer[nOld], iIndex - nOld + 1);
g_type5RemainsLen = iIndex - nOld + 1;
break;
}
case 0x06:
{
dmiType6 type6;
memcpy(&type6, &pBuffer[iIndex], sizeof(dmiType6));
g_type6.insert(g_type6.end(), type6);
// skip remain string
g_type6PhyAddress = dwBaseAddress + iIndex;
iIndex += sizeof(dmiType6);
int nOld = iIndex;
for(; iIndex < 0x1000; ++iIndex)
{
if(pBuffer[iIndex] == 0 && pBuffer[iIndex + 1] == 0)
{
iIndex += 1;
break;
}
}
memcpy(g_type6Remains, &pBuffer[nOld], iIndex - nOld + 1);
g_type6RemainsLen = iIndex - nOld + 1;
break;
}
case 0x07:
{
delete [] pBuffer;
return 0;
}
}
}
}
delete [] pBuffer;
return -1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -