diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2e04075..9f627fb 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -6,8 +6,8 @@ env: REPO: hugsy/pwn-- on: - pull_request: workflow_dispatch: + pull_request: push: branches: - main @@ -67,7 +67,6 @@ jobs: - name: Prepare common environment run: | - mkdir build mkdir artifact - name: Prepare Windows environment diff --git a/CMakeLists.txt b/CMakeLists.txt index fd344a4..037e2ee 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,11 +26,11 @@ option(PWN_DISASSEMBLE_ARM64 "Compile with BinaryNinja disassembler support (ARM # Use CMake's `BUILD_SHARED_LIBS` # option(PWN_BUILD_SHARED_LIBS "Build as a shared library" OFF) - if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) # pwn++ is NOT a top dir (i.e. build as dependency) option(PWN_BUILD_TOOLKIT "Compile the executables of pwn++ toolkit" OFF) option(PWN_BUILD_TESTING "Compile the test suite" OFF) + option(PWN_BUILD_MODULE_CRYPTO "Compile the crypto module (requires m4)" OFF) option(PWN_BUILD_DOCS "Generate the Doxygen API files" OFF) else() # pwn++ is a top dir @@ -52,20 +52,20 @@ if(WIN32) # Listed by dependency order Common - Network - Symbols - System - Security - Registry - Service - Shellcode - - FileSystem - Process - Remote - - Binary - CTF + # Crypto + # Network + # Symbols + # System + # Security + # Registry + # Service + # Shellcode + # FileSystem + # Process + # Remote + + # Binary + # CTF # TODO : ideas for future modules # - WTS diff --git a/Modules/Common/CMakeLists.txt b/Modules/Common/CMakeLists.txt index ef8a41b..c71f7b9 100644 --- a/Modules/Common/CMakeLists.txt +++ b/Modules/Common/CMakeLists.txt @@ -8,19 +8,26 @@ set(HEADER_DIR ${SOURCE_DIR}/Include) set(SOURCE_FILES - ${SOURCE_DIR}/Architecture.cpp - ${SOURCE_DIR}/Context.cpp - ${SOURCE_DIR}/Error.cpp - ${SOURCE_DIR}/Log.cpp - ${SOURCE_DIR}/Utils.cpp + # ${SOURCE_DIR}/Architecture.cpp + # ${SOURCE_DIR}/Context.cpp + # ${SOURCE_DIR}/Error.cpp + # ${SOURCE_DIR}/Log.cpp + # ${SOURCE_DIR}/Utils.cpp ) # # Create and build the target static library # -add_library(${PROJECT_NAME} STATIC) +add_library(${PROJECT_NAME} STATIC ${SOURCE_FILES}) add_library(PWN::Common ALIAS ${PROJECT_NAME}) -target_sources(${PROJECT_NAME} PRIVATE ${SOURCE_FILES}) +target_sources(${PROJECT_NAME} + PRIVATE + FILE_SET CXX_MODULES FILES + + # ${INTERFACE_DIR}/Common.ixx + ${SOURCE_DIR}/Common.cxx +) + target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_23) target_include_directories(${PROJECT_NAME} PUBLIC ${INTERFACE_DIR} PRIVATE ${HEADER_DIR}) diff --git a/Modules/Common/Source/Common.cxx b/Modules/Common/Source/Common.cxx new file mode 100644 index 0000000..e7453c6 --- /dev/null +++ b/Modules/Common/Source/Common.cxx @@ -0,0 +1,25 @@ +module; +#include +export module pwn.common; + +export using u8 = std::uint8_t; +export using u16 = std::uint16_t; +export using u32 = std::uint32_t; +export using u64 = std::uint64_t; +export using i8 = std::int8_t; +export using i16 = std::int16_t; +export using i32 = std::int32_t; +export using i64 = std::int64_t; +#ifdef _M_IX86 +export using usize = unsigned long; +#else +export using usize = std::size_t; +#endif +export using ssize = std::intptr_t; +export using uptr = std::uintptr_t; + +export void +test() +{ + std::cout << "test modules\n"; +} diff --git a/pwn++/CMakeLists.txt b/pwn++/CMakeLists.txt index 3b58658..5f20240 100644 --- a/pwn++/CMakeLists.txt +++ b/pwn++/CMakeLists.txt @@ -14,7 +14,7 @@ set(PWN_BUILD_OS ${CMAKE_SYSTEM_NAME}) set(PWN_MODULES_AS_STRING "") foreach(MODULE ${PWN_MODULES}) - set(PWN_MODULES_AS_STRING "L\"${MODULE}\",${PWN_MODULES_AS_STRING}") + set(PWN_MODULES_AS_STRING "\"${MODULE}\",${PWN_MODULES_AS_STRING}") endforeach() set(INTERFACE_DIR ${PROJECT_SOURCE_DIR}/Include) @@ -30,10 +30,12 @@ endif() message(STATUS "Generating pwn++ main header") list(TRANSFORM PWN_MODULES PREPEND PWN:: OUTPUT_VARIABLE MODULE_NAMESPACES) list(LENGTH MODULE_NAMESPACES PWN_MODULES_LENGTH) -configure_file(${PROJECT_SOURCE_DIR}/pwn.hpp.in ${INTERFACE_DIR}/pwn NEWLINE_STYLE WIN32) +# configure_file(${PROJECT_SOURCE_DIR}/pwn.hpp.in ${INTERFACE_DIR}/pwn NEWLINE_STYLE WIN32) +configure_file(${PROJECT_SOURCE_DIR}/pwn.hpp.in ${INTERFACE_DIR}/pwn.ixx NEWLINE_STYLE WIN32) if(MSVC) target_sources(${PROJECT_NAME} PRIVATE ${SOURCE_DIR}/Win32/dllmain.cpp) + target_sources(${PROJECT_NAME} PRIVATE FILE_SET CXX_MODULES FILES ${INTERFACE_DIR}/pwn.ixx) target_link_options( ${PROJECT_NAME} diff --git a/pwn++/Include/pwn.ixx b/pwn++/Include/pwn.ixx new file mode 100644 index 0000000..a42b1cd --- /dev/null +++ b/pwn++/Include/pwn.ixx @@ -0,0 +1,163 @@ +module; + +/** + * Include non-module, locally only + */ +#include +#include + +/** + * Export module `pwn` + */ +export module pwn; + +/** + * Re-export submodules + */ +export import pwn.common; + +/** + * Additional imports + */ +import std; + +// // clang-format off +// #include "Common.hpp" +// #include "Architecture.hpp" +// #include "Log.hpp" +// #include "Literals.hpp" +// #include "Formatters.hpp" +// #include "Utils.hpp" +// #include "Handle.hpp" +// #include "Context.hpp" + +// #include "Crypto.hpp" + +// #ifdef PWN_INCLUDE_DISASSEMBLER +// #include "Disassembler.hpp" +// #endif // PWN_INCLUDE_DISASSEMBLER + +// #if defined(PWN_BUILD_FOR_WINDOWS) +// #include "Win32/Network.hpp" +// #include "Win32/FileSystem.hpp" +// #include "Win32/System.hpp" +// #include "Win32/PE.hpp" +// #include "Win32/Network.hpp" +// #include "Win32/Job.hpp" +// #include "Win32/Process.hpp" +// #include "Win32/Thread.hpp" +// #include "Win32/Token.hpp" +// #include "Win32/ObjectManager.hpp" +// #include "Win32/System.hpp" +// #include "Win32/Service.hpp" +// #include "Win32/ALPC.hpp" +// #include "Win32/RPC.hpp" +// #include "Win32/API.hpp" +// #include "Win32/Symbols.hpp" +// #include "CTF/Win32/Remote.hpp" +// #include "CTF/Win32/Process.hpp" + +// #elif defined(PWN_BUILD_FOR_LINUX) + +// #include "CTF/Linux/Remote.hpp" +// #include "CTF/Linux/Process.hpp" + +// #else + +// #error "Unsupported OS" + +// #endif // PWN_BUILD_FOR_WINDOWS +// clang-format on + +namespace pwn +{ +// clang-format off +/// +///@brief +/// +export constexpr std::string_view LibraryName = "pwn++"; + +/// +///@brief +/// +export constexpr std::string_view LibraryAuthor = "hugsy"; + +/// +///@brief +/// +export constexpr std::string_view LibraryLicense = "MIT"; + +/// +///@brief +/// +export constexpr std::string_view LibraryBanner = "pwn++" " v" "0.1.3" " - " "Standalone"; +// clang-format on + +/// +///@brief pwn++ version information +/// +constexpr struct VersionType +{ + /// + ///@brief pwn++ major version + /// + const u8 Major; + + /// + ///@brief pwn++ minor version + /// + const u8 Minor; + + /// + ///@brief pwn++ patch information + /// + const u16 Patch; + + /// + ///@brief pwn++ release information + /// + const std::string_view Release; + + /// + ///@brief pwn++ complete version information as wstring + /// + const std::string_view VersionString; +} Version = { + // clang-format off + 0, + 1, + 3, + "Standalone", + "0.1.3", + // clang-format on +}; + +/// +///@brief +/// +constexpr struct HostInfo +{ + /// + ///@brief The host architecture pwn++ was built against + /// + const std::string_view Architecture; + + /// + ///@brief The host OS pwn++ was built against + /// + const std::string_view System; +} Host { + // clang-format off + "AMD64", + "Windows" + // clang-format on +}; +// clang-format off + +/// +///@brief A list of all modules built with pwn++ +/// +export constexpr std::array ModuleNames = {"Common",}; +// clang-format on + +} // namespace pwn diff --git a/pwn++/Source/Win32/dllmain.cpp b/pwn++/Source/Win32/dllmain.cpp index 9027116..6281de6 100644 --- a/pwn++/Source/Win32/dllmain.cpp +++ b/pwn++/Source/Win32/dllmain.cpp @@ -1,6 +1,9 @@ -#include +#include +import pwn; +import std; -using namespace pwn; + +// using namespace pwn; void OnAttachRoutine() @@ -8,7 +11,9 @@ OnAttachRoutine() // // Initialize the RNG // - Utils::Random::Seed(); + // Utils::Random::Seed(); + std::println("loading library {}, {}", pwn::LibraryName, pwn::LibraryBanner); + test(); } @@ -19,10 +24,10 @@ OnDetachRoutine() BOOL APIENTRY -DllMain(_In_ HMODULE hModule, _In_ DWORD ul_reason_for_call, _In_ LPVOID lpReserved) +DllMain(_In_ HMODULE /* hModule */, _In_ DWORD ul_reason_for_call, _In_ LPVOID /* lpReserved */) { - UnusedParameter(hModule); - UnusedParameter(lpReserved); + // UnusedParameter(hModule); + // UnusedParameter(lpReserved); switch ( ul_reason_for_call ) { diff --git a/pwn++/pwn.hpp.in b/pwn++/pwn.hpp.in index 5792933..723d969 100644 --- a/pwn++/pwn.hpp.in +++ b/pwn++/pwn.hpp.in @@ -1,53 +1,72 @@ -#pragma once - -// clang-format off -#include "Common.hpp" -#include "Architecture.hpp" -#include "Log.hpp" -#include "Literals.hpp" -#include "Formatters.hpp" -#include "Utils.hpp" -#include "Handle.hpp" -#include "Context.hpp" - -#ifdef PWN_BUILD_CRYPTO -#include "Crypto.hpp" -#endif // PWN_BUILD_CRYPTO - -#ifdef PWN_INCLUDE_DISASSEMBLER -#include "Disassembler.hpp" -#endif // PWN_INCLUDE_DISASSEMBLER - -#if defined(PWN_BUILD_FOR_WINDOWS) -#include "Win32/Network.hpp" -#include "Win32/FileSystem.hpp" -#include "Win32/System.hpp" -#include "Win32/PE.hpp" -#include "Win32/Network.hpp" -#include "Win32/Job.hpp" -#include "Win32/Process.hpp" -#include "Win32/Thread.hpp" -#include "Win32/Token.hpp" -#include "Win32/ObjectManager.hpp" -#include "Win32/System.hpp" -#include "Win32/Service.hpp" -#include "Win32/ALPC.hpp" -#include "Win32/RPC.hpp" -#include "Win32/API.hpp" -#include "Win32/Symbols.hpp" -#include "CTF/Win32/Remote.hpp" -#include "CTF/Win32/Process.hpp" - -#elif defined(PWN_BUILD_FOR_LINUX) - -#include "CTF/Linux/Remote.hpp" -#include "CTF/Linux/Process.hpp" - -#else - -#error "Unsupported OS" - -#endif // PWN_BUILD_FOR_WINDOWS +module; + +/** + * Include non-module, locally only + */ +#include +#include + +/** + * Export module `pwn` + */ +export module pwn; + +/** + * Re-export submodules + */ +export import pwn.common; + +/** + * Additional imports + */ +import std; + +// // clang-format off +// #include "Common.hpp" +// #include "Architecture.hpp" +// #include "Log.hpp" +// #include "Literals.hpp" +// #include "Formatters.hpp" +// #include "Utils.hpp" +// #include "Handle.hpp" +// #include "Context.hpp" + +// #include "Crypto.hpp" + +// #ifdef PWN_INCLUDE_DISASSEMBLER +// #include "Disassembler.hpp" +// #endif // PWN_INCLUDE_DISASSEMBLER + +// #if defined(PWN_BUILD_FOR_WINDOWS) +// #include "Win32/Network.hpp" +// #include "Win32/FileSystem.hpp" +// #include "Win32/System.hpp" +// #include "Win32/PE.hpp" +// #include "Win32/Network.hpp" +// #include "Win32/Job.hpp" +// #include "Win32/Process.hpp" +// #include "Win32/Thread.hpp" +// #include "Win32/Token.hpp" +// #include "Win32/ObjectManager.hpp" +// #include "Win32/System.hpp" +// #include "Win32/Service.hpp" +// #include "Win32/ALPC.hpp" +// #include "Win32/RPC.hpp" +// #include "Win32/API.hpp" +// #include "Win32/Symbols.hpp" +// #include "CTF/Win32/Remote.hpp" +// #include "CTF/Win32/Process.hpp" + +// #elif defined(PWN_BUILD_FOR_LINUX) + +// #include "CTF/Linux/Remote.hpp" +// #include "CTF/Linux/Process.hpp" + +// #else + +// #error "Unsupported OS" + +// #endif // PWN_BUILD_FOR_WINDOWS // clang-format on namespace pwn @@ -56,81 +75,81 @@ namespace pwn /// ///@brief /// -constexpr std::wstring_view LibraryName = L"@PWN_LIBRARY_NAME@"; +export constexpr std::string_view LibraryName = "@PWN_LIBRARY_NAME@"; /// ///@brief /// -constexpr std::wstring_view LibraryAuthor = L"@PWN_LIBRARY_AUTHOR@"; +export constexpr std::string_view LibraryAuthor = "@PWN_LIBRARY_AUTHOR@"; /// ///@brief /// -constexpr std::wstring_view LibraryLicense = L"@PWN_LIBRARY_LICENSE@"; +export constexpr std::string_view LibraryLicense = "@PWN_LIBRARY_LICENSE@"; /// ///@brief /// -constexpr std::wstring_view LibraryBanner = L"@PWN_LIBRARY_NAME@" L" v" L"@PWN_LIBRARY_VERSION@" L" - " L"@PWN_LIBRARY_VERSION_RELEASE@"; +export constexpr std::string_view LibraryBanner = "@PWN_LIBRARY_NAME@" " v" "@PWN_LIBRARY_VERSION@" " - " "@PWN_LIBRARY_VERSION_RELEASE@"; // clang-format on /// ///@brief pwn++ version information /// -constexpr struct +constexpr struct VersionType { /// ///@brief pwn++ major version /// - u8 Major; + const u8 Major; /// ///@brief pwn++ minor version /// - u8 Minor; + const u8 Minor; /// ///@brief pwn++ patch information /// - u16 Patch; + const u16 Patch; /// ///@brief pwn++ release information /// - std::wstring_view Release; + const std::string_view Release; /// ///@brief pwn++ complete version information as wstring /// - std::wstring_view VersionString; + const std::string_view VersionString; } Version = { // clang-format off @PWN_LIBRARY_VERSION_MAJOR@, @PWN_LIBRARY_VERSION_MINOR@, @PWN_LIBRARY_VERSION_PATCH@, - L"@PWN_LIBRARY_VERSION_RELEASE@", - L"@PWN_LIBRARY_VERSION@", + "@PWN_LIBRARY_VERSION_RELEASE@", + "@PWN_LIBRARY_VERSION@", // clang-format on }; /// ///@brief /// -constexpr struct +constexpr struct HostInfo { /// - ///@brief The target architecture pwn++ was built against + ///@brief The host architecture pwn++ was built against /// - std::wstring_view Architecture; + const std::string_view Architecture; /// - ///@brief The target OS pwn++ was built against + ///@brief The host OS pwn++ was built against /// - std::wstring_view System; -} Target { + const std::string_view System; +} Host { // clang-format off - L"@PWN_BUILD_ARCHITECTURE@", - L"@PWN_BUILD_OS@" + "@PWN_BUILD_ARCHITECTURE@", + "@PWN_BUILD_OS@" // clang-format on }; // clang-format off @@ -138,7 +157,7 @@ constexpr struct /// ///@brief A list of all modules built with pwn++ /// -constexpr std::array ModuleNames = {@PWN_MODULES_AS_STRING@}; +export constexpr std::array ModuleNames = {@PWN_MODULES_AS_STRING@}; // clang-format on } // namespace pwn