src/library/CMakeLists.txt | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/library/base/CMakeLists.txt | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/library/base/base64.cpp | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/library/base/base64.h | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/library/locate/CMakeLists.txt | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/library/os/CMakeLists.txt | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/library/os/windows/.gitignore | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
test/functional/CMakeLists.txt | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
test/library/CMakeLists.txt | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
src/library/CMakeLists.txt
@@ -1,24 +1,27 @@ add_subdirectory("base") add_subdirectory("os") add_subdirectory("locate") add_subdirectory("pc_identifier") ADD_LIBRARY(licensecc_static STATIC licensecc.cpp LicenseReader.cpp pc-identifiers.c limits/license_verifier.cpp ini/ConvertUTF.c $<TARGET_OBJECTS:locate> $<TARGET_OBJECTS:os> $<TARGET_OBJECTS:base> ) add_subdirectory("locate") add_subdirectory("os") define_property(TARGET PROPERTY WITH_OPENSSL BRIEF_DOCS "need openssl to compile" FULL_DOCS "ff") IF(UNIX OR OPENSSL_FOUND) target_compile_definitions(licensecc_static PUBLIC HAS_OPENSSL) set_target_properties(licensecc_static PROPERTIES WITH_OPENSSL 1) target_link_libraries(licensecc_static PUBLIC base OpenSSL::Crypto ${EXTERNAL_LIBS} ${CMAKE_DL_LIBS}) target_link_libraries(licensecc_static PUBLIC OpenSSL::Crypto ${EXTERNAL_LIBS} ${CMAKE_DL_LIBS}) ELSE(UNIX OR OPENSSL_FOUND) set_target_properties(licensecc_static PROPERTIES WITH_OPENSSL 0) target_link_libraries(licensecc_static PUBLIC base ${EXTERNAL_LIBS}) target_link_libraries(licensecc_static PUBLIC ${EXTERNAL_LIBS}) ENDIF(UNIX OR OPENSSL_FOUND) target_include_directories(licensecc_static src/library/base/CMakeLists.txt
@@ -1,10 +1,12 @@ ADD_LIBRARY(base STATIC ADD_LIBRARY(base OBJECT EventRegistry.cpp StringUtils.cpp FileUtils.cpp base64.cpp logger.c base64.c ) add_dependencies( base project_initialize ) if(CODE_COVERAGE AND UNIX) MESSAGE(STATUS "Enabling code coverage") @@ -13,10 +15,6 @@ -g # generate debug info --coverage # sets all required flags ) target_link_libraries(base PUBLIC gcov) endif(CODE_COVERAGE AND UNIX) add_dependencies( base project_initialize ) install(TARGETS base EXPORT licensecc ARCHIVE DESTINATION lib/${PROJECT_NAME}/${LCC_PROJECT_NAME}) src/library/base/base64.cpp
@@ -1,11 +1,15 @@ #include <stdio.h> #include <stdlib.h> const static char* b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; #include "base64.h" namespace license { using namespace std; const static char* b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; // maps A=>0,B=>1.. const static unsigned char unb64[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //10 const static unsigned char unb64[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 10 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //20 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //30 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //40 @@ -30,12 +34,18 @@ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //230 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //240 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //250 0, 0, 0, 0, 0, 0, }; // This array has 255 elements 0, 0, 0, 0, 0, 0, }; // This array has 255 elements //review api char* base64(const void* binaryData, int len, int *flen) { void add_CR_if_needed(string& encodeBuffer, int lineLenght) { if (lineLenght > 0 && ((encodeBuffer.size() + 1) % lineLenght) == 0) { encodeBuffer += '\n'; } } string base64(const void* binaryData, size_t len, int lineLenght) { const unsigned char* bin = (const unsigned char*) binaryData; char* res; int rc = 0; // result counter int byteNo; // I need this after the loop @@ -43,41 +53,55 @@ int modulusLen = len % 3; int pad = ((modulusLen & 1) << 1) + ((modulusLen & 2) >> 1); // 2 gives 1 and 1 gives 2, but 0 gives 0. *flen = 4 * (len + pad) / 3; res = (char*) malloc(*flen + 1); // and one for the null if (!res) { puts("ERROR: base64 could not allocate enough memory."); puts("I must stop because I could not get enough"); return 0; const size_t flen = 4 * (len + pad) / 3; size_t totalLength = flen; if (lineLenght > 0) { totalLength += ((int)flen / lineLenght) + 3; } string encodeBuffer; encodeBuffer.reserve(totalLength); for (byteNo = 0; byteNo <= len - 3; byteNo += 3) { unsigned char BYTE0 = bin[byteNo]; unsigned char BYTE1 = bin[byteNo + 1]; unsigned char BYTE2 = bin[byteNo + 2]; res[rc++] = b64[BYTE0 >> 2]; res[rc++] = b64[((0x3 & BYTE0) << 4) + (BYTE1 >> 4)]; res[rc++] = b64[((0x0f & BYTE1) << 2) + (BYTE2 >> 6)]; res[rc++] = b64[0x3f & BYTE2]; add_CR_if_needed(encodeBuffer, lineLenght); encodeBuffer += b64[BYTE0 >> 2]; add_CR_if_needed(encodeBuffer, lineLenght); encodeBuffer += b64[((0x3 & BYTE0) << 4) + (BYTE1 >> 4)]; add_CR_if_needed(encodeBuffer, lineLenght); encodeBuffer += b64[((0x0f & BYTE1) << 2) + (BYTE2 >> 6)]; add_CR_if_needed(encodeBuffer, lineLenght); encodeBuffer += b64[0x3f & BYTE2]; } if (pad == 2) { res[rc++] = b64[bin[byteNo] >> 2]; res[rc++] = b64[(0x3 & bin[byteNo]) << 4]; res[rc++] = '='; res[rc++] = '='; add_CR_if_needed(encodeBuffer, lineLenght); encodeBuffer += b64[bin[byteNo] >> 2]; add_CR_if_needed(encodeBuffer, lineLenght); encodeBuffer += b64[(0x3 & bin[byteNo]) << 4]; add_CR_if_needed(encodeBuffer, lineLenght); encodeBuffer += '='; add_CR_if_needed(encodeBuffer, lineLenght); encodeBuffer += '='; } else if (pad == 1) { res[rc++] = b64[bin[byteNo] >> 2]; res[rc++] = b64[((0x3 & bin[byteNo]) << 4) + (bin[byteNo + 1] >> 4)]; res[rc++] = b64[(0x0f & bin[byteNo + 1]) << 2]; res[rc++] = '='; add_CR_if_needed(encodeBuffer, lineLenght); encodeBuffer += b64[bin[byteNo] >> 2]; add_CR_if_needed(encodeBuffer, lineLenght); encodeBuffer += b64[((0x3 & bin[byteNo]) << 4) + (bin[byteNo + 1] >> 4)]; add_CR_if_needed(encodeBuffer, lineLenght); encodeBuffer += b64[(0x0f & bin[byteNo + 1]) << 2]; add_CR_if_needed(encodeBuffer, lineLenght); encodeBuffer += '='; } if (lineLenght && encodeBuffer[encodeBuffer.length() - 1] != '\n') { encodeBuffer += '\n'; } return encodeBuffer; } res[rc] = 0; // NULL TERMINATOR! ;) return res; } //FIXME! unsigned char* unbase64(const char* ascii, int len, int *flen) { const unsigned char *safeAsciiPtr = (const unsigned char*) ascii; unsigned char *bin; @@ -87,21 +111,17 @@ if (len < 2) { // 2 accesses below would be OOB. // catch empty string, return NULL as result. puts( "ERROR: You passed an invalid base64 string (too short). You get NULL back."); puts("ERROR: You passed an invalid base64 string (too short). You get NULL back."); *flen = 0; return 0; } if (safeAsciiPtr[len - 1] == '=') ++pad; if (safeAsciiPtr[len - 2] == '=') ++pad; if (safeAsciiPtr[len - 1] == '=') ++pad; if (safeAsciiPtr[len - 2] == '=') ++pad; *flen = 3 * len / 4 - pad; bin = (unsigned char*) malloc(*flen); if (!bin) { puts("ERROR: unbase64 could not allocate enough memory."); puts("I must stop because I could not get enough"); return 0; } @@ -132,3 +152,5 @@ return bin; } } // namespace license src/library/base/base64.h
@@ -1,44 +1,17 @@ /* https://github.com/superwills/NibbleAndAHalf base64.h -- Fast base64 encoding and decoding. version 1.0.0, April 17, 2013 143a Copyright (C) 2013 William Sherif This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. William Sherif will.sherif@gmail.com YWxsIHlvdXIgYmFzZSBhcmUgYmVsb25nIHRvIHVz */ #ifndef BASE64_H #define BASE64_H #ifdef __cplusplus extern "C" { #include <string> #if _WIN32 #include <wtypes.h> #endif namespace license { unsigned char* unbase64(const char* ascii, int len, int *flen); char* base64(const void* binaryData, int len, int *flen); std::string base64(const void* binaryData, size_t len, int lineLenght = -1); #ifdef __cplusplus } #endif } // namespace license #endif src/library/locate/CMakeLists.txt
@@ -1,9 +1,12 @@ target_sources(licensecc_static PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/ApplicationFolder.cpp ${CMAKE_CURRENT_SOURCE_DIR}/EnvironmentVarLocation.cpp ${CMAKE_CURRENT_SOURCE_DIR}/EnvironmentVarData.cpp ${CMAKE_CURRENT_SOURCE_DIR}/ExternalDefinition.cpp ${CMAKE_CURRENT_SOURCE_DIR}/LocatorStrategy.cpp ${CMAKE_CURRENT_SOURCE_DIR}/LocatorFactory.cpp add_library(locate OBJECT ApplicationFolder.cpp EnvironmentVarLocation.cpp EnvironmentVarData.cpp ExternalDefinition.cpp LocatorStrategy.cpp LocatorFactory.cpp ) if(CODE_COVERAGE AND UNIX) target_compile_options(locate PUBLIC -O0 -g --coverage) endif(CODE_COVERAGE AND UNIX) src/library/os/CMakeLists.txt
@@ -1,17 +1,19 @@ IF(UNIX OR OPENSSL_FOUND) IF(UNIX) target_sources(licensecc_static PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/openssl/signature_verifier.cpp ${CMAKE_CURRENT_SOURCE_DIR}/os-linux.c ${CMAKE_CURRENT_SOURCE_DIR}/network_id.c) add_library(os OBJECT openssl/signature_verifier.cpp linux/execution_environment.cpp linux/cpu_info.cpp linux/os-linux.c linux/network_id.c) ELSE(UNIX) target_sources(licensecc_static PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/openssl/signature_verifier.cpp ${CMAKE_CURRENT_SOURCE_DIR}/os-win.c) add_library(os OBJECT openssl/signature_verifier.cpp windows/os-win.c) ENDIF(UNIX) ELSE(UNIX OR OPENSSL_FOUND) target_sources(licensecc_static PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/windows/signature_verifier.cpp ${CMAKE_CURRENT_SOURCE_DIR}/os-win.c) target_sources(os OBJECT windows/signature_verifier.cpp windows/os-win.c) ENDIF(UNIX OR OPENSSL_FOUND) if(CODE_COVERAGE AND UNIX) MESSAGE(STATUS "Enabling code coverage") target_compile_options(os PUBLIC -O0 -g --coverage) endif(CODE_COVERAGE AND UNIX) src/library/os/windows/.gitignore
New file @@ -0,0 +1 @@ /isvm/ test/functional/CMakeLists.txt
@@ -2,20 +2,17 @@ generate-license.cpp ) target_link_libraries( license_generator_snippet target_link_libraries( license_generator_snippet Boost::unit_test_framework Boost::filesystem Boost::system ) add_executable( test_standard_license add_executable( test_standard_license standard-license_test.cpp ) target_link_libraries( test_standard_license target_link_libraries( test_standard_license licensecc_static license_generator_snippet Boost::unit_test_framework @@ -23,13 +20,11 @@ Boost::system ) add_executable( test_date add_executable( test_date date_test.cpp ) target_link_libraries( test_date target_link_libraries( test_date licensecc_static license_generator_snippet Boost::unit_test_framework @@ -37,8 +32,7 @@ Boost::system ) add_executable( test_signature_verifier add_executable( test_signature_verifier signature_verifier_test.cpp ) @@ -52,13 +46,9 @@ ) add_executable( test_volid volid_test.cpp ) add_executable(test_volid volid_test.cpp) target_link_libraries( test_volid target_link_libraries( test_volid licensecc_static license_generator_snippet Boost::unit_test_framework @@ -66,7 +56,17 @@ Boost::system ) add_executable(test_crack crack_test.cpp) target_link_libraries( test_crack licensecc_static license_generator_snippet Boost::unit_test_framework Boost::filesystem Boost::system ) ADD_TEST(NAME test_crack COMMAND test_crack WORKING_DIRECTORY ${CMAKE_BINARY_DIR}) ADD_TEST(NAME test_date COMMAND test_date WORKING_DIRECTORY ${CMAKE_BINARY_DIR}) ADD_TEST(NAME test_standard_license COMMAND test_standard_license WORKING_DIRECTORY ${CMAKE_BINARY_DIR}) ADD_TEST(NAME test_signature_verifier COMMAND test_signature_verifier WORKING_DIRECTORY ${CMAKE_BINARY_DIR}) test/library/CMakeLists.txt
@@ -1,17 +1,13 @@ add_executable( test_license_reader add_executable( test_license_reader LicenseReader_test.cpp ) target_link_libraries( test_license_reader target_link_libraries( test_license_reader licensecc_static Boost::unit_test_framework Boost::filesystem Boost::system ) ADD_TEST(NAME test_license_reader COMMAND test_license_reader) IF(WIN32) #test windows @@ -46,8 +42,6 @@ Boost::system ) ADD_TEST(NAME test_license_locator COMMAND test_license_locator) ### LicenseLocator tests add_executable( test_event_registry @@ -56,10 +50,12 @@ target_link_libraries( test_event_registry base licensecc_static Boost::unit_test_framework Boost::filesystem Boost::system ) 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)