From c8f8e0c1f0a3687539a92169735845814e18c187 Mon Sep 17 00:00:00 2001
From: gcontini <1121667+gcontini@users.noreply.github.com>
Date: 周六, 31 10月 2020 10:15:16 +0800
Subject: [PATCH] read dmi information segfault on windows

---
 src/library/os/windows/dmi_info.cpp        |    5 -
 /dev/null                                  |   51 -----------------
 test/library/os/CMakeLists.txt             |   21 ++++++
 src/library/os/linux/dmi_info.cpp          |   15 +++-
 src/library/os/windows/isvm/BIOSReader.cpp |   49 ++++++++++++----
 src/library/os/linux/cpu_info.cpp          |   10 +-
 test/library/os/dmi_info_test.cpp          |   25 ++++++++
 src/library/os/CMakeLists.txt              |    2 
 8 files changed, 97 insertions(+), 81 deletions(-)

diff --git a/src/library/os/CMakeLists.txt b/src/library/os/CMakeLists.txt
index 1613ea6..732d076 100644
--- a/src/library/os/CMakeLists.txt
+++ b/src/library/os/CMakeLists.txt
@@ -16,7 +16,6 @@
   	    openssl/signature_verifier.cpp 
         execution_environment_common.cpp 
         windows/execution_environment.cpp
-  	    windows/isvm/Native.cpp
         windows/isvm/BIOSReader.cpp
   	    windows/os_win.cpp
   	    windows/network.cpp)
@@ -30,7 +29,6 @@
         windows/signature_verifier.cpp 
         execution_environment_common.cpp 
         windows/execution_environment.cpp
-        windows/isvm/Native.cpp
         windows/isvm/BIOSReader.cpp
         windows/os_win.cpp
         windows/network.cpp)
diff --git a/src/library/os/linux/cpu_info.cpp b/src/library/os/linux/cpu_info.cpp
index 37620cb..cfb4efc 100644
--- a/src/library/os/linux/cpu_info.cpp
+++ b/src/library/os/linux/cpu_info.cpp
@@ -16,9 +16,9 @@
 using namespace std;
 
 struct CPUVendorID {
-	unsigned int ebx;
-	unsigned int edx;
-	unsigned int ecx;
+	uint32_t ebx;
+	uint32_t edx;
+	uint32_t ecx;
 
 	string toString() const { return string(reinterpret_cast<const char *>(this), 12); }
 };
@@ -56,7 +56,7 @@
  * @return true if the cpu hypervisor bit is set to 1
  */
 bool CpuInfo::is_hypervisor_set() const {
-	unsigned int level = 1, eax = 0, ebx = 0, ecx = 0, edx = 0;
+	uint32_t level = 1, eax = 0, ebx = 0, ecx = 0, edx = 0;
 	__get_cpuid(level, &eax, &ebx, &ecx, &edx);
 
 	bool is_virtual = (((ecx >> 31) & 1) == 1);  // hypervisor flag
@@ -64,7 +64,7 @@
 }
 
 uint32_t CpuInfo::model() const {
-	unsigned int level = 1, eax = 0, ebx = 0, ecx = 0, edx = 0;
+	uint32_t level = 1, eax = 0, ebx = 0, ecx = 0, edx = 0;
 	__get_cpuid(level, &eax, &ebx, &ecx, &edx);
 	// ax bits 0-3 stepping,4-7 model,8-11 family id,12-13 processor type
 	//        14-15 reserved, 16-19 extended model, 20-27 extended family, 27-31 reserved
diff --git a/src/library/os/linux/dmi_info.cpp b/src/library/os/linux/dmi_info.cpp
index e03cbd4..13dc3a7 100644
--- a/src/library/os/linux/dmi_info.cpp
+++ b/src/library/os/linux/dmi_info.cpp
@@ -1,7 +1,7 @@
 
 #include "../../base/file_utils.hpp"
 #include "../../base/string_utils.h"
-
+#include "../../base/logger.h"
 #include "../dmi_info.hpp"
 
 namespace license {
@@ -10,8 +10,9 @@
 DmiInfo::DmiInfo() {
 	try {
 		m_bios_vendor = toupper_copy(trim_copy(get_file_contents("/sys/class/dmi/id/sys_vendor", 256)));
-
-	} catch (...) {
+	} catch (std::string &e) {
+		m_bios_vendor = "";
+		LOG_DEBUG("Can not read sys_vendor", e);
 	}
 	try {
 		m_bios_description = toupper_copy(trim_copy(get_file_contents("/sys/class/dmi/id/modalias", 256)));
@@ -19,7 +20,9 @@
 		if (last_char == '\r' || last_char == '\n') {
 			m_bios_description = m_bios_description.erase(m_bios_description.length() - 1);
 		}
-	} catch (...) {
+	} catch (std::string &e) {
+		m_bios_description = "";
+		LOG_DEBUG("Can not read bios_description", e);
 	}
 	try {
 		m_sys_vendor = get_file_contents("/sys/class/dmi/id/sys_vendor", 256);
@@ -27,7 +30,9 @@
 		if (last_char == '\r' || last_char == '\n') {
 			m_sys_vendor = m_sys_vendor.erase(m_sys_vendor.length() - 1);
 		}
-	} catch (...) {
+	} catch (std::string &e) {
+		m_sys_vendor = "";
+		LOG_DEBUG("Can not read bios_description", e);
 	}
 }
 
diff --git a/src/library/os/windows/dmi_info.cpp b/src/library/os/windows/dmi_info.cpp
index 618be23..478b517 100644
--- a/src/library/os/windows/dmi_info.cpp
+++ b/src/library/os/windows/dmi_info.cpp
@@ -5,22 +5,19 @@
  *      Author: devel
  */
 
-#include <windows.h>
 #include "isvm/BIOSReader.h"
-#include "isvm/Native.h"
 #include "../../base/string_utils.h"
 #include "../dmi_info.hpp"
 
 namespace license {
 namespace os {
 DmiInfo::DmiInfo() {
-	if (InitEntryPoints()) {
+	
 		BIOSReader reader;
 		SystemInformation info = reader.readSystemInfo();
 		m_sys_vendor = toupper_copy(info.Manufacturer);
 		m_bios_vendor = toupper_copy(info.ProductName);
 		m_bios_description = toupper_copy(info.SysVersion) + toupper_copy(info.family);
-	}
 }
 }
 } /* namespace license */
diff --git a/src/library/os/windows/isvm/BIOSReader.cpp b/src/library/os/windows/isvm/BIOSReader.cpp
index 3300964..665da27 100644
--- a/src/library/os/windows/isvm/BIOSReader.cpp
+++ b/src/library/os/windows/isvm/BIOSReader.cpp
@@ -1,8 +1,9 @@
-#include "BIOSReader.h"
-
+#include <windows.h>
 #include <cstdint>
-
-#include "Native.h"
+#include <vector>
+#include <stdint.h>
+#include "BIOSReader.h"
+#include "../../../base/logger.h"
 
 struct smbios_structure_header {
 	uint8_t type;
@@ -96,26 +97,50 @@
 	if (0 != t1->family_str) info->family = (std::string::traits_type::char_type *)string_addr[t1->family_str - 1];
 }
 
+struct RawSMBIOSData {
+	BYTE Used20CallingMethod;
+	BYTE SMBIOSMajorVersion;
+	BYTE SMBIOSMinorVersion;
+	BYTE DmiRevision;
+	DWORD Length;
+	BYTE SMBIOSTableData[];
+};
+
+
+bool readSMBIOS(std::vector<uint8_t> &buffer) {
+	const DWORD tableSignature = ('R' << 24) | ('S' << 16) | ('M' << 8) | 'B';
+	bool can_read = false;
+	uint32_t size = GetSystemFirmwareTable(tableSignature, 0, NULL, 0);
+	if (size > 0) {
+		buffer.resize(size);
+		if (GetSystemFirmwareTable(tableSignature, 0, buffer.data(), size) > 0) {
+			can_read = true;
+		}
+	}
+	return can_read;
+}
+
 SystemInformation BIOSReader::readSystemInfo() {
-	SystemInformation info;
+	SystemInformation info = {};
+	std::vector<uint8_t> buffer;
 
-	uint32_t size = 0;
-	RawSMBIOSData *data = (RawSMBIOSData *)(LocateSMBIOS(&size));
+	if (readSMBIOS(buffer)) {
 
-	if (NULL == data || 0 == size) return info;
+		/*RawSMBIOSData *data = (RawSMBIOSData *)(buffer.data());
 
 	smbios_structure_header *header = (smbios_structure_header *)(data->SMBIOSTableData);
 
-	while (NULL != header) {
+	while (nullptr != header) {
 		if (1 == header->type) {
 			read_smbios_type_1((int8_t *)header, &info);
-			header = NULL;	//!	stop
+			header = nullptr;  //!	stop
 		} else {
 			int32_t offset = ((0x0F) & (header->length >> 4)) * 16 + (header->length & 0x0F);
 			header = (smbios_structure_header *)parse_smbiod_content((int8_t *)header + offset, NULL, NULL);
 		}
+		 }*/
+	} else {
+		LOG_DEBUG("Can't read smbios table");
 	}
-
-	free(data);
 	return info;
 }
diff --git a/src/library/os/windows/isvm/Native.cpp b/src/library/os/windows/isvm/Native.cpp
deleted file mode 100644
index f8568e6..0000000
--- a/src/library/os/windows/isvm/Native.cpp
+++ /dev/null
@@ -1,438 +0,0 @@
-#include "Native.h"
-
-#include <tchar.h>
-
-typedef LARGE_INTEGER PHYSICAL_ADDRESS, *PPHYSICAL_ADDRESS; // windbgkd
-
-typedef LONG NTSTATUS;
-#define NT_SUCCESS(Status) ((NTSTATUS)(Status) >= 0)
-
-typedef struct _UNICODE_STRING
-{
-    USHORT Length;
-    USHORT MaximumLength;
-#ifdef MIDL_PASS
-    [size_is(MaximumLength / 2), length_is((Length) / 2)] USHORT * Buffer;
-#else // MIDL_PASS
-    PWSTR  Buffer;
-#endif // MIDL_PASS
-} UNICODE_STRING;
-typedef UNICODE_STRING *PUNICODE_STRING;
-
-typedef enum _SECTION_INHERIT
-{
-    ViewShare = 1,
-    ViewUnmap = 2
-} SECTION_INHERIT;
-
-#define OBJ_INHERIT             0x00000002L
-#define OBJ_PERMANENT           0x00000010L
-#define OBJ_EXCLUSIVE           0x00000020L
-#define OBJ_CASE_INSENSITIVE    0x00000040L
-#define OBJ_OPENIF              0x00000080L
-#define OBJ_OPENLINK            0x00000100L
-#define OBJ_VALID_ATTRIBUTES    0x000001F2L
-
-static bool bIsWindowsXPLater = false;
-static DWORD dwPageSize = 0;
-
-#ifdef _UNICODE
-#define GetVersionExProc "GetVersionExW"
-#else
-#define GetVersionExProc "GetVersionExA"
-#endif
-
-typedef struct _OBJECT_ATTRIBUTES
-{
-    ULONG Length;
-    HANDLE RootDirectory;
-    PUNICODE_STRING ObjectName;
-    ULONG Attributes;
-    PVOID SecurityDescriptor;        // Points to type SECURITY_DESCRIPTOR
-    PVOID SecurityQualityOfService;  // Points to type SECURITY_QUALITY_OF_SERVICE
-} OBJECT_ATTRIBUTES;
-typedef OBJECT_ATTRIBUTES *POBJECT_ATTRIBUTES;
-
-typedef struct SMBIOSEntryPoint
-{
-    char EntryPointString[4];
-    uint8_t Checksum;
-    uint8_t Length;
-    uint8_t MajorVersion;
-    uint8_t MinorVersion;
-    uint16_t MaxStructureSize;
-    uint8_t EntryPointRevision;
-    char FormattedArea[5];
-    char EntryPointString2[5];
-    uint8_t Checksum2;
-    uint16_t TableLength;
-    uint32_t TableAddress;
-    uint16_t NumberOfStructures;
-    uint8_t BCDRevision;
-} SMBIOSEntryPoint, *PSMBIOSEntryPoint;
-
-#define InitializeObjectAttributes( p, n, a, r, s ) { \
-    (p)->Length = sizeof(OBJECT_ATTRIBUTES);          \
-    (p)->RootDirectory = r;                             \
-    (p)->Attributes = a;                                \
-    (p)->ObjectName = n;                                \
-    (p)->SecurityDescriptor = s;                        \
-    (p)->SecurityQualityOfService = NULL;               \
-}
-
-NTSTATUS(WINAPI *NtUnmapViewOfSection)(
-    IN HANDLE  ProcessHandle,
-    IN PVOID  BaseAddress
-    );
-
-NTSTATUS(WINAPI *NtOpenSection)(
-    OUT PHANDLE  SectionHandle,
-    IN ACCESS_MASK  DesiredAccess,
-    IN POBJECT_ATTRIBUTES  ObjectAttributes
-    );
-
-NTSTATUS(WINAPI *NtMapViewOfSection)(
-    IN HANDLE  SectionHandle,
-    IN HANDLE  ProcessHandle,
-    IN OUT PVOID *BaseAddress,
-    IN ULONG  ZeroBits,
-    IN ULONG  CommitSize,
-    IN OUT PLARGE_INTEGER  SectionOffset,	/* optional */
-    IN OUT PULONG  ViewSize,
-    IN SECTION_INHERIT  InheritDisposition,
-    IN ULONG  AllocationType,
-    IN ULONG  Protect
-    );
-
-VOID(WINAPI *RtlInitUnicodeString)(
-    IN OUT PUNICODE_STRING  DestinationString,
-    IN PCWSTR  SourceString
-    );
-
-ULONG(WINAPI *RtlNtStatusToDosError) (
-    IN NTSTATUS Status
-    );
-
-UINT(WINAPI *Win32GetSystemFirmwareTable)(
-    _In_ DWORD FirmwareTableProviderSignature,
-    _In_ DWORD FirmwareTableID,
-    _Out_writes_bytes_to_opt_(BufferSize, return) PVOID pFirmwareTableBuffer,
-    _In_ DWORD BufferSize);
-
-BOOL(WINAPI *Win32GetVersionEx)(
-    _Inout_  LPOSVERSIONINFO lpVersionInfo
-    );
-
-VOID(WINAPI *Win32GetSystemInfo)(
-    _Out_  LPSYSTEM_INFO lpSystemInfo
-    );
-
-BOOL(WINAPI *Win32VirtualProtect)(
-    _In_   LPVOID lpAddress,
-    _In_   SIZE_T dwSize,
-    _In_   DWORD flNewProtect,
-    _Out_  PDWORD lpflOldProtect
-    );
-
-//----------------------------------------------------------------------
-//
-// PrintError
-//
-// Formats an error message for the last error
-//
-// Mark Russinovich
-// Systems Internals
-// http://www.sysinternals.com
-//----------------------------------------------------------------------
-void PrintError(char *message, NTSTATUS status)
-{
-    char *errMsg;
-
-    FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
-        NULL, RtlNtStatusToDosError(status),
-        MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
-        (LPTSTR)&errMsg, 0, NULL);
-    LocalFree(errMsg);
-}
-
-//--------------------------------------------------------
-//
-// UnmapPhysicalMemory
-//
-
-// Maps a view of a section.
-//
-// Mark Russinovich
-// Systems Internals
-// http://www.sysinternals.com
-//--------------------------------------------------------
-static VOID UnmapPhysicalMemory(PVOID Address)
-{
-    NTSTATUS		status;
-
-    status = NtUnmapViewOfSection((HANDLE)-1, Address);
-    if (!NT_SUCCESS(status))
-    {
-        PrintError("Unable to unmap view", status);
-    }
-}
-
-
-//--------------------------------------------------------
-//
-// MapPhysicalMemory
-//
-// Maps a view of a section.
-//
-// Mark Russinovich
-// Systems Internals
-// http://www.sysinternals.com
-//--------------------------------------------------------
-static BOOLEAN MapPhysicalMemory(HANDLE PhysicalMemory,
-    PVOID Address, PDWORD Length,
-    PVOID *VirtualAddress)
-{
-    NTSTATUS			ntStatus;
-    PHYSICAL_ADDRESS	viewBase;
-    char				error[256];
-
-    viewBase.QuadPart = (ULONGLONG)(Address);
-    ntStatus = NtMapViewOfSection(PhysicalMemory,
-        (HANDLE)-1,
-        VirtualAddress,
-        0L, *Length,
-        &viewBase,
-        Length,
-        ViewShare,
-        0,
-        PAGE_READONLY);
-
-    if (!NT_SUCCESS(ntStatus)) {
-
-        PrintError(error, ntStatus);
-        return FALSE;
-    }
-
-    return TRUE;
-}
-
-
-//--------------------------------------------------------
-//
-// OpensPhysicalMemory
-//
-// This function opens the physical memory device. It
-// uses the native API since 
-//
-// Mark Russinovich
-// Systems Internals
-// http://www.sysinternals.com
-//--------------------------------------------------------
-static HANDLE OpenPhysicalMemory()
-{
-    NTSTATUS		status;
-    HANDLE			physmem;
-    UNICODE_STRING	physmemString;
-    OBJECT_ATTRIBUTES attributes;
-    WCHAR			physmemName[] = L"\\device\\physicalmemory";
-
-    RtlInitUnicodeString(&physmemString, physmemName);
-
-    InitializeObjectAttributes(&attributes, &physmemString,
-        OBJ_CASE_INSENSITIVE, NULL, NULL);
-    status = NtOpenSection(&physmem, SECTION_MAP_READ, &attributes);
-
-    if (!NT_SUCCESS(status))
-    {
-        PrintError("Could not open \\device\\physicalmemory", status);
-        return NULL;
-    }
-
-    return physmem;
-}
-
-static PVOID MapPhysicalMemoryWithBase(HANDLE hPhyHandle, PVOID pBase, PDWORD pLen, PVOID *pVirtualBase)
-{
-    DWORD dwOffset = (ULONGLONG)pBase % dwPageSize;
-    DWORD dwLen = *pLen + dwOffset;
-
-    PVOID pVAddr = NULL;
-
-    if (MapPhysicalMemory(hPhyHandle, pBase, &dwLen, &pVAddr))
-    {
-        *pVirtualBase = pVAddr;
-        *pLen = dwLen;
-
-        return (PBYTE)pVAddr + dwOffset;
-    }
-    else
-    {
-        return NULL;
-    }
-}
-
-bool InitEntryPoints()
-{
-    Win32GetVersionEx = decltype(Win32GetVersionEx)(GetProcAddress(::GetModuleHandle(_T("kernel32.dll")), GetVersionExProc));
-    if (!Win32GetVersionEx)
-        return false;
-
-    Win32GetSystemInfo = decltype(Win32GetSystemInfo)(GetProcAddress(::GetModuleHandle(_T("kernel32.dll")), "GetSystemInfo"));
-    if (!Win32GetSystemInfo)
-        return false;
-
-    OSVERSIONINFO osvi;
-    ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
-    osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
-
-    if (!Win32GetVersionEx(&osvi))
-        return false;
-
-    bIsWindowsXPLater = ((osvi.dwMajorVersion > 5) || ((osvi.dwMajorVersion == 5) && (osvi.dwMinorVersion > 1)));
-
-    SYSTEM_INFO sysinfo;
-    ::ZeroMemory(&sysinfo, sizeof (SYSTEM_INFO));
-    Win32GetSystemInfo(&sysinfo);
-
-    dwPageSize = sysinfo.dwPageSize;
-
-    if (bIsWindowsXPLater)
-    {
-        Win32GetSystemFirmwareTable = decltype(Win32GetSystemFirmwareTable)(GetProcAddress(GetModuleHandle(_T("kernel32.dll")), "GetSystemFirmwareTable"));
-        if (!Win32GetSystemFirmwareTable)
-            return false;
-    }
-    else
-    {
-        Win32VirtualProtect = decltype(Win32VirtualProtect)(GetProcAddress(GetModuleHandle(_T("kernel32.dll")), "VirtualProtect"));
-        if (!Win32VirtualProtect)
-            return false;
-
-        RtlInitUnicodeString = (decltype(RtlInitUnicodeString))(GetProcAddress(GetModuleHandle(_T("ntdll.dll")), "RtlInitUnicodeString"));
-        if (!RtlInitUnicodeString)
-            return false;
-
-        NtUnmapViewOfSection = (decltype(NtUnmapViewOfSection))(GetProcAddress(GetModuleHandle(_T("ntdll.dll")), "NtUnmapViewOfSection"));
-        if (!NtUnmapViewOfSection)
-            return false;
-
-        NtOpenSection = (decltype(NtOpenSection))(GetProcAddress(GetModuleHandle(_T("ntdll.dll")), "NtOpenSection"));
-        if (!NtOpenSection)
-            return false;
-
-        NtMapViewOfSection = (decltype(NtMapViewOfSection))(GetProcAddress(GetModuleHandle(_T("ntdll.dll")), "NtMapViewOfSection"));
-        if (!NtMapViewOfSection)
-            return false;
-
-        RtlNtStatusToDosError = (decltype(RtlNtStatusToDosError))(GetProcAddress(GetModuleHandle(_T("ntdll.dll")), "RtlNtStatusToDosError"));
-        if (!NtMapViewOfSection)
-            return false;
-    }
-
-    return true;
-}
-
-void *LocateSMBIOS(uint32_t *smbios_size) {
-    void *buf = NULL;
-	const DWORD tableSignature = ('R' << 24) | ('S' << 16) | ('M' << 8) | 'B';
-
-    if (bIsWindowsXPLater)
-    {
-        uint32_t size = 0;
-		size = Win32GetSystemFirmwareTable(tableSignature, 0, buf, size);
-        if (0 == size)
-        {
-            return NULL;
-        }
-
-        buf = malloc(size);
-        if (buf)
-        {
-			if (0 == Win32GetSystemFirmwareTable(tableSignature, 0, buf, size))
-            {
-                free(buf);
-                buf = NULL;
-            }
-            else
-            {
-                *smbios_size = size;
-            }
-        }
-    }
-    else
-    {
-        HANDLE hPhysMem = OpenPhysicalMemory();
-        if (NULL == hPhysMem)
-            return NULL;
-
-        DWORD dwReadLen = 0x10000;
-        DWORD dwActualLen = dwReadLen;
-        PVOID pBaseVAddr = NULL;
-        PVOID pVAddr = MapPhysicalMemoryWithBase(hPhysMem, (PVOID)0xF0000, &dwActualLen, &pBaseVAddr);
-        if (!pVAddr)
-        {
-            ::CloseHandle(hPhysMem);
-            return NULL;
-        }
-
-        DWORD dwReadOffset = 0;
-
-        PBYTE pbVAddr = (PBYTE)pVAddr;
-        PBYTE pbGuardVAddr = pbVAddr + dwReadLen;
-
-        while (pbVAddr < pbGuardVAddr)
-        {
-            if (pbVAddr[0] == '_' && pbVAddr[1] == 'S' && pbVAddr[2] == 'M' && pbVAddr[3] == '_')
-            {
-                break;
-            }
-
-            pbVAddr += 16;
-        }
-
-        //!	no SMBIOS found
-        if (pbVAddr >= pbGuardVAddr)
-        {
-            UnmapPhysicalMemory(pVAddr);
-            ::CloseHandle(hPhysMem);
-
-            return NULL;
-        }
-
-        PSMBIOSEntryPoint pEntryPoint = (PSMBIOSEntryPoint)pbVAddr;
-
-        RawSMBIOSData *pData = (RawSMBIOSData *)::malloc(pEntryPoint->TableLength + sizeof(RawSMBIOSData));
-        PVOID pTableBaseVAddr = NULL;
-        if (NULL != pData)
-        {
-            DWORD dwTableLen = pEntryPoint->TableLength;
-            PVOID pTableVAddr = MapPhysicalMemoryWithBase(hPhysMem, (PVOID)pEntryPoint->TableAddress, &dwTableLen, &pTableBaseVAddr);
-            if (!pTableVAddr)
-            {
-                UnmapPhysicalMemory(pBaseVAddr);
-                ::CloseHandle(hPhysMem);
-                return NULL;
-            }
-
-            pData->Used20CallingMethod = 0;
-            pData->DmiRevision = 0;
-            pData->SMBIOSMajorVersion = pEntryPoint->MajorVersion;
-            pData->SMBIOSMinorVersion = pEntryPoint->MinorVersion;
-            pData->Length = pEntryPoint->TableLength;
-
-            ::memcpy(pData->SMBIOSTableData, (PVOID)pTableVAddr, pEntryPoint->TableLength);
-            *smbios_size = pEntryPoint->TableLength;
-        }
-
-        if (NULL != pTableBaseVAddr)
-            UnmapPhysicalMemory(pTableBaseVAddr);
-        if (NULL != pBaseVAddr)
-            UnmapPhysicalMemory(pBaseVAddr);
-
-        ::CloseHandle(hPhysMem);
-
-        buf = pData;
-    }
-
-    return buf;
-}
diff --git a/src/library/os/windows/isvm/Native.h b/src/library/os/windows/isvm/Native.h
deleted file mode 100644
index d22a908..0000000
--- a/src/library/os/windows/isvm/Native.h
+++ /dev/null
@@ -1,18 +0,0 @@
-#pragma once
-
-#include <stdint.h>
-#include <windows.h>
-
-struct RawSMBIOSData
-{
-    BYTE    Used20CallingMethod;
-    BYTE    SMBIOSMajorVersion;
-    BYTE    SMBIOSMinorVersion;
-    BYTE    DmiRevision;
-    DWORD   Length;
-    BYTE    SMBIOSTableData[];
-};
-
-bool InitEntryPoints();
-void *LocateSMBIOS(uint32_t *smbios_size);
-
diff --git a/src/library/os/windows/isvm/main.cpp b/src/library/os/windows/isvm/main.cpp
deleted file mode 100644
index 105c105..0000000
--- a/src/library/os/windows/isvm/main.cpp
+++ /dev/null
@@ -1,51 +0,0 @@
-#include "intrin.h"
-
-#include <iostream>
-#include "BIOSReader.h"
-#include "Native.h"
-
-int _tmain(int argc, _TCHAR* argv[])
-{
-    int cpui[4] = { 0 };
-    __cpuid(cpui, 0x1);
-
-    if ((cpui[2] >> 31) & 1)
-    {
-        std::cout << "Inside virual machine!";
-        return 1;
-    }
-
-    if (InitEntryPoints())
-    {
-        BIOSReader reader;
-        SystemInformation info = reader.readSystemInfo();
-
-        const char *vmVendors[] =
-        {
-            "VMware", "Microsoft Corporation", "Virtual Machine", "innotek GmbH", "PowerVM", "Bochs", "KVM"
-        };
-
-        const int count = _countof(vmVendors);
-        for (int i = 0; i != count; ++i)
-        {
-            const char *vendor = vmVendors[i];
-
-            if (std::string::npos != info.Manufacturer.find(vendor) ||
-                std::string::npos != info.ProductName.find(vendor) ||
-                std::string::npos != info.SerialNum.find(vendor))
-            {
-                std::cout << "Inside virual machine!";
-                return 1;
-            }
-        }
-    }
-    else
-    {
-        return -1;
-    }
-
-    std::cout << "Inside host machine!";
-
-    return 0;
-}
-
diff --git a/test/library/os/CMakeLists.txt b/test/library/os/CMakeLists.txt
index 1af4e92..e91e417 100644
--- a/test/library/os/CMakeLists.txt
+++ b/test/library/os/CMakeLists.txt
@@ -1,6 +1,6 @@
 add_executable( test_network
  network_test.cpp
-)
+ "network_test.cpp")
 
 target_link_libraries( test_network
  licensecc_static
@@ -10,6 +10,17 @@
 )
 
 ADD_TEST(NAME test_network COMMAND test_network)
+
+add_executable( test_dmi_info dmi_info_test.cpp "dmi_info_test.cpp")
+
+target_link_libraries( test_dmi_info
+ licensecc_static
+ Boost::unit_test_framework 
+ Boost::filesystem
+ Boost::system
+)
+
+ADD_TEST(NAME test_dmi_info COMMAND test_dmi_info)
 
 add_executable( test_execution_environment
  execution_environment_test.cpp
@@ -23,7 +34,13 @@
 )
 
 ADD_TEST(NAME test_execution_environment COMMAND test_execution_environment)
+
 if(CODE_COVERAGE AND UNIX)
-	target_compile_options(test_network PUBLIC -O0 -g --coverage)
+	target_compile_options(test_dmi_info PUBLIC -O0 -g --coverage)
 	target_compile_options(test_execution_environment PUBLIC -O0 -g --coverage)
+	target_compile_options(test_network PUBLIC -O0 -g --coverage)
 endif(CODE_COVERAGE AND UNIX)
+
+
+
+
diff --git a/test/library/os/dmi_info_test.cpp b/test/library/os/dmi_info_test.cpp
new file mode 100644
index 0000000..ac29cc6
--- /dev/null
+++ b/test/library/os/dmi_info_test.cpp
@@ -0,0 +1,25 @@
+#define BOOST_TEST_MODULE dmi_info_test
+#include <string>
+#include <iostream>
+#include <unordered_map>
+#include <boost/test/unit_test.hpp>
+#include "../../../src/library/os/dmi_info.hpp"
+
+
+namespace license {
+namespace test {
+using namespace std;
+
+BOOST_AUTO_TEST_CASE(dmi_info) {
+	os::DmiInfo dmiInfo;
+//windows bug
+
+#ifdef __unix__
+	BOOST_CHECK_MESSAGE(dmiInfo.bios_vendor().size()>0, "Bios vendor OK");
+	BOOST_CHECK_MESSAGE(dmiInfo.bios_description().size() > 0, "Bios description OK");
+	BOOST_CHECK_MESSAGE(dmiInfo.sys_vendor().size() > 0, "Sys vendor OK");
+#endif
+}
+
+}  // namespace test
+}  // namespace license

--
Gitblit v1.9.1