Skip to content

Commit

Permalink
Add some size and string encoding literals (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
hugsy authored Dec 13, 2023
1 parent 6cbe578 commit 338c78f
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 34 deletions.
15 changes: 1 addition & 14 deletions .github/Invoke-VisualStudio.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

Expand Down
33 changes: 14 additions & 19 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ env:
VERBOSE: "1"

on:
push:
pull_request:
workflow_dispatch:
push:
branches:
- main

jobs:
build:
Expand All @@ -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,'') }}
Expand Down Expand Up @@ -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 }}
Expand All @@ -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
Expand Down Expand Up @@ -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 }}
Expand Down
103 changes: 103 additions & 0 deletions Modules/Common/Include/Literals.hpp
Original file line number Diff line number Diff line change
@@ -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<std::uint32_t>(str[offset] - '0') * 10 + static_cast<std::uint32_t>(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
2 changes: 1 addition & 1 deletion Modules/Common/Source/Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions pwn++/pwn.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 338c78f

Please sign in to comment.