├── Src ├── 000_String │ ├── stdafx.cpp │ ├── ASCII.h │ ├── stdafx.h │ ├── String.h │ ├── BOMT.cpp │ ├── 000_String.h │ ├── POSIX.h │ ├── Exception.cpp │ ├── Exception.h │ ├── EuckrEncoding.h │ ├── BOM.h │ ├── Utility.h │ └── Unicode.cpp ├── 001_Encoder │ ├── stdafx.cpp │ ├── sha256.cpp │ ├── Encoder.h │ ├── 001_Encoder.h │ ├── Hash.h │ ├── stdafx.h │ ├── rc4.h │ ├── HMAC.h │ ├── ISymAlgorithm.h │ ├── SymPlain.h │ ├── IPubKeyCipher.h │ ├── Base64.h │ ├── SymModeECB.h │ ├── SymModePlain.h │ ├── SymSeed128.h │ ├── SymSeed256.h │ ├── SymModeCFB.h │ ├── SymModeOFB.h │ ├── SymModePCBC.h │ ├── SymModeCBC.h │ ├── SymModeCTR.h │ ├── ssdeep │ │ ├── edit_dist.h │ │ └── match.h │ ├── PubKeyCipherFunction.h │ ├── ISymMode.h │ ├── CryptoPPSingleton.cpp │ ├── has160.h │ ├── SymCipherFunction.h │ ├── CryptoPPSingleton.h │ ├── StringSymCipherFunction.h │ ├── SymPlain.cpp │ ├── SymModePlain.cpp │ ├── PubKeyRSA.h │ ├── StringFunction.h │ ├── SymModeECB.cpp │ ├── PubKeyElGamal.h │ ├── SymAES.h │ ├── SymSeed128.cpp │ ├── SymSeed256.cpp │ ├── AES │ │ └── aeshash.c │ ├── rc4.cpp │ ├── SymCipher.h │ ├── HashFunction.h │ ├── Type.h │ └── SymAES.cpp ├── 100_System │ ├── stdafx.cpp │ ├── ELFParser.h │ ├── LogWorker.cpp │ ├── EnvironmentT.cpp │ ├── GlobalSemaphoreMap.cpp │ ├── SocketDefine.cpp │ ├── MemoryLeakFinder.h │ ├── System.h │ ├── MemoryLeakFinder_Linux_Mac.cpp │ ├── FileSystem_Win.cpp │ ├── UtilityT.cpp │ ├── 100_System.h │ ├── stdafx.h │ ├── MemoryLeakFinder_Win.cpp │ ├── LogInstance.h │ ├── Utility.h │ ├── FileSystem_Linux_Mac.cpp │ ├── TZFileParser.h │ ├── LogInstance.cpp │ ├── ExeParserSuper.cpp │ ├── ExeParserSuper.h │ ├── Socket.h │ ├── InterlockedOperation.h │ ├── LogWorker.h │ ├── SharedPtr.h │ └── LogEx.h ├── 200_Common │ ├── stdafx.cpp │ ├── UtilityT.cpp │ ├── PEParserData.h │ ├── TextFileReaderT.cpp │ ├── FileHashFunction.cpp │ ├── zipcommon.h │ ├── Uncopyable.h │ ├── MutexT.cpp │ ├── DuplicatedProcChecker.h │ ├── Thread.cpp │ ├── TextFileWriterT.cpp │ ├── stdafx.h │ ├── RingBuffer.h │ ├── Common.h │ ├── Semaphore.h │ ├── TextFileWriter.h │ ├── SharedMemory.h │ ├── CriticalSection.h │ ├── Mutex.h │ ├── MemoryMappedFile.h │ ├── TextFileReader.cpp │ ├── 200_Common.h │ ├── TextFileReader.h │ ├── MemoryMappedFile.cpp │ ├── SemaphoreT.cpp │ ├── DuplicatedProcChecker.cpp │ ├── RingBuffer.cpp │ ├── INIParserFunc.h │ ├── PipePeer.h │ ├── PEParserT.cpp │ ├── Semaphore.cpp │ ├── FileHashFunction.h │ ├── SafeQueue.h │ ├── SafeStack.h │ ├── CmdLineHelper.h │ ├── ThreadPool.h │ ├── IMemoryAccess.h │ ├── Thread.h │ └── Mutex.cpp ├── 300_Formatter │ ├── stdafx.cpp │ ├── YAMLParser.cpp │ ├── YAMLSerializer.cpp │ ├── Interface.cpp │ ├── 300_Formatter.h │ ├── IChannel.h │ ├── StringWriter.h │ ├── BytesWriter.h │ ├── ANSIStringWritter.h │ ├── UTF8StringWritter.h │ ├── BytesReader.h │ ├── stdafx.h │ ├── StringReader.h │ ├── FileWritter.h │ ├── ANSIFileWritter.h │ ├── ANSIStringReader.h │ ├── UTF8StringReader.h │ ├── UTF8FileWritter.h │ ├── FileReader.h │ ├── ANSIFileReader.h │ ├── UTF8FileReader.h │ ├── InterfaceLegacy.h │ ├── FmtTypes.h │ ├── XMLFunctions.h │ ├── StringWriter.cpp │ ├── BytesWriter.cpp │ ├── FormatterSuper.h │ ├── ANSIStringWritter.cpp │ ├── UTF8StringWritter.cpp │ ├── Interface.h │ ├── HelperFunc.h │ ├── INIFormatter.h │ ├── BytesReader.cpp │ └── FormatterSuper.cpp ├── 400_Server │ ├── stdafx.cpp │ ├── SocketCommon.h │ ├── 400_Server.h │ ├── SyncConnection.cpp │ ├── stdafx.h │ ├── SyncConnection.h │ ├── SyncUDPSocket.h │ ├── Packetizer.h │ ├── ProtocolSuper.cpp │ ├── BinProtocol.h │ ├── JsonProtocol.h │ ├── UBJsonProtocol.h │ ├── SyncTCPSocket.h │ └── SocketCommon.cpp └── __Common │ ├── Compatibility.h │ ├── ErrorCode.h │ └── Define.h ├── Test ├── DummyProcess │ ├── stdafx.cpp │ └── stdafx.h ├── SystemTest │ ├── SystemTest.rc │ ├── ExceptionTest.cpp │ ├── resource.h │ ├── stdafx.h │ └── InformationTest.cpp ├── ServerTest │ ├── ProtocolTest.cpp │ └── stdafx.h ├── DummyDynamicLibrary │ ├── SoMain_Linux_Mac.cpp │ ├── APIEntry.h │ ├── stdafx.h │ ├── APIEntry.cpp │ └── DllMain_Win.cpp ├── StringTest │ ├── stdafx.h │ └── HexConvertTest.cpp ├── EncoderTest │ └── stdafx.h ├── CMakeLists.txt ├── CommonTest │ ├── stdafx.h │ ├── RingBufferTest.cpp │ ├── MemoryAccessTest.cpp │ ├── ThreadTest.cpp │ ├── CriticalSectionTest.cpp │ ├── SyncQueueTest.cpp │ ├── CmdLineHelperTest.cpp │ └── MutexTest.cpp └── FormatterTest │ ├── stdafx.h │ └── JSONFormatterTest.cpp ├── .gitattributes ├── Build ├── Test │ ├── Unicode │ │ ├── UTF8Sample.txt │ │ ├── ANSISample.txt │ │ ├── UTF16BESample.txt │ │ ├── UTF16Sample.txt │ │ ├── UTF32BESample.txt │ │ └── UTF32Sample.txt │ ├── Ascii │ │ └── HexDump.txt │ ├── Encoder │ │ ├── Colosseum.db │ │ ├── CipherData │ │ │ ├── SYM_CIPHER_TYPE_AES128_SYM_CIPHER_MODE_CBC.enc │ │ │ ├── SYM_CIPHER_TYPE_AES128_SYM_CIPHER_MODE_CFB.enc │ │ │ ├── SYM_CIPHER_TYPE_AES128_SYM_CIPHER_MODE_CTR.enc │ │ │ ├── SYM_CIPHER_TYPE_AES128_SYM_CIPHER_MODE_ECB.enc │ │ │ ├── SYM_CIPHER_TYPE_AES128_SYM_CIPHER_MODE_OFB.enc │ │ │ ├── SYM_CIPHER_TYPE_AES192_SYM_CIPHER_MODE_CBC.enc │ │ │ ├── SYM_CIPHER_TYPE_AES192_SYM_CIPHER_MODE_CFB.enc │ │ │ ├── SYM_CIPHER_TYPE_AES192_SYM_CIPHER_MODE_CTR.enc │ │ │ ├── SYM_CIPHER_TYPE_AES192_SYM_CIPHER_MODE_ECB.enc │ │ │ ├── SYM_CIPHER_TYPE_AES192_SYM_CIPHER_MODE_OFB.enc │ │ │ ├── SYM_CIPHER_TYPE_AES256_SYM_CIPHER_MODE_CBC.enc │ │ │ ├── SYM_CIPHER_TYPE_AES256_SYM_CIPHER_MODE_CFB.enc │ │ │ ├── SYM_CIPHER_TYPE_AES256_SYM_CIPHER_MODE_CTR.enc │ │ │ ├── SYM_CIPHER_TYPE_AES256_SYM_CIPHER_MODE_ECB.enc │ │ │ ├── SYM_CIPHER_TYPE_AES256_SYM_CIPHER_MODE_OFB.enc │ │ │ ├── SYM_CIPHER_TYPE_AES128_SYM_CIPHER_MODE_PCBC.enc │ │ │ ├── SYM_CIPHER_TYPE_AES192_SYM_CIPHER_MODE_PCBC.enc │ │ │ ├── SYM_CIPHER_TYPE_AES256_SYM_CIPHER_MODE_PCBC.enc │ │ │ ├── SYM_CIPHER_TYPE_SEED128_SYM_CIPHER_MODE_CBC.enc │ │ │ ├── SYM_CIPHER_TYPE_SEED128_SYM_CIPHER_MODE_CFB.enc │ │ │ ├── SYM_CIPHER_TYPE_SEED128_SYM_CIPHER_MODE_CTR.enc │ │ │ ├── SYM_CIPHER_TYPE_SEED128_SYM_CIPHER_MODE_ECB.enc │ │ │ ├── SYM_CIPHER_TYPE_SEED128_SYM_CIPHER_MODE_OFB.enc │ │ │ ├── SYM_CIPHER_TYPE_SEED128_SYM_CIPHER_MODE_PCBC.enc │ │ │ ├── SYM_CIPHER_TYPE_SEED256_SYM_CIPHER_MODE_CBC.enc │ │ │ ├── SYM_CIPHER_TYPE_SEED256_SYM_CIPHER_MODE_CFB.enc │ │ │ ├── SYM_CIPHER_TYPE_SEED256_SYM_CIPHER_MODE_CTR.enc │ │ │ ├── SYM_CIPHER_TYPE_SEED256_SYM_CIPHER_MODE_ECB.enc │ │ │ ├── SYM_CIPHER_TYPE_SEED256_SYM_CIPHER_MODE_OFB.enc │ │ │ └── SYM_CIPHER_TYPE_SEED256_SYM_CIPHER_MODE_PCBC.enc │ │ └── 768VXjhEic9MFigyGrAemiGflKsHPBWVaJAWjTaE2VXBaMgPGO4svAa5Tan.ssdeep │ ├── TimeZoneTest │ │ ├── Seoul │ │ ├── Canberra │ │ ├── Santiago │ │ └── Vancouver │ ├── RunTest.sh │ ├── RunTest.bat │ └── MemoryMappedFileTest │ │ └── document1.xml └── BuildTest_And_Run.bat ├── Doc └── cppcore.vsd ├── CMakeLists.txt ├── Sample ├── DummyProcess │ ├── main.cpp │ ├── stdafx.h │ └── stdafx.cpp ├── MultiThread │ ├── main.cpp │ ├── stdafx.h │ └── stdafx.cpp ├── ProcessTest │ ├── main.cpp │ ├── stdafx.h │ ├── stdafx.cpp │ ├── DllWrapper.h │ └── DllWrapper.cpp └── DummyDLL │ ├── APIEntry.h │ └── APIEntry.cpp ├── Inc ├── cryptopp700 │ ├── nr.h │ ├── resource.h │ ├── hashfwd.h │ ├── pch.h │ ├── adler32.h │ ├── trdlocal.h │ ├── tiger.h │ ├── aes.h │ ├── seed.h │ ├── md5.h │ ├── whrlpool.h │ ├── md4.h │ ├── modexppc.h │ ├── camellia.h │ ├── ttmac.h │ ├── blumshub.h │ ├── dsa.h │ ├── gf256.h │ ├── serpent.h │ └── mars.h └── cppcore.h └── License └── cppcore.txt /Src/000_String/stdafx.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" -------------------------------------------------------------------------------- /Src/001_Encoder/stdafx.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" -------------------------------------------------------------------------------- /Src/100_System/stdafx.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" -------------------------------------------------------------------------------- /Src/200_Common/stdafx.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" -------------------------------------------------------------------------------- /Src/300_Formatter/stdafx.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" -------------------------------------------------------------------------------- /Src/400_Server/stdafx.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" -------------------------------------------------------------------------------- /Test/DummyProcess/stdafx.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.lib filter=lfs diff=lfs merge=lfs -text 2 | -------------------------------------------------------------------------------- /Build/Test/Unicode/UTF8Sample.txt: -------------------------------------------------------------------------------- 1 | 안녕하세요! 문자열 테스트를 위한 텍스트 파일입니다. -------------------------------------------------------------------------------- /Doc/cppcore.vsd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/profrog-jeon/cppcore/HEAD/Doc/cppcore.vsd -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.1) 2 | add_subdirectory(Src) 3 | add_subdirectory(Test) -------------------------------------------------------------------------------- /Src/001_Encoder/sha256.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/profrog-jeon/cppcore/HEAD/Src/001_Encoder/sha256.cpp -------------------------------------------------------------------------------- /Src/100_System/ELFParser.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/profrog-jeon/cppcore/HEAD/Src/100_System/ELFParser.h -------------------------------------------------------------------------------- /Test/DummyProcess/stdafx.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "../../Inc/cppcore.h" -------------------------------------------------------------------------------- /Build/Test/Ascii/HexDump.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/profrog-jeon/cppcore/HEAD/Build/Test/Ascii/HexDump.txt -------------------------------------------------------------------------------- /Sample/DummyProcess/main.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/profrog-jeon/cppcore/HEAD/Sample/DummyProcess/main.cpp -------------------------------------------------------------------------------- /Sample/DummyProcess/stdafx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/profrog-jeon/cppcore/HEAD/Sample/DummyProcess/stdafx.h -------------------------------------------------------------------------------- /Sample/MultiThread/main.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/profrog-jeon/cppcore/HEAD/Sample/MultiThread/main.cpp -------------------------------------------------------------------------------- /Sample/MultiThread/stdafx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/profrog-jeon/cppcore/HEAD/Sample/MultiThread/stdafx.h -------------------------------------------------------------------------------- /Sample/ProcessTest/main.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/profrog-jeon/cppcore/HEAD/Sample/ProcessTest/main.cpp -------------------------------------------------------------------------------- /Sample/ProcessTest/stdafx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/profrog-jeon/cppcore/HEAD/Sample/ProcessTest/stdafx.h -------------------------------------------------------------------------------- /Src/100_System/LogWorker.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/profrog-jeon/cppcore/HEAD/Src/100_System/LogWorker.cpp -------------------------------------------------------------------------------- /Src/200_Common/UtilityT.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/profrog-jeon/cppcore/HEAD/Src/200_Common/UtilityT.cpp -------------------------------------------------------------------------------- /Build/Test/Encoder/Colosseum.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/profrog-jeon/cppcore/HEAD/Build/Test/Encoder/Colosseum.db -------------------------------------------------------------------------------- /Build/Test/TimeZoneTest/Seoul: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/profrog-jeon/cppcore/HEAD/Build/Test/TimeZoneTest/Seoul -------------------------------------------------------------------------------- /Sample/DummyProcess/stdafx.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/profrog-jeon/cppcore/HEAD/Sample/DummyProcess/stdafx.cpp -------------------------------------------------------------------------------- /Sample/MultiThread/stdafx.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/profrog-jeon/cppcore/HEAD/Sample/MultiThread/stdafx.cpp -------------------------------------------------------------------------------- /Sample/ProcessTest/stdafx.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/profrog-jeon/cppcore/HEAD/Sample/ProcessTest/stdafx.cpp -------------------------------------------------------------------------------- /Src/100_System/EnvironmentT.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/profrog-jeon/cppcore/HEAD/Src/100_System/EnvironmentT.cpp -------------------------------------------------------------------------------- /Src/200_Common/PEParserData.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/profrog-jeon/cppcore/HEAD/Src/200_Common/PEParserData.h -------------------------------------------------------------------------------- /Test/SystemTest/SystemTest.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/profrog-jeon/cppcore/HEAD/Test/SystemTest/SystemTest.rc -------------------------------------------------------------------------------- /Build/Test/TimeZoneTest/Canberra: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/profrog-jeon/cppcore/HEAD/Build/Test/TimeZoneTest/Canberra -------------------------------------------------------------------------------- /Build/Test/TimeZoneTest/Santiago: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/profrog-jeon/cppcore/HEAD/Build/Test/TimeZoneTest/Santiago -------------------------------------------------------------------------------- /Build/Test/TimeZoneTest/Vancouver: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/profrog-jeon/cppcore/HEAD/Build/Test/TimeZoneTest/Vancouver -------------------------------------------------------------------------------- /Build/Test/Unicode/ANSISample.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/profrog-jeon/cppcore/HEAD/Build/Test/Unicode/ANSISample.txt -------------------------------------------------------------------------------- /Inc/cryptopp700/nr.h: -------------------------------------------------------------------------------- 1 | #ifndef CRYPTOPP_NR_H 2 | #define CRYPTOPP_NR_H 3 | 4 | #include "gfpcrypt.h" 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /Src/300_Formatter/YAMLParser.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/profrog-jeon/cppcore/HEAD/Src/300_Formatter/YAMLParser.cpp -------------------------------------------------------------------------------- /Test/ServerTest/ProtocolTest.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/profrog-jeon/cppcore/HEAD/Test/ServerTest/ProtocolTest.cpp -------------------------------------------------------------------------------- /Build/Test/Unicode/UTF16BESample.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/profrog-jeon/cppcore/HEAD/Build/Test/Unicode/UTF16BESample.txt -------------------------------------------------------------------------------- /Build/Test/Unicode/UTF16Sample.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/profrog-jeon/cppcore/HEAD/Build/Test/Unicode/UTF16Sample.txt -------------------------------------------------------------------------------- /Build/Test/Unicode/UTF32BESample.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/profrog-jeon/cppcore/HEAD/Build/Test/Unicode/UTF32BESample.txt -------------------------------------------------------------------------------- /Build/Test/Unicode/UTF32Sample.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/profrog-jeon/cppcore/HEAD/Build/Test/Unicode/UTF32Sample.txt -------------------------------------------------------------------------------- /Src/200_Common/TextFileReaderT.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/profrog-jeon/cppcore/HEAD/Src/200_Common/TextFileReaderT.cpp -------------------------------------------------------------------------------- /Src/300_Formatter/YAMLSerializer.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/profrog-jeon/cppcore/HEAD/Src/300_Formatter/YAMLSerializer.cpp -------------------------------------------------------------------------------- /Src/400_Server/SocketCommon.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace core 4 | { 5 | ECODE SetCommonSockOpt(SOCKET hSocket); 6 | } 7 | -------------------------------------------------------------------------------- /Src/100_System/GlobalSemaphoreMap.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/profrog-jeon/cppcore/HEAD/Src/100_System/GlobalSemaphoreMap.cpp -------------------------------------------------------------------------------- /Src/200_Common/FileHashFunction.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "FileHashFunction.h" 3 | 4 | namespace core 5 | { 6 | 7 | } -------------------------------------------------------------------------------- /Src/100_System/SocketDefine.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "SocketDefine.h" 3 | 4 | const int INVALID_SOCKET_ = (SOCKET)~0; 5 | const int SOCKET_ERROR_ = -1; 6 | -------------------------------------------------------------------------------- /Build/Test/RunTest.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | REPORT_DIR=../Report 4 | 5 | for TEST_EXE in $(ls *A *W); do 6 | ./$TEST_EXE --gtest_output=xml:${REPORT_DIR}/${TEST_EXE}.linux.xml 7 | done 8 | -------------------------------------------------------------------------------- /Src/300_Formatter/Interface.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "Interface.h" 3 | #include "300_Formatter.h" 4 | #include "FmtTypes.h" 5 | 6 | namespace core 7 | { 8 | } 9 | 10 | -------------------------------------------------------------------------------- /Test/DummyDynamicLibrary/SoMain_Linux_Mac.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | 3 | HANDLE g_hModule = NULL; 4 | 5 | __attribute__((constructor)) void on_load(void) 6 | { 7 | g_hModule = (HANDLE)on_load; 8 | } -------------------------------------------------------------------------------- /Build/Test/Encoder/CipherData/SYM_CIPHER_TYPE_AES128_SYM_CIPHER_MODE_CBC.enc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/profrog-jeon/cppcore/HEAD/Build/Test/Encoder/CipherData/SYM_CIPHER_TYPE_AES128_SYM_CIPHER_MODE_CBC.enc -------------------------------------------------------------------------------- /Build/Test/Encoder/CipherData/SYM_CIPHER_TYPE_AES128_SYM_CIPHER_MODE_CFB.enc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/profrog-jeon/cppcore/HEAD/Build/Test/Encoder/CipherData/SYM_CIPHER_TYPE_AES128_SYM_CIPHER_MODE_CFB.enc -------------------------------------------------------------------------------- /Build/Test/Encoder/CipherData/SYM_CIPHER_TYPE_AES128_SYM_CIPHER_MODE_CTR.enc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/profrog-jeon/cppcore/HEAD/Build/Test/Encoder/CipherData/SYM_CIPHER_TYPE_AES128_SYM_CIPHER_MODE_CTR.enc -------------------------------------------------------------------------------- /Build/Test/Encoder/CipherData/SYM_CIPHER_TYPE_AES128_SYM_CIPHER_MODE_ECB.enc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/profrog-jeon/cppcore/HEAD/Build/Test/Encoder/CipherData/SYM_CIPHER_TYPE_AES128_SYM_CIPHER_MODE_ECB.enc -------------------------------------------------------------------------------- /Build/Test/Encoder/CipherData/SYM_CIPHER_TYPE_AES128_SYM_CIPHER_MODE_OFB.enc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/profrog-jeon/cppcore/HEAD/Build/Test/Encoder/CipherData/SYM_CIPHER_TYPE_AES128_SYM_CIPHER_MODE_OFB.enc -------------------------------------------------------------------------------- /Build/Test/Encoder/CipherData/SYM_CIPHER_TYPE_AES192_SYM_CIPHER_MODE_CBC.enc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/profrog-jeon/cppcore/HEAD/Build/Test/Encoder/CipherData/SYM_CIPHER_TYPE_AES192_SYM_CIPHER_MODE_CBC.enc -------------------------------------------------------------------------------- /Build/Test/Encoder/CipherData/SYM_CIPHER_TYPE_AES192_SYM_CIPHER_MODE_CFB.enc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/profrog-jeon/cppcore/HEAD/Build/Test/Encoder/CipherData/SYM_CIPHER_TYPE_AES192_SYM_CIPHER_MODE_CFB.enc -------------------------------------------------------------------------------- /Build/Test/Encoder/CipherData/SYM_CIPHER_TYPE_AES192_SYM_CIPHER_MODE_CTR.enc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/profrog-jeon/cppcore/HEAD/Build/Test/Encoder/CipherData/SYM_CIPHER_TYPE_AES192_SYM_CIPHER_MODE_CTR.enc -------------------------------------------------------------------------------- /Build/Test/Encoder/CipherData/SYM_CIPHER_TYPE_AES192_SYM_CIPHER_MODE_ECB.enc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/profrog-jeon/cppcore/HEAD/Build/Test/Encoder/CipherData/SYM_CIPHER_TYPE_AES192_SYM_CIPHER_MODE_ECB.enc -------------------------------------------------------------------------------- /Build/Test/Encoder/CipherData/SYM_CIPHER_TYPE_AES192_SYM_CIPHER_MODE_OFB.enc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/profrog-jeon/cppcore/HEAD/Build/Test/Encoder/CipherData/SYM_CIPHER_TYPE_AES192_SYM_CIPHER_MODE_OFB.enc -------------------------------------------------------------------------------- /Build/Test/Encoder/CipherData/SYM_CIPHER_TYPE_AES256_SYM_CIPHER_MODE_CBC.enc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/profrog-jeon/cppcore/HEAD/Build/Test/Encoder/CipherData/SYM_CIPHER_TYPE_AES256_SYM_CIPHER_MODE_CBC.enc -------------------------------------------------------------------------------- /Build/Test/Encoder/CipherData/SYM_CIPHER_TYPE_AES256_SYM_CIPHER_MODE_CFB.enc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/profrog-jeon/cppcore/HEAD/Build/Test/Encoder/CipherData/SYM_CIPHER_TYPE_AES256_SYM_CIPHER_MODE_CFB.enc -------------------------------------------------------------------------------- /Build/Test/Encoder/CipherData/SYM_CIPHER_TYPE_AES256_SYM_CIPHER_MODE_CTR.enc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/profrog-jeon/cppcore/HEAD/Build/Test/Encoder/CipherData/SYM_CIPHER_TYPE_AES256_SYM_CIPHER_MODE_CTR.enc -------------------------------------------------------------------------------- /Build/Test/Encoder/CipherData/SYM_CIPHER_TYPE_AES256_SYM_CIPHER_MODE_ECB.enc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/profrog-jeon/cppcore/HEAD/Build/Test/Encoder/CipherData/SYM_CIPHER_TYPE_AES256_SYM_CIPHER_MODE_ECB.enc -------------------------------------------------------------------------------- /Build/Test/Encoder/CipherData/SYM_CIPHER_TYPE_AES256_SYM_CIPHER_MODE_OFB.enc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/profrog-jeon/cppcore/HEAD/Build/Test/Encoder/CipherData/SYM_CIPHER_TYPE_AES256_SYM_CIPHER_MODE_OFB.enc -------------------------------------------------------------------------------- /Src/__Common/Compatibility.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define MakeLowerCase MakeLower 4 | #define MakeUpperCase MakeUpper 5 | #define BecomeLowerCase BecomeLower 6 | #define BecomeUpperCase BecomeUpper 7 | -------------------------------------------------------------------------------- /Build/Test/Encoder/CipherData/SYM_CIPHER_TYPE_AES128_SYM_CIPHER_MODE_PCBC.enc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/profrog-jeon/cppcore/HEAD/Build/Test/Encoder/CipherData/SYM_CIPHER_TYPE_AES128_SYM_CIPHER_MODE_PCBC.enc -------------------------------------------------------------------------------- /Build/Test/Encoder/CipherData/SYM_CIPHER_TYPE_AES192_SYM_CIPHER_MODE_PCBC.enc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/profrog-jeon/cppcore/HEAD/Build/Test/Encoder/CipherData/SYM_CIPHER_TYPE_AES192_SYM_CIPHER_MODE_PCBC.enc -------------------------------------------------------------------------------- /Build/Test/Encoder/CipherData/SYM_CIPHER_TYPE_AES256_SYM_CIPHER_MODE_PCBC.enc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/profrog-jeon/cppcore/HEAD/Build/Test/Encoder/CipherData/SYM_CIPHER_TYPE_AES256_SYM_CIPHER_MODE_PCBC.enc -------------------------------------------------------------------------------- /Build/Test/Encoder/CipherData/SYM_CIPHER_TYPE_SEED128_SYM_CIPHER_MODE_CBC.enc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/profrog-jeon/cppcore/HEAD/Build/Test/Encoder/CipherData/SYM_CIPHER_TYPE_SEED128_SYM_CIPHER_MODE_CBC.enc -------------------------------------------------------------------------------- /Build/Test/Encoder/CipherData/SYM_CIPHER_TYPE_SEED128_SYM_CIPHER_MODE_CFB.enc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/profrog-jeon/cppcore/HEAD/Build/Test/Encoder/CipherData/SYM_CIPHER_TYPE_SEED128_SYM_CIPHER_MODE_CFB.enc -------------------------------------------------------------------------------- /Build/Test/Encoder/CipherData/SYM_CIPHER_TYPE_SEED128_SYM_CIPHER_MODE_CTR.enc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/profrog-jeon/cppcore/HEAD/Build/Test/Encoder/CipherData/SYM_CIPHER_TYPE_SEED128_SYM_CIPHER_MODE_CTR.enc -------------------------------------------------------------------------------- /Build/Test/Encoder/CipherData/SYM_CIPHER_TYPE_SEED128_SYM_CIPHER_MODE_ECB.enc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/profrog-jeon/cppcore/HEAD/Build/Test/Encoder/CipherData/SYM_CIPHER_TYPE_SEED128_SYM_CIPHER_MODE_ECB.enc -------------------------------------------------------------------------------- /Build/Test/Encoder/CipherData/SYM_CIPHER_TYPE_SEED128_SYM_CIPHER_MODE_OFB.enc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/profrog-jeon/cppcore/HEAD/Build/Test/Encoder/CipherData/SYM_CIPHER_TYPE_SEED128_SYM_CIPHER_MODE_OFB.enc -------------------------------------------------------------------------------- /Build/Test/Encoder/CipherData/SYM_CIPHER_TYPE_SEED128_SYM_CIPHER_MODE_PCBC.enc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/profrog-jeon/cppcore/HEAD/Build/Test/Encoder/CipherData/SYM_CIPHER_TYPE_SEED128_SYM_CIPHER_MODE_PCBC.enc -------------------------------------------------------------------------------- /Build/Test/Encoder/CipherData/SYM_CIPHER_TYPE_SEED256_SYM_CIPHER_MODE_CBC.enc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/profrog-jeon/cppcore/HEAD/Build/Test/Encoder/CipherData/SYM_CIPHER_TYPE_SEED256_SYM_CIPHER_MODE_CBC.enc -------------------------------------------------------------------------------- /Build/Test/Encoder/CipherData/SYM_CIPHER_TYPE_SEED256_SYM_CIPHER_MODE_CFB.enc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/profrog-jeon/cppcore/HEAD/Build/Test/Encoder/CipherData/SYM_CIPHER_TYPE_SEED256_SYM_CIPHER_MODE_CFB.enc -------------------------------------------------------------------------------- /Build/Test/Encoder/CipherData/SYM_CIPHER_TYPE_SEED256_SYM_CIPHER_MODE_CTR.enc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/profrog-jeon/cppcore/HEAD/Build/Test/Encoder/CipherData/SYM_CIPHER_TYPE_SEED256_SYM_CIPHER_MODE_CTR.enc -------------------------------------------------------------------------------- /Build/Test/Encoder/CipherData/SYM_CIPHER_TYPE_SEED256_SYM_CIPHER_MODE_ECB.enc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/profrog-jeon/cppcore/HEAD/Build/Test/Encoder/CipherData/SYM_CIPHER_TYPE_SEED256_SYM_CIPHER_MODE_ECB.enc -------------------------------------------------------------------------------- /Build/Test/Encoder/CipherData/SYM_CIPHER_TYPE_SEED256_SYM_CIPHER_MODE_OFB.enc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/profrog-jeon/cppcore/HEAD/Build/Test/Encoder/CipherData/SYM_CIPHER_TYPE_SEED256_SYM_CIPHER_MODE_OFB.enc -------------------------------------------------------------------------------- /Build/Test/Encoder/CipherData/SYM_CIPHER_TYPE_SEED256_SYM_CIPHER_MODE_PCBC.enc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/profrog-jeon/cppcore/HEAD/Build/Test/Encoder/CipherData/SYM_CIPHER_TYPE_SEED256_SYM_CIPHER_MODE_PCBC.enc -------------------------------------------------------------------------------- /Src/300_Formatter/300_Formatter.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Interface.h" 4 | #include "InterfaceLegacy.h" 5 | #include "FormatterSuper.h" 6 | #include "TCHARFormatter.h" 7 | #include "UTF8Formatter.h" 8 | -------------------------------------------------------------------------------- /Test/DummyDynamicLibrary/APIEntry.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | DECLARE_EXPORT int nSomeVariable; 4 | DECLARE_EXPORT int SomeFunc(int a, int b); 5 | DECLARE_EXPORT ECODE GetName(char* pszBuffer, size_t tBufferSize); 6 | -------------------------------------------------------------------------------- /Build/Test/Encoder/768VXjhEic9MFigyGrAemiGflKsHPBWVaJAWjTaE2VXBaMgPGO4svAa5Tan.ssdeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/profrog-jeon/cppcore/HEAD/Build/Test/Encoder/768VXjhEic9MFigyGrAemiGflKsHPBWVaJAWjTaE2VXBaMgPGO4svAa5Tan.ssdeep -------------------------------------------------------------------------------- /Src/000_String/ASCII.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | extern const BYTE g_bTextAscii[256]; 4 | extern const BYTE g_bDisplayableAscii[256]; 5 | extern const char g_cHexCharTable[0x10]; 6 | extern const signed char g_cHexCharAscii[256]; -------------------------------------------------------------------------------- /Src/001_Encoder/Encoder.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Base64.h" 4 | #include "Type.h" 5 | #include "StringFunction.h" 6 | #include "HashFunction.h" 7 | #include "SymCipherFunction.h" 8 | #include "StringSymCipherFunction.h" -------------------------------------------------------------------------------- /Build/Test/RunTest.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | SET REPORT_DIR=..\Report 4 | 5 | RD /S /Q %REPORT_DIR% 6 | MKDIR %REPORT_DIR% 7 | for %%i in (*.exe) do ( 8 | "%%i" --gtest_output=xml:%REPORT_DIR%\%%i.windows.xml 9 | ) 10 | 11 | pause -------------------------------------------------------------------------------- /Src/100_System/MemoryLeakFinder.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace core 4 | { 5 | struct ST_MEMORYLEAK_FINDER 6 | { 7 | ST_MEMORYLEAK_FINDER(int nSetBreakAllocCounter = 0); 8 | ~ST_MEMORYLEAK_FINDER(void); 9 | }; 10 | } 11 | -------------------------------------------------------------------------------- /Src/200_Common/zipcommon.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef UNICODE 4 | #define internal_zip internal_zip_w 5 | #else 6 | #define internal_zip internal_zip_a 7 | #endif 8 | 9 | typedef void* HZIP; 10 | typedef DWORD ZRESULT; 11 | 12 | -------------------------------------------------------------------------------- /Src/200_Common/Uncopyable.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace core 4 | { 5 | class Uncopyable 6 | { 7 | Uncopyable(const Uncopyable& other); 8 | Uncopyable& operator=(const Uncopyable& other); 9 | 10 | public: 11 | Uncopyable(void) {} 12 | }; 13 | } 14 | -------------------------------------------------------------------------------- /Src/100_System/System.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Struct.h" 4 | #include "SocketDefine.h" 5 | #include "Environment.h" 6 | #include "Information.h" 7 | #include "FileSystem.h" 8 | #include "KernelObject.h" 9 | #include "Log.h" 10 | #include "InterlockedOperation.h" -------------------------------------------------------------------------------- /Test/DummyDynamicLibrary/stdafx.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../../Src/__Common/Define.h" 4 | #include "../../Src/__Common/ErrorCode.h" 5 | #include "../../Src/__Common/Type.h" 6 | #include "../../Src/000_String/000_String.h" 7 | #include "../../Src/100_System/100_System.h" 8 | -------------------------------------------------------------------------------- /Src/400_Server/400_Server.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "SyncServer.h" 4 | #include "SyncConnection.h" 5 | #include "SyncTCPSocket.h" 6 | #include "SyncUDPSocket.h" 7 | #include "Packetizer.h" 8 | #include "BinProtocol.h" 9 | #include "JsonProtocol.h" 10 | #include "UBJsonProtocol.h" -------------------------------------------------------------------------------- /Test/StringTest/stdafx.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define _CRT_SECURE_NO_WARNINGS 4 | 5 | #include 6 | #include "../../Src/000_String/000_String.h" 7 | #include "../../Src/001_Encoder/001_Encoder.h" 8 | #include "../../Src/200_Common/200_Common.h" 9 | 10 | using namespace core; 11 | -------------------------------------------------------------------------------- /Src/100_System/MemoryLeakFinder_Linux_Mac.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "MemoryLeakFinder.h" 3 | 4 | namespace core 5 | { 6 | ST_MEMORYLEAK_FINDER::ST_MEMORYLEAK_FINDER(int nSetBreakAllocCounter) 7 | { 8 | } 9 | ST_MEMORYLEAK_FINDER::~ST_MEMORYLEAK_FINDER(void) 10 | { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Test/EncoderTest/stdafx.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "gtest/gtest.h" 9 | #include "../../Src/000_String/000_String.h" 10 | #include "../../Src/001_Encoder/001_Encoder.h" 11 | 12 | using namespace core; -------------------------------------------------------------------------------- /Src/100_System/FileSystem_Win.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include 3 | #include "FileSystem.h" 4 | 5 | namespace core 6 | { 7 | ////////////////////////////////////////////////////////////////////////// 8 | void FindClose(HANDLE hFindFile) 9 | { 10 | ::FindClose(hFindFile); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Src/400_Server/SyncConnection.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "SyncConnection.h" 3 | 4 | namespace core 5 | { 6 | CSyncConnection::CSyncConnection(CSyncTCPSocket* pSocket) 7 | : m_pSocket(pSocket) 8 | , m_strClientIP() 9 | { 10 | } 11 | 12 | CSyncConnection::~CSyncConnection() 13 | { 14 | } 15 | } 16 | 17 | -------------------------------------------------------------------------------- /Test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.1) 2 | add_subdirectory(StringTest) 3 | #add_subdirectory(EncoderTest) 4 | add_subdirectory(SystemTest) 5 | add_subdirectory(CommonTest) 6 | add_subdirectory(FormatterTest) 7 | add_subdirectory(ServerTest) 8 | add_subdirectory(DummyProcess) 9 | add_subdirectory(DummyDynamicLibrary) -------------------------------------------------------------------------------- /Src/001_Encoder/001_Encoder.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Base64.h" 4 | #include "Type.h" 5 | #include "StringFunction.h" 6 | #include "Hash.h" 7 | #include "HMAC.h" 8 | #include "HashFunction.h" 9 | #include "PubKeyCipherFunction.h" 10 | #include "SymCipherFunction.h" 11 | #include "StringSymCipherFunction.h" 12 | #include "rc4.h" -------------------------------------------------------------------------------- /Src/200_Common/MutexT.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "Mutex.h" 3 | 4 | namespace core 5 | { 6 | CMutex::CMutex(LPCTSTR pszName) 7 | : m_hMutex(NULL) 8 | { 9 | m_hMutex = CreateMutex(false, pszName); 10 | if( NULL == m_hMutex ) 11 | Log_Error(TEXT("CreateMutex(false, %s) has failed in CMutex"), pszName); 12 | } 13 | } -------------------------------------------------------------------------------- /Src/300_Formatter/IChannel.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../__Common/Type.h" 4 | #include "FmtTypes.h" 5 | 6 | namespace core 7 | { 8 | struct IChannel 9 | { 10 | virtual ~IChannel() {} 11 | virtual bool CheckValidity(std::tstring& refStrErrMsg) = 0; 12 | virtual size_t Access(void* pData, size_t tDataSize) = 0; 13 | }; 14 | } 15 | -------------------------------------------------------------------------------- /Src/200_Common/DuplicatedProcChecker.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace core 4 | { 5 | struct ST_DUPLICATED_PROC_CHECKER 6 | { 7 | bool bDuplicated; 8 | ST_DUPLICATED_PROC_CHECKER(LPCSTR pszName = NULL); // if pszName==NULL, will be used ModuleFileName 9 | 10 | bool IsDuplicated(void) { 11 | return bDuplicated; 12 | } 13 | }; 14 | } 15 | -------------------------------------------------------------------------------- /Src/200_Common/Thread.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "Thread.h" 3 | 4 | namespace core 5 | { 6 | int InternalThreadCaller(void* pContext) 7 | { 8 | INTERNAL_COMMON_THREAD_DATA* pThreadData = (INTERNAL_COMMON_THREAD_DATA*)pContext; 9 | int nErrCode = pThreadData->ThreadFunc(); 10 | delete pThreadData; 11 | return nErrCode; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Src/000_String/stdafx.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define _CRT_SECURE_NO_WARNINGS 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #include "../__Common/Type.h" 14 | #include "../__Common/Define.h" 15 | #include "../__Common/ErrorCode.h" 16 | -------------------------------------------------------------------------------- /Src/100_System/UtilityT.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "Utility.h" 3 | #include "FileSystem.h" 4 | 5 | namespace core 6 | { 7 | CCurrentDirectorySettter::CCurrentDirectorySettter(std::tstring strWorkingDir) 8 | : m_strOriginalDir() 9 | { 10 | m_strOriginalDir = GetCurrentDirectoryW(); 11 | m_bDirChanged = SetCurrentDirectory(strWorkingDir.c_str()); 12 | } 13 | } -------------------------------------------------------------------------------- /Sample/DummyDLL/APIEntry.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../../Inc/cppcore.h" 4 | 5 | enum E_CMD 6 | { 7 | CMD_SET_VALUE = 0, 8 | CMD_GET_VALUE, 9 | CMD_ANALYZE_FILE, 10 | }; 11 | 12 | DECLARE_EXPORT HANDLE Create(void); 13 | DECLARE_EXPORT ECODE Operate(HANDLE hContext, E_CMD nCmd, LPCSTR pszInput, LPCSTR pszOutput); 14 | DECLARE_EXPORT void Destroy(HANDLE hContext); 15 | -------------------------------------------------------------------------------- /Src/001_Encoder/Hash.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "../__Common/Type.h" 6 | #include "Type.h" 7 | 8 | namespace core 9 | { 10 | HANDLE InitHash(E_HASH_TYPE dwHashType); 11 | void UpdateHash(HANDLE hHash, LPCBYTE pData, size_t tSize); 12 | void FinalHash(HANDLE hHash, std::vector& outBuff); 13 | std::string FinalHash(HANDLE hHash); 14 | } 15 | -------------------------------------------------------------------------------- /Src/001_Encoder/stdafx.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define _CRT_SECURE_NO_WARNINGS 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include "../__Common/Type.h" 12 | #include "../__Common/Define.h" 13 | #include "../__Common/ErrorCode.h" 14 | #include "../000_String/000_String.h" 15 | #include "Type.h" 16 | -------------------------------------------------------------------------------- /Src/200_Common/TextFileWriterT.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "TextFileWriter.h" 3 | 4 | namespace core 5 | { 6 | ////////////////////////////////////////////////////////////////////////// 7 | CTextFileWriter::~CTextFileWriter(void) 8 | { 9 | if( m_hFile ) 10 | { 11 | FlushFileBuffers(m_hFile); 12 | CloseFile(m_hFile); 13 | m_hFile = NULL; 14 | } 15 | } 16 | } -------------------------------------------------------------------------------- /Src/001_Encoder/rc4.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace core { 4 | 5 | typedef struct { 6 | WORD wIndex; 7 | WORD wSwapPointerIndex; 8 | BYTE SBox[256]; 9 | } RC4_CTX; 10 | 11 | void RC4Init(RC4_CTX* rcContext, const unsigned char* key, DWORD dwKeyLength); 12 | void RC4Update(RC4_CTX* rcContext, unsigned char* strBuf, DWORD dwBufLength); 13 | void Rc4Swap(BYTE& bLeft, BYTE& bRight); 14 | } 15 | -------------------------------------------------------------------------------- /Src/200_Common/stdafx.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define _CRT_SECURE_NO_WARNINGS 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include "../__Common/Type.h" 10 | #include "../__Common/Define.h" 11 | #include "../__Common/ErrorCode.h" 12 | 13 | #include "../000_String/000_String.h" 14 | #include "../001_Encoder/001_Encoder.h" 15 | #include "../100_System/100_System.h" 16 | -------------------------------------------------------------------------------- /Test/SystemTest/ExceptionTest.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | 3 | TEST(SystemTest, ExceptionTest) 4 | { 5 | std::string strErrMsg = "Test SystemTest Exception"; 6 | std::string strCatchMsg; 7 | try 8 | { 9 | throw exception_format("%s", strErrMsg.c_str()); 10 | } 11 | catch (std::exception& e) 12 | { 13 | strCatchMsg = e.what(); 14 | } 15 | 16 | EXPECT_EQ(strErrMsg, strCatchMsg); 17 | } 18 | 19 | -------------------------------------------------------------------------------- /Inc/cppcore.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../Src/__Common/Type.h" 4 | #include "../Src/__Common/Define.h" 5 | #include "../Src/__Common/ErrorCode.h" 6 | #include "../Src/000_String/000_String.h" 7 | #include "../Src/001_Encoder/001_Encoder.h" 8 | #include "../Src/100_System/100_System.h" 9 | #include "../Src/200_Common/200_Common.h" 10 | #include "../Src/300_Formatter/300_Formatter.h" 11 | #include "../Src/400_Server/400_Server.h" -------------------------------------------------------------------------------- /Src/000_String/String.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../__Common/Type.h" 4 | #include "../__Common/Define.h" 5 | #include "../__Common/ErrorCode.h" 6 | 7 | #include "BOM.h" 8 | #include "Exception.h" 9 | #include "Unicode.h" 10 | #include "UnicodeEncoding.h" 11 | #include "POSIX.h" 12 | #include "Utility.h" 13 | #include "STLString.h" 14 | #include "StdString.h" 15 | #include "StdStringLegacy.h" 16 | #include "NumericString.h" 17 | -------------------------------------------------------------------------------- /Src/001_Encoder/HMAC.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "../__Common/Type.h" 6 | #include "Type.h" 7 | 8 | namespace core 9 | { 10 | HANDLE InitHMAC(E_HASH_TYPE nHashType, std::string strKey); 11 | HANDLE InitHMAC(E_HASH_TYPE nHashType, LPCBYTE pKey, size_t tKeyLength); 12 | void UpdateHMAC(HANDLE hHash, LPCBYTE pData, size_t tSize); 13 | void FinalHMAC(HANDLE hHash, std::vector& outBuff); 14 | } 15 | -------------------------------------------------------------------------------- /Src/001_Encoder/ISymAlgorithm.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Type.h" 4 | 5 | namespace core 6 | { 7 | struct ISymAlgorithm 8 | { 9 | virtual ~ISymAlgorithm(void) {} 10 | virtual ECODE Init(E_CIPHER_METHOD nMethod, const ST_SYM_CIPHER_KEY& stKey) = 0; 11 | virtual size_t BlockSize(void) = 0; 12 | virtual ECODE Encrypt(LPCBYTE pSrc, LPBYTE pDest) = 0; 13 | virtual ECODE Decrypt(LPCBYTE pSrc, LPBYTE pDest) = 0; 14 | }; 15 | } 16 | -------------------------------------------------------------------------------- /Src/000_String/BOMT.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "BOM.h" 3 | 4 | namespace core 5 | { 6 | ////////////////////////////////////////////////////////////////////////// 7 | E_BOM_TYPE GetCurrentBOM(void) 8 | { 9 | #ifdef _MSC_VER 10 | #ifdef UNICODE 11 | return BOM_UTF16; 12 | #else 13 | return BOM_EUCKR; 14 | #endif 15 | #else 16 | #ifdef UNICODE 17 | return BOM_UTF32; 18 | #else 19 | return BOM_UTF8; 20 | #endif 21 | #endif 22 | } 23 | } -------------------------------------------------------------------------------- /Test/DummyDynamicLibrary/APIEntry.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "APIEntry.h" 3 | 4 | extern HANDLE g_hModule; 5 | 6 | int nSomeVariable = 15; 7 | int SomeFunc(int a, int b) 8 | { 9 | return a + b; 10 | } 11 | 12 | ECODE GetName(char* pszBuffer, size_t tBufferSize) 13 | { 14 | std::string strModuleName = core::GetModuleFileNameA(g_hModule); 15 | core::SafeStrCpy(pszBuffer, tBufferSize, strModuleName.c_str()); 16 | return EC_SUCCESS; 17 | } 18 | -------------------------------------------------------------------------------- /Src/001_Encoder/SymPlain.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "ISymAlgorithm.h" 4 | 5 | namespace core 6 | { 7 | class CSymPlain : public ISymAlgorithm 8 | { 9 | public: 10 | CSymPlain(void); 11 | ~CSymPlain(void); 12 | 13 | ECODE Init(E_CIPHER_METHOD nMethod, const ST_SYM_CIPHER_KEY& stKey); 14 | ECODE Encrypt(LPCBYTE pSrc, LPBYTE pDest); 15 | ECODE Decrypt(LPCBYTE pSrc, LPBYTE pDest); 16 | size_t BlockSize(void) { return 16; } 17 | }; 18 | } 19 | -------------------------------------------------------------------------------- /Test/DummyDynamicLibrary/DllMain_Win.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "stdafx.h" 3 | 4 | HANDLE g_hModule = NULL; 5 | 6 | BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) 7 | { 8 | g_hModule = hModule; 9 | switch (ul_reason_for_call) 10 | { 11 | case DLL_PROCESS_ATTACH: 12 | case DLL_THREAD_ATTACH: 13 | case DLL_THREAD_DETACH: 14 | case DLL_PROCESS_DETACH: 15 | break; 16 | } 17 | return TRUE; 18 | } 19 | 20 | -------------------------------------------------------------------------------- /Src/001_Encoder/IPubKeyCipher.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include "Type.h" 5 | 6 | namespace core 7 | { 8 | struct ST_PUBKEY_CIPHER_INFO 9 | { 10 | DWORD dwPlainBlockSize; 11 | DWORD dwCipherBlockSize; 12 | }; 13 | 14 | struct IPubKeyCipher 15 | { 16 | virtual ~IPubKeyCipher() {} 17 | 18 | virtual void QueryInfo(ST_PUBKEY_CIPHER_INFO& outInfo) = 0; 19 | virtual ECODE Crypt(LPCBYTE btSrc, LPBYTE btDest) = 0; 20 | }; 21 | 22 | } 23 | -------------------------------------------------------------------------------- /Src/100_System/100_System.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Struct.h" 4 | #include "Environment.h" 5 | #include "Information.h" 6 | #include "ExeParserSuper.h" 7 | #include "ELFParser.h" 8 | #include "FileSystem.h" 9 | #include "KernelObject.h" 10 | #include "Log.h" 11 | #include "LogEx.h" 12 | #include "MemoryLeakFinder.h" 13 | #include "Socket.h" 14 | #include "SocketDefine.h" 15 | #include "InterlockedOperation.h" 16 | #include "Network.h" 17 | #include "Utility.h" -------------------------------------------------------------------------------- /Src/001_Encoder/Base64.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef UNICODE 4 | #define EncodeBase64 EncodeBase64W 5 | #else 6 | #define EncodeBase64 EncodeBase64A 7 | #endif 8 | 9 | namespace core 10 | { 11 | std::string EncodeBase64A(LPCBYTE pData, size_t tDataSize); 12 | std::wstring EncodeBase64W(LPCBYTE pData, size_t tDataSize); 13 | size_t DecodeBase64(std::string strBase64, LPBYTE pDest = NULL); 14 | size_t DecodeBase64(std::wstring strBase64, LPBYTE pDest = NULL); 15 | } 16 | -------------------------------------------------------------------------------- /Src/200_Common/RingBuffer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include "CriticalSection.h" 5 | 6 | namespace core 7 | { 8 | class CRingBuffer 9 | { 10 | CCriticalSection m_csPos; 11 | size_t m_tPos; 12 | std::vector m_vecBuffer; 13 | 14 | public: 15 | CRingBuffer(void); 16 | ~CRingBuffer(void); 17 | 18 | ECODE Create(size_t tSize); 19 | void Destroy(void); 20 | 21 | LPBYTE Alloc(size_t tSize, size_t tReservedSize = 0); 22 | }; 23 | } 24 | -------------------------------------------------------------------------------- /Inc/cryptopp700/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Developer Studio generated include file. 3 | // Used by cryptopp.rc 4 | // 5 | 6 | // Next default values for new objects 7 | // 8 | #ifdef APSTUDIO_INVOKED 9 | #ifndef APSTUDIO_READONLY_SYMBOLS 10 | #define _APS_NEXT_RESOURCE_VALUE 101 11 | #define _APS_NEXT_COMMAND_VALUE 40001 12 | #define _APS_NEXT_CONTROL_VALUE 1000 13 | #define _APS_NEXT_SYMED_VALUE 101 14 | #endif 15 | #endif 16 | -------------------------------------------------------------------------------- /Test/SystemTest/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by SystemTest.rc 4 | // 5 | 6 | // Next default values for new objects 7 | // 8 | #ifdef APSTUDIO_INVOKED 9 | #ifndef APSTUDIO_READONLY_SYMBOLS 10 | #define _APS_NEXT_RESOURCE_VALUE 101 11 | #define _APS_NEXT_COMMAND_VALUE 40001 12 | #define _APS_NEXT_CONTROL_VALUE 1001 13 | #define _APS_NEXT_SYMED_VALUE 101 14 | #endif 15 | #endif 16 | -------------------------------------------------------------------------------- /Test/SystemTest/stdafx.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define _CRT_SECURE_NO_WARNINGS 4 | 5 | #include 6 | 7 | #include "../../Src/__Common/Type.h" 8 | #include "../../Src/__Common/Define.h" 9 | #include "../../Src/__Common/ErrorCode.h" 10 | #include "../../Src/000_String/000_String.h" 11 | #include "../../Src/001_Encoder/001_Encoder.h" 12 | #include "../../Src/100_System/100_System.h" 13 | #include "../../Src/200_Common/200_Common.h" 14 | 15 | using namespace core; 16 | -------------------------------------------------------------------------------- /Src/001_Encoder/SymModeECB.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "ISymMode.h" 4 | 5 | namespace core 6 | { 7 | class CSymModeECB : public ISymMode 8 | { 9 | public: 10 | CSymModeECB(void); 11 | ~CSymModeECB(void); 12 | 13 | ECODE Init(E_CIPHER_METHOD nMethod, ISymAlgorithm* pAlgorithm, const ST_SYM_CIPHER_KEY& stKey); 14 | ECODE Encrypt(ISymAlgorithm* pAlgorithm, LPCBYTE pSrc, LPBYTE pDest); 15 | ECODE Decrypt(ISymAlgorithm* pAlgorithm, LPCBYTE pSrc, LPBYTE pDest); 16 | }; 17 | 18 | } 19 | -------------------------------------------------------------------------------- /Src/100_System/stdafx.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define _CRT_SECURE_NO_WARNINGS 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #include "../__Common/Type.h" 14 | #include "../__Common/Define.h" 15 | #include "../__Common/ErrorCode.h" 16 | #include "../000_String/000_String.h" 17 | #include "../001_Encoder/001_Encoder.h" 18 | #include "Struct.h" 19 | 20 | #pragma comment(lib, "Psapi.lib") -------------------------------------------------------------------------------- /Src/001_Encoder/SymModePlain.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "ISymMode.h" 4 | 5 | namespace core 6 | { 7 | class CSymModePlain : public ISymMode 8 | { 9 | public: 10 | CSymModePlain(void); 11 | ~CSymModePlain(void); 12 | 13 | ECODE Init(E_CIPHER_METHOD nMethod, ISymAlgorithm* pAlgorithm, const ST_SYM_CIPHER_KEY& stKey); 14 | ECODE Encrypt(ISymAlgorithm* pAlgorithm, LPCBYTE pSrc, LPBYTE pDest); 15 | ECODE Decrypt(ISymAlgorithm* pAlgorithm, LPCBYTE pSrc, LPBYTE pDest); 16 | }; 17 | 18 | } 19 | -------------------------------------------------------------------------------- /Src/001_Encoder/SymSeed128.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "ISymAlgorithm.h" 4 | 5 | namespace core 6 | { 7 | class CSymSeed128 : public ISymAlgorithm 8 | { 9 | DWORD m_dwRoundKey[32]; 10 | 11 | public: 12 | CSymSeed128(void); 13 | ~CSymSeed128(void); 14 | 15 | ECODE Init(E_CIPHER_METHOD nMethod, const ST_SYM_CIPHER_KEY& stKey); 16 | ECODE Encrypt(LPCBYTE pSrc, LPBYTE pDest); 17 | ECODE Decrypt(LPCBYTE pSrc, LPBYTE pDest); 18 | size_t BlockSize(void) { return 16; } 19 | }; 20 | } 21 | -------------------------------------------------------------------------------- /Src/001_Encoder/SymSeed256.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "ISymAlgorithm.h" 4 | 5 | namespace core 6 | { 7 | class CSymSeed256 : public ISymAlgorithm 8 | { 9 | DWORD m_dwRoundKey[48]; 10 | 11 | public: 12 | CSymSeed256(void); 13 | ~CSymSeed256(void); 14 | 15 | ECODE Init(E_CIPHER_METHOD nMethod, const ST_SYM_CIPHER_KEY& stKey); 16 | ECODE Encrypt(LPCBYTE pSrc, LPBYTE pDest); 17 | ECODE Decrypt(LPCBYTE pSrc, LPBYTE pDest); 18 | size_t BlockSize(void) { return 16; } 19 | }; 20 | } 21 | -------------------------------------------------------------------------------- /Src/200_Common/Common.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "CriticalSection.h" 4 | #include "Mutex.h" 5 | #include "Log.h" 6 | #include "SafeQueue.h" 7 | #include "SyncQueue.h" 8 | #include "LockFreeQueue.h" 9 | #include "CircularQueue.h" 10 | #include "SharedMemory.h" 11 | #include "MemoryMappedFile.h" 12 | #include "FileUtility.h" 13 | #include "Utility.h" 14 | #include "HashFunction.h" 15 | #include "Semaphore.h" 16 | #include "TextFileReader.h" 17 | #include "TextFileWriter.h" 18 | #include "Thread.h" 19 | -------------------------------------------------------------------------------- /Test/CommonTest/stdafx.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define _CRT_SECURE_NO_WARNINGS 4 | 5 | #include 6 | #include 7 | 8 | #include "../../Src/__Common/Type.h" 9 | #include "../../Src/__Common/Define.h" 10 | #include "../../Src/__Common/ErrorCode.h" 11 | #include "../../Src/000_String/000_String.h" 12 | #include "../../Src/001_Encoder/001_Encoder.h" 13 | #include "../../Src/100_System/100_System.h" 14 | #include "../../Src/200_Common/200_Common.h" 15 | 16 | using namespace core; 17 | -------------------------------------------------------------------------------- /Test/FormatterTest/stdafx.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define _CRT_SECURE_NO_WARNINGS 4 | 5 | #include 6 | #include 7 | 8 | #include "gtest/gtest.h" 9 | #include "../../Src/000_String/000_String.h" 10 | #include "../../Src/100_System/100_System.h" 11 | #include "../../Src/200_Common/200_Common.h" 12 | #include "../../Src/300_Formatter/300_Formatter.h" 13 | 14 | #ifdef UNICODE 15 | #define std_cout std::wcout 16 | #else 17 | #define std_cout std::cout 18 | #endif 19 | 20 | using namespace core; 21 | -------------------------------------------------------------------------------- /Src/100_System/MemoryLeakFinder_Win.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "MemoryLeakFinder.h" 3 | #define _CRTDBG_MAP_ALLOC 4 | #include 5 | #include 6 | 7 | namespace core 8 | { 9 | ST_MEMORYLEAK_FINDER::ST_MEMORYLEAK_FINDER(int nSetBreakAllocCounter) 10 | { 11 | _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); 12 | if (nSetBreakAllocCounter > 0) 13 | _CrtSetBreakAlloc(nSetBreakAllocCounter); 14 | } 15 | ST_MEMORYLEAK_FINDER::~ST_MEMORYLEAK_FINDER(void) 16 | { 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Src/300_Formatter/StringWriter.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "FmtTypes.h" 6 | #include "IChannel.h" 7 | 8 | namespace fmt_internal 9 | { 10 | class CStringWriter : public core::IChannel 11 | { 12 | private: 13 | std::tstring& m_strOutput; 14 | 15 | public: 16 | CStringWriter(std::tstring& strOutput); 17 | ~CStringWriter(void); 18 | 19 | bool CheckValidity(std::tstring& refStrErrMsg); 20 | 21 | private: 22 | size_t Access(void* pData, size_t tDataSize); 23 | }; 24 | } 25 | 26 | -------------------------------------------------------------------------------- /Src/400_Server/stdafx.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define _CRT_SECURE_NO_WARNINGS 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include "../__Common/Type.h" 10 | #include "../__Common/Define.h" 11 | #include "../__Common/ErrorCode.h" 12 | 13 | #include "../000_String/000_String.h" 14 | #include "../001_Encoder/001_Encoder.h" 15 | #include "../100_System/100_System.h" 16 | #include "../200_Common/200_Common.h" 17 | #include "../300_Formatter/300_Formatter.h" 18 | 19 | #include "SocketCommon.h" -------------------------------------------------------------------------------- /Src/300_Formatter/BytesWriter.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "FmtTypes.h" 6 | #include "IChannel.h" 7 | 8 | namespace fmt_internal 9 | { 10 | class CBytesWriter : public core::IChannel 11 | { 12 | private: 13 | std::vector& m_vecOutput; 14 | 15 | public: 16 | CBytesWriter(std::vector& vecOutput); 17 | ~CBytesWriter(void); 18 | 19 | bool CheckValidity(std::tstring& refStrErrMsg); 20 | 21 | private: 22 | size_t Access(void* pData, size_t tDataSize); 23 | }; 24 | } 25 | 26 | -------------------------------------------------------------------------------- /Src/000_String/000_String.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../__Common/Type.h" 4 | #include "../__Common/Define.h" 5 | #include "../__Common/ErrorCode.h" 6 | #include "../__Common/Compatibility.h" 7 | 8 | #include "ASCII.h" 9 | #include "BOM.h" 10 | #include "EuckrEncoding.h" 11 | #include "Exception.h" 12 | #include "Unicode.h" 13 | #include "UnicodeEncoding.h" 14 | #include "POSIX.h" 15 | #include "Utility.h" 16 | #include "STLString.h" 17 | #include "StdString.h" 18 | #include "StdStringLegacy.h" 19 | #include "NumericString.h" 20 | -------------------------------------------------------------------------------- /Src/000_String/POSIX.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #define wtoi _wtoi 6 | 7 | #ifdef UNICODE 8 | 9 | #define fputts fputws 10 | #define tprintf wprintf 11 | #define vsntprintf vswprintf 12 | #define _tcstoui64 _wcstoui64 13 | #define tcstod wcstod 14 | #define gettc getwc 15 | 16 | #else 17 | 18 | #define fputts fputs 19 | #define tprintf printf 20 | #define vsntprintf vsnprintf 21 | #define _tcstoui64 _strtoui64 22 | #define tcstod strtod 23 | #define gettc getc 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /Src/100_System/LogInstance.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace core 6 | { 7 | struct ST_LOG_CONTEXT 8 | { 9 | HANDLE hFileCS ; 10 | DWORD dwProcessID ; 11 | DWORD dwInputFlag ; 12 | DWORD dwOutputFlag ; 13 | DWORD dwMaxFileSize ; 14 | DWORD dwMaxFileCount ; 15 | std::wstring strOutputPath ; 16 | std::string strModuleName ; 17 | void (*fpCustomOutput)(const char* pszPrefix, const char* pszMsg); 18 | 19 | ST_LOG_CONTEXT(void); 20 | ~ST_LOG_CONTEXT(void); 21 | }; 22 | } -------------------------------------------------------------------------------- /Src/300_Formatter/ANSIStringWritter.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "FmtTypes.h" 6 | #include "IChannel.h" 7 | 8 | namespace fmt_internal 9 | { 10 | class CANSIStringWriter : public core::IChannel 11 | { 12 | private: 13 | std::string& m_strOutput; 14 | 15 | public: 16 | CANSIStringWriter(std::string& strOutput); 17 | ~CANSIStringWriter(void); 18 | 19 | bool CheckValidity(std::tstring& refStrErrMsg); 20 | 21 | private: 22 | size_t Access(void* pData, size_t tDataSize); 23 | }; 24 | } 25 | 26 | -------------------------------------------------------------------------------- /Src/300_Formatter/UTF8StringWritter.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "FmtTypes.h" 6 | #include "IChannel.h" 7 | 8 | namespace fmt_internal 9 | { 10 | class CUTF8StringWriter : public core::IChannel 11 | { 12 | private: 13 | std::string& m_strOutput; 14 | 15 | public: 16 | CUTF8StringWriter(std::string& strOutput); 17 | ~CUTF8StringWriter(void); 18 | 19 | bool CheckValidity(std::tstring& refStrErrMsg); 20 | 21 | private: 22 | size_t Access(void* pData, size_t tDataSize); 23 | }; 24 | } 25 | 26 | -------------------------------------------------------------------------------- /Src/200_Common/Semaphore.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace core 4 | { 5 | class CSemaphore 6 | { 7 | HANDLE m_hSemaphore; 8 | 9 | public: 10 | CSemaphore(void); 11 | ~CSemaphore(void); 12 | 13 | ECODE Create(int nInitialCount, const char* pszName = NULL); 14 | ECODE Create(int nInitialCount, const wchar_t* pszName = NULL); 15 | ECODE Open(const char* pszName); 16 | ECODE Open(const wchar_t* pszName); 17 | void Close(void); 18 | 19 | ECODE Release(int nReleaseCount = 1); 20 | ECODE Wait(DWORD dwTimeOut); 21 | }; 22 | } 23 | -------------------------------------------------------------------------------- /Src/200_Common/TextFileWriter.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../000_String/BOM.h" 4 | #include "Uncopyable.h" 5 | 6 | namespace core 7 | { 8 | class CTextFileWriter : private Uncopyable 9 | { 10 | HANDLE m_hFile; 11 | E_BOM_TYPE m_nBOMType; 12 | 13 | public: 14 | CTextFileWriter(std::string strFileName, E_BOM_TYPE nBOMType); 15 | CTextFileWriter(std::wstring strFileName, E_BOM_TYPE nBOMType); 16 | ~CTextFileWriter(void); 17 | 18 | int WriteLine(std::string strContext); 19 | int WriteLine(std::wstring strContext); 20 | }; 21 | } 22 | -------------------------------------------------------------------------------- /Src/001_Encoder/SymModeCFB.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "ISymMode.h" 4 | 5 | namespace core 6 | { 7 | class CSymModeCFB : public ISymMode 8 | { 9 | DWORD m_dwXOR[8]; 10 | size_t m_tBlockSize; 11 | 12 | public: 13 | CSymModeCFB(void); 14 | ~CSymModeCFB(void); 15 | 16 | ECODE Init(E_CIPHER_METHOD nMethod, ISymAlgorithm* pAlgorithm, const ST_SYM_CIPHER_KEY& stKey); 17 | ECODE Encrypt(ISymAlgorithm* pAlgorithm, LPCBYTE pSrc, LPBYTE pDest); 18 | ECODE Decrypt(ISymAlgorithm* pAlgorithm, LPCBYTE pSrc, LPBYTE pDest); 19 | }; 20 | 21 | } 22 | -------------------------------------------------------------------------------- /Src/001_Encoder/SymModeOFB.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "ISymMode.h" 4 | 5 | namespace core 6 | { 7 | class CSymModeOFB : public ISymMode 8 | { 9 | DWORD m_dwXOR[8]; 10 | size_t m_tBlockSize; 11 | 12 | public: 13 | CSymModeOFB(void); 14 | ~CSymModeOFB(void); 15 | 16 | ECODE Init(E_CIPHER_METHOD nMethod, ISymAlgorithm* pAlgorithm, const ST_SYM_CIPHER_KEY& stKey); 17 | ECODE Encrypt(ISymAlgorithm* pAlgorithm, LPCBYTE pSrc, LPBYTE pDest); 18 | ECODE Decrypt(ISymAlgorithm* pAlgorithm, LPCBYTE pSrc, LPBYTE pDest); 19 | }; 20 | 21 | } 22 | -------------------------------------------------------------------------------- /Src/001_Encoder/SymModePCBC.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "ISymMode.h" 4 | 5 | namespace core 6 | { 7 | class CSymModePCBC : public ISymMode 8 | { 9 | DWORD m_dwXOR[8]; 10 | size_t m_tBlockSize; 11 | 12 | public: 13 | CSymModePCBC(void); 14 | ~CSymModePCBC(void); 15 | 16 | ECODE Init(E_CIPHER_METHOD nMethod, ISymAlgorithm* pAlgorithm, const ST_SYM_CIPHER_KEY& stKey); 17 | ECODE Encrypt(ISymAlgorithm* pAlgorithm, LPCBYTE pSrc, LPBYTE pDest); 18 | ECODE Decrypt(ISymAlgorithm* pAlgorithm, LPCBYTE pSrc, LPBYTE pDest); 19 | }; 20 | 21 | } 22 | -------------------------------------------------------------------------------- /Test/ServerTest/stdafx.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define _CRT_SECURE_NO_WARNINGS 4 | 5 | #include 6 | #include 7 | 8 | #include "gtest/gtest.h" 9 | #include "../../Src/000_String/000_String.h" 10 | #include "../../Src/100_System/100_System.h" 11 | #include "../../Src/200_Common/200_Common.h" 12 | #include "../../Src/300_Formatter/300_Formatter.h" 13 | #include "../../Src/400_Server/400_Server.h" 14 | 15 | #ifdef UNICODE 16 | #define std_cout std::wcout 17 | #else 18 | #define std_cout std::cout 19 | #endif 20 | 21 | using namespace core; 22 | -------------------------------------------------------------------------------- /Src/300_Formatter/BytesReader.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "FmtTypes.h" 4 | #include "IChannel.h" 5 | 6 | namespace fmt_internal 7 | { 8 | class CBytesReader : public core::IChannel 9 | { 10 | private: 11 | const BYTE* m_pBytes; 12 | size_t m_tBytesSize; 13 | size_t m_tReadPos; 14 | 15 | public: 16 | CBytesReader(const void* pBytes, size_t tBytesSize); 17 | ~CBytesReader(void); 18 | 19 | bool CheckValidity(std::tstring& refStrErrMsg); 20 | 21 | private: 22 | size_t Access(void* pData, size_t tDataSize); 23 | }; 24 | 25 | } 26 | -------------------------------------------------------------------------------- /Src/100_System/Utility.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace core 4 | { 5 | bool operator<(const core::ST_VERSIONINFO& lhs, const core::ST_VERSIONINFO& rhs); 6 | bool operator<(const core::ST_SYSTEMTIME& lhs, const core::ST_SYSTEMTIME& rhs); 7 | 8 | class CCurrentDirectorySettter 9 | { 10 | std::wstring m_strOriginalDir; 11 | bool m_bDirChanged; 12 | 13 | public: 14 | CCurrentDirectorySettter(std::string strWorkingDir); 15 | CCurrentDirectorySettter(std::wstring strWorkingDir); 16 | ~CCurrentDirectorySettter(void); 17 | 18 | bool DirChanged(void); 19 | }; 20 | } -------------------------------------------------------------------------------- /Src/200_Common/SharedMemory.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "IMemoryAccess.h" 4 | 5 | namespace core 6 | { 7 | class CSharedMemory : public IMemoryAccess 8 | { 9 | HANDLE m_hFileMap; 10 | void* m_pMemory; 11 | size_t m_tSize; 12 | 13 | public: 14 | CSharedMemory(void); 15 | ~CSharedMemory(void); 16 | 17 | ECODE Create(DWORD dwKey, size_t tSize, E_PAGE_PROTECTION nProtectMode, DWORD dwFileMapAccess); 18 | void Destroy(void); 19 | 20 | LPBYTE Ptr(void) { return (LPBYTE)m_pMemory; } 21 | size_t Size(void) { return m_tSize; } 22 | }; 23 | } -------------------------------------------------------------------------------- /Src/001_Encoder/SymModeCBC.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Type.h" 4 | #include "ISymMode.h" 5 | 6 | namespace core 7 | { 8 | class CSymModeCBC : public ISymMode 9 | { 10 | DWORD m_dwXOR[8]; 11 | size_t m_tBlockSize; 12 | 13 | public: 14 | CSymModeCBC(void); 15 | ~CSymModeCBC(void); 16 | 17 | ECODE Init(E_CIPHER_METHOD nMethod, ISymAlgorithm* pAlgorithm, const ST_SYM_CIPHER_KEY& stKey); 18 | ECODE Encrypt(ISymAlgorithm* pAlgorithm, LPCBYTE pSrc, LPBYTE pDest); 19 | ECODE Decrypt(ISymAlgorithm* pAlgorithm, LPCBYTE pSrc, LPBYTE pDest); 20 | }; 21 | 22 | } 23 | -------------------------------------------------------------------------------- /Src/001_Encoder/SymModeCTR.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "ISymMode.h" 4 | 5 | namespace core 6 | { 7 | class CSymModeCTR : public ISymMode 8 | { 9 | DWORD m_dwXOR[8]; 10 | size_t m_tBlockSize; 11 | DWORD m_dwCounter; 12 | 13 | public: 14 | CSymModeCTR(void); 15 | ~CSymModeCTR(void); 16 | 17 | ECODE Init(E_CIPHER_METHOD nMethod, ISymAlgorithm* pAlgorithm, const ST_SYM_CIPHER_KEY& stKey); 18 | ECODE Encrypt(ISymAlgorithm* pAlgorithm, LPCBYTE pSrc, LPBYTE pDest); 19 | ECODE Decrypt(ISymAlgorithm* pAlgorithm, LPCBYTE pSrc, LPBYTE pDest); 20 | }; 21 | 22 | } 23 | -------------------------------------------------------------------------------- /Src/001_Encoder/ssdeep/edit_dist.h: -------------------------------------------------------------------------------- 1 | #ifndef __EDIT_DIST_H 2 | #define __EDIT_DIST_H 3 | /** 4 | * Modified levenshtein distance calculation 5 | * 6 | * This program can be used, redistributed or modified under any of 7 | * Boost Software License 1.0, GPL v2 or GPL v3 8 | * See the file COPYING for details. 9 | * 10 | * $Id$ 11 | * 12 | * Copyright (C) 2014 kikairoya 13 | * Copyright (C) 2014 Jesse Kornblum 14 | */ 15 | 16 | int edit_distn(const char *s1, size_t s1len, const char *s2, size_t s2len); 17 | 18 | #endif // ifndef __EDIT_DIST_H 19 | -------------------------------------------------------------------------------- /Src/300_Formatter/stdafx.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define _CRT_SECURE_NO_WARNINGS 4 | 5 | #include "../__Common/Define.h" 6 | #include "../__Common/Type.h" 7 | #include "../__Common/ErrorCode.h" 8 | 9 | #include "../000_String/000_String.h" 10 | #include "../100_System/100_System.h" 11 | #include "../200_Common/200_Common.h" 12 | 13 | #include "300_Formatter.h" 14 | #include "FmtTypes.h" 15 | #include "Interface.h" 16 | #include "FormatterSuper.h" 17 | #include "HelperFunc.h" 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | using namespace core; 25 | -------------------------------------------------------------------------------- /Src/300_Formatter/StringReader.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "FmtTypes.h" 6 | #include "IChannel.h" 7 | 8 | namespace fmt_internal 9 | { 10 | class CStringReader : public core::IChannel 11 | { 12 | private: 13 | size_t m_tReadPos; 14 | std::tstring m_strContext; 15 | 16 | public: 17 | CStringReader(LPCBYTE pContext, size_t tSize); 18 | CStringReader(const TCHAR* pszContext); 19 | CStringReader(std::tstring& strContext); 20 | ~CStringReader(void); 21 | 22 | bool CheckValidity(std::tstring& refStrErrMsg); 23 | size_t Access(void* pData, size_t tDataSize); 24 | }; 25 | 26 | } 27 | -------------------------------------------------------------------------------- /Src/300_Formatter/FileWritter.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "../__Common/Type.h" 6 | #include "../__Common/Define.h" 7 | #include "FmtTypes.h" 8 | #include "IChannel.h" 9 | 10 | namespace fmt_internal 11 | { 12 | class CFileWritter : public core::IChannel 13 | { 14 | private: 15 | std::tstring m_strFilename; 16 | HANDLE m_hFile; 17 | 18 | public: 19 | CFileWritter(std::tstring strFilename); 20 | ~CFileWritter(void); 21 | 22 | bool CheckValidity(std::tstring& refStrErrMsg); 23 | 24 | private: 25 | size_t Access(void* pData, size_t tDataSize); 26 | }; 27 | } 28 | 29 | -------------------------------------------------------------------------------- /Src/300_Formatter/ANSIFileWritter.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "../__Common/Type.h" 6 | #include "../__Common/Define.h" 7 | #include "FmtTypes.h" 8 | #include "IChannel.h" 9 | 10 | namespace fmt_internal 11 | { 12 | class CANSIFileWritter : public core::IChannel 13 | { 14 | private: 15 | std::tstring m_strFilename; 16 | HANDLE m_hFile; 17 | 18 | public: 19 | CANSIFileWritter(std::tstring strFilename); 20 | ~CANSIFileWritter(void); 21 | 22 | bool CheckValidity(std::tstring& refStrErrMsg); 23 | 24 | private: 25 | size_t Access(void* pData, size_t tDataSize); 26 | }; 27 | } 28 | 29 | -------------------------------------------------------------------------------- /Src/200_Common/CriticalSection.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Uncopyable.h" 4 | 5 | namespace core 6 | { 7 | class CCriticalSection : private Uncopyable 8 | { 9 | public: 10 | //------------------------------------ 11 | class Owner 12 | { 13 | private: 14 | CCriticalSection& m_Instance; 15 | 16 | public: 17 | Owner(CCriticalSection& obj); 18 | ~Owner(void); 19 | }; 20 | //------------------------------------ 21 | 22 | private: 23 | HANDLE m_hCriticalSection; 24 | 25 | public: 26 | CCriticalSection(void); 27 | ~CCriticalSection(void); 28 | void Enter(void); 29 | void Leave(void); 30 | }; 31 | } 32 | -------------------------------------------------------------------------------- /Src/001_Encoder/PubKeyCipherFunction.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "../__Common/Type.h" 6 | #include "Type.h" 7 | #include "IPubKeyCipher.h" 8 | 9 | namespace core 10 | { 11 | ECODE GenerateCipherKey(E_PUBKEY_CIPHER_TYPE nType, size_t tKeyLen, const char* pszSEED, std::vector& vecPrivKey, std::vector& vecPubKey); 12 | 13 | HANDLE InitPubKeyCipher(E_PUBKEY_CIPHER_TYPE nType, std::vector vecKey, std::string strSeed, E_CIPHER_METHOD nMethod, ST_PUBKEY_CIPHER_INFO& outInfo); 14 | ECODE UpdatePubKeyCipher(HANDLE hCipher, const BYTE* pSrc, BYTE* pDest); 15 | void FinalPubKeyCipher(HANDLE hCipher); 16 | } -------------------------------------------------------------------------------- /Src/300_Formatter/ANSIStringReader.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "FmtTypes.h" 6 | #include "IChannel.h" 7 | 8 | namespace fmt_internal 9 | { 10 | class CANSIStringReader : public core::IChannel 11 | { 12 | private: 13 | size_t m_tReadPos; 14 | std::tstring m_strContext; 15 | 16 | public: 17 | CANSIStringReader(LPCBYTE pContext, size_t tSize); 18 | CANSIStringReader(const char* pszContext); 19 | CANSIStringReader(std::string& strContext); 20 | ~CANSIStringReader(void); 21 | 22 | bool CheckValidity(std::tstring& refStrErrMsg); 23 | size_t Access(void* pData, size_t tDataSize); 24 | }; 25 | 26 | } 27 | -------------------------------------------------------------------------------- /Src/300_Formatter/UTF8StringReader.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "FmtTypes.h" 6 | #include "IChannel.h" 7 | 8 | namespace fmt_internal 9 | { 10 | class CUTF8StringReader : public core::IChannel 11 | { 12 | private: 13 | size_t m_tReadPos; 14 | std::tstring m_strContext; 15 | 16 | public: 17 | CUTF8StringReader(LPCBYTE pContext, size_t tSize); 18 | CUTF8StringReader(const char* pszContext); 19 | CUTF8StringReader(std::string& strContext); 20 | ~CUTF8StringReader(void); 21 | 22 | bool CheckValidity(std::tstring& refStrErrMsg); 23 | size_t Access(void* pData, size_t tDataSize); 24 | }; 25 | 26 | } 27 | -------------------------------------------------------------------------------- /Src/300_Formatter/UTF8FileWritter.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "../__Common/Type.h" 6 | #include "../__Common/Define.h" 7 | #include "FmtTypes.h" 8 | #include "IChannel.h" 9 | 10 | namespace fmt_internal 11 | { 12 | class CUTF8FileWritter : public core::IChannel 13 | { 14 | private: 15 | std::tstring m_strFilename; 16 | HANDLE m_hFile; 17 | 18 | public: 19 | CUTF8FileWritter(std::tstring strFilename, bool bUseBOM = true); 20 | ~CUTF8FileWritter(void); 21 | 22 | bool CheckValidity(std::tstring& refStrErrMsg); 23 | 24 | private: 25 | size_t Access(void* pData, size_t tDataSize); 26 | }; 27 | } 28 | 29 | -------------------------------------------------------------------------------- /Src/000_String/Exception.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "Exception.h" 3 | #include "StdString.h" 4 | #include "StdStringLegacy.h" 5 | #include "Unicode.h" 6 | 7 | namespace core 8 | { 9 | ////////////////////////////////////////////////////////////////////////// 10 | exception_format::exception_format(const TCHAR* pszFormat, ...) 11 | : std::exception() 12 | { 13 | const size_t tBuffSize = 2048; 14 | TCHAR szBuff[tBuffSize] = { 0, }; 15 | va_list list; 16 | va_start(list, pszFormat); 17 | SafeSVPrintf(szBuff, tBuffSize, pszFormat, list); 18 | va_end(list); 19 | 20 | m_strWhatA = MBSFromTCS(szBuff); 21 | m_strWhatW = WCSFromTCS(szBuff); 22 | } 23 | } 24 | 25 | -------------------------------------------------------------------------------- /Src/400_Server/SyncConnection.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "SyncTCPSocket.h" 4 | 5 | namespace core 6 | { 7 | class CSyncConnection 8 | { 9 | friend class CSyncServer; 10 | 11 | protected: 12 | CSyncTCPSocket* m_pSocket; 13 | std::string m_strClientIP; 14 | 15 | public: 16 | CSyncConnection(CSyncTCPSocket* pSocket); 17 | virtual ~CSyncConnection(); 18 | 19 | virtual ECODE SetAcceptedSocket(SOCKET hNewSocket) { return m_pSocket->Assign(hNewSocket); } 20 | virtual CSyncTCPSocket* Raw(void) { return m_pSocket; } 21 | 22 | virtual void OnConnect(void) = 0; 23 | virtual void OnClose(void) = 0; 24 | virtual void OnRecv(void) = 0; 25 | }; 26 | } 27 | -------------------------------------------------------------------------------- /Src/300_Formatter/FileReader.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "../__Common/Type.h" 6 | #include "../__Common/Define.h" 7 | #include "../000_String/BOM.h" 8 | #include "FmtTypes.h" 9 | #include "IChannel.h" 10 | 11 | namespace fmt_internal 12 | { 13 | class CFileReader : public core::IChannel 14 | { 15 | private: 16 | E_BOM_TYPE m_nBomType ; 17 | std::tstring m_strFilename ; 18 | HANDLE m_hFile ; 19 | 20 | public: 21 | CFileReader(std::tstring strFilename); 22 | ~CFileReader(void); 23 | 24 | bool CheckValidity(std::tstring& refStrErrMsg); 25 | 26 | private: 27 | size_t Access(void* pData, size_t tDataSize); 28 | }; 29 | 30 | } 31 | -------------------------------------------------------------------------------- /Src/400_Server/SyncUDPSocket.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace core 4 | { 5 | class CSyncUDPSocket 6 | { 7 | SOCKET m_hSocket; 8 | 9 | public: 10 | CSyncUDPSocket(void); 11 | virtual ~CSyncUDPSocket(); 12 | 13 | virtual ECODE Listen(WORD wPort); 14 | virtual ECODE Create(void); 15 | virtual void Destroy(void); 16 | 17 | virtual ECODE Broadcast(DWORD dwIP, WORD wPort, const void* pData, size_t tDataSize); 18 | virtual ECODE SendTo(const ST_SOURCE_INFO& pSourceInfo, const void* pBuff, size_t tBufSize, DWORD dwTimeOut, size_t* ptSent = NULL); 19 | virtual ECODE RecvFrom(void* pBuff, size_t tBufSize, DWORD dwTimeOut, size_t* ptRead = NULL, ST_SOURCE_INFO* pSourceInfo = NULL); 20 | }; 21 | } 22 | -------------------------------------------------------------------------------- /Src/200_Common/Mutex.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "../__Common/Type.h" 6 | #include "../__Common/Define.h" 7 | #include "Uncopyable.h" 8 | 9 | namespace core 10 | { 11 | class CMutex : private Uncopyable 12 | { 13 | public: 14 | //------------------------------------ 15 | class Owner 16 | { 17 | private: 18 | CMutex& m_Instance; 19 | 20 | public: 21 | Owner(CMutex& obj); 22 | ~Owner(void); 23 | }; 24 | //------------------------------------ 25 | 26 | private: 27 | HANDLE m_hMutex; 28 | 29 | public: 30 | CMutex(const char* pszName); 31 | CMutex(const wchar_t* pszName); 32 | ~CMutex(void); 33 | 34 | void Enter(void); 35 | void Leave(void); 36 | }; 37 | } 38 | -------------------------------------------------------------------------------- /Sample/ProcessTest/DllWrapper.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../DummyDLL/APIEntry.h" 4 | 5 | class CDllWrapper 6 | { 7 | HANDLE m_hModule; 8 | 9 | typedef HANDLE (*FP_Create)(void); 10 | typedef ECODE (*FP_Operate)(HANDLE hContext, E_CMD nCmd, LPCSTR pszInput, LPSTR pszOutput); 11 | typedef void (*FP_Destroy)(HANDLE hContext); 12 | 13 | FP_Create m_fpCreate; 14 | FP_Operate m_fpOperate; 15 | FP_Destroy m_fpDestroy; 16 | 17 | public: 18 | CDllWrapper(); 19 | ~CDllWrapper(); 20 | 21 | bool LoadLibrary(LPCTSTR pszFilePath); 22 | void FreeLibrary(void); 23 | 24 | HANDLE Create(void); 25 | ECODE Operate(HANDLE hContext, E_CMD nCmd, LPCSTR pszInput, LPSTR pszOutput); 26 | void Destroy(HANDLE hContext); 27 | }; 28 | 29 | -------------------------------------------------------------------------------- /Src/300_Formatter/ANSIFileReader.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "../__Common/Type.h" 6 | #include "../__Common/Define.h" 7 | #include "../000_String/BOM.h" 8 | #include "FmtTypes.h" 9 | #include "IChannel.h" 10 | 11 | namespace fmt_internal 12 | { 13 | class CANSIFileReader : public core::IChannel 14 | { 15 | std::tstring m_strFilename ; 16 | HANDLE m_hFile ; 17 | std::string m_strBuffer ; 18 | std::tstring m_strContext ; 19 | 20 | public: 21 | CANSIFileReader(std::tstring strFilename); 22 | ~CANSIFileReader(void); 23 | 24 | bool CheckValidity(std::tstring& refStrErrMsg); 25 | 26 | private: 27 | size_t Access(void* pData, size_t tDataSize); 28 | }; 29 | 30 | } 31 | -------------------------------------------------------------------------------- /Inc/cryptopp700/hashfwd.h: -------------------------------------------------------------------------------- 1 | // hashfwd.h - written and placed in the public domain by Jeffrey Walton 2 | 3 | /// \file hashfwd.h 4 | /// \brief Forward declarations for hash functions used in signature encoding methods 5 | 6 | #ifndef CRYPTOPP_HASHFWD_H 7 | #define CRYPTOPP_HASHFWD_H 8 | 9 | #include "config.h" 10 | 11 | NAMESPACE_BEGIN(CryptoPP) 12 | 13 | class SHA1; 14 | class SHA224; 15 | class SHA256; 16 | class SHA384; 17 | class SHA512; 18 | 19 | class SHA3_256; 20 | class SHA3_384; 21 | class SHA3_512; 22 | 23 | class Tiger; 24 | class RIPEMD128; 25 | class RIPEMD160; 26 | class Whirlpool; 27 | 28 | namespace Weak1 { 29 | class MD2; 30 | class MD5; 31 | } 32 | 33 | NAMESPACE_END 34 | 35 | #endif // CRYPTOPP_HASHFWD_H 36 | -------------------------------------------------------------------------------- /Src/200_Common/MemoryMappedFile.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "IMemoryAccess.h" 4 | #include "../100_System/100_System.h" 5 | 6 | namespace core 7 | { 8 | class CMemoryMappedFile : public IMemoryAccess 9 | { 10 | HANDLE m_hFileMap; 11 | void* m_pMemory; 12 | size_t m_tSize; 13 | 14 | public: 15 | CMemoryMappedFile(void); 16 | ~CMemoryMappedFile(void); 17 | 18 | ECODE Create(std::string strFilePath, E_PAGE_PROTECTION nProtectMode, DWORD dwFileMapAccess); 19 | ECODE Create(std::wstring strFilePath, E_PAGE_PROTECTION nProtectMode, DWORD dwFileMapAccess); 20 | void Destroy(void); 21 | 22 | LPBYTE Ptr(void) { return (LPBYTE)m_pMemory; } 23 | size_t Size(void) { return m_tSize; } 24 | }; 25 | 26 | } 27 | -------------------------------------------------------------------------------- /Src/000_String/Exception.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | 4 | namespace core 5 | { 6 | class exception_format : public std::exception 7 | { 8 | private: 9 | std::string m_strWhatA; 10 | std::wstring m_strWhatW; 11 | 12 | public: 13 | exception_format(const char* pszFormat, ...); 14 | exception_format(const wchar_t* pszFormat, ...); 15 | ~exception_format(void) noexcept {} 16 | 17 | const char* what(void) const throw() { return m_strWhatA.c_str(); } 18 | const wchar_t* whatW(void) const throw() { return m_strWhatW.c_str(); } 19 | 20 | const TCHAR* whatT(void) const throw() 21 | { 22 | #ifdef UNICODE 23 | return m_strWhatW.c_str(); 24 | #else 25 | return m_strWhatA.c_str(); 26 | #endif 27 | } 28 | }; 29 | } 30 | 31 | -------------------------------------------------------------------------------- /Src/200_Common/TextFileReader.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "TextFileReader.h" 3 | #include "Utility.h" 4 | 5 | namespace core 6 | { 7 | ////////////////////////////////////////////////////////////////////////// 8 | CTextFileReader::~CTextFileReader(void) 9 | { 10 | if( m_pContext) 11 | m_MemMappedFile.Destroy(); 12 | m_pContext = NULL; 13 | m_tFileSize = 0; 14 | } 15 | 16 | ////////////////////////////////////////////////////////////////////////// 17 | bool CTextFileReader::IsNotValid(void) 18 | { 19 | return (NULL == m_pContext); 20 | } 21 | 22 | ////////////////////////////////////////////////////////////////////////// 23 | bool CTextFileReader::IsEof(void) 24 | { 25 | return m_tReadPos == m_tFileSize; 26 | } 27 | } -------------------------------------------------------------------------------- /Src/300_Formatter/UTF8FileReader.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "../__Common/Type.h" 6 | #include "../__Common/Define.h" 7 | #include "../000_String/BOM.h" 8 | #include "FmtTypes.h" 9 | #include "IChannel.h" 10 | 11 | namespace fmt_internal 12 | { 13 | class CUTF8FileReader : public core::IChannel 14 | { 15 | E_BOM_TYPE m_nBomType ; 16 | std::tstring m_strFilename ; 17 | HANDLE m_hFile ; 18 | std::string m_strBuffer ; 19 | std::tstring m_strContext ; 20 | 21 | public: 22 | CUTF8FileReader(std::tstring strFilename); 23 | ~CUTF8FileReader(void); 24 | 25 | bool CheckValidity(std::tstring& refStrErrMsg); 26 | 27 | private: 28 | size_t Access(void* pData, size_t tDataSize); 29 | }; 30 | 31 | } 32 | -------------------------------------------------------------------------------- /Src/001_Encoder/ISymMode.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Type.h" 4 | #include "ISymAlgorithm.h" 5 | 6 | namespace core 7 | { 8 | struct ISymModeSuper 9 | { 10 | virtual ~ISymModeSuper(void) {} 11 | virtual ECODE Init(E_CIPHER_METHOD nMethod, ISymAlgorithm* pAlgorithm, const ST_SYM_CIPHER_KEY& stKey) = 0; 12 | }; 13 | 14 | struct ISymEncryptMode : public ISymModeSuper 15 | { 16 | virtual ECODE Encrypt(ISymAlgorithm* pAlgorithm, LPCBYTE pSrc, LPBYTE pDest) = 0; 17 | }; 18 | 19 | struct ISymDecryptMode : public ISymModeSuper 20 | { 21 | virtual ECODE Decrypt(ISymAlgorithm* pAlgorithm, LPCBYTE pSrc, LPBYTE pDest) = 0; 22 | }; 23 | 24 | struct ISymMode : public ISymEncryptMode, public ISymDecryptMode 25 | { 26 | virtual ~ISymMode(void) {} 27 | }; 28 | } 29 | -------------------------------------------------------------------------------- /Src/001_Encoder/CryptoPPSingleton.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "CryptoPPSingleton.h" 3 | 4 | #include 5 | 6 | namespace core 7 | { 8 | using namespace CryptoPP; 9 | 10 | CCryptoPPSingleton::CCryptoPPSingleton() 11 | { 12 | std::string seed = IntToString(time(NULLPTR)); 13 | seed.resize(16, ' '); 14 | RandPool.IncorporateEntropy((byte *)seed.c_str(), seed.length()); 15 | 16 | // Fetch the Symmetric Cipher interface, not the RandomNumberGenerator interface, to key the underlying cipher 17 | CryptoPP::OFB_Mode::Encryption GlobalRNG; 18 | OFB_Mode::Encryption& aesg = dynamic_cast::Encryption&>(dynamic_cast(GlobalRNG)); 19 | aesg.SetKeyWithIV((byte *)seed.data(), 16, (byte *)seed.data()); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Src/200_Common/200_Common.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "CriticalSection.h" 4 | #include "CmdLineHelper.h" 5 | #include "DuplicatedProcChecker.h" 6 | #include "Mutex.h" 7 | #include "PEParser.h" 8 | #include "SafeQueue.h" 9 | #include "SafeStack.h" 10 | #include "SyncQueue.h" 11 | #include "LockFreeQueue.h" 12 | #include "CircularQueue.h" 13 | #include "SharedMemory.h" 14 | #include "MemoryMappedFile.h" 15 | #include "FileUtility.h" 16 | #include "Utility.h" 17 | #include "FileHashFunction.h" 18 | #include "INIParser.h" 19 | #include "INIParserFunc.h" 20 | #include "Semaphore.h" 21 | #include "TextFileReader.h" 22 | #include "TextFileWriter.h" 23 | #include "Thread.h" 24 | #include "ThreadPool.h" 25 | #include "zip.h" 26 | #include "unzip.h" 27 | #include "RingBuffer.h" 28 | #include "WavFile.h" -------------------------------------------------------------------------------- /Src/000_String/EuckrEncoding.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef _MSC_VER 4 | #define MBSFromEUCKR EUCKRFromEUCKR 5 | #else 6 | #define MBSFromEUCKR UTF8FromEUCKR 7 | #endif 8 | 9 | #ifdef UNICODE 10 | #define TCSFromEUCKR WCSFromEUCKR 11 | #else 12 | #define TCSFromEUCKR MBSFromEUCKR 13 | #endif 14 | 15 | namespace core 16 | { 17 | void SetUnreadableMaskChar(char cMask = '?'); 18 | 19 | std::wstring WCSFromEUCKR(std::string strEUCKR); 20 | std::string EUCKRFromEUCKR(std::string strEUCKR); 21 | std::string UTF8FromEUCKR(std::string strEUCKR); 22 | 23 | bool IsInvalidEUCKR(const char* pSrc, size_t tSrcSize); 24 | bool IsInvalidEUCKR(const std::string& strContext); 25 | void MaskUnreadableEUCKR(char* pSrc, size_t tSrcSize); 26 | std::string& MaskUnreadableEUCKR(std::string& strContext); 27 | } 28 | -------------------------------------------------------------------------------- /Src/100_System/FileSystem_Linux_Mac.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "Information.h" 3 | #ifdef __APPLE__ 4 | #include "System_Mac.h" 5 | #else 6 | #include "System_Linux.h" 7 | #endif 8 | #include "FileSystem.h" 9 | #include "Log.h" 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | namespace core 23 | { 24 | ////////////////////////////////////////////////////////////////////////// 25 | void FindClose(HANDLE hFindFile) 26 | { 27 | _ST_FINDFIRSTFILE* pHandle = (_ST_FINDFIRSTFILE*)hFindFile; 28 | ::closedir(pHandle->pDir); 29 | delete pHandle; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Src/200_Common/TextFileReader.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include "../000_String/BOM.h" 5 | #include "Uncopyable.h" 6 | #include "MemoryMappedFile.h" 7 | 8 | namespace core 9 | { 10 | class CTextFileReader : private Uncopyable 11 | { 12 | CMemoryMappedFile m_MemMappedFile; 13 | LPCBYTE m_pContext; 14 | 15 | E_BOM_TYPE m_nBOMType; 16 | size_t m_tFileSize; 17 | size_t m_tReadPos; 18 | 19 | public: 20 | CTextFileReader(std::string strFileName, E_BOM_TYPE nEncodeType = BOM_UNDEFINED); 21 | CTextFileReader(std::wstring strFileName, E_BOM_TYPE nEncodeType = BOM_UNDEFINED); 22 | ~CTextFileReader(void); 23 | 24 | bool IsNotValid(void); 25 | bool IsEof(void); 26 | ECODE ReadLine(std::string& strContext); 27 | ECODE ReadLine(std::wstring& strContext); 28 | }; 29 | } 30 | -------------------------------------------------------------------------------- /Src/100_System/TZFileParser.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../__Common/Type.h" 4 | 5 | namespace core 6 | { 7 | #define TZ_MAX_CHARS 50 8 | 9 | ////////////////////////////////////////////////////////////////////////// 10 | struct ST_TZ_TYPE 11 | { 12 | int nGMTOffset ; 13 | BYTE IsDST ; 14 | BYTE btAbbrind ; 15 | BYTE IsGMT ; 16 | BYTE IsSTD ; 17 | }; 18 | 19 | ////////////////////////////////////////////////////////////////////////// 20 | typedef std::map CTZTypeMap; 21 | typedef CTZTypeMap::iterator CTZTypeMapIt; 22 | struct ST_TZ_INFO 23 | { 24 | char szAbbreviation[TZ_MAX_CHARS]; 25 | std::vector vecType; 26 | CTZTypeMap mapTransitTime; 27 | }; 28 | 29 | ECODE ParseTZFile(LPCSTR pszFileName, ST_TZ_INFO& outInfo); 30 | void PrintOut(ST_TZ_INFO& info); 31 | } 32 | -------------------------------------------------------------------------------- /Src/400_Server/Packetizer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../300_Formatter/300_Formatter.h" 4 | #include "SyncTCPSocket.h" 5 | 6 | namespace core 7 | { 8 | struct ST_PACKET_HEADER 9 | { 10 | DWORD dwID; 11 | DWORD dwLen; 12 | }; 13 | 14 | // BIN type 15 | ECODE Packetize(DWORD dwPacketID, IFormatterObjectA* pPacket, std::vector& outPacket); 16 | ECODE Packetize(DWORD dwPacketID, IFormatterObjectW* pPacket, std::vector& outPacket); 17 | ECODE UnpacketizeA(const std::vector& inPacket, ST_PACKET_HEADER* pHeader); 18 | ECODE UnpacketizeW(const std::vector& inPacket, ST_PACKET_HEADER* pHeader); 19 | ECODE Unpacketize(const std::vector& inPacket, DWORD dwPacketID, IFormatterObjectA* pOutPacket); 20 | ECODE Unpacketize(const std::vector& inPacket, DWORD dwPacketID, IFormatterObjectW* pOutPacket); 21 | } 22 | -------------------------------------------------------------------------------- /Src/300_Formatter/InterfaceLegacy.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef UNICODE 4 | #define sPair sPairW 5 | #else 6 | #define sPair sPairA 7 | #endif 8 | 9 | namespace core 10 | { 11 | template 12 | struct ST_PAIR_W 13 | { 14 | std::wstring strKey; 15 | T& Value; 16 | 17 | ST_PAIR_W(std::wstring k, T& v) 18 | : strKey(k), Value(v) 19 | { 20 | } 21 | }; 22 | 23 | template 24 | struct ST_PAIR_A 25 | { 26 | std::string strKey; 27 | T& Value; 28 | 29 | ST_PAIR_A(std::string k, T& v) 30 | : strKey(k), Value(v) 31 | { 32 | } 33 | }; 34 | 35 | template 36 | ST_PAIR_W* sPairW(std::wstring k, T& v) 37 | { 38 | return new ST_PAIR_W(k, v); 39 | } 40 | 41 | template 42 | ST_PAIR_A* sPairA(std::string k, T& v) 43 | { 44 | return new ST_PAIR_A(k, v); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Build/Test/MemoryMappedFileTest/document1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /Src/001_Encoder/has160.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * file has160.h 3 | * brief HAS160 Digest Algorithm(TTAS.KO-12.0011/R1(HAS160)) 4 | * author 5 | * Copyright (c) 2011 by 6 | */ 7 | #ifndef HAS160_HEADER 8 | #define HAS160_HEADER 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | #define HAS160_BLOCK_SIZE 64 15 | #define HAS160_DIGEST_LENGTH 20 16 | 17 | typedef struct has160_state_st{ 18 | unsigned int state[5]; 19 | unsigned int length[2]; 20 | unsigned char data[64]; 21 | } KISA_HAS160; 22 | 23 | int KISA_HAS160_init(KISA_HAS160 *has160); 24 | int KISA_HAS160_update(KISA_HAS160 *has160, const unsigned char *data, unsigned int length); 25 | int KISA_HAS160_final(KISA_HAS160 *has160, unsigned char* md); 26 | int KISA_HAS160_MD(unsigned char *in, int len, unsigned char *out); 27 | #ifdef __cplusplus 28 | } 29 | #endif 30 | 31 | #endif 32 | 33 | -------------------------------------------------------------------------------- /Src/300_Formatter/FmtTypes.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../__Common/Type.h" 4 | 5 | #include 6 | #include 7 | 8 | #ifdef UNICODE 9 | #define fmt_internal fmt_internalW 10 | #else 11 | #define fmt_internal fmt_internalA 12 | #endif 13 | 14 | namespace fmt_internal 15 | { 16 | ////////////////////////////////////////////////////////////////////////// 17 | enum E_GROUPING_TYPE 18 | { 19 | GT_ROOT, 20 | GT_DICTIONARY, 21 | GT_ARRAY, 22 | GT_OBJECT 23 | }; 24 | 25 | ////////////////////////////////////////////////////////////////////////// 26 | enum E_TOKEN_TYPE 27 | { 28 | TT_UNKNOWN, 29 | TT_BRACE_OPEN, 30 | TT_BRACE_CLOSE, 31 | TT_SQURE_BRACKET_OPEN, 32 | TT_SQURE_BRACKET_CLOSE, 33 | TT_COMMA, 34 | TT_COLON, 35 | TT_KEY, 36 | TT_VALUE 37 | }; 38 | 39 | typedef std::vector CTStringVec; 40 | } 41 | -------------------------------------------------------------------------------- /Inc/cryptopp700/pch.h: -------------------------------------------------------------------------------- 1 | // pch.h - originally written and placed in the public domain by Wei Dai 2 | 3 | /// \file pch.h 4 | /// \brief Precompiled header file 5 | /// \details The precompiled header files are used Windows. 6 | 7 | #ifndef CRYPTOPP_PCH_H 8 | #define CRYPTOPP_PCH_H 9 | 10 | # ifdef CRYPTOPP_GENERATE_X64_MASM 11 | #include "cpu.h" 12 | 13 | # else 14 | #include "config.h" 15 | 16 | #ifdef USE_PRECOMPILED_HEADERS 17 | #include "simple.h" 18 | #include "secblock.h" 19 | #include "misc.h" 20 | #include "smartptr.h" 21 | #include "stdcpp.h" 22 | #endif 23 | # endif 24 | 25 | // Enable file and line numbers, if available. 26 | // #if defined(_MSC_VER) && defined(_DEBUG) && defined(USE_PRECOMPILED_HEADERS) 27 | // # define DEBUG_NEW new(_NORMAL_BLOCK, __FILE__, __LINE__) 28 | // # define new DEBUG_NEW 29 | // #endif 30 | 31 | #endif // CRYPTOPP_PCH_H 32 | -------------------------------------------------------------------------------- /Src/300_Formatter/XMLFunctions.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../__Common/Type.h" 4 | 5 | namespace fmt_internal 6 | { 7 | ////////////////////////////////////////////////////////////////////////// 8 | struct ST_XML_ATTR 9 | { 10 | std::tstring strKey; 11 | std::tstring strValue; 12 | }; 13 | 14 | ////////////////////////////////////////////////////////////////////////// 15 | struct ST_XML_NODE 16 | { 17 | std::tstring strKey; 18 | std::tstring strValue; 19 | std::vector vecAttr; 20 | std::vector vecChild; 21 | }; 22 | 23 | ////////////////////////////////////////////////////////////////////////// 24 | bool ParseXmlContext(const std::tstring& strContext, ST_XML_NODE& stOutRoot, std::tstring& strOutErrMsg); 25 | std::tstring EncodeXmlString(std::tstring strContext); 26 | std::tstring DecodeXmlString(std::tstring strContext); 27 | } 28 | 29 | -------------------------------------------------------------------------------- /Src/200_Common/MemoryMappedFile.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "MemoryMappedFile.h" 3 | 4 | namespace core 5 | { 6 | ////////////////////////////////////////////////////////////////////////// 7 | CMemoryMappedFile::CMemoryMappedFile(void) 8 | : IMemoryAccess() 9 | , m_hFileMap(NULL) 10 | , m_pMemory(NULL) 11 | , m_tSize(0) 12 | { 13 | } 14 | 15 | ////////////////////////////////////////////////////////////////////////// 16 | CMemoryMappedFile::~CMemoryMappedFile(void) 17 | { 18 | Destroy(); 19 | } 20 | 21 | ////////////////////////////////////////////////////////////////////////// 22 | void CMemoryMappedFile::Destroy(void) 23 | { 24 | if( m_pMemory ) 25 | { 26 | UnmapViewOfFile(m_hFileMap, m_pMemory); 27 | m_pMemory = NULL; 28 | } 29 | 30 | if( m_hFileMap ) 31 | { 32 | CloseFileMappingHandle(m_hFileMap); 33 | m_hFileMap = NULL; 34 | } 35 | } 36 | } -------------------------------------------------------------------------------- /Src/400_Server/ProtocolSuper.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "ProtocolSuper.h" 3 | 4 | namespace core 5 | { 6 | CProtocolSuper::CProtocolSuper(core::CSyncTCPSocket* pSocket) 7 | : m_pSocket(pSocket) 8 | { 9 | } 10 | 11 | CProtocolSuper::~CProtocolSuper(void) 12 | { 13 | } 14 | 15 | ECODE CProtocolSuper::Connect(std::string strIP, WORD wPort, DWORD dwTimeOut) 16 | { 17 | return m_pSocket->Connect(strIP.c_str(), wPort, dwTimeOut); 18 | } 19 | 20 | void CProtocolSuper::Close(void) 21 | { 22 | m_pSocket->Close(); 23 | } 24 | 25 | ECODE CProtocolSuper::PeekHeader(ST_PACKET_HEADER& header, DWORD dwTimeOut) 26 | { 27 | size_t tReadSize = 0; 28 | ECODE nRet = m_pSocket->Peek(&header, sizeof(header), dwTimeOut, &tReadSize); 29 | if (EC_SUCCESS != nRet) 30 | return nRet; 31 | 32 | if (tReadSize < sizeof(header)) 33 | return EC_NOT_READY; 34 | 35 | return EC_SUCCESS; 36 | } 37 | } -------------------------------------------------------------------------------- /Src/001_Encoder/SymCipherFunction.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "../__Common/Type.h" 6 | #include "Type.h" 7 | 8 | namespace core 9 | { 10 | ECODE GenerateCipherKey(E_SYM_CIPHER_TYPE nType, E_SYM_CIPHER_MODE nMode, std::string strKey, OUT ST_SYM_CIPHER_KEY &stCipher); 11 | ECODE GenerateCipherKey(E_SYM_CIPHER_TYPE nType, E_SYM_CIPHER_MODE nMode, const BYTE pKey[], const BYTE pIV[], OUT ST_SYM_CIPHER_KEY &stCipher); 12 | HANDLE InitSymCipher(const ST_SYM_CIPHER_KEY& stCipherKey, E_CIPHER_METHOD nMethod); 13 | ECODE UpdateSymCipher(HANDLE hCipher, const BYTE* pSrc, size_t tBlockCount, BYTE* pDest); 14 | ECODE FinalSymCipher(HANDLE hCipher); 15 | 16 | size_t EncodeData(const ST_SYM_CIPHER_KEY& stCipherKey, LPCBYTE pSrc, size_t tSrcSize, LPBYTE pDest = NULL); 17 | size_t DecodeData(const ST_SYM_CIPHER_KEY& stCipherKey, LPCBYTE pSrc, size_t tSrcSize, LPBYTE pDest = NULL); 18 | } 19 | -------------------------------------------------------------------------------- /Src/200_Common/SemaphoreT.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "Semaphore.h" 3 | 4 | namespace core 5 | { 6 | ////////////////////////////////////////////////////////////////////////// 7 | ECODE CSemaphore::Create(int nInitialCount, LPCTSTR pszName) 8 | { 9 | if( m_hSemaphore ) 10 | return EC_ALREADY_CREATED; 11 | 12 | HANDLE hSemaphore = CreateSemaphore(nInitialCount, pszName); 13 | if( NULL == hSemaphore ) 14 | return GetLastError(); 15 | 16 | m_hSemaphore = hSemaphore; 17 | return EC_SUCCESS; 18 | } 19 | 20 | ////////////////////////////////////////////////////////////////////////// 21 | ECODE CSemaphore::Open(LPCTSTR pszName) 22 | { 23 | if( m_hSemaphore ) 24 | return EC_ALREADY_CREATED; 25 | 26 | HANDLE hSemaphore = OpenSemaphore(pszName); 27 | if( NULL == hSemaphore ) 28 | return GetLastError(); 29 | 30 | m_hSemaphore = hSemaphore; 31 | return EC_SUCCESS; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Src/200_Common/DuplicatedProcChecker.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "DuplicatedProcChecker.h" 3 | 4 | namespace core 5 | { 6 | class DupCheckWorker 7 | { 8 | HANDLE m_hMutex; 9 | bool m_bDuplicated; 10 | 11 | public: 12 | DupCheckWorker(std::string strName) 13 | : m_hMutex(NULL) 14 | , m_bDuplicated(false) 15 | { 16 | m_hMutex = CreateMutexA(false, strName.c_str()); 17 | m_bDuplicated = (EC_ALREADY_EXISTS == GetLastError()); 18 | } 19 | 20 | ~DupCheckWorker(void) 21 | { 22 | CloseMutex(m_hMutex); 23 | } 24 | 25 | bool IsDuplicated(void) { return m_bDuplicated; } 26 | }; 27 | 28 | ST_DUPLICATED_PROC_CHECKER::ST_DUPLICATED_PROC_CHECKER(LPCSTR pszName) 29 | { 30 | std::string strModuleFileName = ExtractFileName(GetFileNameA()); 31 | 32 | static DupCheckWorker g_DupCheckWorker(pszName == NULL? strModuleFileName : pszName); 33 | bDuplicated = g_DupCheckWorker.IsDuplicated(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Test/CommonTest/RingBufferTest.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | 3 | TEST(RingBufferTest, CircularUsage) 4 | { 5 | CRingBuffer buffer; 6 | EXPECT_EQ(EC_SUCCESS, buffer.Create(1024)); 7 | 8 | LPBYTE pBuffer1 = buffer.Alloc(512); 9 | LPBYTE pBuffer2 = buffer.Alloc(512); 10 | EXPECT_EQ(pBuffer1, buffer.Alloc(512)); 11 | buffer.Destroy(); 12 | } 13 | 14 | TEST(RingBufferTest, ReservedAlloc) 15 | { 16 | CRingBuffer buffer; 17 | EXPECT_EQ(EC_SUCCESS, buffer.Create(1024)); 18 | 19 | LPBYTE pBuffer1 = buffer.Alloc(512); 20 | EXPECT_NE(pBuffer1, buffer.Alloc(256, 256)); 21 | EXPECT_NE(pBuffer1, buffer.Alloc(256)); 22 | EXPECT_EQ(pBuffer1, buffer.Alloc(256)); 23 | buffer.Destroy(); 24 | } 25 | 26 | TEST(RingBufferTest, ReservedAllocReuse) 27 | { 28 | CRingBuffer buffer; 29 | EXPECT_EQ(EC_SUCCESS, buffer.Create(1024)); 30 | 31 | LPBYTE pBuffer1 = buffer.Alloc(512); 32 | EXPECT_EQ(pBuffer1, buffer.Alloc(512, 512)); 33 | buffer.Destroy(); 34 | } -------------------------------------------------------------------------------- /Src/200_Common/RingBuffer.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "RingBuffer.h" 3 | 4 | namespace core 5 | { 6 | CRingBuffer::CRingBuffer(void) 7 | : m_csPos() 8 | , m_tPos(0) 9 | , m_vecBuffer() 10 | { 11 | } 12 | 13 | CRingBuffer::~CRingBuffer(void) 14 | { 15 | } 16 | 17 | ECODE CRingBuffer::Create(size_t tSize) 18 | { 19 | m_vecBuffer.resize(tSize); 20 | if (m_vecBuffer.size() != tSize) 21 | return EC_NOT_ENOUGH_MEMORY; 22 | 23 | m_tPos = 0; 24 | return EC_SUCCESS; 25 | } 26 | 27 | void CRingBuffer::Destroy(void) 28 | { 29 | m_vecBuffer.clear(); 30 | } 31 | 32 | LPBYTE CRingBuffer::Alloc(size_t tSize, size_t tReservedSize) 33 | { 34 | CCriticalSection::Owner lock(m_csPos); 35 | 36 | size_t tPrePos = m_tPos; 37 | 38 | m_tPos += tSize; 39 | if ((m_tPos + tReservedSize) <= m_vecBuffer.size()) 40 | return &m_vecBuffer[tPrePos]; 41 | 42 | m_tPos = tSize; 43 | return &m_vecBuffer[0]; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Src/100_System/LogInstance.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "LogInstance.h" 3 | #include "Log.h" 4 | #include "KernelObject.h" 5 | #include "Environment.h" 6 | #include "FileSystem.h" 7 | 8 | namespace core 9 | { 10 | ////////////////////////////////////////////////////////////////////////// 11 | ST_LOG_CONTEXT g_stLogContext; 12 | 13 | ////////////////////////////////////////////////////////////////////////// 14 | ST_LOG_CONTEXT::ST_LOG_CONTEXT(void) 15 | : hFileCS(NULL), dwProcessID(0), dwInputFlag(LOG_DEFAULT), dwOutputFlag(LOG_OUTPUT_CONSOLE|LOG_OUTPUT_DBGWND), dwMaxFileSize(10 * 1000 * 1000), dwMaxFileCount(3), fpCustomOutput(NULL) 16 | { 17 | hFileCS = InitializeCriticalSection(); 18 | dwProcessID = GetCurrentProcessId(); 19 | strModuleName = ExtractFileName(GetFileNameA()); 20 | } 21 | 22 | ////////////////////////////////////////////////////////////////////////// 23 | ST_LOG_CONTEXT::~ST_LOG_CONTEXT(void) 24 | { 25 | } 26 | } -------------------------------------------------------------------------------- /Inc/cryptopp700/adler32.h: -------------------------------------------------------------------------------- 1 | // adler32.h - originally written and placed in the public domain by Wei Dai 2 | 3 | /// \file adler32.h 4 | /// \brief Class file for ADLER-32 checksum calculations 5 | 6 | #ifndef CRYPTOPP_ADLER32_H 7 | #define CRYPTOPP_ADLER32_H 8 | 9 | #include "cryptlib.h" 10 | 11 | NAMESPACE_BEGIN(CryptoPP) 12 | 13 | /// ADLER-32 checksum calculations 14 | class Adler32 : public HashTransformation 15 | { 16 | public: 17 | CRYPTOPP_CONSTANT(DIGESTSIZE = 4) 18 | Adler32() {Reset();} 19 | void Update(const byte *input, size_t length); 20 | void TruncatedFinal(byte *hash, size_t size); 21 | unsigned int DigestSize() const {return DIGESTSIZE;} 22 | CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return "Adler32";} 23 | std::string AlgorithmName() const {return StaticAlgorithmName();} 24 | 25 | private: 26 | void Reset() {m_s1 = 1; m_s2 = 0;} 27 | 28 | word16 m_s1, m_s2; 29 | }; 30 | 31 | NAMESPACE_END 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /Src/100_System/ExeParserSuper.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "ExeParserSuper.h" 3 | #include "KernelObject.h" 4 | 5 | namespace core 6 | { 7 | ECODE CExeParserSuper::Open(std::tstring strFilePath) 8 | { 9 | return Open(strFilePath.c_str()); 10 | } 11 | 12 | ECODE CExeParserSuper::Open(LPCTSTR pszFilePath) 13 | { 14 | ECODE nRet = EC_SUCCESS; 15 | HANDLE hFile = NULL; 16 | try 17 | { 18 | hFile = CreateFile(pszFilePath, GENERIC_READ_, OPEN_EXISTING_, 0); 19 | if (NULL == hFile) 20 | throw exception_format(TEXT("%s CreateFile failure"), pszFilePath); 21 | 22 | nRet = OpenWorker(hFile); 23 | if (EC_SUCCESS != nRet) 24 | throw exception_format(TEXT("%s Open failure"), pszFilePath); 25 | 26 | CloseFile(hFile); 27 | hFile = NULL; 28 | } 29 | catch (std::exception& e) 30 | { 31 | if (hFile) 32 | CloseFile(hFile); 33 | Close(); 34 | return nRet; 35 | } 36 | 37 | return EC_SUCCESS; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Src/100_System/ExeParserSuper.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Struct.h" 4 | 5 | namespace core 6 | { 7 | class CExeParserSuper 8 | { 9 | public: 10 | CExeParserSuper(void) {} 11 | virtual ~CExeParserSuper(void) {} 12 | 13 | ECODE Open(std::string strFilePath); 14 | ECODE Open(std::wstring strFilePath); 15 | ECODE Open(LPCSTR pszFilePath); 16 | ECODE Open(LPCWSTR pszFilePath); 17 | 18 | virtual ECODE OpenWorker(HANDLE hFile) = 0; 19 | virtual void Close(void) = 0; 20 | 21 | virtual ECODE GetFileVersion(ST_VERSIONINFO& outVersionInfo) = 0; 22 | virtual ECODE GetProductVersion(ST_VERSIONINFO& outVersionInfo) = 0; 23 | 24 | // For lower version compatibility 25 | virtual ECODE QueryFileVersion(ST_VERSIONINFO& outVersionInfo) 26 | { 27 | return GetFileVersion(outVersionInfo); 28 | } 29 | 30 | virtual ECODE QueryProductVersion(ST_VERSIONINFO& outVersionInfo) 31 | { 32 | return GetProductVersion(outVersionInfo); 33 | } 34 | }; 35 | } 36 | -------------------------------------------------------------------------------- /Src/400_Server/BinProtocol.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "ProtocolSuper.h" 4 | 5 | namespace core 6 | { 7 | class CBinProtocol : public CProtocolSuper 8 | { 9 | public: 10 | CBinProtocol(core::CSyncTCPSocket* pSocket) 11 | : CProtocolSuper(pSocket) 12 | {} 13 | 14 | template 15 | ECODE SendPacket(T* pPacket, DWORD dwTimeOut = 60000) 16 | { 17 | return SendPacket(T::ID, pPacket, dwTimeOut); 18 | } 19 | 20 | template 21 | ECODE RecvPacket(T* pPacket, DWORD dwTimeOut = 60000) 22 | { 23 | return RecvPacket(T::ID, pPacket, dwTimeOut); 24 | } 25 | 26 | ECODE SendPacket(DWORD dwID, core::IFormatterObjectA* pPacket, DWORD dwTimeOut = 60000); 27 | ECODE SendPacket(DWORD dwID, core::IFormatterObjectW* pPacket, DWORD dwTimeOut = 60000); 28 | ECODE RecvPacket(DWORD dwID, core::IFormatterObjectA* pPacket, DWORD dwTimeOut = 60000); 29 | ECODE RecvPacket(DWORD dwID, core::IFormatterObjectW* pPacket, DWORD dwTimeOut = 60000); 30 | }; 31 | } 32 | 33 | -------------------------------------------------------------------------------- /Inc/cryptopp700/trdlocal.h: -------------------------------------------------------------------------------- 1 | #ifndef CRYPTOPP_TRDLOCAL_H 2 | #define CRYPTOPP_TRDLOCAL_H 3 | 4 | #include "config.h" 5 | 6 | #if !defined(NO_OS_DEPENDENCE) && defined(THREADS_AVAILABLE) 7 | 8 | #include "misc.h" 9 | 10 | #ifdef HAS_WINTHREADS 11 | typedef unsigned long ThreadLocalIndexType; 12 | #else 13 | #include 14 | typedef pthread_key_t ThreadLocalIndexType; 15 | #endif 16 | 17 | NAMESPACE_BEGIN(CryptoPP) 18 | 19 | /// thread local storage 20 | class CRYPTOPP_DLL ThreadLocalStorage : public NotCopyable 21 | { 22 | public: 23 | /// exception thrown by ThreadLocalStorage class 24 | class Err : public OS_Error 25 | { 26 | public: 27 | Err(const std::string& operation, int error); 28 | }; 29 | 30 | ThreadLocalStorage(); 31 | ~ThreadLocalStorage() CRYPTOPP_THROW; 32 | 33 | void SetValue(void *value); 34 | void *GetValue() const; 35 | 36 | private: 37 | ThreadLocalIndexType m_index; 38 | }; 39 | 40 | NAMESPACE_END 41 | 42 | #endif // THREADS_AVAILABLE 43 | 44 | #endif // CRYPTOPP_TRDLOCAL_H 45 | -------------------------------------------------------------------------------- /Src/001_Encoder/CryptoPPSingleton.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../../Inc/cryptopp700/randpool.h" 4 | #include "../../Inc/cryptopp700/rsa.h" 5 | #include "../../Inc/cryptopp700/hex.h" 6 | #include "../../Inc/cryptopp700/files.h" 7 | #include "../../Inc/cryptopp700/filters.h" 8 | #include "../../Inc/cryptopp700/aes.h" 9 | #include "../../Inc/cryptopp700/modes.h" 10 | #include "../../Inc/cryptopp700/default.h" 11 | #include "../../Inc/cryptopp700/cryptlib.h" 12 | #include "../../Inc/cryptopp700/elgamal.h" 13 | #include "../../Inc/cryptopp700/osrng.h" 14 | 15 | namespace core 16 | { 17 | class CCryptoPPSingleton 18 | { 19 | CCryptoPPSingleton(void); 20 | ~CCryptoPPSingleton(void) {} 21 | 22 | public: 23 | CryptoPP::RandomPool RandPool; 24 | 25 | static CCryptoPPSingleton* GetInstance(void) 26 | { 27 | static CCryptoPPSingleton instance; 28 | return &instance; 29 | } 30 | }; 31 | 32 | inline CCryptoPPSingleton* CryptoPP(void) 33 | { 34 | return CCryptoPPSingleton::GetInstance(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Src/001_Encoder/StringSymCipherFunction.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../__Common/Type.h" 4 | #include "Type.h" 5 | 6 | #ifdef UNICODE 7 | #define EncodeString EncodeStringW 8 | #define DefaultEncodeString DefaultEncodeStringW 9 | #else 10 | #define EncodeString EncodeStringA 11 | #define DefaultEncodeString DefaultEncodeStringA 12 | #endif 13 | 14 | namespace core 15 | { 16 | std::string EncodeStringA(const ST_SYM_CIPHER_KEY& stCipherKey, std::string strUTF8); 17 | std::wstring EncodeStringW(const ST_SYM_CIPHER_KEY& stCipherKey, std::string strUTF8); 18 | std::string DecodeString(const ST_SYM_CIPHER_KEY& stCipherKey, std::string strEncrypted); 19 | std::string DecodeString(const ST_SYM_CIPHER_KEY& stCipherKey, std::wstring strEncrypted); 20 | 21 | std::string DefaultEncodeStringA(std::string strUTF8); 22 | std::wstring DefaultEncodeStringW(std::string strUTF8); 23 | std::string DefaultDecodeString(std::string strEncrypted); 24 | std::string DefaultDecodeString(std::wstring strEncrypted); 25 | 26 | } -------------------------------------------------------------------------------- /Src/200_Common/INIParserFunc.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../__Common/Type.h" 4 | 5 | #ifdef UNICODE 6 | #define FlushINI FlushINIA 7 | #define DestroyINIHandle DestroyINIHandleA 8 | #else 9 | #define FlushINI FlushINIW 10 | #define DestroyINIHandle DestroyINIHandleW 11 | #endif 12 | namespace core 13 | { 14 | HANDLE CreateINIHandle(std::string strPath); 15 | HANDLE CreateINIHandle(std::wstring strPath); 16 | 17 | std::string GetINIValue(HANDLE hINI, std::string strSection, std::string strKey, std::string strDefault); 18 | std::wstring GetINIValue(HANDLE hINI, std::wstring strSection, std::wstring strKey, std::wstring strDefault); 19 | ECODE SetINIValue(HANDLE hINI, std::string strSection, std::string strKey, std::string strValue); 20 | ECODE SetINIValue(HANDLE hINI, std::wstring strSection, std::wstring strKey, std::wstring strValue); 21 | 22 | ECODE FlushINIA(HANDLE hINI); 23 | ECODE FlushINIW(HANDLE hINI); 24 | ECODE DestroyINIHandleA(HANDLE hINI); 25 | ECODE DestroyINIHandleW(HANDLE hINI); 26 | } 27 | -------------------------------------------------------------------------------- /Src/300_Formatter/StringWriter.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "StringWriter.h" 3 | 4 | namespace fmt_internal 5 | { 6 | ////////////////////////////////////////////////////////////////////////// 7 | CStringWriter::CStringWriter(std::tstring& strOutput) 8 | : IChannel() 9 | , m_strOutput(strOutput) 10 | { 11 | } 12 | 13 | ////////////////////////////////////////////////////////////////////////// 14 | CStringWriter::~CStringWriter(void) 15 | { 16 | } 17 | 18 | ////////////////////////////////////////////////////////////////////////// 19 | bool CStringWriter::CheckValidity(std::tstring& refStrErrMsg) 20 | { 21 | return true; 22 | } 23 | 24 | ////////////////////////////////////////////////////////////////////////// 25 | size_t CStringWriter::Access(void* pData, size_t tDataSize) 26 | { 27 | std::tstring strTemp; 28 | strTemp.resize(tDataSize / sizeof(TCHAR)); 29 | memcpy(&strTemp[0], pData, tDataSize); 30 | 31 | m_strOutput = m_strOutput + strTemp; 32 | return tDataSize; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Src/000_String/BOM.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../__Common/ErrorCode.h" 4 | 5 | #ifdef UNICODE 6 | #define GetCurrentBOM GetCurrentBOMW 7 | #else 8 | #define GetCurrentBOM GetCurrentBOMA 9 | #endif 10 | 11 | #define BOM_EUCKR BOM_UNDEFINED 12 | 13 | namespace core 14 | { 15 | enum E_BOM_TYPE 16 | { 17 | BOM_UTF32_BE = 0, 18 | BOM_UTF32 , 19 | BOM_UTF16_BE , 20 | BOM_UTF16 , 21 | BOM_UTF8 , 22 | BOM_UTF_EBCDIC , 23 | BOM_GB_18030 , 24 | BOM_UTF1 , 25 | BOM_SCSU , 26 | BOM_BOCU_1 , 27 | 28 | BOM_COUNT , 29 | BOM_UNDEFINED = 0xFFFFFFFF, 30 | }; 31 | 32 | struct ST_BOM_INFO 33 | { 34 | size_t tSize; 35 | BYTE btSeq[5]; 36 | }; 37 | 38 | E_BOM_TYPE GetCurrentBOMA(void); 39 | E_BOM_TYPE GetCurrentBOMW(void); 40 | 41 | E_BOM_TYPE ReadBOM(FILE* pFile); 42 | E_BOM_TYPE ReadBOM(const unsigned char* pszContents, size_t tLength, ST_BOM_INFO& outInfo); 43 | ECODE WriteBOM(FILE* pFile, E_BOM_TYPE nType); 44 | 45 | const ST_BOM_INFO* GetBOMInfo(E_BOM_TYPE nType); 46 | } 47 | -------------------------------------------------------------------------------- /Src/400_Server/JsonProtocol.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "ProtocolSuper.h" 4 | #include "Packetizer.h" 5 | 6 | namespace core 7 | { 8 | class CJsonProtocol : public CProtocolSuper 9 | { 10 | public: 11 | CJsonProtocol(core::CSyncTCPSocket* pSocket) 12 | : CProtocolSuper(pSocket) 13 | {} 14 | 15 | template 16 | ECODE SendPacket(T* pPacket, DWORD dwTimeOut = 60000) 17 | { 18 | return SendPacket(T::ID, pPacket, dwTimeOut); 19 | } 20 | 21 | template 22 | ECODE RecvPacket(T* pPacket, DWORD dwTimeOut = 60000) 23 | { 24 | return RecvPacket(T::ID, pPacket, dwTimeOut); 25 | } 26 | 27 | ECODE SendPacket(DWORD dwID, core::IFormatterObjectA* pPacket, DWORD dwTimeOut = 60000); 28 | ECODE SendPacket(DWORD dwID, core::IFormatterObjectW* pPacket, DWORD dwTimeOut = 60000); 29 | ECODE RecvPacket(DWORD dwID, core::IFormatterObjectA* pPacket, DWORD dwTimeOut = 60000); 30 | ECODE RecvPacket(DWORD dwID, core::IFormatterObjectW* pPacket, DWORD dwTimeOut = 60000); 31 | }; 32 | } 33 | 34 | -------------------------------------------------------------------------------- /Src/001_Encoder/SymPlain.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "SymPlain.h" 3 | 4 | namespace core 5 | { 6 | ////////////////////////////////////////////////////////////////////////// 7 | CSymPlain::CSymPlain(void) 8 | { 9 | } 10 | 11 | ////////////////////////////////////////////////////////////////////////// 12 | CSymPlain::~CSymPlain(void) 13 | { 14 | } 15 | 16 | ////////////////////////////////////////////////////////////////////////// 17 | ECODE CSymPlain::Init(E_CIPHER_METHOD nMethod, const ST_SYM_CIPHER_KEY& stKey) 18 | { 19 | return EC_SUCCESS; 20 | } 21 | 22 | ////////////////////////////////////////////////////////////////////////// 23 | ECODE CSymPlain::Encrypt(LPCBYTE pSrc, LPBYTE pDest) 24 | { 25 | memcpy(pDest, pSrc, BlockSize()); 26 | return EC_SUCCESS; 27 | } 28 | 29 | ////////////////////////////////////////////////////////////////////////// 30 | ECODE CSymPlain::Decrypt(LPCBYTE pSrc, LPBYTE pDest) 31 | { 32 | memcpy(pDest, pSrc, BlockSize()); 33 | return EC_SUCCESS; 34 | } 35 | } 36 | 37 | -------------------------------------------------------------------------------- /Src/400_Server/UBJsonProtocol.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "ProtocolSuper.h" 4 | #include "Packetizer.h" 5 | 6 | namespace core 7 | { 8 | class CUBJsonProtocol : public CProtocolSuper 9 | { 10 | public: 11 | CUBJsonProtocol(core::CSyncTCPSocket* pSocket) 12 | : CProtocolSuper(pSocket) 13 | {} 14 | 15 | template 16 | ECODE SendPacket(T* pPacket, DWORD dwTimeOut = 60000) 17 | { 18 | return SendPacket(T::ID, pPacket, dwTimeOut); 19 | } 20 | 21 | template 22 | ECODE RecvPacket(T* pPacket, DWORD dwTimeOut = 60000) 23 | { 24 | return RecvPacket(T::ID, pPacket, dwTimeOut); 25 | } 26 | 27 | ECODE SendPacket(DWORD dwID, core::IFormatterObjectA* pPacket, DWORD dwTimeOut = 60000); 28 | ECODE SendPacket(DWORD dwID, core::IFormatterObjectW* pPacket, DWORD dwTimeOut = 60000); 29 | ECODE RecvPacket(DWORD dwID, core::IFormatterObjectA* pPacket, DWORD dwTimeOut = 60000); 30 | ECODE RecvPacket(DWORD dwID, core::IFormatterObjectW* pPacket, DWORD dwTimeOut = 60000); 31 | }; 32 | } 33 | 34 | -------------------------------------------------------------------------------- /Src/300_Formatter/BytesWriter.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "BytesWriter.h" 3 | 4 | namespace fmt_internal 5 | { 6 | ////////////////////////////////////////////////////////////////////////// 7 | CBytesWriter::CBytesWriter(std::vector& vecOutput) 8 | : IChannel() 9 | , m_vecOutput(vecOutput) 10 | { 11 | } 12 | 13 | ////////////////////////////////////////////////////////////////////////// 14 | CBytesWriter::~CBytesWriter(void) 15 | { 16 | } 17 | 18 | ////////////////////////////////////////////////////////////////////////// 19 | bool CBytesWriter::CheckValidity(std::tstring& refStrErrMsg) 20 | { 21 | return true; 22 | } 23 | 24 | ////////////////////////////////////////////////////////////////////////// 25 | size_t CBytesWriter::Access(void* pData, size_t tDataSize) 26 | { 27 | if (0 == tDataSize) 28 | return 0; 29 | 30 | size_t tCurSize = m_vecOutput.size(); 31 | m_vecOutput.resize(tCurSize + tDataSize); 32 | memcpy(&m_vecOutput[tCurSize], pData, tDataSize); 33 | return tDataSize; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Src/300_Formatter/FormatterSuper.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "IChannel.h" 4 | #include "IFormatterA.h" 5 | #include "IFormatterW.h" 6 | 7 | namespace fmt_internal 8 | { 9 | class CFormatterSuper : public core::IFormatter 10 | { 11 | protected: 12 | core::IChannel& m_Channel; 13 | 14 | public: 15 | CFormatterSuper(core::IChannel& channel); 16 | virtual ~CFormatterSuper(); 17 | 18 | bool Transform(const core::IFormatterObject* pObject, std::tstring* pOutErrMsg = NULL, std::tstring* pRootName = NULL); 19 | bool Transform(core::IFormatterObject* pObject, std::tstring* pOutErrMsg = NULL, std::tstring* pRootName = NULL); 20 | 21 | protected: 22 | virtual bool OnPrepare(core::IFormatterObject* pObject, std::tstring& strErrMsg) = 0; 23 | 24 | virtual void OnBeginRoot(std::tstring& strRootName) = 0; 25 | virtual void OnEndRoot() = 0; 26 | 27 | core::IFormatter& OnSync(std::tstring& strKey, core::IFormatterObject* pObject); 28 | core::IFormatter& OnSync(std::tstring& strKey, core::IFormatterObject** pObject); 29 | }; 30 | } 31 | -------------------------------------------------------------------------------- /Src/300_Formatter/ANSIStringWritter.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "ANSIStringWritter.h" 3 | 4 | namespace fmt_internal 5 | { 6 | ////////////////////////////////////////////////////////////////////////// 7 | CANSIStringWriter::CANSIStringWriter(std::string& strOutput) 8 | : IChannel() 9 | , m_strOutput(strOutput) 10 | { 11 | } 12 | 13 | ////////////////////////////////////////////////////////////////////////// 14 | CANSIStringWriter::~CANSIStringWriter(void) 15 | { 16 | } 17 | 18 | ////////////////////////////////////////////////////////////////////////// 19 | bool CANSIStringWriter::CheckValidity(std::tstring& refStrErrMsg) 20 | { 21 | return true; 22 | } 23 | 24 | ////////////////////////////////////////////////////////////////////////// 25 | size_t CANSIStringWriter::Access(void* pData, size_t tDataSize) 26 | { 27 | std::tstring strTemp; 28 | strTemp.resize(tDataSize / sizeof(TCHAR)); 29 | memcpy(&strTemp[0], pData, tDataSize); 30 | 31 | m_strOutput = m_strOutput + ANSIFromTCS(strTemp); 32 | return tDataSize; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Src/300_Formatter/UTF8StringWritter.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "UTF8StringWritter.h" 3 | 4 | namespace fmt_internal 5 | { 6 | ////////////////////////////////////////////////////////////////////////// 7 | CUTF8StringWriter::CUTF8StringWriter(std::string& strOutput) 8 | : IChannel() 9 | , m_strOutput(strOutput) 10 | { 11 | } 12 | 13 | ////////////////////////////////////////////////////////////////////////// 14 | CUTF8StringWriter::~CUTF8StringWriter(void) 15 | { 16 | } 17 | 18 | ////////////////////////////////////////////////////////////////////////// 19 | bool CUTF8StringWriter::CheckValidity(std::tstring& refStrErrMsg) 20 | { 21 | return true; 22 | } 23 | 24 | ////////////////////////////////////////////////////////////////////////// 25 | size_t CUTF8StringWriter::Access(void* pData, size_t tDataSize) 26 | { 27 | std::tstring strTemp; 28 | strTemp.resize(tDataSize / sizeof(TCHAR)); 29 | memcpy(&strTemp[0], pData, tDataSize); 30 | 31 | m_strOutput = m_strOutput + UTF8FromTCS(strTemp); 32 | return tDataSize; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Src/200_Common/PipePeer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace core 4 | { 5 | class CPipePeerA 6 | { 7 | HANDLE m_hSendPipe; 8 | HANDLE m_hRecvPipe; 9 | 10 | public: 11 | CPipePeerA(void); 12 | ~CPipePeerA(void); 13 | 14 | ECODE Create(std::string strName); 15 | ECODE Open(std::string strName); 16 | void Close(void); 17 | 18 | ECODE Send(std::string strContext); 19 | ECODE Recv(std::string& strRecved); 20 | 21 | private: 22 | ECODE SendWorker(const void* pContext, size_t tLength); 23 | }; 24 | 25 | class CPipePeerW 26 | { 27 | HANDLE m_hSendPipe; 28 | HANDLE m_hRecvPipe; 29 | 30 | public: 31 | CPipePeerW(void); 32 | ~CPipePeerW(void); 33 | 34 | ECODE Create(std::wstring strName); 35 | ECODE Open(std::wstring strName); 36 | void Close(void); 37 | 38 | ECODE Send(std::wstring strContext); 39 | ECODE Recv(std::wstring& strRecved); 40 | 41 | private: 42 | ECODE SendWorker(const void* pContext, size_t tLength); 43 | }; 44 | 45 | #ifdef UNICODE 46 | #define CPipePeer CPipePeerW 47 | #else 48 | #define CPipePeer CPipePeerA 49 | #endif 50 | } 51 | -------------------------------------------------------------------------------- /Test/StringTest/HexConvertTest.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | 3 | ////////////////////////////////////////////////////////////////////////// 4 | TEST(StringTest, HexToStringConvert) 5 | { 6 | BYTE btOriginalData[16] = { 0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70 7 | , 0x80, 0x90, 0xA0, 0xB0, 0xC0, 0xD0, 0xE0, 0xF0 }; 8 | BYTE btRestoredData[16] = { 0, }; 9 | 10 | std::tstring strConvertedContext = StringFromHex(btOriginalData, sizeof(btOriginalData)); 11 | EXPECT_EQ(TEXT("00102030405060708090A0B0C0D0E0F0"), strConvertedContext); 12 | HexFromString(btRestoredData, sizeof(btRestoredData), strConvertedContext); 13 | EXPECT_EQ(0, memcmp(btOriginalData, btRestoredData, sizeof(btOriginalData))); 14 | } 15 | 16 | ////////////////////////////////////////////////////////////////////////// 17 | TEST(StringTest, StringToHexConvert) 18 | { 19 | std::tstring strContext = TEXT("0123456789ABCDEF"); 20 | BYTE btData[8] = { 0, }; 21 | HexFromString(btData, sizeof(btData), strContext); 22 | std::tstring strRestored = StringFromHex(btData, sizeof(btData)); 23 | EXPECT_EQ(strContext, strRestored); 24 | } -------------------------------------------------------------------------------- /Src/001_Encoder/SymModePlain.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "SymModePlain.h" 3 | 4 | namespace core 5 | { 6 | ////////////////////////////////////////////////////////////////////////// 7 | CSymModePlain::CSymModePlain(void) 8 | { 9 | } 10 | 11 | ////////////////////////////////////////////////////////////////////////// 12 | CSymModePlain::~CSymModePlain(void) 13 | { 14 | } 15 | 16 | ////////////////////////////////////////////////////////////////////////// 17 | ECODE CSymModePlain::Init(E_CIPHER_METHOD nMethod, ISymAlgorithm* pAlgorithm, const ST_SYM_CIPHER_KEY& stKey) 18 | { 19 | return EC_SUCCESS; 20 | } 21 | 22 | ////////////////////////////////////////////////////////////////////////// 23 | ECODE CSymModePlain::Encrypt(ISymAlgorithm* pAlgorithm, LPCBYTE pSrc, LPBYTE pDest) 24 | { 25 | return pAlgorithm->Encrypt(pSrc, pDest); 26 | } 27 | 28 | ////////////////////////////////////////////////////////////////////////// 29 | ECODE CSymModePlain::Decrypt(ISymAlgorithm* pAlgorithm, LPCBYTE pSrc, LPBYTE pDest) 30 | { 31 | return pAlgorithm->Decrypt(pSrc, pDest); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Src/300_Formatter/Interface.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include "../000_String/000_String.h" 11 | #include "FmtTypes.h" 12 | 13 | #ifdef UNICODE 14 | #define CFormatterSuper CFormatterSuperW 15 | #define IFormatter IFormatterW 16 | #define IFormatterT IFormatterW 17 | #define IFormatterObject IFormatterObjectW 18 | #define IFormatterObjectT IFormatterObjectW 19 | #else 20 | #define CFormatterSuper CFormatterSuperA 21 | #define IFormatter IFormatterA 22 | #define IFormatterT IFormatterA 23 | #define IFormatterObject IFormatterObjectA 24 | #define IFormatterObjectT IFormatterObjectA 25 | #endif 26 | 27 | namespace core 28 | { 29 | struct IFormatterA; 30 | struct IFormatterObjectA 31 | { 32 | virtual ~IFormatterObjectA() {} 33 | virtual void OnSync(IFormatterA& formatter) = 0; 34 | }; 35 | 36 | struct IFormatterW; 37 | struct IFormatterObjectW 38 | { 39 | virtual ~IFormatterObjectW() {} 40 | virtual void OnSync(IFormatterW& formatter) = 0; 41 | }; 42 | } 43 | -------------------------------------------------------------------------------- /Src/001_Encoder/PubKeyRSA.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../../Inc/cryptopp700/randpool.h" 4 | #include "../../Inc/cryptopp700/rsa.h" 5 | #include "../../Inc/cryptopp700/hex.h" 6 | #include "../../Inc/cryptopp700/files.h" 7 | #include "../../Inc/cryptopp700/filters.h" 8 | #include "../../Inc/cryptopp700/aes.h" 9 | #include "../../Inc/cryptopp700/modes.h" 10 | 11 | #include "IPubKeyCipher.h" 12 | 13 | namespace core 14 | { 15 | class CPubKeyRSAEncoder : public IPubKeyCipher 16 | { 17 | CryptoPP::RSAES_OAEP_SHA_Encryptor* m_pCryptor; 18 | 19 | public: 20 | CPubKeyRSAEncoder(std::vector vecKey, std::string strSeed); 21 | ~CPubKeyRSAEncoder(); 22 | 23 | void QueryInfo(ST_PUBKEY_CIPHER_INFO& outInfo); 24 | ECODE Crypt(LPCBYTE btSrc, LPBYTE btDest); 25 | }; 26 | 27 | class CPubKeyRSADecoder : public IPubKeyCipher 28 | { 29 | CryptoPP::RSAES_OAEP_SHA_Decryptor* m_pCryptor; 30 | 31 | public: 32 | CPubKeyRSADecoder(std::vector vecKey, std::string strSeed); 33 | ~CPubKeyRSADecoder(); 34 | 35 | void QueryInfo(ST_PUBKEY_CIPHER_INFO& outInfo); 36 | ECODE Crypt(LPCBYTE btSrc, LPBYTE btDest); 37 | }; 38 | } 39 | -------------------------------------------------------------------------------- /Sample/DummyDLL/APIEntry.cpp: -------------------------------------------------------------------------------- 1 | #include "APIEntry.h" 2 | 3 | using namespace core; 4 | 5 | struct ST_CONTEXT 6 | { 7 | std::tstring strTimeStamp; 8 | }; 9 | 10 | HANDLE Create(void) 11 | { 12 | ST_CONTEXT* pContext = new ST_CONTEXT; 13 | 14 | ST_SYSTEMTIME stTime; 15 | GetLocalTime(&stTime); 16 | pContext->strTimeStamp = Format(TEXT("%04d%02d%02dT%02d:%02d:%02d") 17 | , stTime.wYear, stTime.wMonth, stTime.wDay, stTime.wHour, stTime.wMinute, stTime.wSecond); 18 | return pContext; 19 | } 20 | 21 | ECODE Operate(HANDLE hContext, E_CMD nCmd, LPCSTR pszInput, LPCSTR pszOutput) 22 | { 23 | ST_CONTEXT* pContext = (ST_CONTEXT*)hContext; 24 | 25 | switch( nCmd ) 26 | { 27 | case CMD_SET_VALUE: 28 | printf("[CMD] SET_VALUE\n"); 29 | break; 30 | 31 | case CMD_GET_VALUE: 32 | printf("[CMD] GET_VALUE\n"); 33 | break; 34 | 35 | case CMD_ANALYZE_FILE: 36 | printf("[CMD] ANALYZE_FILE\n"); 37 | break; 38 | } 39 | 40 | if( pszInput ) 41 | printf("[INPUT] %s\n", pszInput); 42 | return EC_SUCCESS; 43 | } 44 | 45 | void Destroy(HANDLE hContext) 46 | { 47 | ST_CONTEXT* pContext = (ST_CONTEXT*)hContext; 48 | delete pContext; 49 | } -------------------------------------------------------------------------------- /Src/001_Encoder/StringFunction.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Type.h" 4 | 5 | #ifdef UNICODE 6 | #define GetHashTypeString GetHashTypeStringW 7 | #define GetCipherTypeString GetCipherTypeStringW 8 | #define GetSymEncModeString GetSymEncModeStringW 9 | #define GetPubKeyCipherTypeString GetASymCipherTypeStringW 10 | #else 11 | #define GetHashTypeString GetHashTypeStringA 12 | #define GetCipherTypeString GetCipherTypeStringA 13 | #define GetSymEncModeString GetSymEncModeStringA 14 | #define GetPubKeyCipherTypeString GetASymCipherTypeStringA 15 | #endif 16 | 17 | namespace core 18 | { 19 | LPCSTR GetHashTypeStringA (E_HASH_TYPE dwHashType); 20 | LPCSTR GetCipherTypeStringA (E_SYM_CIPHER_TYPE dwHashType); 21 | LPCSTR GetSymEncModeStringA (E_SYM_CIPHER_MODE dwEncMode); 22 | LPCSTR GetASymCipherTypeStringA(E_PUBKEY_CIPHER_TYPE dwHashType); 23 | 24 | LPCWSTR GetHashTypeStringW (E_HASH_TYPE dwHashType); 25 | LPCWSTR GetCipherTypeStringW (E_SYM_CIPHER_TYPE dwHashType); 26 | LPCWSTR GetSymEncModeStringW (E_SYM_CIPHER_MODE dwEncMode); 27 | LPCWSTR GetASymCipherTypeStringW(E_PUBKEY_CIPHER_TYPE dwHashType); 28 | } 29 | -------------------------------------------------------------------------------- /Src/001_Encoder/SymModeECB.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "SymModeECB.h" 3 | 4 | namespace core 5 | { 6 | ////////////////////////////////////////////////////////////////////////// 7 | CSymModeECB::CSymModeECB(void) 8 | { 9 | } 10 | 11 | ////////////////////////////////////////////////////////////////////////// 12 | CSymModeECB::~CSymModeECB(void) 13 | { 14 | } 15 | 16 | ////////////////////////////////////////////////////////////////////////// 17 | ECODE CSymModeECB::Init(E_CIPHER_METHOD nMethod, ISymAlgorithm* pAlgorithm, const ST_SYM_CIPHER_KEY& stKey) 18 | { 19 | return pAlgorithm->Init(nMethod, stKey); 20 | } 21 | 22 | ////////////////////////////////////////////////////////////////////////// 23 | ECODE CSymModeECB::Encrypt(ISymAlgorithm* pAlgorithm, LPCBYTE pSrc, LPBYTE pDest) 24 | { 25 | pAlgorithm->Encrypt(pSrc, pDest); 26 | return EC_SUCCESS; 27 | } 28 | 29 | ////////////////////////////////////////////////////////////////////////// 30 | ECODE CSymModeECB::Decrypt(ISymAlgorithm* pAlgorithm, LPCBYTE pSrc, LPBYTE pDest) 31 | { 32 | pAlgorithm->Decrypt(pSrc, pDest); 33 | return EC_SUCCESS; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /License/cppcore.txt: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 profrog-jeon 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Src/200_Common/PEParserT.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "PEParser.h" 3 | 4 | namespace core 5 | { 6 | ////////////////////////////////////////////////////////////////////////// 7 | bool CPEParser::Parse(std::tstring strFilePath) 8 | { 9 | return CExeParserSuper::Open(strFilePath) == EC_SUCCESS; 10 | } 11 | 12 | ////////////////////////////////////////////////////////////////////////// 13 | ECODE CPEParser::GetSection(std::tstring strName, ST_SECTION_DATA & data) 14 | { 15 | std::string strNameA = MBSFromTCS(strName); 16 | 17 | size_t i; 18 | for (i = 0; i < m_vecImageSectionHeader.size(); i++) 19 | { 20 | if (m_vecImageSectionHeader[i].Name != strNameA) 21 | continue; 22 | 23 | const ST_IMAGE_SECTION_HEADER& header = m_vecImageSectionHeader[i]; 24 | 25 | size_t tEndOfAddress = header.PointerToRawData + header.SizeOfRawData; 26 | if (m_tFileSize < tEndOfAddress) 27 | return EC_INVALID_DATA; 28 | 29 | data.dwFileAddress = header.PointerToRawData; 30 | data.pData = m_pFileContents + header.PointerToRawData; 31 | data.tSize = header.SizeOfRawData; 32 | return EC_SUCCESS; 33 | } 34 | 35 | return EC_NO_DATA; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Src/100_System/Socket.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../__Common/Type.h" 4 | 5 | typedef size_t SOCKET; 6 | 7 | namespace core 8 | { 9 | struct ST_ACCEPT_INFO 10 | { 11 | DWORD dwIP; 12 | DWORD dwFamily; 13 | }; 14 | 15 | struct ST_SOURCE_INFO 16 | { 17 | DWORD dwIP; 18 | WORD wPort; 19 | }; 20 | 21 | struct ST_LINGER 22 | { 23 | int l_onoff; 24 | int l_linger; 25 | }; 26 | 27 | SOCKET socket(int af, int type, int protocol); 28 | int bind(SOCKET s, DWORD dwIP, WORD wPort); 29 | int listen(SOCKET s, int nPendingCount); 30 | SOCKET accept(SOCKET s, ST_ACCEPT_INFO* pOutInfo = NULL); 31 | int shutdown(SOCKET s, int how); 32 | int closesocket(SOCKET s); 33 | int connect(SOCKET s, DWORD dwIP, WORD wPort); 34 | int setsockopt(SOCKET s, int level, int optname, const char* optval, int optlen); 35 | int recv(SOCKET s, char* buf, int len, int flags); 36 | int send(SOCKET s, const char* buf, int len, int flags); 37 | int sendto(SOCKET s, const char* buf, int len, int flags, DWORD dwIP, WORD wPort); 38 | int recvfrom(SOCKET s, char* buf, int len, int flags, ST_SOURCE_INFO* pSourceInfo); 39 | 40 | std::string GetHostByName(std::string strDomain); 41 | } -------------------------------------------------------------------------------- /Src/300_Formatter/HelperFunc.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include "FmtTypes.h" 6 | 7 | namespace fmt_internal 8 | { 9 | struct sGroupingData 10 | { 11 | std::tstring strName; 12 | E_GROUPING_TYPE nType; 13 | size_t tTotalCount; 14 | size_t tSequence; 15 | 16 | sGroupingData(E_GROUPING_TYPE t, size_t tCount) 17 | : strName(), nType(t), tTotalCount(tCount), tSequence(0) {} 18 | 19 | sGroupingData(std::tstring inName, E_GROUPING_TYPE t, size_t tCount) 20 | : strName(inName), nType(t), tTotalCount(tCount), tSequence(0) {} 21 | }; 22 | 23 | void TokenToVector(std::tstring& strContext, std::tstring strDelimiter, std::vector& outTokenVec); 24 | void TokenToVector(std::tstring& strContext, const TCHAR cSeperator, const TCHAR cQuotator, std::vector& outTokenVec); 25 | void TokenToVectorByExactDelimiter(std::tstring& strContext, std::tstring strExactDelimiter, std::vector& outTokenVec); 26 | 27 | std::tstring WrapupSpecialChar(std::tstring strValue, TCHAR cSeperator, TCHAR cQuotator); 28 | std::tstring StripSpecialChar(std::tstring strValue, TCHAR cSeperator, TCHAR cQuotator); 29 | } 30 | 31 | -------------------------------------------------------------------------------- /Src/400_Server/SyncTCPSocket.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace core 4 | { 5 | class CSyncTCPSocket 6 | { 7 | friend class CSyncServer; 8 | friend class CSyncConnection; 9 | 10 | protected: 11 | SOCKET m_hSocket; 12 | 13 | public: 14 | CSyncTCPSocket(void); 15 | virtual ~CSyncTCPSocket(); 16 | 17 | virtual ECODE Assign(SOCKET hAcceptedSocket); 18 | virtual ECODE Connect(const char* pszIP, WORD wPort, DWORD dwTimeOut); 19 | virtual void Close(void); 20 | 21 | virtual ECODE Send(const void* pBuff, size_t tBufSize, DWORD dwTimeOut); 22 | virtual ECODE Recv(void* pBuff, size_t tBufSize, DWORD dwTimeOut); 23 | virtual ECODE Recv(void* pBuff, size_t tBufSize, size_t* ptRead, DWORD dwTimeOut); 24 | virtual ECODE Peek(void* pBuff, size_t tBufSize, DWORD dwTimeOut, size_t* ptRead = NULL); 25 | 26 | protected: 27 | virtual ECODE SendWorker(SOCKET hSocket, const void* pBuff, size_t tBufSize, DWORD dwTimeOut, size_t* ptSent); 28 | virtual ECODE RecvWorker(SOCKET hSocket, void* pBuff, size_t tBufSize, DWORD dwTimeOut, size_t* ptRead); 29 | virtual ECODE PeekWorker(SOCKET hSocket, void* pBuff, size_t tBufSize, DWORD dwTimeOut, size_t* ptRead); 30 | }; 31 | 32 | } 33 | -------------------------------------------------------------------------------- /Src/100_System/InterlockedOperation.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace core 4 | { 5 | template 6 | T InterlockedAnd_(T volatile* pDest, T Value); // Returns old value 7 | template 8 | T InterlockedOr_(T volatile* pDest, T Value); // Returns old value 9 | template 10 | T InterlockedXor_(T volatile* pDest, T Value); // Returns old value 11 | template 12 | T InterlockedIncrement_(T volatile* pDest); // Returns new value 13 | template 14 | T InterlockedDecrement_(T volatile* pDest); // Returns new value 15 | template 16 | T InterlockedExchange_(T volatile* pDest, T Exchange); // Returns old value 17 | template 18 | T InterlockedExchangeAdd_(T volatile* pDest, T nValue); // Returns new value 19 | template 20 | T InterlockedCompareExchange_(T volatile* pDest, T Exchange, T Comperand); // Returns old Destination 21 | 22 | void* InterlockedExchangePointer_(void* volatile* pDest, void* pExchange); // Returns old Target 23 | void* InterlockedCompareExchangePointer_(void* volatile* pDest, void* pExchange, void* pComperand); // Returns old Destination 24 | } -------------------------------------------------------------------------------- /Src/001_Encoder/PubKeyElGamal.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../../Inc/cryptopp700/randpool.h" 4 | #include "../../Inc/cryptopp700/rsa.h" 5 | #include "../../Inc/cryptopp700/elgamal.h" 6 | #include "../../Inc/cryptopp700/hex.h" 7 | #include "../../Inc/cryptopp700/files.h" 8 | #include "../../Inc/cryptopp700/filters.h" 9 | #include "../../Inc/cryptopp700/aes.h" 10 | #include "../../Inc/cryptopp700/modes.h" 11 | 12 | #include "IPubKeyCipher.h" 13 | 14 | namespace core 15 | { 16 | class CPubKeyElGamalEncoder : public IPubKeyCipher 17 | { 18 | CryptoPP::ElGamal::Encryptor* m_pCryptor; 19 | 20 | public: 21 | CPubKeyElGamalEncoder(std::vector vecKey, std::string strSeed); 22 | ~CPubKeyElGamalEncoder(); 23 | 24 | void QueryInfo(ST_PUBKEY_CIPHER_INFO& outInfo); 25 | ECODE Crypt(LPCBYTE btSrc, LPBYTE btDest); 26 | }; 27 | 28 | class CPubKeyElGamalDecoder : public IPubKeyCipher 29 | { 30 | CryptoPP::ElGamal::Decryptor* m_pCryptor; 31 | 32 | public: 33 | CPubKeyElGamalDecoder(std::vector vecKey, std::string strSeed); 34 | ~CPubKeyElGamalDecoder(); 35 | 36 | void QueryInfo(ST_PUBKEY_CIPHER_INFO& outInfo); 37 | ECODE Crypt(LPCBYTE btSrc, LPBYTE btDest); 38 | }; 39 | } 40 | -------------------------------------------------------------------------------- /Src/200_Common/Semaphore.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "Semaphore.h" 3 | 4 | namespace core 5 | { 6 | ////////////////////////////////////////////////////////////////////////// 7 | CSemaphore::CSemaphore(void) 8 | : m_hSemaphore(NULL) 9 | { 10 | } 11 | 12 | ////////////////////////////////////////////////////////////////////////// 13 | CSemaphore::~CSemaphore(void) 14 | { 15 | Close(); 16 | } 17 | 18 | ////////////////////////////////////////////////////////////////////////// 19 | void CSemaphore::Close(void) 20 | { 21 | if( NULL == m_hSemaphore ) 22 | return; 23 | CloseSemaphore(m_hSemaphore); 24 | m_hSemaphore = NULL; 25 | } 26 | 27 | ////////////////////////////////////////////////////////////////////////// 28 | ECODE CSemaphore::Release(int nReleaseCount) 29 | { 30 | if( NULL == m_hSemaphore ) 31 | return EC_INVALID_HANDLE; 32 | return ReleaseSemaphore(m_hSemaphore, nReleaseCount); 33 | } 34 | 35 | ////////////////////////////////////////////////////////////////////////// 36 | ECODE CSemaphore::Wait(DWORD dwTimeOut) 37 | { 38 | if( NULL == m_hSemaphore ) 39 | return EC_INVALID_HANDLE; 40 | return WaitForSemaphore(m_hSemaphore, dwTimeOut); 41 | } 42 | } -------------------------------------------------------------------------------- /Src/001_Encoder/SymAES.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "ISymAlgorithm.h" 4 | 5 | namespace core 6 | { 7 | ////////////////////////////////////////////////////////////////////////// 8 | class CSymAES : public ISymAlgorithm 9 | { 10 | void* m_pCtx; 11 | size_t m_tLengthOfKey; 12 | 13 | protected: 14 | CSymAES(size_t tLengthOfKey); 15 | virtual ~CSymAES(void); 16 | 17 | public: 18 | ECODE Init(E_CIPHER_METHOD nMethod, const ST_SYM_CIPHER_KEY& stKey); 19 | ECODE Encrypt(LPCBYTE pSrc, LPBYTE pDest); 20 | ECODE Decrypt(LPCBYTE pSrc, LPBYTE pDest); 21 | size_t BlockSize(void) { return 16; } 22 | }; 23 | 24 | ////////////////////////////////////////////////////////////////////////// 25 | class CSymAES128 : public CSymAES 26 | { 27 | public: 28 | CSymAES128(void): CSymAES(16) {} 29 | }; 30 | 31 | ////////////////////////////////////////////////////////////////////////// 32 | class CSymAES192 : public CSymAES 33 | { 34 | public: 35 | CSymAES192(void): CSymAES(24) {} 36 | }; 37 | 38 | ////////////////////////////////////////////////////////////////////////// 39 | class CSymAES256 : public CSymAES 40 | { 41 | public: 42 | CSymAES256(void): CSymAES(32) {} 43 | }; 44 | } 45 | -------------------------------------------------------------------------------- /Src/200_Common/FileHashFunction.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define HashFile BuildHash // for lower compatibility 4 | 5 | namespace core 6 | { 7 | std::string BuildHash(E_HASH_TYPE nType, std::string strFilePath); 8 | std::string BuildHash(E_HASH_TYPE nType, std::wstring strFilePath); 9 | 10 | ECODE BuildHMAC(E_HASH_TYPE nHashType, const std::vector& Key, const std::vector& Message, std::vector& outResult); 11 | ECODE BuildHMAC(E_HASH_TYPE nHashType, const std::string& Key, const std::string& Message, std::vector& outResult); 12 | 13 | std::string BuildFileHash(E_HASH_TYPE nType, std::string strFilePath); 14 | std::wstring BuildFileHash(E_HASH_TYPE nType, std::wstring strFilePath); 15 | std::string BuildFileHashA(E_HASH_TYPE nType, std::string strFilePath); 16 | std::string BuildFileHashA(E_HASH_TYPE nType, std::wstring strFilePath); 17 | std::wstring BuildFileHashW(E_HASH_TYPE nType, std::string strFilePath); 18 | std::wstring BuildFileHashW(E_HASH_TYPE nType, std::wstring strFilePath); 19 | bool BuildFileHash(E_HASH_TYPE nType, std::string strFilePath, std::vector& vecHash); 20 | bool BuildFileHash(E_HASH_TYPE nType, std::wstring strFilePath, std::vector& vecHash); 21 | } -------------------------------------------------------------------------------- /Src/200_Common/SafeQueue.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include "CriticalSection.h" 5 | 6 | namespace core 7 | { 8 | template 9 | class CSafeQueue : private Uncopyable 10 | { 11 | CCriticalSection m_csData; 12 | std::queue m_queData; 13 | 14 | public: 15 | CSafeQueue(void) : m_csData(), m_queData() {} 16 | ~CSafeQueue(void) {} 17 | 18 | void Clear(void) 19 | { 20 | CCriticalSection::Owner Lock(m_csData); 21 | while(!m_queData.empty()) 22 | m_queData.pop(); 23 | } 24 | 25 | bool IsEmpty(void) 26 | { 27 | CCriticalSection::Owner Lock(m_csData); 28 | return m_queData.empty(); 29 | } 30 | 31 | size_t Count(void) 32 | { 33 | CCriticalSection::Owner Lock(m_csData); 34 | return m_queData.size(); 35 | } 36 | 37 | ECODE Push(const T& data) 38 | { 39 | CCriticalSection::Owner Lock(m_csData); 40 | m_queData.push(data); 41 | return EC_SUCCESS; 42 | } 43 | 44 | ECODE Pop(T& outItem) 45 | { 46 | CCriticalSection::Owner Lock(m_csData); 47 | if( m_queData.empty() ) 48 | return EC_NO_DATA; 49 | 50 | outItem = m_queData.front(); 51 | m_queData.pop(); 52 | return EC_SUCCESS; 53 | } 54 | }; 55 | 56 | } 57 | -------------------------------------------------------------------------------- /Src/200_Common/SafeStack.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include "CriticalSection.h" 5 | 6 | namespace core 7 | { 8 | template 9 | class CSafeStack : private Uncopyable 10 | { 11 | CCriticalSection m_csData; 12 | std::stack m_queData; 13 | 14 | public: 15 | CSafeStack(void) : m_csData(), m_queData() {} 16 | ~CSafeStack(void) {} 17 | 18 | void Clear(void) 19 | { 20 | CCriticalSection::Owner Lock(m_csData); 21 | while(!m_queData.empty()) 22 | m_queData.pop(); 23 | } 24 | 25 | bool IsEmpty(void) 26 | { 27 | CCriticalSection::Owner Lock(m_csData); 28 | return m_queData.empty(); 29 | } 30 | 31 | size_t Count(void) 32 | { 33 | CCriticalSection::Owner Lock(m_csData); 34 | return m_queData.size(); 35 | } 36 | 37 | ECODE Push(const T& data) 38 | { 39 | CCriticalSection::Owner Lock(m_csData); 40 | m_queData.push(data); 41 | return EC_SUCCESS; 42 | } 43 | 44 | ECODE Pop(T& outItem) 45 | { 46 | CCriticalSection::Owner Lock(m_csData); 47 | if( m_queData.empty() ) 48 | return EC_NO_DATA; 49 | 50 | outItem = m_queData.top(); 51 | m_queData.pop(); 52 | return EC_SUCCESS; 53 | } 54 | }; 55 | 56 | } 57 | -------------------------------------------------------------------------------- /Inc/cryptopp700/tiger.h: -------------------------------------------------------------------------------- 1 | // tiger.h - originally written and placed in the public domain by Wei Dai 2 | 3 | /// \file tiger.h 4 | /// \brief Classes for the Tiger message digest 5 | /// \since Crypto++ 2.1 6 | 7 | #ifndef CRYPTOPP_TIGER_H 8 | #define CRYPTOPP_TIGER_H 9 | 10 | #include "config.h" 11 | #include "iterhash.h" 12 | 13 | // Clang 3.3 integrated assembler crash on Linux 14 | // http://github.com/weidai11/cryptopp/issues/264 15 | #if defined(CRYPTOPP_LLVM_CLANG_VERSION) && (CRYPTOPP_LLVM_CLANG_VERSION < 30400) 16 | # define CRYPTOPP_DISABLE_TIGER_ASM 17 | #endif 18 | 19 | NAMESPACE_BEGIN(CryptoPP) 20 | 21 | /// \brief Tiger message digest 22 | /// \sa Tiger 23 | /// \since Crypto++ 2.1 24 | class Tiger : public IteratedHashWithStaticTransform 25 | { 26 | public: 27 | static void InitState(HashWordType *state); 28 | static void Transform(word64 *digest, const word64 *data); 29 | void TruncatedFinal(byte *hash, size_t size); 30 | CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return "Tiger";} 31 | 32 | protected: 33 | static const word64 table[4*256+3]; 34 | }; 35 | 36 | NAMESPACE_END 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /Sample/ProcessTest/DllWrapper.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "DllWrapper.h" 3 | 4 | CDllWrapper::CDllWrapper() 5 | : m_hModule(NULL) 6 | , m_fpCreate(NULL) 7 | , m_fpOperate(NULL) 8 | , m_fpDestroy(NULL) 9 | { 10 | } 11 | 12 | CDllWrapper::~CDllWrapper() 13 | { 14 | } 15 | 16 | bool CDllWrapper::LoadLibrary(LPCTSTR pszFilePath) 17 | { 18 | m_hModule = core::LoadLibrary(pszFilePath); 19 | if( NULL == m_hModule ) 20 | return false; 21 | 22 | m_fpCreate = (FP_Create)core::GetProcAddress(m_hModule, "Create"); 23 | m_fpOperate = (FP_Operate)core::GetProcAddress(m_hModule, "Operate"); 24 | m_fpDestroy = (FP_Destroy)core::GetProcAddress(m_hModule, "Destroy"); 25 | return true; 26 | } 27 | 28 | void CDllWrapper::FreeLibrary(void) 29 | { 30 | if( NULL == m_hModule ) 31 | return; 32 | 33 | core::FreeLibrary(m_hModule); 34 | m_hModule = NULL; 35 | } 36 | 37 | HANDLE CDllWrapper::Create(void) 38 | { 39 | return m_fpCreate(); 40 | } 41 | 42 | ECODE CDllWrapper::Operate(HANDLE hContext, E_CMD nCmd, LPCSTR pszInput, LPSTR pszOutput) 43 | { 44 | return m_fpOperate(hContext, nCmd, pszInput, pszOutput); 45 | } 46 | 47 | void CDllWrapper::Destroy(HANDLE hContext) 48 | { 49 | return m_fpDestroy(hContext); 50 | } -------------------------------------------------------------------------------- /Src/200_Common/CmdLineHelper.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace core 4 | { 5 | std::string MakeCmdLine(const std::vector& vecArgs); 6 | std::wstring MakeCmdLine(const std::vector& vecArgs); 7 | std::string MakeCmdLine(const std::string& strProcExe, std::vector vecArgs); 8 | std::wstring MakeCmdLine(const std::wstring& strProcExe, std::vector vecArgs); 9 | 10 | // same with MakeCmdLine, just for diversity 11 | std::string BuildCmdLine(const std::vector& vecArgs); 12 | std::wstring BuildCmdLine(const std::vector& vecArgs); 13 | std::string BuildCmdLine(const std::string& strProcExe, std::vector vecArgs); 14 | std::wstring BuildCmdLine(const std::wstring& strProcExe, std::vector vecArgs); 15 | 16 | void ParseCmdLine(const std::string& strCmdLine, std::vector& outArgs); 17 | void ParseCmdLine(const std::wstring& strCmdLine, std::vector& outArgs); 18 | 19 | // same with ParseCmdLine, just for diversity 20 | void TokenizeCmdLine(const std::string& strCmdLine, std::vector& outArgs); 21 | void TokenizeCmdLine(const std::wstring& strCmdLine, std::vector& outArgs); 22 | } -------------------------------------------------------------------------------- /Test/CommonTest/MemoryAccessTest.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | 3 | ////////////////////////////////////////////////////////////////////////// 4 | TEST(CommonTest, SharedMemoryTest) 5 | { 6 | const DWORD dwKey = 123; 7 | const DWORD dwSize = 1024 * 1024; 8 | 9 | CSharedMemory SharedMem, SharedMem2; 10 | EXPECT_EQ(EC_SUCCESS, SharedMem.Create(dwKey, dwSize, PAGE_READWRITE_, FILE_MAP_READ_|FILE_MAP_WRITE_) ); 11 | EXPECT_EQ(EC_SUCCESS, SharedMem2.Create(dwKey, dwSize, PAGE_READONLY_, FILE_MAP_READ_) ); 12 | 13 | LPSTR pszContext = (LPSTR)SharedMem.Ptr(); 14 | LPSTR pszContext2 = (LPSTR)SharedMem2.Ptr(); 15 | if( pszContext && pszContext2 ) 16 | { 17 | LPCSTR pszText = "Hello world?"; 18 | SafeStrCpy(pszContext, dwSize, pszText); 19 | 20 | EXPECT_STREQ(pszContext2, pszText); 21 | } 22 | 23 | SharedMem.Destroy(); 24 | SharedMem2.Destroy(); 25 | } 26 | 27 | ////////////////////////////////////////////////////////////////////////// 28 | TEST(CommonTest, MemoryMappedFileTest) 29 | { 30 | CMemoryMappedFile MemMappedFile; 31 | EXPECT_EQ(EC_SUCCESS, MemMappedFile.Create(TEXT("../../Build/Test/MemoryMappedFileTest/document1.xml"), PAGE_READONLY_, FILE_MAP_READ_) ); 32 | EXPECT_FALSE(MemMappedFile.Size() == 0); 33 | } 34 | -------------------------------------------------------------------------------- /Src/001_Encoder/SymSeed128.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "SymSeed128.h" 3 | #include "SEED/SEED_128_KISA.h" 4 | 5 | namespace core 6 | { 7 | ////////////////////////////////////////////////////////////////////////// 8 | CSymSeed128::CSymSeed128(void) 9 | { 10 | } 11 | 12 | ////////////////////////////////////////////////////////////////////////// 13 | CSymSeed128::~CSymSeed128(void) 14 | { 15 | } 16 | 17 | ////////////////////////////////////////////////////////////////////////// 18 | ECODE CSymSeed128::Init(E_CIPHER_METHOD nMethod, const ST_SYM_CIPHER_KEY& stKey) 19 | { 20 | seed128::SeedRoundKey(m_dwRoundKey, stKey.btKey); 21 | return EC_SUCCESS; 22 | } 23 | 24 | ////////////////////////////////////////////////////////////////////////// 25 | ECODE CSymSeed128::Encrypt(LPCBYTE pSrc, LPBYTE pDest) 26 | { 27 | memcpy(pDest, pSrc, BlockSize()); 28 | seed128::SeedEncrypt(pDest, m_dwRoundKey); 29 | return EC_SUCCESS; 30 | } 31 | 32 | ////////////////////////////////////////////////////////////////////////// 33 | ECODE CSymSeed128::Decrypt(LPCBYTE pSrc, LPBYTE pDest) 34 | { 35 | memcpy(pDest, pSrc, BlockSize()); 36 | seed128::SeedDecrypt(pDest, m_dwRoundKey); 37 | return EC_SUCCESS; 38 | } 39 | } 40 | 41 | -------------------------------------------------------------------------------- /Src/001_Encoder/SymSeed256.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "SymSeed256.h" 3 | #include "SEED/SEED_256_KISA.h" 4 | 5 | namespace core 6 | { 7 | ////////////////////////////////////////////////////////////////////////// 8 | CSymSeed256::CSymSeed256(void) 9 | { 10 | } 11 | 12 | ////////////////////////////////////////////////////////////////////////// 13 | CSymSeed256::~CSymSeed256(void) 14 | { 15 | } 16 | 17 | ////////////////////////////////////////////////////////////////////////// 18 | ECODE CSymSeed256::Init(E_CIPHER_METHOD nMethod, const ST_SYM_CIPHER_KEY& stKey) 19 | { 20 | seed256::SeedRoundKey(m_dwRoundKey, stKey.btKey); 21 | return EC_SUCCESS; 22 | } 23 | 24 | ////////////////////////////////////////////////////////////////////////// 25 | ECODE CSymSeed256::Encrypt(LPCBYTE pSrc, LPBYTE pDest) 26 | { 27 | memcpy(pDest, pSrc, BlockSize()); 28 | seed256::SeedEncrypt(pDest, m_dwRoundKey); 29 | return EC_SUCCESS; 30 | } 31 | 32 | ////////////////////////////////////////////////////////////////////////// 33 | ECODE CSymSeed256::Decrypt(LPCBYTE pSrc, LPBYTE pDest) 34 | { 35 | memcpy(pDest, pSrc, BlockSize()); 36 | seed256::SeedDecrypt(pDest, m_dwRoundKey); 37 | return EC_SUCCESS; 38 | } 39 | } 40 | 41 | -------------------------------------------------------------------------------- /Inc/cryptopp700/aes.h: -------------------------------------------------------------------------------- 1 | // aes.h - originally written and placed in the public domain by Wei Dai 2 | 3 | /// \file 4 | /// \brief Class file for the AES cipher (Rijndael) 5 | /// \details AES is a typdef for Rijndael classes. All key sizes are supported. 6 | /// The library only provides Rijndael with 128-bit blocks, and not 192-bit or 256-bit blocks 7 | /// \since Rijndael since Crypto++ 3.1, Intel AES-NI since Crypto++ 5.6.1, ARMv8 AES since Crypto++ 6.0, 8 | /// Power8 AES since Crypto++ 6.0 9 | 10 | #ifndef CRYPTOPP_AES_H 11 | #define CRYPTOPP_AES_H 12 | 13 | #include "rijndael.h" 14 | 15 | NAMESPACE_BEGIN(CryptoPP) 16 | 17 | /// \brief AES block cipher (Rijndael) 18 | /// \details AES is a typdef for Rijndael classes. All key sizes are supported. 19 | /// The library only provides Rijndael with 128-bit blocks, and not 192-bit or 256-bit blocks 20 | /// \sa AES winner, announced on 10/2/2000 21 | /// \since Rijndael since Crypto++ 3.1, Intel AES-NI since Crypto++ 5.6.1, ARMv8 AES since Crypto++ 6.0, 22 | /// Power8 AES since Crypto++ 6.0 23 | DOCUMENTED_TYPEDEF(Rijndael, AES) 24 | 25 | typedef RijndaelEncryption AESEncryption; 26 | typedef RijndaelDecryption AESDecryption; 27 | 28 | NAMESPACE_END 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /Src/000_String/Utility.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef UNICODE 4 | #define MakeHexDumpStr MakeHexDumpStrW 5 | #else 6 | #define MakeHexDumpStr MakeHexDumpStrA 7 | #endif 8 | 9 | namespace core 10 | { 11 | bool IsReadableChar(char cChar); 12 | bool IsReadableChar(wchar_t cChar); 13 | 14 | std::string& MakeFormalPath(std::string& strInformalPath); 15 | std::wstring& MakeFormalPath(std::wstring& strInformalPath); 16 | std::string MakeFormalPath(LPCSTR pszInformalPath); 17 | std::wstring MakeFormalPath(LPCWSTR pszInformalPath); 18 | 19 | std::string ExtractDirectory(std::string strFullPath); 20 | std::wstring ExtractDirectory(std::wstring strFullPath); 21 | std::string ExtractFileName(std::string strFullPath); 22 | std::wstring ExtractFileName(std::wstring strFullPath); 23 | std::string ExtractFileNameWithoutExt(std::string strFilename); 24 | std::wstring ExtractFileNameWithoutExt(std::wstring strFilename); 25 | std::string ExtractFileExt(std::string strFullPath); 26 | std::wstring ExtractFileExt(std::wstring strFullPath); 27 | 28 | std::string MakeHexDumpStrA(LPCBYTE pData, size_t tSize); 29 | std::wstring MakeHexDumpStrW(LPCBYTE pData, size_t tSize); 30 | std::string MakeHexDumpStrA(std::string strHexDump); 31 | std::wstring MakeHexDumpStrW(std::wstring strHexDump); 32 | } 33 | -------------------------------------------------------------------------------- /Src/300_Formatter/INIFormatter.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "../__Common/Type.h" 9 | #include "../__Common/Define.h" 10 | #include "IChannel.h" 11 | 12 | namespace fmt_internal 13 | { 14 | typedef std::map CStringMap; 15 | typedef std::map::iterator CStringMapIt; 16 | 17 | class CINIFormatter 18 | { 19 | private: 20 | typedef std::list CStringList; 21 | typedef std::list::iterator CStringListIt; 22 | 23 | CStringList m_listString; 24 | 25 | protected: 26 | std::tstring m_strFilename; 27 | 28 | public: 29 | CINIFormatter(void); 30 | virtual ~CINIFormatter(void); 31 | 32 | DWORD Open(std::tstring strContext); 33 | void Close(void); 34 | 35 | DWORD Flush(core::IChannel& channel); 36 | 37 | DWORD GetSectionNames(std::vector& outNames); 38 | DWORD GetValue(LPCTSTR pszSection, LPCTSTR pszKey, std::tstring& refValue); 39 | DWORD GetValues(LPCTSTR pszSection, LPCTSTR pszKey, std::vector& refValues); 40 | DWORD GetSectionValues(LPCTSTR pszSection, CStringMap& refMap); 41 | 42 | DWORD SetValue(LPCTSTR pszSection, LPCTSTR pszKey, LPCTSTR pszValue); 43 | }; 44 | } 45 | -------------------------------------------------------------------------------- /Test/SystemTest/InformationTest.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | 3 | TEST(InformationTest, SystemTimeFromStringTest) 4 | { 5 | ST_SYSTEMTIME stLocalTime; 6 | GetLocalTime(&stLocalTime); 7 | 8 | std::tstring strTime = StringFrom(stLocalTime); 9 | 10 | ST_SYSTEMTIME stRestoredTime = SystemTimeFrom(strTime); 11 | EXPECT_EQ(stLocalTime.wYear , stRestoredTime.wYear ); 12 | EXPECT_EQ(stLocalTime.wMonth , stRestoredTime.wMonth ); 13 | EXPECT_EQ(stLocalTime.wDayOfWeek , stRestoredTime.wDayOfWeek ); 14 | EXPECT_EQ(stLocalTime.wDay , stRestoredTime.wDay ); 15 | EXPECT_EQ(stLocalTime.wHour , stRestoredTime.wHour ); 16 | EXPECT_EQ(stLocalTime.wMinute , stRestoredTime.wMinute ); 17 | EXPECT_EQ(stLocalTime.wSecond , stRestoredTime.wSecond ); 18 | //EXPECT_EQ(stLocalTime.wMilliseconds , stRestoredTime.wMilliseconds ); 19 | } 20 | 21 | TEST(InformationTest, VersionFromStringTest) 22 | { 23 | const ST_VERSIONINFO stVersion = { 1, 4, 3, 2 }; 24 | 25 | std::tstring strVersion = StringFrom(stVersion); 26 | 27 | ST_VERSIONINFO stRestoredVersion = VersionFrom(strVersion); 28 | EXPECT_EQ(stVersion.dwMajor, stRestoredVersion.dwMajor); 29 | EXPECT_EQ(stVersion.dwMinor, stRestoredVersion.dwMinor); 30 | EXPECT_EQ(stVersion.dwPatch, stRestoredVersion.dwPatch); 31 | EXPECT_EQ(stVersion.dwBuild, stRestoredVersion.dwBuild); 32 | } 33 | -------------------------------------------------------------------------------- /Src/001_Encoder/AES/aeshash.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include "aes.h" 7 | 8 | enum { 9 | l_c = 0, 10 | r_c = 1 11 | }; 12 | 13 | static const unsigned char key[2][32] = {{0x23, 0xce, 0x45, 0x19, 0xc5, 0xb6, 0xb5, 0x82, 14 | 0x19, 0x14, 0x36, 0x26, 0xa4, 0xe0, 0x9c, 0xa2}, 15 | {0x20, 0xce, 0x49, 0x19, 0xc5, 0xb6, 0xd5, 0xe2, 16 | 0xb6, 0x1d, 0xf6, 0x56, 0xa5, 0xef, 0xfc, 0xe2}}; 17 | static aes_ctx ctx[2]; 18 | 19 | void aeshash_type(const unsigned char in[], unsigned char out[], int type) 20 | { 21 | memset(out, 0, BLOCK_SIZE); 22 | aes_enc_blk(in, out, ctx + type); 23 | ((unsigned __int64 *) out)[0] ^= ((unsigned __int64 *) in)[0]; 24 | ((unsigned __int64 *) out)[1] ^= ((unsigned __int64 *) in)[1]; 25 | } 26 | void aeshash_l(const unsigned char in[], unsigned char out[]) 27 | { 28 | aeshash_type(in, out, l_c); 29 | } 30 | void aeshash_r(const unsigned char in[], unsigned char out[]) 31 | { 32 | aeshash_type(in, out, r_c); 33 | } 34 | 35 | void aeshash_init_type(int type) 36 | { 37 | ctx[type].n_rnd = 0; // ensure all flags are initially set to zero 38 | ctx[type].n_blk = 0; 39 | aes_enc_key(key[type], 16, ctx + type); 40 | } 41 | void aeshash_init(void) 42 | { 43 | aeshash_init_type(l_c); 44 | aeshash_init_type(r_c); 45 | } 46 | -------------------------------------------------------------------------------- /Src/200_Common/ThreadPool.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include "SafeQueue.h" 5 | 6 | namespace core 7 | { 8 | class CThreadPool; 9 | namespace internal 10 | { 11 | struct ST_THREADPOOL_DATA 12 | { 13 | std::tstring strName; 14 | HANDLE hThread; 15 | HANDLE hEvent; 16 | bool* pbEscapeFlag; 17 | 18 | CThreadPool* pOwner; 19 | 20 | int (*pfThreadFunc)(void *pContext); 21 | void* pContext; 22 | 23 | ST_THREADPOOL_DATA(void) 24 | : strName(), hThread(NULL), hEvent(NULL) 25 | , pbEscapeFlag(NULL), pOwner(NULL) 26 | , pfThreadFunc(NULL), pContext(NULL) 27 | {} 28 | }; 29 | } 30 | 31 | typedef internal::ST_THREADPOOL_DATA* HTHREADPOOL; 32 | 33 | class CThreadPool 34 | { 35 | std::vector m_vecInstance; 36 | CSafeQueue m_queReady; 37 | 38 | bool m_bEscapeFlag; 39 | bool m_bReserved[7]; 40 | 41 | public: 42 | CThreadPool(); 43 | virtual ~CThreadPool(); 44 | 45 | ECODE Init(size_t tPoolCount, E_THREAD_PRIORITY nPriority = THREAD_PRIORITY_MIDDLE); 46 | void Destroy(void); 47 | 48 | ECODE CreateThread(int(*pfEntry)(void* pContext), void* pContext); 49 | 50 | private: 51 | friend int ThreadPoolWorker(void* pContext); 52 | void ReturnThread(HTHREADPOOL hThread); 53 | }; 54 | } 55 | -------------------------------------------------------------------------------- /Inc/cryptopp700/seed.h: -------------------------------------------------------------------------------- 1 | // seed.h - originally written and placed in the public domain by Wei Dai 2 | 3 | /// \file seed.h 4 | /// \brief Classes for the SEED block cipher 5 | /// \since Crypto++ 5.6.0 6 | 7 | #ifndef CRYPTOPP_SEED_H 8 | #define CRYPTOPP_SEED_H 9 | 10 | #include "seckey.h" 11 | #include "secblock.h" 12 | 13 | NAMESPACE_BEGIN(CryptoPP) 14 | 15 | /// \brief SEED block cipher information 16 | /// \since Crypto++ 5.6.0 17 | struct SEED_Info : public FixedBlockSize<16>, public FixedKeyLength<16>, public FixedRounds<16> 18 | { 19 | CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return "SEED";} 20 | }; 21 | 22 | /// \brief SEED block cipher 23 | /// \sa SEED 24 | /// \since Crypto++ 5.6.0 25 | class SEED : public SEED_Info, public BlockCipherDocumentation 26 | { 27 | class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl 28 | { 29 | public: 30 | void UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs ¶ms); 31 | void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const; 32 | 33 | protected: 34 | FixedSizeSecBlock m_k; 35 | }; 36 | 37 | public: 38 | typedef BlockCipherFinal Encryption; 39 | typedef BlockCipherFinal Decryption; 40 | }; 41 | 42 | NAMESPACE_END 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /Src/300_Formatter/BytesReader.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "BytesReader.h" 3 | 4 | namespace fmt_internal 5 | { 6 | ////////////////////////////////////////////////////////////////////////// 7 | CBytesReader::CBytesReader(const void* pBytes, size_t tBytesSize) 8 | : IChannel() 9 | , m_pBytes((const BYTE*)pBytes) 10 | , m_tBytesSize(tBytesSize) 11 | , m_tReadPos(0) 12 | { 13 | } 14 | 15 | ////////////////////////////////////////////////////////////////////////// 16 | CBytesReader::~CBytesReader(void) 17 | { 18 | } 19 | 20 | ////////////////////////////////////////////////////////////////////////// 21 | bool CBytesReader::CheckValidity(std::tstring& refStrErrMsg) 22 | { 23 | return true; 24 | } 25 | 26 | ////////////////////////////////////////////////////////////////////////// 27 | size_t CBytesReader::Access(void* pData, size_t tDataSize) 28 | { 29 | const size_t tContextSize = m_tBytesSize; 30 | const size_t tRemainedSize = tContextSize < m_tReadPos? 0 : tContextSize - m_tReadPos; 31 | if( tRemainedSize == 0 ) 32 | return 0; 33 | 34 | if( tDataSize > tRemainedSize ) 35 | { 36 | memcpy(pData, &m_pBytes[m_tReadPos], tRemainedSize); 37 | m_tReadPos += tRemainedSize; 38 | return tRemainedSize; 39 | } 40 | 41 | memcpy(pData, &m_pBytes[m_tReadPos], tDataSize); 42 | m_tReadPos += tDataSize; 43 | return tDataSize; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Build/BuildTest_And_Run.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | SET CUR_DIR=%CD% 4 | SET TEST_DIR=%CD%\Test 5 | 6 | REM ======================================= 7 | REM =========== WINDOWS BUILD =========== 8 | REM ======================================= 9 | SET MSBUILD="C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\MSBuild.exe" 10 | SET SLNFILE=..\Test\_BuildAll.sln 11 | 12 | %MSBUILD% %SLNFILE% /m /t:Rebuild /p:Configuration=ReleaseMT;Platform=x64 13 | IF %ERRORLEVEL% NEQ 0 GOTO Error 14 | 15 | cd %TEST_DIR% 16 | call RunTest.bat 17 | IF %ERRORLEVEL% NEQ 0 GOTO Error 18 | 19 | REM ===================================== 20 | REM =========== LINUX BUILD =========== 21 | REM ===================================== 22 | SET LINUX_OUTPUT_DIR=..\Output\LinuxRelease 23 | 24 | cd %CUR_DIR% 25 | rd /S /Q %LINUX_OUTPUT_DIR% 26 | 27 | mkdir %LINUX_OUTPUT_DIR% 28 | cd %LINUX_OUTPUT_DIR% 29 | wsl cmake ../../Test 30 | wsl cmake --build . 31 | IF %ERRORLEVEL% NEQ 0 GOTO Error 32 | 33 | cd %TEST_DIR% 34 | wsl dos2unix ./RunTest.sh 35 | wsl chmod 0755 ./RunTest.sh 36 | wsl ./RunTest.sh 37 | IF %ERRORLEVEL% NEQ 0 GOTO Error 38 | 39 | REM ================================== 40 | REM =========== FINALIZE =========== 41 | REM ================================== 42 | :Success 43 | echo Test succeeded 44 | exit /b 0 45 | 46 | :Error 47 | echo Error occurred, code:%ERRORLEVEL% 48 | pause 49 | exit /b -1 -------------------------------------------------------------------------------- /Src/400_Server/SocketCommon.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "SocketCommon.h" 3 | 4 | namespace core 5 | { 6 | ECODE SetCommonSockOpt(SOCKET hSocket) 7 | { 8 | ECODE nRet = EC_SUCCESS; 9 | try 10 | { 11 | ST_LINGER stLinger; 12 | stLinger.l_onoff = 1; 13 | stLinger.l_linger = 5000; 14 | nRet = core::setsockopt(hSocket, SOL_SOCKET_, SO_LINGER_, (char*)&stLinger, sizeof(stLinger)); 15 | if (SOCKET_ERROR_ == nRet) 16 | Log_Warn("core::setsockopt(m_hSocket, SOL_SOCKET, SO_LINGER, (char*)&stLinger, sizeof(stLinger)) failure, %d", core::GetLastError()); 17 | 18 | int bReuseAddr = 1; 19 | nRet = core::setsockopt(hSocket, SOL_SOCKET_, SO_REUSEADDR_, (char*)&bReuseAddr, sizeof(bReuseAddr)); 20 | if (SOCKET_ERROR_ == nRet) 21 | Log_Warn("core::setsockopt(m_hSocket, SOL_SOCKET, SO_REUSEADDR, (char*)&bReuseAddr, sizeof(bReuseAddr)) failure, %d", core::GetLastError()); 22 | 23 | int bNodelay = 1; 24 | nRet = core::setsockopt(hSocket, IPPROTO_TCP_, TCP_NODELAY_, (char*)&bNodelay, sizeof(bNodelay)); 25 | if (SOCKET_ERROR_ == nRet) 26 | Log_Warn("core::setsockopt(m_hSocket, IPPROTO_TCP, TCP_NODELAY, (char*)&bNodelay, sizeof(bNodelay)) failure, %d", core::GetLastError()); 27 | } 28 | catch (std::exception& e) 29 | { 30 | nRet = GetLastError(); 31 | Log_Error("%s", e.what()); 32 | return nRet; 33 | } 34 | 35 | return EC_SUCCESS; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Inc/cryptopp700/md5.h: -------------------------------------------------------------------------------- 1 | #ifndef CRYPTOPP_MD5_H 2 | #define CRYPTOPP_MD5_H 3 | 4 | #include "iterhash.h" 5 | 6 | NAMESPACE_BEGIN(CryptoPP) 7 | 8 | namespace Weak1 { 9 | 10 | /// \brief MD5 message digest 11 | /// \sa MD5 12 | /// \since Crypto++ 1.0 13 | class MD5 : public IteratedHashWithStaticTransform 14 | { 15 | public: 16 | static void InitState(HashWordType *state); 17 | static void Transform(word32 *digest, const word32 *data); 18 | CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return "MD5";} 19 | }; 20 | 21 | } 22 | #if CRYPTOPP_ENABLE_NAMESPACE_WEAK >= 1 23 | namespace Weak {using namespace Weak1;} // import Weak1 into CryptoPP::Weak 24 | #else 25 | using namespace Weak1; // import Weak1 into CryptoPP with warning 26 | #ifdef __GNUC__ 27 | #warning "You may be using a weak algorithm that has been retained for backwards compatibility. Please '#define CRYPTOPP_ENABLE_NAMESPACE_WEAK 1' before including this .h file and prepend the class name with 'Weak::' to remove this warning." 28 | #else 29 | #pragma message("You may be using a weak algorithm that has been retained for backwards compatibility. Please '#define CRYPTOPP_ENABLE_NAMESPACE_WEAK 1' before including this .h file and prepend the class name with 'Weak::' to remove this warning.") 30 | #endif 31 | #endif 32 | 33 | NAMESPACE_END 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /Src/001_Encoder/ssdeep/match.h: -------------------------------------------------------------------------------- 1 | #ifndef __MATCH_H 2 | #define __MATCH_H 3 | 4 | // SSDEEP 5 | // $Id$ 6 | // Copyright (C) 2012 Kyrus. 7 | #include "ssdeep.h" 8 | #include "filedata.h" 9 | 10 | // ********************************************************************* 11 | // Matching functions 12 | // ********************************************************************* 13 | 14 | /// @brief Match the file f against the set of knowns 15 | /// 16 | /// @return Returns false if there are no matches, true if at least one match 17 | /// @param s State variable 18 | /// @param f Filedata structure for the file. 19 | bool match_compare(state *s, Filedata * f); 20 | 21 | /// @brief Load a file of known hashes 22 | /// 23 | /// @return Returns false on success, true on error 24 | bool match_load(state *s, const char *fn); 25 | 26 | /// @brief Add a single new hash to the set of known hashes 27 | /// 28 | /// @return Returns false on success, true on error 29 | bool match_add(state *s, Filedata * f); 30 | 31 | /// Find and display all matches in the set of known hashes 32 | bool find_matches_in_known(state *s); 33 | 34 | /// Load the known hashes from the file fn and compare them to the 35 | /// set of known hashes 36 | bool match_compare_unknown(state *s, const char * fn); 37 | 38 | /// Display the results of clustering operations 39 | void display_clusters(const state *s); 40 | 41 | 42 | 43 | #endif // ifndef __MATCH_H 44 | -------------------------------------------------------------------------------- /Inc/cryptopp700/whrlpool.h: -------------------------------------------------------------------------------- 1 | // whrlpool.h - originally modified by Kevin Springle from Paulo Barreto and Vincent Rijmen's 2 | // public domain code, whirlpool.c. Updated to Whirlpool version 3.0, optimized 3 | // and SSE version added by WD. All modifications are placed in the public domain. 4 | 5 | #ifndef CRYPTOPP_WHIRLPOOL_H 6 | #define CRYPTOPP_WHIRLPOOL_H 7 | 8 | /// \file whrlpool.h 9 | /// \brief Classes for the Whirlpool message digest 10 | /// \details Crypto++ provides version 3.0 of the Whirlpool algorithm. 11 | /// This version of the algorithm was submitted for ISO standardization. 12 | 13 | #include "config.h" 14 | #include "iterhash.h" 15 | 16 | NAMESPACE_BEGIN(CryptoPP) 17 | 18 | /// \brief Whirlpool message digest 19 | /// \details Crypto++ provides version 3.0 of the Whirlpool algorithm. 20 | /// This version of the algorithm was submitted for ISO standardization. 21 | /// \since Crypto++ 5.2 22 | /// \sa Whirlpool 23 | class Whirlpool : public IteratedHashWithStaticTransform 24 | { 25 | public: 26 | static void InitState(HashWordType *state); 27 | static void Transform(word64 *digest, const word64 *data); 28 | void TruncatedFinal(byte *hash, size_t size); 29 | CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return "Whirlpool";} 30 | }; 31 | 32 | NAMESPACE_END 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /Test/CommonTest/ThreadTest.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | 3 | ////////////////////////////////////////////////////////////////////////// 4 | static std::tstring g_strSuccessMessage = TEXT("Member function thread message."); 5 | static int g_nExitCode = 123; 6 | 7 | ////////////////////////////////////////////////////////////////////////// 8 | class CMemberFuncThreadTest 9 | { 10 | public: 11 | std::tstring strMessage; 12 | CMemberFuncThreadTest(void) {} 13 | 14 | int ThreadFunc(void* pContext) 15 | { 16 | strMessage = g_strSuccessMessage; 17 | return g_nExitCode; 18 | } 19 | }; 20 | 21 | ////////////////////////////////////////////////////////////////////////// 22 | TEST(MemberFuncThreadTest, FunctionCallingTest) 23 | { 24 | CMemberFuncThreadTest Test; 25 | HANDLE hThread = CreateThread(&Test, &CMemberFuncThreadTest::ThreadFunc, NULL); 26 | ASSERT_NE((HANDLE)NULL, hThread); 27 | 28 | int nExitCode = 0; 29 | EXPECT_EQ(EC_SUCCESS, JoinThread(hThread, &nExitCode)); 30 | EXPECT_EQ(g_strSuccessMessage, Test.strMessage); 31 | } 32 | 33 | ////////////////////////////////////////////////////////////////////////// 34 | TEST(MemberFuncThreadTest, FunctionRetCodeTest) 35 | { 36 | CMemberFuncThreadTest Test; 37 | HANDLE hThread = CreateThread(&Test, &CMemberFuncThreadTest::ThreadFunc, NULL); 38 | ASSERT_NE((HANDLE)NULL, hThread); 39 | 40 | int nExitCode = 0; 41 | EXPECT_EQ(EC_SUCCESS, JoinThread(hThread, &nExitCode)); 42 | EXPECT_EQ(g_nExitCode, nExitCode); 43 | } -------------------------------------------------------------------------------- /Inc/cryptopp700/md4.h: -------------------------------------------------------------------------------- 1 | #ifndef CRYPTOPP_MD4_H 2 | #define CRYPTOPP_MD4_H 3 | 4 | #include "iterhash.h" 5 | 6 | NAMESPACE_BEGIN(CryptoPP) 7 | 8 | namespace Weak1 { 9 | 10 | /// MD4 11 | /*! \warning MD4 is considered insecure, and should not be used 12 | unless you absolutely need it for compatibility. */ 13 | class MD4 : public IteratedHashWithStaticTransform 14 | { 15 | public: 16 | static void InitState(HashWordType *state); 17 | static void Transform(word32 *digest, const word32 *data); 18 | CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return "MD4";} 19 | }; 20 | 21 | } 22 | #if CRYPTOPP_ENABLE_NAMESPACE_WEAK >= 1 23 | namespace Weak {using namespace Weak1;} // import Weak1 into CryptoPP::Weak 24 | #else 25 | using namespace Weak1; // import Weak1 into CryptoPP with warning 26 | #ifdef __GNUC__ 27 | #warning "You may be using a weak algorithm that has been retained for backwards compatibility. Please '#define CRYPTOPP_ENABLE_NAMESPACE_WEAK 1' before including this .h file and prepend the class name with 'Weak::' to remove this warning." 28 | #else 29 | #pragma message("You may be using a weak algorithm that has been retained for backwards compatibility. Please '#define CRYPTOPP_ENABLE_NAMESPACE_WEAK 1' before including this .h file and prepend the class name with 'Weak::' to remove this warning.") 30 | #endif 31 | #endif 32 | 33 | NAMESPACE_END 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /Src/100_System/LogWorker.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include "Log.h" 5 | 6 | namespace core 7 | { 8 | namespace internal 9 | { 10 | struct ST_LOG_CONTEXT 11 | { 12 | HANDLE hFileCS; 13 | DWORD dwProcessID; 14 | DWORD dwInputFlag; 15 | DWORD dwOutputFlag; 16 | DWORD dwMaxFileSize; 17 | DWORD dwMaxFileCount; 18 | E_LOG_ROTATION nRotationType; 19 | std::wstring strOutputFile; 20 | std::string strID; 21 | ST_SYSTEMTIME stLastTime; 22 | ST_SYSTEMTIME stLastCheckTime; 23 | void(*fpCustomOutput)(const char* pszPrefix, const char* pszMsg); 24 | 25 | ST_LOG_CONTEXT(void); 26 | ~ST_LOG_CONTEXT(void); 27 | }; 28 | 29 | class CGlobalLogContext : public ST_LOG_CONTEXT 30 | { 31 | CGlobalLogContext(void); 32 | ~CGlobalLogContext(void); 33 | 34 | public: 35 | static CGlobalLogContext* GetInstance(void) 36 | { 37 | static CGlobalLogContext instance; 38 | return &instance; 39 | } 40 | }; 41 | 42 | inline CGlobalLogContext* GlobalLog(void) { return CGlobalLogContext::GetInstance(); } 43 | 44 | void Log_FormatV(DWORD dwInputType, const char* pszFormat, va_list vaList); 45 | void Log_FormatV(DWORD dwInputType, const wchar_t* pszFormat, va_list vaList); 46 | void Log_FormatVEx(ST_LOG_CONTEXT* pContext, DWORD dwInputType, const char* pszFormat, va_list vaList); 47 | void Log_FormatVEx(ST_LOG_CONTEXT* pContext, DWORD dwInputType, const wchar_t* pszFormat, va_list vaList); 48 | } 49 | } -------------------------------------------------------------------------------- /Src/__Common/ErrorCode.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | typedef int ECODE; 4 | 5 | #define EC_SUCCESS 0 6 | #define EC_INVALID_FILE 20000 7 | #define EC_ENDOFFILE 20001 8 | #define EC_NO_FILE 20002 9 | #define EC_ALREADY_CREATED 20003 10 | #define EC_ALREADY_EXISTS 20004 11 | #define EC_AUTHORIZATION_ERROR 20005 12 | #define EC_NOT_ENOUGH_MEMORY 20006 13 | #define EC_NO_DATA 20007 14 | #define EC_WRITE_FAILURE 20008 15 | #define EC_READ_FAILURE 20009 16 | #define EC_INVALID_DATA 20010 17 | #define EC_INVALID_BOM_TYPE 20011 18 | #define EC_INVALID_FUNCTION 20012 19 | #define EC_INVALID_BLOCK 20013 20 | #define EC_INVALID_HANDLE 20014 21 | #define EC_INVALID_ARGUMENT 20015 22 | #define EC_NOT_IMPLEMENTED 20016 23 | #define EC_NOT_SUPPORTED 20017 24 | #define EC_INTERNAL_ERROR 20018 25 | #define EC_TIMEOUT 20019 26 | #define EC_ABANDONED 20020 27 | #define EC_CANCELED 20021 28 | #define EC_CONNECTION_LIMIT 20022 29 | #define EC_DISCONNECTED 20023 30 | #define EC_INVALID_IP_STRING 20024 31 | #define EC_DATA_FULL 20025 32 | #define EC_MORE_DATA 20026 33 | #define EC_NOT_CONNECTED 20027 34 | #define EC_OPEN_FAILURE 20028 35 | #define EC_COPY_FAILURE 20029 36 | #define EC_CREATING_DIRECTORY_FAILURE 20030 37 | 38 | #define EC_ALREADY_INUSE 20040 39 | #define EC_SYSTEM_ERROR 20041 40 | #define EC_DEVICE_FAILURE 20042 41 | #define EC_NOT_CREATED 20043 42 | #define EC_NOT_READY 20044 43 | 44 | #define EC_MALICIOUS_LOOP 20060 45 | #define EC_CORRUPTED_DATA 20061 -------------------------------------------------------------------------------- /Src/001_Encoder/rc4.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "rc4.h" 3 | namespace core { 4 | void RC4Init(RC4_CTX* rcContext, const unsigned char* key, DWORD dwKeyLength) 5 | { 6 | BYTE K[256]; 7 | 8 | WORD wIndex = 0; 9 | for (wIndex = 0; wIndex < 256; wIndex++) 10 | { 11 | rcContext->SBox[wIndex] = wIndex; 12 | K[wIndex] = key[wIndex % dwKeyLength]; 13 | } 14 | 15 | WORD wSwapPointerIndex = 0; 16 | for (wIndex = 0; wIndex < 256; wIndex++) 17 | { 18 | wSwapPointerIndex = (wSwapPointerIndex + rcContext->SBox[wIndex] + K[wIndex]) % 256; 19 | Rc4Swap(rcContext->SBox[wIndex], rcContext->SBox[wSwapPointerIndex]); 20 | } 21 | 22 | rcContext->wIndex = 0; 23 | rcContext->wSwapPointerIndex = 0; 24 | } 25 | 26 | void RC4Update(RC4_CTX* rcContext, unsigned char* strBuf, DWORD dwBufLength) 27 | { 28 | BYTE temp = 0; 29 | 30 | for (DWORD counter = 0; counter < dwBufLength; counter++) 31 | { 32 | rcContext->wIndex = (rcContext->wIndex + 1) % 256; 33 | rcContext->wSwapPointerIndex = (rcContext->wSwapPointerIndex + rcContext->SBox[rcContext->wIndex]) % 256; 34 | 35 | Rc4Swap(rcContext->SBox[rcContext->wIndex], rcContext->SBox[rcContext->wSwapPointerIndex]); 36 | 37 | temp = (rcContext->SBox[rcContext->wIndex] + rcContext->SBox[rcContext->wSwapPointerIndex]) % 256; 38 | 39 | strBuf[counter] ^= rcContext->SBox[temp]; 40 | } 41 | } 42 | 43 | void Rc4Swap(BYTE& bLeft, BYTE& bRight) 44 | { 45 | BYTE bTemp = bLeft; 46 | bLeft = bRight; 47 | bRight = bTemp; 48 | } 49 | } -------------------------------------------------------------------------------- /Inc/cryptopp700/modexppc.h: -------------------------------------------------------------------------------- 1 | #ifndef CRYPTOPP_MODEXPPC_H 2 | #define CRYPTOPP_MODEXPPC_H 3 | 4 | #include "cryptlib.h" 5 | #include "modarith.h" 6 | #include "integer.h" 7 | #include "algebra.h" 8 | #include "eprecomp.h" 9 | #include "smartptr.h" 10 | #include "pubkey.h" 11 | 12 | #if CRYPTOPP_MSC_VERSION 13 | # pragma warning(push) 14 | # pragma warning(disable: 4231 4275) 15 | #endif 16 | 17 | NAMESPACE_BEGIN(CryptoPP) 18 | 19 | CRYPTOPP_DLL_TEMPLATE_CLASS DL_FixedBasePrecomputationImpl; 20 | 21 | class ModExpPrecomputation : public DL_GroupPrecomputation 22 | { 23 | public: 24 | virtual ~ModExpPrecomputation() {} 25 | 26 | // DL_GroupPrecomputation 27 | bool NeedConversions() const {return true;} 28 | Element ConvertIn(const Element &v) const {return m_mr->ConvertIn(v);} 29 | virtual Element ConvertOut(const Element &v) const {return m_mr->ConvertOut(v);} 30 | const AbstractGroup & GetGroup() const {return m_mr->MultiplicativeGroup();} 31 | Element BERDecodeElement(BufferedTransformation &bt) const {return Integer(bt);} 32 | void DEREncodeElement(BufferedTransformation &bt, const Element &v) const {v.DEREncode(bt);} 33 | 34 | // non-inherited 35 | void SetModulus(const Integer &v) {m_mr.reset(new MontgomeryRepresentation(v));} 36 | const Integer & GetModulus() const {return m_mr->GetModulus();} 37 | 38 | private: 39 | value_ptr m_mr; 40 | }; 41 | 42 | NAMESPACE_END 43 | 44 | #if CRYPTOPP_MSC_VERSION 45 | # pragma warning(pop) 46 | #endif 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /Test/CommonTest/CriticalSectionTest.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include 3 | 4 | ////////////////////////////////////////////////////////////////////////// 5 | struct ST_CS_TEST_DATA 6 | { 7 | CCriticalSection csResult; 8 | std::vector vecResult; 9 | }; 10 | 11 | ////////////////////////////////////////////////////////////////////////// 12 | static int CriticalSectionTestThreadFunc(void* pContext) 13 | { 14 | ST_CS_TEST_DATA* pTestData = (ST_CS_TEST_DATA*)pContext; 15 | 16 | Sleep(100); 17 | { 18 | CCriticalSection::Owner Lock(pTestData->csResult); 19 | pTestData->vecResult.push_back(5); 20 | pTestData->vecResult.push_back(6); 21 | pTestData->vecResult.push_back(7); 22 | pTestData->vecResult.push_back(8); 23 | } 24 | 25 | return 0; 26 | } 27 | 28 | ////////////////////////////////////////////////////////////////////////// 29 | TEST(CommonTest, CriticalSectionTest) 30 | { 31 | ST_CS_TEST_DATA testData; 32 | 33 | HANDLE hThread = CreateThread(CriticalSectionTestThreadFunc, &testData); 34 | EXPECT_TRUE(hThread != NULL); 35 | 36 | { 37 | CCriticalSection::Owner Lock(testData.csResult); 38 | 39 | testData.vecResult.push_back(1); Sleep(100); 40 | testData.vecResult.push_back(2); Sleep(100); 41 | testData.vecResult.push_back(3); Sleep(100); 42 | testData.vecResult.push_back(4); Sleep(100); 43 | } 44 | 45 | JoinThread(hThread); 46 | 47 | size_t i; 48 | for(i=1; i 4 | #include "ISymMode.h" 5 | #include "ISymAlgorithm.h" 6 | 7 | namespace core 8 | { 9 | ////////////////////////////////////////////////////////////////////////// 10 | struct ISymCipher 11 | { 12 | virtual ~ISymCipher(void) {} 13 | virtual ECODE Init(ST_SYM_CIPHER_KEY stKey) = 0; 14 | virtual ECODE Update(LPCBYTE pSrc, size_t tBlockCount, LPBYTE pDest) = 0; 15 | virtual ECODE Final(void) = 0; 16 | }; 17 | 18 | ////////////////////////////////////////////////////////////////////////// 19 | class CSymEncoder : public ISymCipher 20 | { 21 | ISymAlgorithm* m_pAlgorithm ; 22 | ISymEncryptMode* m_pMode ; 23 | 24 | size_t m_tBlockSize ; 25 | 26 | public: 27 | CSymEncoder(ISymAlgorithm* pAlgorithm, ISymEncryptMode* pMode); 28 | virtual ~CSymEncoder(void); 29 | 30 | ECODE Init(ST_SYM_CIPHER_KEY stKey); 31 | ECODE Update(LPCBYTE pSrc, size_t tBlockCount, LPBYTE pDest); 32 | ECODE Final(void); 33 | }; 34 | 35 | ////////////////////////////////////////////////////////////////////////// 36 | class CSymDecoder : public ISymCipher 37 | { 38 | ISymAlgorithm* m_pAlgorithm ; 39 | ISymDecryptMode* m_pMode ; 40 | 41 | size_t m_tBlockSize ; 42 | 43 | public: 44 | CSymDecoder(ISymAlgorithm* pAlgorithm, ISymDecryptMode* pMode); 45 | virtual ~CSymDecoder(void); 46 | 47 | ECODE Init(ST_SYM_CIPHER_KEY stKey); 48 | ECODE Update(LPCBYTE pSrc, size_t tBlockCount, LPBYTE pDest); 49 | ECODE Final(void); 50 | }; 51 | } 52 | -------------------------------------------------------------------------------- /Src/300_Formatter/FormatterSuper.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "FormatterSuper.h" 3 | 4 | namespace fmt_internal 5 | { 6 | using namespace core; 7 | 8 | CFormatterSuper::CFormatterSuper(core::IChannel& channel) 9 | : m_Channel(channel) 10 | { 11 | 12 | } 13 | 14 | CFormatterSuper::~CFormatterSuper() 15 | { 16 | } 17 | 18 | bool CFormatterSuper::Transform(const IFormatterObject* pObject, std::tstring* pOutErrMsg, std::tstring* pRootName) 19 | { 20 | return Transform((IFormatterObject*)pObject, pOutErrMsg, pRootName); 21 | } 22 | 23 | bool CFormatterSuper::Transform(IFormatterObject* pObject, std::tstring* pOutErrMsg, std::tstring* pRootName) 24 | { 25 | std::tstring strErrMsg; 26 | if (!OnPrepare(pObject, strErrMsg)) 27 | { 28 | if (pOutErrMsg) 29 | (*pOutErrMsg) = std::move(strErrMsg); 30 | return false; 31 | } 32 | 33 | std::tstring strRootName; 34 | if (pRootName) 35 | strRootName = (*pRootName); 36 | 37 | OnBeginRoot(strRootName); 38 | pObject->OnSync(*this); 39 | OnEndRoot(); 40 | 41 | if (pRootName) 42 | (*pRootName) = std::move(strRootName); 43 | return true; 44 | } 45 | 46 | IFormatter& CFormatterSuper::OnSync(std::tstring& strKey, IFormatterObject* pObject) 47 | { 48 | OnBeginObject(strKey); 49 | pObject->OnSync(*this); 50 | OnEndObject(); 51 | return *this; 52 | } 53 | 54 | IFormatter& CFormatterSuper::OnSync(std::tstring& strKey, IFormatterObject** pObject) 55 | { 56 | OnBeginObject(strKey); 57 | (*pObject)->OnSync(*this); 58 | OnEndObject(); 59 | return *this; 60 | } 61 | } 62 | 63 | -------------------------------------------------------------------------------- /Inc/cryptopp700/camellia.h: -------------------------------------------------------------------------------- 1 | // camellia.h - originally written and placed in the public domain by Wei Dai 2 | 3 | /// \file camellia.h 4 | /// \brief Classes for the Camellia block cipher 5 | 6 | #ifndef CRYPTOPP_CAMELLIA_H 7 | #define CRYPTOPP_CAMELLIA_H 8 | 9 | #include "config.h" 10 | #include "seckey.h" 11 | #include "secblock.h" 12 | 13 | NAMESPACE_BEGIN(CryptoPP) 14 | 15 | /// \brief Camellia block cipher information 16 | struct Camellia_Info : public FixedBlockSize<16>, public VariableKeyLength<16, 16, 32, 8> 17 | { 18 | CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return "Camellia";} 19 | }; 20 | 21 | /// \brief Camellia block cipher 22 | /// \sa Camellia 23 | class Camellia : public Camellia_Info, public BlockCipherDocumentation 24 | { 25 | class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl 26 | { 27 | public: 28 | void UncheckedSetKey(const byte *key, unsigned int keylen, const NameValuePairs ¶ms); 29 | void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const; 30 | 31 | protected: 32 | CRYPTOPP_ALIGN_DATA(4) static const byte s1[256]; 33 | static const word32 SP[4][256]; 34 | 35 | unsigned int m_rounds; 36 | SecBlock m_key; 37 | }; 38 | 39 | public: 40 | typedef BlockCipherFinal Encryption; 41 | typedef BlockCipherFinal Decryption; 42 | }; 43 | 44 | typedef Camellia::Encryption CamelliaEncryption; 45 | typedef Camellia::Decryption CamelliaDecryption; 46 | 47 | NAMESPACE_END 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /Src/200_Common/IMemoryAccess.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace core 6 | { 7 | struct IMemoryAccess 8 | { 9 | template 10 | T Cast(size_t tOffset = 0) 11 | { 12 | return (T)(Ptr() + tOffset); 13 | } 14 | 15 | template 16 | ECODE Query(size_t tOffset, T* pOut) 17 | { 18 | LPBYTE pPtr = Ptr(); 19 | if( NULL == pPtr ) 20 | return EC_INVALID_DATA; 21 | 22 | if( Size() < (tOffset + sizeof(T)) ) 23 | return EC_NO_DATA; 24 | 25 | memcpy(pOut, pPtr + tOffset, sizeof(T)); 26 | return EC_SUCCESS; 27 | } 28 | 29 | template 30 | T* ArrayAt(size_t tIndex) 31 | { 32 | T* pArray = (T*)Ptr(); 33 | if( NULL == pArray ) 34 | return NULL; 35 | 36 | if( Size() < ((tIndex+1) * sizeof(T)) ) 37 | return NULL; 38 | 39 | return pArray + tIndex; 40 | } 41 | 42 | template 43 | T* Read(size_t& tPos) 44 | { 45 | LPBYTE pPtr = Ptr(); 46 | if( NULL == pPtr ) 47 | return NULL; 48 | 49 | if( Size() < (tPos + sizeof(T)) ) 50 | return NULL; 51 | 52 | T* pRet = (T*)(pPtr + tPos); 53 | tPos += sizeof(T); 54 | return pRet; 55 | } 56 | 57 | ECODE Read(size_t& tPos, void* pDest, size_t tSize) 58 | { 59 | LPBYTE pPtr = Ptr(); 60 | if( NULL == pPtr ) 61 | return EC_NO_DATA; 62 | 63 | if( Size() < (tPos + tSize) ) 64 | return EC_NO_DATA; 65 | 66 | memcpy(pDest, pPtr + tPos, tSize); 67 | tPos += tSize; 68 | return EC_SUCCESS; 69 | } 70 | 71 | virtual LPBYTE Ptr(void) = 0; 72 | virtual size_t Size(void) = 0; 73 | }; 74 | } -------------------------------------------------------------------------------- /Test/CommonTest/SyncQueueTest.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | 3 | ////////////////////////////////////////////////////////////////////////// 4 | int __internal_SyncQueueTest_HelperThread(void* pContext) 5 | { 6 | TSyncQueue* pSyncQueue = (TSyncQueue*)pContext; 7 | 8 | printf("try to wait\n"); 9 | int nItem = 0; 10 | pSyncQueue->Pop(&nItem); 11 | printf("wait finished, %d\n", nItem); 12 | return 0; 13 | } 14 | 15 | ////////////////////////////////////////////////////////////////////////// 16 | TEST(CommonTest, SyncQueueTest_Pop) 17 | { 18 | TSyncQueue TestQueue; 19 | ASSERT_EQ(EC_SUCCESS, TestQueue.Create()); 20 | HANDLE hThread = CreateThread(__internal_SyncQueueTest_HelperThread, &TestQueue); 21 | ASSERT_NE((HANDLE)NULL, hThread); 22 | Sleep(10); 23 | TestQueue.Push(3); 24 | printf("data pushed\n"); 25 | 26 | DWORD dwStartTick = GetTickCount(); 27 | JoinThread(hThread); 28 | DWORD dwElapsedTick = GetTickCount() - dwStartTick; 29 | EXPECT_LT(dwElapsedTick, (DWORD)1000); 30 | TestQueue.Destroy(); 31 | } 32 | 33 | ////////////////////////////////////////////////////////////////////////// 34 | TEST(CommonTest, SyncQueueTest_Destroy) 35 | { 36 | TSyncQueue TestQueue; 37 | ASSERT_EQ((DWORD)EC_SUCCESS, TestQueue.Create()); 38 | HANDLE hThread = CreateThread(__internal_SyncQueueTest_HelperThread, &TestQueue); 39 | ASSERT_NE((HANDLE)NULL, hThread); 40 | Sleep(500); 41 | TestQueue.Destroy(); 42 | 43 | DWORD dwStartTick = GetTickCount(); 44 | JoinThread(hThread); 45 | DWORD dwElapsedTick = GetTickCount() - dwStartTick; 46 | EXPECT_LT(dwElapsedTick, (DWORD)1000); 47 | } 48 | -------------------------------------------------------------------------------- /Test/CommonTest/CmdLineHelperTest.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | 3 | TEST(CmdLineHelperTest, args2CmdLine2args) 4 | { 5 | std::vector vecArgs; 6 | vecArgs.push_back(TEXT("1")); 7 | vecArgs.push_back(TEXT("2 3")); 8 | vecArgs.push_back(TEXT("4")); 9 | 10 | std::tstring strCmdLine = MakeCmdLine(vecArgs); 11 | std::vector vecArgsRestored; 12 | ParseCmdLine(strCmdLine, vecArgsRestored); 13 | 14 | ASSERT_EQ(vecArgs.size(), vecArgsRestored.size()); 15 | 16 | for (size_t i = 0; i < vecArgs.size(); i++) 17 | { 18 | EXPECT_EQ(vecArgs[i], vecArgsRestored[i]); 19 | } 20 | } 21 | 22 | TEST(CmdLineHelperTest, CmdLine2args2CmdLine) 23 | { 24 | std::tstring strCmdLine = TEXT("1 \"2 3\" 4"); 25 | 26 | std::vector vecArgs; 27 | ParseCmdLine(strCmdLine, vecArgs); 28 | 29 | std::tstring strCmdLineRestored = MakeCmdLine(vecArgs); 30 | EXPECT_EQ(strCmdLine, strCmdLineRestored); 31 | } 32 | 33 | TEST(CmdLineHelperTest, QuotaionIncludeTest) 34 | { 35 | std::tstring strCmdLine = TEXT("some.exe log-path:\"c:\\hello\\world\""); 36 | 37 | std::vector vecArgs; 38 | ParseCmdLine(strCmdLine, vecArgs); 39 | 40 | std::tstring strCmdLineRestored = MakeCmdLine(vecArgs); 41 | EXPECT_EQ(strCmdLine, strCmdLineRestored); 42 | } 43 | 44 | TEST(CmdLineHelperTest, QuotaionIncludeTest2) 45 | { 46 | std::tstring strCmdLine = TEXT("some.exe log-path:\"c:\\hello world\""); 47 | 48 | std::vector vecArgs; 49 | ParseCmdLine(strCmdLine, vecArgs); 50 | 51 | std::tstring strCmdLineRestored = MakeCmdLine(vecArgs); 52 | EXPECT_EQ(strCmdLine, strCmdLineRestored); 53 | } 54 | -------------------------------------------------------------------------------- /Test/CommonTest/MutexTest.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include 3 | 4 | ////////////////////////////////////////////////////////////////////////// 5 | struct ST_MUTEX_TEST_DATA 6 | { 7 | LPCTSTR pszMutexKey; 8 | std::vector vecResult; 9 | }; 10 | 11 | ////////////////////////////////////////////////////////////////////////// 12 | static int MutexTestThreadFunc(void* pContext) 13 | { 14 | ST_MUTEX_TEST_DATA* pTestData = (ST_MUTEX_TEST_DATA*)pContext; 15 | CMutex mutex(pTestData->pszMutexKey); 16 | 17 | Sleep(100); 18 | { 19 | CMutex::Owner Lock(mutex); 20 | pTestData->vecResult.push_back(5); 21 | pTestData->vecResult.push_back(6); 22 | pTestData->vecResult.push_back(7); 23 | pTestData->vecResult.push_back(8); 24 | } 25 | 26 | return 0; 27 | } 28 | 29 | ////////////////////////////////////////////////////////////////////////// 30 | TEST(CommonTest, MutexTest) 31 | { 32 | ST_MUTEX_TEST_DATA testData; 33 | testData.pszMutexKey = TEXT("1944"); 34 | 35 | CMutex mutex(testData.pszMutexKey); 36 | 37 | HANDLE hThread = CreateThread(MutexTestThreadFunc, &testData); 38 | EXPECT_TRUE(hThread != NULL); 39 | 40 | { 41 | CMutex::Owner Lock(mutex); 42 | 43 | testData.vecResult.push_back(1); Sleep(100); 44 | testData.vecResult.push_back(2); Sleep(100); 45 | testData.vecResult.push_back(3); Sleep(100); 46 | testData.vecResult.push_back(4); Sleep(100); 47 | } 48 | 49 | JoinThread(hThread); 50 | 51 | EXPECT_GT(testData.vecResult.size(), 0U); 52 | 53 | size_t i; 54 | for(i=1; i 12 | struct INTERNAL_TEMPLATE_THREAD_DATA : public INTERNAL_COMMON_THREAD_DATA 13 | { 14 | T* pInstance; 15 | int (T::*pfMemberFunc)(void* pContext); 16 | void* pContext; 17 | int ThreadFunc(void) { return (pInstance->*pfMemberFunc)(pContext); } 18 | }; 19 | 20 | int InternalThreadCaller(void* pContext); 21 | 22 | template 23 | HANDLE CreateThread(T* pInstance, int (T::*pfEntry)(void*), void* pContext, E_THREAD_PRIORITY nPriority = THREAD_PRIORITY_MIDDLE) 24 | { 25 | INTERNAL_TEMPLATE_THREAD_DATA* pThreadData = new(std::nothrow) INTERNAL_TEMPLATE_THREAD_DATA; 26 | if( NULL == pThreadData ) 27 | return NULL; 28 | pThreadData->pInstance = pInstance; 29 | pThreadData->pfMemberFunc = pfEntry; 30 | pThreadData->pContext = pContext; 31 | return CreateThread(InternalThreadCaller, pThreadData, nPriority); 32 | } 33 | 34 | template 35 | HANDLE CreateClassMethodThread(T* pInstance, int (T::*pfEntry)(void*), void* pContext, E_THREAD_PRIORITY nPriority = THREAD_PRIORITY_MIDDLE) 36 | { 37 | INTERNAL_TEMPLATE_THREAD_DATA* pThreadData = new(std::nothrow) INTERNAL_TEMPLATE_THREAD_DATA; 38 | if( NULL == pThreadData ) 39 | return NULL; 40 | pThreadData->pInstance = pInstance; 41 | pThreadData->pfMemberFunc = pfEntry; 42 | pThreadData->pContext = pContext; 43 | return CreateThread(InternalThreadCaller, pThreadData, nPriority); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Src/200_Common/Mutex.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "Mutex.h" 3 | 4 | namespace core 5 | { 6 | ////////////////////////////////////////////////////////////////////////// 7 | CMutex::~CMutex(void) 8 | { 9 | if( NULL == m_hMutex ) 10 | return; 11 | 12 | CloseMutex(m_hMutex); 13 | m_hMutex = NULL; 14 | } 15 | 16 | ////////////////////////////////////////////////////////////////////////// 17 | void CMutex::Enter(void) 18 | { 19 | if( NULL == m_hMutex ) 20 | { 21 | Log_Error("Enter Mutex, m_hMutex is NULL"); 22 | return; 23 | } 24 | EWAIT nRet = WaitForMutex(m_hMutex, INFINITE); 25 | if( WAIT_OBJECT_0_ != nRet ) 26 | Log_Error("WaitForMutex calling failure, %d", nRet); 27 | } 28 | 29 | ////////////////////////////////////////////////////////////////////////// 30 | void CMutex::Leave(void) 31 | { 32 | if( NULL == m_hMutex ) 33 | { 34 | Log_Error("Leave Mutex, m_hMutex is NULL"); 35 | return; 36 | } 37 | 38 | if( !ReleaseMutex(m_hMutex) ) 39 | Log_Error("ReleaseMutex calling failure"); 40 | } 41 | 42 | ////////////////////////////////////////////////////////////////////////// 43 | CMutex::Owner::Owner(CMutex& obj) 44 | : m_Instance(obj) 45 | { 46 | if( NULL == m_Instance.m_hMutex ) 47 | { 48 | Log_Error("EnterMutex, hMutex is NULL"); 49 | return; 50 | } 51 | m_Instance.Enter(); 52 | } 53 | 54 | ////////////////////////////////////////////////////////////////////////// 55 | CMutex::Owner::~Owner(void) 56 | { 57 | if( NULL == m_Instance.m_hMutex ) 58 | { 59 | Log_Error("LeaveMutex, hMutex is NULL"); 60 | return; 61 | } 62 | m_Instance.Leave(); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /Inc/cryptopp700/ttmac.h: -------------------------------------------------------------------------------- 1 | // ttmac.h - written and placed in the public domain by Kevin Springle 2 | 3 | /// \file ttmac.h 4 | /// \brief Classes for the TTMAC message authentication code 5 | 6 | #ifndef CRYPTOPP_TTMAC_H 7 | #define CRYPTOPP_TTMAC_H 8 | 9 | #include "seckey.h" 10 | #include "iterhash.h" 11 | #include "secblock.h" 12 | 13 | NAMESPACE_BEGIN(CryptoPP) 14 | 15 | /// \brief TTMAC message authentication code information 16 | class CRYPTOPP_NO_VTABLE TTMAC_Base : public FixedKeyLength<20>, public IteratedHash 17 | { 18 | public: 19 | static std::string StaticAlgorithmName() {return std::string("Two-Track-MAC");} 20 | CRYPTOPP_CONSTANT(DIGESTSIZE=20) 21 | 22 | unsigned int DigestSize() const {return DIGESTSIZE;}; 23 | void UncheckedSetKey(const byte *userKey, unsigned int keylength, const NameValuePairs ¶ms); 24 | void TruncatedFinal(byte *mac, size_t size); 25 | 26 | protected: 27 | static void Transform (word32 *digest, const word32 *X, bool last); 28 | void HashEndianCorrectedBlock(const word32 *data) {Transform(m_digest, data, false);} 29 | void Init(); 30 | word32* StateBuf() {return m_digest;} 31 | 32 | FixedSizeSecBlock m_digest; 33 | FixedSizeSecBlock m_key; 34 | }; 35 | 36 | /// \brief Two-Track-MAC message authentication code 37 | /// \tparam T HashTransformation class 38 | /// \details 160-bit MAC with 160-bit key 39 | /// \sa MessageAuthenticationCode(), Two-Track-MAC 40 | DOCUMENTED_TYPEDEF(MessageAuthenticationCodeFinal, TTMAC) 41 | 42 | NAMESPACE_END 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /Src/000_String/Unicode.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "Unicode.h" 3 | #include "UnicodeEncoding.h" 4 | 5 | namespace core 6 | { 7 | ////////////////////////////////////////////////////////////////////////// 8 | std::string ANSIFromUTF8(std::string strInput, size_t* ptReadSize) 9 | { 10 | if( strInput.empty() ) 11 | return ""; 12 | 13 | std::vector vecUTF16; 14 | { 15 | size_t tRequiredCch = UTF8_TO_UTF16(strInput.c_str(), strInput.length(), NULL, 0); 16 | vecUTF16.resize(tRequiredCch); 17 | UTF8_TO_UTF16(strInput.c_str(), strInput.length(), &vecUTF16[0], tRequiredCch, ptReadSize); 18 | } 19 | 20 | std::string strRet; 21 | size_t tRequiredCch = UTF16_TO_ANSI(&vecUTF16[0], vecUTF16.size(), NULL, 0); 22 | strRet.resize(tRequiredCch); 23 | UTF16_TO_ANSI(&vecUTF16[0], vecUTF16.size(), (char*)strRet.c_str(), tRequiredCch); 24 | return strRet; 25 | } 26 | 27 | ////////////////////////////////////////////////////////////////////////// 28 | std::string UTF8FromANSI(std::string strInput, size_t* ptReadSize) 29 | { 30 | if( strInput.empty() ) 31 | return ""; 32 | 33 | std::vector vecUTF16; 34 | { 35 | size_t tRequiredCch = ANSI_TO_UTF16(strInput.c_str(), strInput.length(), NULL, 0); 36 | vecUTF16.resize(tRequiredCch); 37 | ANSI_TO_UTF16(strInput.c_str(), strInput.length(), &vecUTF16[0], tRequiredCch, ptReadSize); 38 | } 39 | 40 | std::string strRet; 41 | size_t tRequiredCch = UTF16_TO_UTF8(&vecUTF16[0], vecUTF16.size(), NULL, 0); 42 | strRet.resize(tRequiredCch); 43 | UTF16_TO_UTF8(&vecUTF16[0], vecUTF16.size(), (char*)strRet.c_str(), tRequiredCch); 44 | return strRet; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Src/001_Encoder/HashFunction.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define HashFile BuildHash // for lower compatibility 4 | 5 | namespace core 6 | { 7 | void AppendData(std::vector& vecDest, const std::vector& vecData); 8 | void AppendData(std::vector& vecDest, LPCBYTE pData, size_t tDataSize); 9 | 10 | std::string BuildHash(E_HASH_TYPE nType, const std::vector& vecData); 11 | void BuildHash(E_HASH_TYPE nType, LPCBYTE pData, size_t tDataSize, std::vector& outHash); 12 | void BuildHash(E_HASH_TYPE nType, const std::vector& vecData, std::vector& outHash); 13 | 14 | ECODE BuildHMAC(E_HASH_TYPE nHashType, const std::vector& Key, LPCBYTE pMessage, size_t tMessageSize, std::vector& outResult); 15 | ECODE BuildHMAC(E_HASH_TYPE nHashType, const std::vector& Key, const std::vector& Message, std::vector& outResult); 16 | ECODE BuildHMAC(E_HASH_TYPE nHashType, const std::string& Key, const std::string& Message, std::vector& outResult); 17 | 18 | std::string BuildStringHash(E_HASH_TYPE nType, std::string strContext); 19 | std::wstring BuildStringHash(E_HASH_TYPE nType, std::wstring strContext); 20 | std::string BuildStringHashA(E_HASH_TYPE nType, std::string strContext); 21 | std::string BuildStringHashA(E_HASH_TYPE nType, std::wstring strContext); 22 | std::wstring BuildStringHashW(E_HASH_TYPE nType, std::string strContext); 23 | std::wstring BuildStringHashW(E_HASH_TYPE nType, std::wstring strContext); 24 | bool BuildStringHash(E_HASH_TYPE nType, std::string strContext, std::vector& vecHash); 25 | bool BuildStringHash(E_HASH_TYPE nType, std::wstring strContext, std::vector& vecHash); 26 | } -------------------------------------------------------------------------------- /Inc/cryptopp700/blumshub.h: -------------------------------------------------------------------------------- 1 | // blumshub.h - originally written and placed in the public domain by Wei Dai 2 | 3 | /// \file blumshub.h 4 | /// \brief Classes for Blum Blum Shub generator 5 | 6 | #ifndef CRYPTOPP_BLUMSHUB_H 7 | #define CRYPTOPP_BLUMSHUB_H 8 | 9 | #include "cryptlib.h" 10 | #include "modarith.h" 11 | #include "integer.h" 12 | 13 | NAMESPACE_BEGIN(CryptoPP) 14 | 15 | /// BlumBlumShub without factorization of the modulus 16 | class PublicBlumBlumShub : public RandomNumberGenerator, 17 | public StreamTransformation 18 | { 19 | public: 20 | virtual ~PublicBlumBlumShub() {} 21 | 22 | PublicBlumBlumShub(const Integer &n, const Integer &seed); 23 | 24 | unsigned int GenerateBit(); 25 | byte GenerateByte(); 26 | void GenerateBlock(byte *output, size_t size); 27 | void ProcessData(byte *outString, const byte *inString, size_t length); 28 | 29 | bool IsSelfInverting() const {return true;} 30 | bool IsForwardTransformation() const {return true;} 31 | 32 | protected: 33 | ModularArithmetic modn; 34 | Integer current; 35 | word maxBits, bitsLeft; 36 | }; 37 | 38 | /// BlumBlumShub with factorization of the modulus 39 | class BlumBlumShub : public PublicBlumBlumShub 40 | { 41 | public: 42 | virtual ~BlumBlumShub() {} 43 | 44 | // Make sure p and q are both primes congruent to 3 mod 4 and at least 512 bits long, 45 | // seed is the secret key and should be about as big as p*q 46 | BlumBlumShub(const Integer &p, const Integer &q, const Integer &seed); 47 | 48 | bool IsRandomAccess() const {return true;} 49 | void Seek(lword index); 50 | 51 | protected: 52 | const Integer p, q; 53 | const Integer x0; 54 | }; 55 | 56 | NAMESPACE_END 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /Src/001_Encoder/Type.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../__Common/Type.h" 4 | #include "../__Common/Define.h" 5 | #include "../__Common/ErrorCode.h" 6 | 7 | namespace core 8 | { 9 | enum E_HASH_TYPE 10 | { 11 | HASH_TYPE_NONE = 0, 12 | HASH_TYPE_MD5 , 13 | HASH_TYPE_SHA1 , 14 | HASH_TYPE_SHA256 , 15 | HASH_TYPE_SHA512 , 16 | HASH_TYPE_HAS160 , 17 | HASH_TYPE_SSDEEP , 18 | HASH_TYPE_COUNT , 19 | HASH_TYPE_UNDEFINED , 20 | }; 21 | 22 | enum E_SYM_CIPHER_TYPE 23 | { 24 | SYM_CIPHER_TYPE_PLAIN = 0, 25 | SYM_CIPHER_TYPE_SEED128 , 26 | SYM_CIPHER_TYPE_SEED256 , 27 | SYM_CIPHER_TYPE_AES128 , 28 | SYM_CIPHER_TYPE_AES192 , 29 | SYM_CIPHER_TYPE_AES256 , 30 | SYM_CIPHER_TYPE_COUNT , 31 | SYM_CIPHER_TYPE_UNDEFINED , 32 | }; 33 | 34 | enum E_SYM_CIPHER_MODE 35 | { 36 | SYM_CIPHER_MODE_PLAIN = 0, 37 | SYM_CIPHER_MODE_ECB , 38 | SYM_CIPHER_MODE_CBC , 39 | SYM_CIPHER_MODE_PCBC , 40 | SYM_CIPHER_MODE_CFB , 41 | SYM_CIPHER_MODE_OFB , 42 | SYM_CIPHER_MODE_CTR , 43 | SYM_CIPHER_MODE_COUNT , 44 | SYM_CIPHER_MODE_UNDEFINED , 45 | }; 46 | 47 | enum E_PUBKEY_CIPHER_TYPE 48 | { 49 | PUBKEY_CIPHER_TYPE_RSA = 0, 50 | PUBKEY_CIPHER_TYPE_ELGAMAL , 51 | PUBKEY_CIPHER_TYPE_ECC , 52 | PUBKEY_CIPHER_TYPE_COUNT , 53 | PUBKEY_CIPHER_TYPE_UNDEFINED, 54 | }; 55 | 56 | enum E_CIPHER_METHOD 57 | { 58 | CIPHER_METHOD_UNDEFINED = 0, 59 | CIPHER_METHOD_ENCRYPT , 60 | CIPHER_METHOD_DECRYPT , 61 | }; 62 | 63 | struct ST_SYM_CIPHER_KEY 64 | { 65 | E_SYM_CIPHER_TYPE nType; 66 | E_SYM_CIPHER_MODE nMode; 67 | DWORD dwBlockSize; 68 | BYTE btInitialVector[16]; 69 | BYTE btKey[32]; 70 | }; 71 | } 72 | -------------------------------------------------------------------------------- /Src/001_Encoder/SymAES.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "SymAES.h" 3 | #include "AES/aes.h" 4 | 5 | namespace core 6 | { 7 | ////////////////////////////////////////////////////////////////////////// 8 | CSymAES::CSymAES(size_t tLengthOfKey) 9 | : m_pCtx(NULL) 10 | , m_tLengthOfKey(tLengthOfKey) 11 | { 12 | m_pCtx = new(std::nothrow) aes_ctx; 13 | } 14 | 15 | ////////////////////////////////////////////////////////////////////////// 16 | CSymAES::~CSymAES(void) 17 | { 18 | if( m_pCtx ) 19 | delete (aes_ctx*)m_pCtx; 20 | } 21 | 22 | ////////////////////////////////////////////////////////////////////////// 23 | ECODE CSymAES::Init(E_CIPHER_METHOD nMethod, const ST_SYM_CIPHER_KEY& stKey) 24 | { 25 | aes_ctx* pCtx = (aes_ctx*)m_pCtx; 26 | pCtx->n_rnd = 0; 27 | pCtx->n_blk = (aes_32t)BlockSize(); 28 | switch(nMethod) 29 | { 30 | case CIPHER_METHOD_ENCRYPT: 31 | aes_enc_key(stKey.btKey, m_tLengthOfKey, pCtx); 32 | break; 33 | case CIPHER_METHOD_DECRYPT: 34 | aes_dec_key(stKey.btKey, m_tLengthOfKey, pCtx); 35 | break; 36 | default: 37 | return EC_INVALID_ARGUMENT; 38 | } 39 | return EC_SUCCESS; 40 | } 41 | 42 | ////////////////////////////////////////////////////////////////////////// 43 | ECODE CSymAES::Encrypt(LPCBYTE pSrc, LPBYTE pDest) 44 | { 45 | if( aes_good != aes_enc_blk(pSrc, pDest, (aes_ctx*)m_pCtx) ) 46 | return EC_INVALID_FUNCTION; 47 | return EC_SUCCESS; 48 | } 49 | 50 | ////////////////////////////////////////////////////////////////////////// 51 | ECODE CSymAES::Decrypt(LPCBYTE pSrc, LPBYTE pDest) 52 | { 53 | if( aes_good != aes_dec_blk(pSrc, pDest, (aes_ctx*)m_pCtx) ) 54 | return EC_INVALID_FUNCTION; 55 | return EC_SUCCESS; 56 | } 57 | } 58 | 59 | -------------------------------------------------------------------------------- /Src/100_System/SharedPtr.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef DEBUG_LINUX 4 | #define PRINT_DEBUG printf 5 | #else 6 | #define PRINT_DEBUG(...) 7 | #endif 8 | 9 | namespace core 10 | { 11 | template 12 | class CSharedPtr 13 | { 14 | T* m_pInstance; 15 | int* m_pnReferenceCount; 16 | 17 | public: 18 | CSharedPtr(void) 19 | : m_pInstance(NULL) 20 | , m_pnReferenceCount(NULL) 21 | { 22 | } 23 | 24 | CSharedPtr(T* pInstance) 25 | : m_pInstance(pInstance) 26 | , m_pnReferenceCount(NULL) 27 | { 28 | m_pnReferenceCount = new int(1); 29 | PRINT_DEBUG("m_pnReferenceCount=%d\n", *m_pnReferenceCount); 30 | } 31 | 32 | CSharedPtr(const CSharedPtr& other) 33 | : m_pInstance(other.m_pInstance) 34 | , m_pnReferenceCount(other.m_pnReferenceCount) 35 | { 36 | __sync_add_and_fetch(m_pnReferenceCount, 1); 37 | PRINT_DEBUG("m_pnReferenceCount=%d\n", *m_pnReferenceCount); 38 | } 39 | 40 | ~CSharedPtr(void) 41 | { 42 | if( m_pnReferenceCount && (0 == __sync_sub_and_fetch(m_pnReferenceCount, 1)) ) 43 | { 44 | PRINT_DEBUG("m_pnReferenceCount=%d 1\n", *m_pnReferenceCount); 45 | delete m_pInstance; 46 | delete m_pnReferenceCount; 47 | } 48 | else if( m_pnReferenceCount ) 49 | { 50 | PRINT_DEBUG("m_pnReferenceCount=%d 2\n", *m_pnReferenceCount); 51 | } 52 | } 53 | 54 | CSharedPtr& operator=(const CSharedPtr& other) 55 | { 56 | m_pInstance = other.m_pInstance; 57 | m_pnReferenceCount = other.m_pnReferenceCount; 58 | __sync_add_and_fetch(m_pnReferenceCount, 1); 59 | PRINT_DEBUG("m_pnReferenceCount=%d\n", *m_pnReferenceCount); 60 | return *this; 61 | } 62 | 63 | T* operator->() const 64 | { 65 | return m_pInstance; 66 | } 67 | }; 68 | } 69 | -------------------------------------------------------------------------------- /Inc/cryptopp700/dsa.h: -------------------------------------------------------------------------------- 1 | // dsa.h - originally written and placed in the public domain by Wei Dai 2 | 3 | /// \file dsa.h 4 | /// \brief Classes for the DSA signature algorithm 5 | 6 | #ifndef CRYPTOPP_DSA_H 7 | #define CRYPTOPP_DSA_H 8 | 9 | #include "cryptlib.h" 10 | #include "gfpcrypt.h" 11 | 12 | NAMESPACE_BEGIN(CryptoPP) 13 | 14 | /// \brief DSA Signature Format 15 | /// \details The DSA signature format used by Crypto++ is as defined by IEEE P1363. 16 | /// Java and .Net use the DER format, and OpenPGP uses the OpenPGP format. 17 | enum DSASignatureFormat { 18 | /// \brief Crypto++ native signature encoding format 19 | DSA_P1363, 20 | /// \brief signature encoding format used by Java and .Net 21 | DSA_DER, 22 | /// \brief OpenPGP signature encoding format 23 | DSA_OPENPGP 24 | }; 25 | 26 | /// \brief Converts between signature encoding formats 27 | /// \param buffer byte buffer for the converted signature encoding 28 | /// \param bufferSize the length of the converted signature encoding buffer 29 | /// \param toFormat the source signature format 30 | /// \param signature byte buffer for the existing signature encoding 31 | /// \param signatureLen the length of the existing signature encoding buffer 32 | /// \param fromFormat the source signature format 33 | /// \details This function converts between these formats, and returns length 34 | /// of signature in the target format. If toFormat == DSA_P1363, then 35 | /// bufferSize must equal publicKey.SignatureLength() 36 | /// \since Crypto++ 1.0 37 | size_t DSAConvertSignatureFormat(byte *buffer, size_t bufferSize, DSASignatureFormat toFormat, 38 | const byte *signature, size_t signatureLen, DSASignatureFormat fromFormat); 39 | 40 | NAMESPACE_END 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /Inc/cryptopp700/gf256.h: -------------------------------------------------------------------------------- 1 | // gf256.h - originally written and placed in the public domain by Wei Dai 2 | 3 | /// \file gf256.h 4 | /// \brief Classes and functions for schemes over GF(256) 5 | 6 | #ifndef CRYPTOPP_GF256_H 7 | #define CRYPTOPP_GF256_H 8 | 9 | #include "cryptlib.h" 10 | #include "misc.h" 11 | 12 | NAMESPACE_BEGIN(CryptoPP) 13 | 14 | /// \brief GF(256) with polynomial basis 15 | class GF256 16 | { 17 | public: 18 | typedef byte Element; 19 | typedef int RandomizationParameter; 20 | 21 | GF256(byte modulus) : m_modulus(modulus) {} 22 | 23 | Element RandomElement(RandomNumberGenerator &rng, int ignored = 0) const 24 | {CRYPTOPP_UNUSED(ignored); return rng.GenerateByte();} 25 | 26 | bool Equal(Element a, Element b) const 27 | {return a==b;} 28 | 29 | Element Zero() const 30 | {return 0;} 31 | 32 | Element Add(Element a, Element b) const 33 | {return a^b;} 34 | 35 | Element& Accumulate(Element &a, Element b) const 36 | {return a^=b;} 37 | 38 | Element Inverse(Element a) const 39 | {return a;} 40 | 41 | Element Subtract(Element a, Element b) const 42 | {return a^b;} 43 | 44 | Element& Reduce(Element &a, Element b) const 45 | {return a^=b;} 46 | 47 | Element Double(Element a) const 48 | {CRYPTOPP_UNUSED(a); return 0;} 49 | 50 | Element One() const 51 | {return 1;} 52 | 53 | Element Multiply(Element a, Element b) const; 54 | 55 | Element Square(Element a) const 56 | {return Multiply(a, a);} 57 | 58 | bool IsUnit(Element a) const 59 | {return a != 0;} 60 | 61 | Element MultiplicativeInverse(Element a) const; 62 | 63 | Element Divide(Element a, Element b) const 64 | {return Multiply(a, MultiplicativeInverse(b));} 65 | 66 | private: 67 | word m_modulus; 68 | }; 69 | 70 | NAMESPACE_END 71 | 72 | #endif 73 | -------------------------------------------------------------------------------- /Inc/cryptopp700/serpent.h: -------------------------------------------------------------------------------- 1 | // serpent.h - originally written and placed in the public domain by Wei Dai 2 | 3 | /// \file serpent.h 4 | /// \brief Classes for the Serpent block cipher 5 | 6 | #ifndef CRYPTOPP_SERPENT_H 7 | #define CRYPTOPP_SERPENT_H 8 | 9 | #include "seckey.h" 10 | #include "secblock.h" 11 | 12 | NAMESPACE_BEGIN(CryptoPP) 13 | 14 | /// \brief Serpent block cipher information 15 | /// \since Crypto++ 3.1 16 | struct Serpent_Info : public FixedBlockSize<16>, public VariableKeyLength<16, 16, 32, 8>, public FixedRounds<32> 17 | { 18 | CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return "Serpent";} 19 | }; 20 | 21 | /// \brief Serpent block cipher 22 | /// \sa Serpent 23 | /// \since Crypto++ 3.1 24 | class Serpent : public Serpent_Info, public BlockCipherDocumentation 25 | { 26 | class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl 27 | { 28 | public: 29 | void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs ¶ms); 30 | 31 | protected: 32 | FixedSizeSecBlock m_key; 33 | }; 34 | 35 | class CRYPTOPP_NO_VTABLE Enc : public Base 36 | { 37 | public: 38 | void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const; 39 | }; 40 | 41 | class CRYPTOPP_NO_VTABLE Dec : public Base 42 | { 43 | public: 44 | void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const; 45 | }; 46 | 47 | public: 48 | typedef BlockCipherFinal Encryption; 49 | typedef BlockCipherFinal Decryption; 50 | }; 51 | 52 | typedef Serpent::Encryption SerpentEncryption; 53 | typedef Serpent::Decryption SerpentDecryption; 54 | 55 | NAMESPACE_END 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /Src/100_System/LogEx.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include "Log.h" 5 | 6 | #ifdef UNICODE 7 | #define DestroyLogHandle DestroyLogHandleW 8 | #else 9 | #define DestroyLogHandle DestroyLogHandleA 10 | #endif 11 | 12 | namespace core 13 | { 14 | HANDLE CreateLogHandle(const ST_LOG_INIT_PARAM_EXA& stParam); 15 | HANDLE CreateLogHandle(const ST_LOG_INIT_PARAM_EXW& stParam); 16 | void DestroyLogHandleA(HANDLE hLog); 17 | void DestroyLogHandleW(HANDLE hLog); 18 | 19 | void Debug(HANDLE hLog, const char* pszFormat, ...); 20 | void Debug(HANDLE hLog, const wchar_t* pszFormat, ...); 21 | void Debug(HANDLE hLog, const char* pszFormat, va_list list); 22 | void Debug(HANDLE hLog, const wchar_t* pszFormat, va_list list); 23 | 24 | void Info(HANDLE hLog, const char* pszFormat, ...); 25 | void Info(HANDLE hLog, const wchar_t* pszFormat, ...); 26 | void Info(HANDLE hLog, const char* pszFormat, va_list list); 27 | void Info(HANDLE hLog, const wchar_t* pszFormat, va_list list); 28 | 29 | void Warn(HANDLE hLog, const char* pszFormat, ...); 30 | void Warn(HANDLE hLog, const wchar_t* pszFormat, ...); 31 | void Warn(HANDLE hLog, const char* pszFormat, va_list list); 32 | void Warn(HANDLE hLog, const wchar_t* pszFormat, va_list list); 33 | 34 | void Error(HANDLE hLog, const char* pszFormat, ...); 35 | void Error(HANDLE hLog, const wchar_t* pszFormat, ...); 36 | void Error(HANDLE hLog, const char* pszFormat, va_list list); 37 | void Error(HANDLE hLog, const wchar_t* pszFormat, va_list list); 38 | 39 | void Trace(HANDLE hLog, const char* pszFormat, ...); 40 | void Trace(HANDLE hLog, const wchar_t* pszFormat, ...); 41 | void Trace(HANDLE hLog, const char* pszFormat, va_list list); 42 | void Trace(HANDLE hLog, const wchar_t* pszFormat, va_list list); 43 | } 44 | -------------------------------------------------------------------------------- /Src/__Common/Define.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef UNICODE 4 | #ifndef TEXT 5 | #define TEXT(x) L##x 6 | #endif 7 | #ifndef _T 8 | #define _T(x) L##x 9 | #endif 10 | #ifndef TMAIN 11 | #define TMAIN wmain 12 | #endif 13 | #else 14 | #ifndef TEXT 15 | #define TEXT(x) x 16 | #endif 17 | #ifndef _T 18 | #define _T(x) x 19 | #endif 20 | #ifndef TMAIN 21 | #define TMAIN main 22 | #endif 23 | #endif 24 | 25 | #ifndef CASE_TO_STR 26 | #define CASE_TO_STR(x) case x: return TEXT(#x); 27 | #endif 28 | 29 | #ifndef CASE_TO_STR_T 30 | #define CASE_TO_STR_T(x) case x: return TEXT(#x); 31 | #endif 32 | 33 | #ifndef CASE_TO_STR_A 34 | #define CASE_TO_STR_A(x) case x: return #x; 35 | #endif 36 | 37 | #ifndef CASE_TO_STR_W 38 | #define CASE_TO_STR_W(x) case x: return L#x; 39 | #endif 40 | 41 | #ifndef MAKEQWORD 42 | #define MAKEQWORD(l, h) (((QWORD)h << 32) | ((QWORD) l)) 43 | #endif 44 | 45 | #ifndef NULL 46 | #define NULL 0 47 | #endif 48 | 49 | #define OPT 50 | #define IN 51 | #define OUT 52 | #define INOUT 53 | 54 | #ifndef TRUE 55 | #define TRUE 1 56 | #endif 57 | 58 | #ifndef FALSE 59 | #define FALSE 0 60 | #endif 61 | 62 | #ifndef MAX_PATH 63 | #define MAX_PATH 260 64 | #endif 65 | 66 | #ifndef INFINITE 67 | #define INFINITE 0xFFFFFFFF 68 | #define INFINITE32 0xFFFFFFFF 69 | #define INFINITE64 0xFFFFFFFFFFFFFFFFull 70 | #endif 71 | 72 | #define MAX(A, B) ((A) > (B)? (A) : (B)) 73 | #define MIN(A, B) ((A) < (B)? (A) : (B)) 74 | #define DIFF(A, B) ((A) < (B)? ((B)-(A)) : ((A)-(B))) 75 | 76 | #define SAFE_DELETE(x) if( NULL != (x) ) { delete (x); (x) = NULL; } 77 | 78 | #ifdef _MSC_VER 79 | #define DECLARE_EXPORT extern "C" __declspec(dllexport) 80 | #else 81 | #define DECLARE_EXPORT extern "C" __attribute__((visibility("default"))) 82 | #endif 83 | -------------------------------------------------------------------------------- /Test/FormatterTest/JSONFormatterTest.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | 3 | struct ST_MALICOUS_PATTERN_INFO : public core::IFormatterObject 4 | { 5 | std::tstring strPatternName; 6 | DWORD dwTotalChainCount; 7 | DWORD dwCurrentProcessingChainNo; 8 | 9 | void OnSync(core::IFormatter& formatter) 10 | { 11 | formatter.Sync(TEXT("PatternName"), strPatternName); 12 | formatter.Sync(TEXT("TotalChainCount"), dwTotalChainCount); 13 | formatter.Sync(TEXT("CurrentProcessingChainNo"), dwCurrentProcessingChainNo); 14 | } 15 | }; 16 | 17 | struct ST_FILELESS_STATUS : public core::IFormatterObject 18 | { 19 | std::map mapPatternStatus; 20 | 21 | void OnSync(core::IFormatter& formatter) 22 | { 23 | formatter.Sync(TEXT("PatternStatus"), mapPatternStatus); 24 | } 25 | }; 26 | 27 | TEST(FormatterTest, Simpletest) 28 | { 29 | ST_FILELESS_STATUS stStatus; 30 | 31 | { 32 | ST_MALICOUS_PATTERN_INFO info; 33 | info.strPatternName = TEXT("Hollow_1"); 34 | info.dwTotalChainCount = 10; 35 | info.dwCurrentProcessingChainNo = 0; 36 | stStatus.mapPatternStatus.insert(std::make_pair(info.strPatternName, info)); 37 | } 38 | 39 | { 40 | ST_MALICOUS_PATTERN_INFO info; 41 | info.strPatternName = TEXT("Pattern_1"); 42 | info.dwTotalChainCount = 5; 43 | info.dwCurrentProcessingChainNo = 2; 44 | stStatus.mapPatternStatus.insert(std::make_pair(info.strPatternName, info)); 45 | } 46 | 47 | const std::tstring strFileName = GenerateGuid() + TEXT(".txt"); 48 | core::UTF8::WriteJsonToFile(&stStatus, strFileName); 49 | 50 | ST_FILELESS_STATUS stStatusRestored; 51 | core::UTF8::ReadJsonFromFile(&stStatusRestored, strFileName); 52 | 53 | DeleteFile(strFileName.c_str()); 54 | 55 | EXPECT_EQ(2U, stStatusRestored.mapPatternStatus.size()); 56 | } 57 | -------------------------------------------------------------------------------- /Inc/cryptopp700/mars.h: -------------------------------------------------------------------------------- 1 | // mars.h - originally written and placed in the public domain by Wei Dai 2 | 3 | /// \file mars.h 4 | /// \brief Classes for the MARS block cipher (IBM AES submission) 5 | /// \since Crypto++ 3.0 6 | 7 | #ifndef CRYPTOPP_MARS_H 8 | #define CRYPTOPP_MARS_H 9 | 10 | #include "seckey.h" 11 | #include "secblock.h" 12 | 13 | NAMESPACE_BEGIN(CryptoPP) 14 | 15 | /// \brief MARS block cipher information 16 | /// \since Crypto++ 3.0 17 | struct MARS_Info : public FixedBlockSize<16>, public VariableKeyLength<16, 16, 56, 8> 18 | { 19 | CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return "MARS";} 20 | }; 21 | 22 | /// \brief MARS block cipher 23 | /// \sa MARS 24 | /// \since Crypto++ 3.0 25 | class MARS : public MARS_Info, public BlockCipherDocumentation 26 | { 27 | class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl 28 | { 29 | public: 30 | void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs ¶ms); 31 | 32 | protected: 33 | static const word32 Sbox[512]; 34 | 35 | FixedSizeSecBlock m_k; 36 | }; 37 | 38 | class CRYPTOPP_NO_VTABLE Enc : public Base 39 | { 40 | public: 41 | void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const; 42 | }; 43 | 44 | class CRYPTOPP_NO_VTABLE Dec : public Base 45 | { 46 | public: 47 | void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const; 48 | }; 49 | 50 | public: 51 | typedef BlockCipherFinal Encryption; 52 | typedef BlockCipherFinal Decryption; 53 | }; 54 | 55 | typedef MARS::Encryption MARSEncryption; 56 | typedef MARS::Decryption MARSDecryption; 57 | 58 | NAMESPACE_END 59 | 60 | #endif 61 | --------------------------------------------------------------------------------