read dmi information segfault on windows
| | |
| | | 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) |
| | |
| | | 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) |
| | |
| | | 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); } |
| | | }; |
| | |
| | | * @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 |
| | |
| | | } |
| | | |
| | | 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 |
| | |
| | | |
| | | #include "../../base/file_utils.hpp" |
| | | #include "../../base/string_utils.h" |
| | | |
| | | #include "../../base/logger.h" |
| | | #include "../dmi_info.hpp" |
| | | |
| | | namespace license { |
| | |
| | | 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))); |
| | |
| | | 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); |
| | |
| | | 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); |
| | | } |
| | | } |
| | | |
| | |
| | | * 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 */ |
| | |
| | | #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; |
| | |
| | | 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; |
| | | } |
| | |
| | | add_executable( test_network |
| | | network_test.cpp |
| | | ) |
| | | "network_test.cpp") |
| | | |
| | | target_link_libraries( test_network |
| | | licensecc_static |
| | |
| | | ) |
| | | |
| | | 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 |
| | |
| | | ) |
| | | |
| | | 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) |
| | | |
| | | |
| | | |
| | | |
New file |
| | |
| | | #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 |