commit 1a0e126330a482eb90509f20a0b0c152ec2e04fe Author: HappyTanuki Date: Wed Apr 22 06:35:17 2026 +0000 first commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..028e728 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.vs +build +output +.cache diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..16d885a --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,17 @@ +{ + "editor.rulers": [ + { + "column": 80 + } + ], + "editor.renderWhitespace": "boundary", + "editor.formatOnSave": true, + "cmake.generator": "Ninja", + "C_Cpp.autocomplete": "disabled", + "files.exclude": { + "**/*.rpyc": true, + "**/*.rpa": true, + "**/*.rpymc": true, + "**/cache/": true + } +} \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..b97549d --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,162 @@ +cmake_minimum_required (VERSION 3.25) + +# ============================================================ +# Policy +# ============================================================ +if(WIN32 AND POLICY CMP0091) + cmake_policy(SET CMP0091 NEW) +endif() + +# ============================================================ +# Project +# ============================================================ +set(SUB_PROJECT_NAME "Test") +project(${SUB_PROJECT_NAME} LANGUAGES CXX) + +set(CMAKE_CXX_STANDARD 23) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + +# ============================================================ +# Dependencies +# ============================================================ +include(FetchContent) + +if(NOT DEFINED ROOT_PROJECT_NAME) + set(ROOT_PROJECT_NAME "Root") +endif() + +FetchContent_Declare( + Common + GIT_REPOSITORY https://github.com/HappyTanuki/Bedrock-Common.git + GIT_TAG master + GIT_SHALLOW ON +) +FetchContent_MakeAvailable(Common) + +FetchContent_Declare( + Encryption + GIT_REPOSITORY https://github.com/HappyTanuki/Bedrock-Encryption.git + GIT_TAG master + GIT_SHALLOW ON +) +FetchContent_MakeAvailable(Encryption) + +# ============================================================ +# Target – Networking +# ============================================================ +file(GLOB_RECURSE SOURCES "src/*.cc") + +if (CMAKE_MSVC_RUNTIME_LIBRARY MATCHES "DLL$") + add_executable(${SUB_PROJECT_NAME} ${SOURCES}) +else () + add_executable(${SUB_PROJECT_NAME} ${SOURCES}) +endif () + +target_link_libraries(${SUB_PROJECT_NAME} PUBLIC ${ROOT_PROJECT_NAME}::Common) +target_link_libraries(${SUB_PROJECT_NAME} PUBLIC ${ROOT_PROJECT_NAME}::Encryption) + +target_include_directories(${SUB_PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include) + +# ============================================================ +# Compiler Options +# ============================================================ +if (TARGET ${SUB_PROJECT_NAME}) + target_precompile_headers(${SUB_PROJECT_NAME} PRIVATE + "${CMAKE_CURRENT_SOURCE_DIR}/include/pch.h" + ) + if(MSVC) + target_compile_options(${SUB_PROJECT_NAME} PRIVATE /MP) + endif() +endif() + +if(UNIX AND NOT APPLE AND CMAKE_BUILD_TYPE STREQUAL "Release") + set_target_properties(${SUB_PROJECT_NAME} PROPERTIES + BUILD_WITH_INSTALL_RPATH TRUE + INSTALL_RPATH "$ORIGIN" + SKIP_BUILD_RPATH FALSE + BUILD_RPATH "$ORIGIN" + ) +endif() + +if (NOT WIN32) + target_compile_options( + ${SUB_PROJECT_NAME} PRIVATE + -maes + -msse2 + -mssse3 + -fno-exceptions -fno-rtti + ) +else() + add_compile_options(/utf-8) +endif() + +if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") + add_compile_options(-Wuseless-cast) +elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") + add_compile_options( + -Weverything + -Wno-c++98-compat + -Wno-c++98-compat-pedantic + -Wno-unused-macros + -Wno-padded + ) +endif () + +if(WIN32) + target_link_libraries(${SUB_PROJECT_NAME} PUBLIC ws2_32) + target_link_libraries(${SUB_PROJECT_NAME} PUBLIC crypt32) + set_target_properties(${SUB_PROJECT_NAME} PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON) +else() + add_compile_options( + -Werror + -Wall + -Wextra + -Wpedantic + -Wconversion + -Wsign-conversion + -Wshadow + -Wundef + -Wunreachable-code + -Wstrict-aliasing + -Wnull-dereference + -Wdouble-promotion + -Wformat=2 + -Wcast-qual + -Wcast-align + ) +endif() + +# ============================================================ +# clang-tidy (Linux only) +# ============================================================ +find_program(CLANG_TIDY_EXE NAMES clang-tidy) +if(CLANG_TIDY_EXE) + set(CMAKE_CXX_CLANG_TIDY + $<$:clang-tidy;-checks=-*,google-readability-casting;-fix;-fix-errors> + ) + if (PROJECT_IS_TOP_LEVEL AND CMAKE_EXPORT_COMPILE_COMMANDS) + execute_process( + COMMAND ${CMAKE_COMMAND} -E create_symlink + ${CMAKE_BINARY_DIR}/compile_commands.json + ${CMAKE_BINARY_DIR}/../compile_commands.json + ) + endif() +endif() + +if (${PROJECT_IS_TOP_LEVEL}) + set(BUILD_TESTING ON) + + include(CTest) + enable_testing() + + add_subdirectory(test) + + add_custom_command(TARGET ${SUB_PROJECT_NAME} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different + "$" + "${CMAKE_BINARY_DIR}/test" + COMMENT "Copying ${SUB_PROJECT_NAME} DLL/so to test output directory" + ) +endif() diff --git a/CMakePresets.json b/CMakePresets.json new file mode 100644 index 0000000..5c96880 --- /dev/null +++ b/CMakePresets.json @@ -0,0 +1,294 @@ +{ + "version": 9, + "configurePresets": [ + { + "name": "Paths", + "hidden": true, + "binaryDir": "${sourceDir}/output/${presetName}", + "installDir": "${sourceDir}/build/${presetName}", + "cacheVariables": { + "CMAKE_ARCHIVE_OUTPUT_DIRECTORY": "${sourceDir}/build/${presetName}", + "CMAKE_LIBRARY_OUTPUT_DIRECTORY": "${sourceDir}/build/${presetName}", + "CMAKE_RUNTIME_OUTPUT_DIRECTORY": "${sourceDir}/build/${presetName}" + } + }, + { + "name": "Linux-Clang-Build", + "hidden": true, + "inherits": [ + "Paths" + ], + "generator": "Ninja Multi-Config", + "cacheVariables": { + "CMAKE_CXX_COMPILER": "/usr/bin/clang++" + }, + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Linux" + } + }, + { + "name": "Linux-GCC-Build", + "hidden": true, + "inherits": [ + "Paths" + ], + "generator": "Ninja Multi-Config", + "cacheVariables": { + "CMAKE_CXX_COMPILER": "/usr/bin/g++" + }, + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Linux" + } + }, + { + "name": "Windows-Build", + "hidden": true, + "inherits": [ + "Paths" + ], + "generator": "Ninja", + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Windows" + } + }, + { + "name": "x64Windows", + "hidden": true, + "architecture": { + "value": "x64", + "strategy": "external" + } + }, + { + "name": "x64Linux", + "hidden": true, + "cacheVariables": { + "CMAKE_CXX_FLAGS": "-m64" + } + }, + { + "name": "x86Windows", + "hidden": true, + "architecture": { + "value": "x86", + "strategy": "external" + } + }, + { + "name": "x86Linux", + "hidden": true, + "cacheVariables": { + "CMAKE_CXX_FLAGS": "-m32", + "CMAKE_EXE_LINKER_FLAGS": "-m32", + "CMAKE_SHARED_LINKER_FLAGS": "-m32" + } + }, + { + "name": "Debug", + "hidden": true, + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug" + } + }, + { + "name": "Release", + "hidden": true, + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Release" + } + }, + { + "name": "MD", + "hidden": true, + "cacheVariables": { + "CMAKE_MSVC_RUNTIME_LIBRARY": "MultiThreadedDLL" + }, + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Windows" + } + }, + { + "name": "MT", + "hidden": true, + "cacheVariables": { + "CMAKE_MSVC_RUNTIME_LIBRARY": "MultiThreaded" + }, + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Windows" + } + }, + { + "name": "MDd", + "hidden": true, + "cacheVariables": { + "CMAKE_MSVC_RUNTIME_LIBRARY": "MultiThreadedDebugDLL" + }, + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Windows" + } + }, + { + "name": "MTd", + "hidden": true, + "cacheVariables": { + "CMAKE_MSVC_RUNTIME_LIBRARY": "MultiThreadedDebug" + }, + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Windows" + } + }, + { + "name": "Windows-x64-Debug", + "displayName": "Windows x64 Debug", + "inherits": [ + "Windows-Build", + "Debug", + "x64Windows", + "MDd" + ] + }, + { + "name": "Windows-x86-Debug", + "displayName": "Windows x86 Debug", + "inherits": [ + "Windows-Build", + "Debug", + "x86Windows", + "MDd" + ] + }, + { + "name": "Windows-x64-Release", + "displayName": "Windows x64 Release", + "inherits": [ + "Windows-Build", + "Release", + "x64Windows", + "MD" + ] + }, + { + "name": "Windows-x86-Release", + "displayName": "Windows x86 Release", + "inherits": [ + "Windows-Build", + "Release", + "x86Windows", + "MD" + ] + }, + { + "name": "Windows-x64-Debug-MT", + "displayName": "Windows x64 Debug MT", + "inherits": [ + "Windows-Build", + "Debug", + "x64Windows", + "MTd" + ] + }, + { + "name": "Windows-x86-Debug-MT", + "displayName": "Windows x86 Debug MT", + "inherits": [ + "Windows-Build", + "Debug", + "x86Windows", + "MTd" + ] + }, + { + "name": "Windows-x64-Release-MT", + "displayName": "Windows x64 Release MT", + "inherits": [ + "Windows-Build", + "Release", + "x64Windows", + "MT" + ] + }, + { + "name": "Windows-x86-Release-MT", + "displayName": "Windows x86 Release MT", + "inherits": [ + "Windows-Build", + "Release", + "x86Windows", + "MT" + ] + }, + { + "name": "Clang-x64", + "displayName": "Clang x64", + "inherits": [ + "Linux-Clang-Build", + "x64Linux" + ] + }, + { + "name": "GCC-x64", + "displayName": "GCC x64", + "inherits": [ + "Linux-GCC-Build", + "x64Linux" + ] + } + ], + "buildPresets": [ + { + "name": "Linux-Only", + "hidden": true, + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Linux" + } + }, + { + "name": "Debug-Clang-x64", + "inherits": [ + "Linux-Only" + ], + "configurePreset": "Clang-x64", + "configuration": "Debug" + }, + { + "name": "Release-Clang-x64", + "inherits": [ + "Linux-Only" + ], + "configurePreset": "Clang-x64", + "configuration": "Release" + }, + { + "name": "Debug-GCC-x64", + "inherits": [ + "Linux-Only" + ], + "configurePreset": "GCC-x64", + "configuration": "Debug" + }, + { + "name": "Release-GCC-x64", + "inherits": [ + "Linux-Only" + ], + "configurePreset": "GCC-x64", + "configuration": "Release" + } + ] +} \ No newline at end of file diff --git a/include/pch.h b/include/pch.h new file mode 100644 index 0000000..7b9637e --- /dev/null +++ b/include/pch.h @@ -0,0 +1 @@ +#pragma once \ No newline at end of file diff --git a/src/main.cc b/src/main.cc new file mode 100644 index 0000000..90f6a07 --- /dev/null +++ b/src/main.cc @@ -0,0 +1,27 @@ +#include +#include "encryption/util/helper.h" +#include + +int main() { + std::ifstream payload1_file; + + payload1_file.open("payload1.txt"); + if (!payload1_file) { + std::cout << "파일 열기 실패\n"; + return 1; + } + payload1_file.seekg(0, std::ios::end); + + // 현재 위치 = 파일 크기 + std::streampos size = payload1_file.tellg(); + + std::string payload1; + payload1.resize(size); + payload1_file.read(payload1.data(), size); + + std::cout << "red: " << payload1 << std::endl; + + auto bytes = bedrock::util::HexStrToBytes(payload1); + + return 0; +} \ No newline at end of file diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 0000000..bb9954f --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,12 @@ +file(GLOB TEST_SOURCES "*.cc") + +foreach(test_src ${TEST_SOURCES}) + get_filename_component(test_name ${test_src} NAME_WE) + add_executable(${test_name} ${test_src}) + target_link_libraries(${test_name} PRIVATE ${PROJECT_NAME}) + if(NOT WIN32) + target_compile_options(${test_name} PRIVATE -fno-exceptions -march=native -maes -msse2 -msse3 -mssse3 -msse4.1 -msse4.2) + endif() + add_test(NAME ${test_name} COMMAND ${test_name}) + set_tests_properties(${test_name} PROPERTIES WORKING_DIRECTORY ${CMAKE_BINARY_DIR}) +endforeach()