Beispiel #1
0
int _tmain(int argc, _TCHAR* argv[])
{
	DWORD needBufferSize = 0;
	// the seqence just for x86, but don't worry we know SMBIOS/DMI only exist on x86 platform
	const BYTE byteSignature[] = { 'B', 'M', 'S', 'R' };
	const DWORD Signature = *((DWORD*)byteSignature);
	LPBYTE pBuff = NULL;

	needBufferSize = GetSystemFirmwareTable(Signature, 0, NULL, 0);

	_tprintf(TEXT("We need prepare %d bytes for recevie SMBIOS/DMI Table\n"), needBufferSize);
	pBuff = (LPBYTE) malloc(needBufferSize);
	if (pBuff)
	{
		GetSystemFirmwareTable(Signature, 0, pBuff, needBufferSize);

		const PRawSMBIOSData pDMIData = (PRawSMBIOSData)pBuff;
		_tprintf(TEXT("SMBIOS version:%d.%d\n"), pDMIData->SMBIOSMajorVersion, pDMIData->SMBIOSMinorVersion);
		_tprintf(TEXT("DMI Revision:%x\n"), pDMIData->DmiRevision);
		_tprintf(TEXT("Total length: %d\n"), pDMIData->Length);
		_tprintf(TEXT("DMI at address %x\n"), (DWORD)((PBYTE)&pDMIData->SMBIOSTableData));

		DumpSMBIOSStruct(&(pDMIData->SMBIOSTableData), pDMIData->Length);
	}
	else
		_tprintf(TEXT("Can not allocate memory for recevice SMBIOS/DMI table\n"));

	if (pBuff)
		free(pBuff);
	return 0;
}
Beispiel #2
0
errno_t SMBIOSParse(_Out_ ULONG64 *IDEN_UUID) {
	//Parse some part of SMBIOS, from
	//https://github.com/KunYi/DumpSMBIOS/blob/master/DumpSMBIOS/DumpSMBIOS.cpp

	//Get SMBIOS
	const BYTE byteSignature[] = { 'B', 'M', 'S', 'R' };
	const DWORD Signature = *((DWORD*)byteSignature);
	DWORD needBufferSize = GetSystemFirmwareTable(Signature, 0, NULL, 0);
	LPBYTE pBuff = (LPBYTE)malloc(needBufferSize);
	if (pBuff)
	{
		GetSystemFirmwareTable(Signature, 0, pBuff, needBufferSize);
	}
	else {
		return E_OUTOFMEMORY;
	}
	//Parse
	const PRawSMBIOSData pDMIData = (PRawSMBIOSData)pBuff;
	LPBYTE p = (LPBYTE)(&(pDMIData->SMBIOSTableData));
	const DWORD lastAddress = ((DWORD)p) + pDMIData->Length;
	PSMBIOSHEADER pHeader;
	for (;;) {
		pHeader = (PSMBIOSHEADER)p;
		switch (pHeader->Type)
		{
		case 0://BIOS Info
		{
			PBIOSInfo pBiosInfo = (PBIOSInfo)(pHeader);
			IDEN_UUID[3] = pBiosInfo->Characteristics;
			break;
		}
		case 1://ProcSysInfo
		{
			PSystemInfo pSysInfo = (PSystemInfo)(pHeader);
			memcpy(IDEN_UUID, pSysInfo->UUID, sizeof(pSysInfo->UUID));
			break;
		}
		case 4://CPUInfo
		{
			PProcessorInfo pProcInfo = (PProcessorInfo)(pHeader);
			IDEN_UUID[2] = pProcInfo->ID;
			break;
		}
		default:
			break;
		}
		PBYTE nt = p + pHeader->Length; // point to struct end
		while (0 != (*nt | *(nt + 1))) nt++; // skip string area
		nt += 2;
		if ((DWORD)nt > lastAddress)
			break;
		p = nt;
	}

	free(pBuff);

	return NOERROR;
}