From 338c78f64ece349fd027957472a45c9a0d1abedf Mon Sep 17 00:00:00 2001 From: crazy hugsy Date: Wed, 13 Dec 2023 13:24:55 -0800 Subject: [PATCH] Add some size and string encoding literals (#32) --- .github/Invoke-VisualStudio.ps1 | 15 +--- .github/workflows/build.yml | 33 ++++----- Modules/Common/Include/Literals.hpp | 103 ++++++++++++++++++++++++++++ Modules/Common/Source/Context.cpp | 2 +- pwn++/pwn.hpp.in | 1 + 5 files changed, 120 insertions(+), 34 deletions(-) create mode 100644 Modules/Common/Include/Literals.hpp diff --git a/.github/Invoke-VisualStudio.ps1 b/.github/Invoke-VisualStudio.ps1 index 09e73c9..6e4f774 100644 --- a/.github/Invoke-VisualStudio.ps1 +++ b/.github/Invoke-VisualStudio.ps1 @@ -11,20 +11,7 @@ Function Invoke-CmdScript { } } - -Function Invoke-VisualStudio2019x86 { - Invoke-CmdScript "C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/VC/Auxiliary/Build/vcvars32.bat" -} - -Function Invoke-VisualStudio2019x64 { - Invoke-CmdScript "C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/VC/Auxiliary/Build/vcvars64.bat" -} - -Function Invoke-VisualStudio2019arm64 { - Invoke-CmdScript "C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/VC/Auxiliary/Build/vcvarsamd64_arm64.bat" -} - -Function Invoke-VisualStudio2022x86 { +Function Invoke-VisualStudio2022win32 { Invoke-CmdScript "C:/Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Auxiliary/Build/vcvars32.bat" } diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a227fff..e7631b2 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -7,9 +7,11 @@ env: VERBOSE: "1" on: - push: pull_request: workflow_dispatch: + push: + branches: + - main jobs: build: @@ -22,21 +24,21 @@ jobs: fail-fast: false matrix: variants: - - {os: windows-latest, arch: x64, config: Debug, build: full} + # - {os: windows-latest, arch: x64, config: Debug, build: full} + # - {os: windows-latest, arch: win32, config: Debug, build: full} + # - {os: windows-latest, arch: arm64, config: Debug, build: full} + # - {os: windows-latest, arch: arm, config: Debug, build: full} + # - {os: ubuntu-latest, arch: x64, config: Debug, build: full} - {os: windows-latest, arch: x64, config: RelWithDebInfo, build: full} - - {os: windows-latest, arch: x86, config: Debug, build: full} - - {os: windows-latest, arch: x86, config: RelWithDebInfo, build: full} - - {os: windows-latest, arch: arm64, config: Debug, build: full} + - {os: windows-latest, arch: win32, config: RelWithDebInfo, build: full} - {os: windows-latest, arch: arm64, config: RelWithDebInfo, build: full} - - {os: windows-latest, arch: arm, config: Debug, build: full} - {os: windows-latest, arch: arm, config: RelWithDebInfo, build: full} - - {os: ubuntu-latest, arch: x64, config: Debug, build: full} - {os: ubuntu-latest, arch: x64, config: RelWithDebInfo, build: full} runs-on: ${{ matrix.variants.os }} outputs: windows-latest-x64-full: ${{ join(steps.*.outputs.windows-latest-x64-full,'') }} - windows-latest-x86-full: ${{ join(steps.*.outputs.windows-latest-x86-full,'') }} + windows-latest-win32-full: ${{ join(steps.*.outputs.windows-latest-win32-full,'') }} windows-latest-arm-full: ${{ join(steps.*.outputs.windows-latest-arm-full,'') }} windows-latest-arm64-full: ${{ join(steps.*.outputs.windows-latest-arm64-full,'') }} ubuntu-latest-x64-full: ${{ join(steps.*.outputs.ubuntu-latest-x64-full,'') }} @@ -87,13 +89,8 @@ jobs: - name: Build environment information run: env - - name: Initialize cmake (Windows/x86) - if: matrix.variants.os == 'windows-latest' && matrix.variants.arch == 'x86' - run: | - cmake -S . -B ./build -A win32 ${{ env.CMAKE_FLAGS }} - - - name: Initialize cmake (Windows) - if: matrix.variants.os == 'windows-latest' && matrix.variants.arch != 'x86' + - name: Initialize cmake + if: matrix.variants.os == 'windows-latest' run: | cmake -S . -B ./build -A ${{ matrix.variants.arch }} ${{ env.CMAKE_FLAGS }} @@ -110,9 +107,7 @@ jobs: if: matrix.variants.build == 'full' && matrix.variants.config == 'RelWithDebInfo' && ( matrix.variants.arch == 'x86' || matrix.variants.arch == 'x64' ) continue-on-error: true run: | - cd build - ctest --parallel ${{ env.NB_CPU }} --progress --extra-verbose --build-config ${{ matrix.variants.config }} -T test - cd .. + ctest --parallel ${{ env.NB_CPU }} --progress --build-config ${{ matrix.variants.config }} -T test --test-dir ./build - name: Populate the successful output (Windows) id: output_success_win @@ -173,7 +168,7 @@ jobs: ● [Detail Page](${{ env.RUN_URL }}) ${{ needs.build.outputs.windows-latest-x64-full }} - ${{ needs.build.outputs.windows-latest-x86-full }} + ${{ needs.build.outputs.windows-latest-win32-full }} ${{ needs.build.outputs.windows-latest-arm-full }} ${{ needs.build.outputs.windows-latest-arm64-full }} ${{ needs.build.outputs.ubuntu-latest-x64-full }} diff --git a/Modules/Common/Include/Literals.hpp b/Modules/Common/Include/Literals.hpp new file mode 100644 index 0000000..7c2488a --- /dev/null +++ b/Modules/Common/Include/Literals.hpp @@ -0,0 +1,103 @@ +#pragma once +#include "Common.hpp" + + +namespace pwn::literals +{ +constexpr static std::uint32_t +convert_substring_to_int(const char* str, int offset) +{ + return static_cast(str[offset] - '0') * 10 + static_cast(str[offset + 1] - '0'); +} + +constexpr char key = convert_substring_to_int(__TIME__, 0) ^ convert_substring_to_int(__TIME__, 3) ^ + convert_substring_to_int(__TIME__, 6); + + +/// +/// @brief Convenience wrapper to represent size in bytes +/// +/// @param x +/// @return usize +/// +auto constexpr +operator""_B(unsigned long long x) noexcept -> usize +{ + return x; +} + +/// +/// @brief Convenience wrapper to represent size in kilobytes +/// +/// @param x +/// @return usize +/// +auto constexpr +operator""_KB(unsigned long long x) noexcept -> usize +{ + return 1024 * x; +} + +/// +/// @brief Convenience wrapper to represent size in megabytes +/// +/// @param x +/// @return usize +/// +auto constexpr +operator""_MB(unsigned long long x) noexcept -> usize +{ + return 1024 * 1024 * x; +} + +/// +/// @brief Convenience wrapper to represent size in gigabytes +/// +/// @param x +/// @return usize +/// +auto constexpr +operator""_GB(unsigned long long x) noexcept -> usize +{ + return 1024 * 1024 * 1024 * x; +} + + +/// +/// @brief Lightweight wrapper class to decode strings +/// +struct encoded_string +{ + const std::string m_str {}; + constexpr const std::string + str() const noexcept + { + std::string b {m_str}; + for ( char i = 0; auto& c : b ) + c ^= key + (i++); + return b; + } +}; + + +/// +/// @brief constexpr strings obfuscator +/// +/// @param str +/// @param t +/// @return constexpr encoded_string +/// +constexpr encoded_string +operator""_es(const char* str, std::size_t t) +{ + return {[&str, &t]() + { + std::string b {str, t}; + for ( char i = 0; auto& c : b ) + c ^= key + (i++); + return b; + }()}; +} + + +} // namespace pwn::literals diff --git a/Modules/Common/Source/Context.cpp b/Modules/Common/Source/Context.cpp index 820ace1..1754628 100644 --- a/Modules/Common/Source/Context.cpp +++ b/Modules/Common/Source/Context.cpp @@ -10,7 +10,7 @@ struct GlobalContext Context; GlobalContext::GlobalContext() { Utils::Random::Seed(std::chrono::system_clock::now().time_since_epoch().count()); - SetArchitecture(ArchitectureType::x64); + Set(ArchitectureType::x64); }; void diff --git a/pwn++/pwn.hpp.in b/pwn++/pwn.hpp.in index 5dac1a5..1f47eed 100644 --- a/pwn++/pwn.hpp.in +++ b/pwn++/pwn.hpp.in @@ -4,6 +4,7 @@ #include "Common.hpp" #include "Architecture.hpp" #include "Log.hpp" +#include "Literals.hpp" #include "Formatters.hpp" #include "Utils.hpp" #include "Handle.hpp"