From a1b64080d1525a7a65e53f33d1a3fd257957e732 Mon Sep 17 00:00:00 2001 From: Gabriele Contini <contini.mailing@gmail.com> Date: 周日, 15 3月 2020 11:00:39 +0800 Subject: [PATCH] fix compilation errors --- test/library/CMakeLists.txt | 4 ++ test/library/os/network_test.cpp | 6 +- doc/snippets.txt | 3 + src/library/os/windows/os-win.cpp | 25 ++++++------ src/inspector/inspector.cpp | 9 ++-- test/library/os/execution_environment_test.cpp | 6 +- CMakeLists.txt | 14 ++---- src/library/os/CMakeLists.txt | 6 +-- src/library/base/base64.cpp | 4 +- src/library/os/windows/isvm/Native.cpp | 9 ++-- 10 files changed, 43 insertions(+), 43 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f464593..7159721 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -60,7 +60,7 @@ endif() endif(THREADS_HAVE_PTHREAD_ARG) - #Zlib required when openssl version < 1.0.1f (centos 7) + #Zlib required with old openssl version < 1.0.1f in centos 7 IF(OPENSSL_VERSION VERSION_LESS_EQUAL 1.0.2) SET ( ZLIB_USE_STATIC_LIBS ON ) find_package(ZLIB REQUIRED) @@ -90,16 +90,12 @@ string(REPLACE "/MDd" "/MTd" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}") SET(Boost_USE_STATIC_RUNTIME ON) endif(${STATIC_RUNTIME}) - add_definitions("/D _CRT_SECURE_NO_WARNINGS") + list(APPEND EXTERNAL_LIBS "bcrypt" "crypt32" "ws2_32" "iphlpapi") else(MSVC) - if(MINGW) - list(APPEND EXTERNAL_LIBS "-lcrypt32 -lbcrypt -lws2_32 -liphlpapi") - SET(CMAKE_EXE_LINKER_FLAGS "-static") - #super ugly bug when cross compiling in cmake 3.16 - #IF(CMAKE_CROSSCOMPILING) - # link_directories(BEFORE /usr/lib/gcc/x86_64-w64-mingw32/7.3-win32) - #ENDIF() + if(MINGW) + list(APPEND EXTERNAL_LIBS "-lbcrypt" "-lcrypt32" "-lws2_32" "-liphlpapi") + SET(CMAKE_EXE_LINKER_FLAGS "-static -static-libstdc++") endif(MINGW) endif(MSVC) set(main_lib_dest "${PROJECT_NAME}") diff --git a/doc/snippets.txt b/doc/snippets.txt index 6aa124c..537187c 100644 --- a/doc/snippets.txt +++ b/doc/snippets.txt @@ -22,4 +22,5 @@ linux cross compile for windows openssl - ./Configure no-zlib no-shared --prefix=$PWD/dist-win-64 --cross-compile-prefix=x86_64-w64-mingw32- mingw64 \ No newline at end of file + ./Configure no-zlib no-shared --prefix=$PWD/dist-win-64 --cross-compile-prefix=x86_64-w64-mingw32- mingw64 + /usr/local/bin/cmake -DCMAKE_TOOLCHAIN_FILE=../cmake/toolchain-ubuntu-mingw64.cmake -DCMAKE_INSTALL_PREFIX=../../install -DBOOST_ROOT=$PWD/../../boost_1_69_0/dist-win-x64/ -DOPENSSL_ROOT_DIR=$PWD/../../openssl-OpenSSL_1_1_1d/dist-win-64/ -DBoost_ARCHITECTURE="-x64" -DCMAKE_CXX_COMPILER_ARCHITECTURE_ID="x64" -DCMAKE_SH="CMAKE_SH-NOTFOUND" -DCMAKE_VERBOSE_MAKEFILE=ON -DLOGS_DISABLED=ON .. \ No newline at end of file diff --git a/src/inspector/inspector.cpp b/src/inspector/inspector.cpp index e5ee64d..07330eb 100644 --- a/src/inspector/inspector.cpp +++ b/src/inspector/inspector.cpp @@ -9,10 +9,11 @@ using namespace std; using namespace license::os; -const map<int, string> stringByStrategyId = {{STRATEGY_DEFAULT, "DEFAULT"}, {STRATEGY_ETHERNET, "MAC"}, - {STRATEGY_IP_ADDRESS, "IP"}, {STRATEGY_DISK_NUM, "Disk1"}, - {STRATEGY_DISK_LABEL, "Disk2"}, {STRATEGY_NONE, "Custom"}}; - +const map<int, string> stringByStrategyId = {{STRATEGY_DEFAULT, "DEFAULT"}, + {STRATEGY_ETHERNET, "MAC"}, + {STRATEGY_IP_ADDRESS, "IP"}, + {STRATEGY_DISK_NUM, "Disk1"}, + {STRATEGY_DISK_LABEL, "Disk2"}}; const unordered_map<int, string> descByVirtDetail = {{BARE_TO_METAL, "No virtualization"}, {VMWARE, "Vmware"}, diff --git a/src/library/base/base64.cpp b/src/library/base/base64.cpp index a8f1c4c..f508d4a 100644 --- a/src/library/base/base64.cpp +++ b/src/library/base/base64.cpp @@ -111,7 +111,7 @@ int cb = 0; int charNo; int pad = 0; - int len = tmp_str.size(); + size_t len = tmp_str.size(); if (len < 2) { // 2 accesses below would be OOB. // catch empty string, return NULL as result. @@ -121,7 +121,7 @@ if (safeAsciiPtr[len - 1] == '=') ++pad; if (safeAsciiPtr[len - 2] == '=') ++pad; - unsigned int flen = 3 * len / 4 - pad; + size_t flen = 3 * len / 4 - pad; bin.reserve(flen); for (charNo = 0; charNo <= len - 4 - pad; charNo += 4) { diff --git a/src/library/os/CMakeLists.txt b/src/library/os/CMakeLists.txt index 487213a..42bf47d 100644 --- a/src/library/os/CMakeLists.txt +++ b/src/library/os/CMakeLists.txt @@ -8,9 +8,8 @@ linux/cpu_info.cpp linux/network.cpp linux/os-linux.cpp) - - target_link_libraries(os PUBLIC OpenSSL::Crypto) ELSE(UNIX) + #windows and openssl add_library(os OBJECT cpu_info_common.cpp windows/cpu_info.cpp openssl/signature_verifier.cpp @@ -19,9 +18,8 @@ windows/isvm/BIOSReader.cpp windows/os-win.cpp windows/network.cpp) - - target_link_libraries(os PUBLIC OpenSSL::Crypto) ENDIF(UNIX) + target_include_directories(os PUBLIC ${OPENSSL_INCLUDE_DIR}) ELSE(UNIX OR OPENSSL_FOUND) #windows no openssl add_library(os OBJECT diff --git a/src/library/os/windows/isvm/Native.cpp b/src/library/os/windows/isvm/Native.cpp index 99fbf8f..f8568e6 100644 --- a/src/library/os/windows/isvm/Native.cpp +++ b/src/library/os/windows/isvm/Native.cpp @@ -332,13 +332,14 @@ return true; } -void *LocateSMBIOS(uint32_t *smbios_size) -{ +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('RSMB', 0, buf, size); + size = Win32GetSystemFirmwareTable(tableSignature, 0, buf, size); if (0 == size) { return NULL; @@ -347,7 +348,7 @@ buf = malloc(size); if (buf) { - if (0 == Win32GetSystemFirmwareTable('RSMB', 0, buf, size)) + if (0 == Win32GetSystemFirmwareTable(tableSignature, 0, buf, size)) { free(buf); buf = NULL; diff --git a/src/library/os/windows/os-win.cpp b/src/library/os/windows/os-win.cpp index d8d04eb..48356f7 100644 --- a/src/library/os/windows/os-win.cpp +++ b/src/library/os/windows/os-win.cpp @@ -1,15 +1,13 @@ -/*#ifdef _MSC_VER -#include <Windows.h> -#endif*/ -#include "../../base/logger.h" -#include "../os.h" - +#define NOMINMAX +#include <windows.h> +#include <algorithm> #include <licensecc/datatypes.h> #include <iphlpapi.h> #include <stdio.h> -//#pragma comment(lib, "IPHLPAPI.lib") -unsigned char* unbase64(const char* ascii, int len, int *flen); +#include "../../base/logger.h" +#include "../os.h" +using namespace std; FUNCTION_RETURN getMachineName(unsigned char identifier[6]) { FUNCTION_RETURN result = FUNC_RET_ERROR; @@ -33,7 +31,7 @@ //bug check return with diskinfos == null func_ret_ok FUNCTION_RETURN getDiskInfos(DiskInfo * diskInfos, size_t * disk_info_size) { DWORD fileMaxLen; - int ndrives = 0; + size_t ndrives = 0; DWORD fileFlags; char volName[MAX_PATH], fileSysName[MAX_PATH]; DWORD volSerial = 0; @@ -63,10 +61,11 @@ LOG_DEBUG("Filesystem : %s", fileSysName); if (diskInfos != NULL) { if (ndrives < (int)*disk_info_size) { - diskInfos[ndrives].id = ndrives; - strncpy(diskInfos[ndrives].device, volName, cmin(MAX_PATH, sizeof(volName)) - 1); + diskInfos[ndrives].id = (int)ndrives; + strncpy(diskInfos[ndrives].device, volName, + min(std::size_t{MAX_PATH}, sizeof(volName)) - 1); strncpy(diskInfos[ndrives].label, fileSysName, - cmin(sizeof(diskInfos[ndrives].label), sizeof(fileSysName)) - 1); + min(sizeof(diskInfos[ndrives].label), sizeof(fileSysName)) - 1); memcpy(diskInfos[ndrives].disk_sn, &volSerial, sizeof(DWORD)); diskInfos[ndrives].preferred = (szSingleDrive[0] == 'C'); } else { @@ -92,7 +91,7 @@ } *disk_info_size = ndrives; } else { - *disk_info_size = cmin(ndrives, *disk_info_size); + *disk_info_size = min(ndrives, *disk_info_size); } return return_value; } diff --git a/test/library/CMakeLists.txt b/test/library/CMakeLists.txt index 55fe54f..8e1946f 100644 --- a/test/library/CMakeLists.txt +++ b/test/library/CMakeLists.txt @@ -55,6 +55,10 @@ Boost::system ) +if(CODE_COVERAGE AND UNIX) + target_link_libraries(test_event_registry gcov) +endif(CODE_COVERAGE AND UNIX) + ADD_TEST(NAME test_license_reader COMMAND test_license_reader) ADD_TEST(NAME test_license_locator COMMAND test_license_locator) ADD_TEST(NAME test_event_registry COMMAND test_event_registry) diff --git a/test/library/os/execution_environment_test.cpp b/test/library/os/execution_environment_test.cpp index 1ca14b0..b604d11 100644 --- a/test/library/os/execution_environment_test.cpp +++ b/test/library/os/execution_environment_test.cpp @@ -5,9 +5,9 @@ #include <licensecc_properties.h> #include <licensecc_properties_test.h> -#include "../../src/library/base/StringUtils.h" -#include "../../src/library/os/network.hpp" -#include "../../src/library/os/execution_environment.hpp" +#include "../../../src/library/base/StringUtils.h" +#include "../../../src/library/os/network.hpp" +#include "../../../src/library/os/execution_environment.hpp" namespace license { namespace os { diff --git a/test/library/os/network_test.cpp b/test/library/os/network_test.cpp index 49705c6..f5a7483 100644 --- a/test/library/os/network_test.cpp +++ b/test/library/os/network_test.cpp @@ -5,9 +5,9 @@ #include <licensecc_properties.h> #include <licensecc_properties_test.h> -#include "../../src/library/base/StringUtils.h" -#include "../../src/library/os/network.hpp" -#include "../../src/library/os/execution_environment.hpp" +#include "../../../src/library/base/StringUtils.h" +#include "../../../src/library/os/network.hpp" +#include "../../../src/library/os/execution_environment.hpp" namespace license { namespace os { -- Gitblit v1.9.1