mirror of
https://github.com/orange-cpp/omath.git
synced 2026-02-13 07:03:25 +00:00
Removes PE definition files
Removes the PE definition files and related functions as they are no longer needed.
This commit is contained in:
@@ -28,6 +28,7 @@ if (OMATH_USE_AVX2 AND NOT COMPILER_SUPPORTS_AVX2)
|
||||
set(OMATH_USE_AVX2 OFF CACHE BOOL "Omath will use AVX2 to boost performance" FORCE)
|
||||
endif ()
|
||||
|
||||
if (${PROJECT_IS_TOP_LEVEL})
|
||||
message(STATUS "[${PROJECT_NAME}]: Building on ${CMAKE_HOST_SYSTEM_NAME}, compiler ${CMAKE_CXX_COMPILER_ID}")
|
||||
message(STATUS "[${PROJECT_NAME}]: Warnings as errors ${OMATH_THREAT_WARNING_AS_ERROR}")
|
||||
message(STATUS "[${PROJECT_NAME}]: Build unit tests ${OMATH_BUILD_TESTS}")
|
||||
@@ -39,11 +40,11 @@ message(STATUS "[${PROJECT_NAME}]: Example projects ${OMATH_BUILD_EXAMPLES}")
|
||||
message(STATUS "[${PROJECT_NAME}]: AVX2 feature status ${OMATH_USE_AVX2}")
|
||||
message(STATUS "[${PROJECT_NAME}]: ImGUI integration feature status ${OMATH_IMGUI_INTEGRATION}")
|
||||
message(STATUS "[${PROJECT_NAME}]: Legacy features support ${OMATH_ENABLE_LEGACY}")
|
||||
endif ()
|
||||
|
||||
file(GLOB_RECURSE OMATH_SOURCES CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/source/*.cpp")
|
||||
file(GLOB_RECURSE OMATH_HEADERS CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/include/*.hpp")
|
||||
|
||||
|
||||
if (OMATH_BUILD_AS_SHARED_LIBRARY)
|
||||
add_library(${PROJECT_NAME} SHARED ${OMATH_SOURCES} ${OMATH_HEADERS})
|
||||
else ()
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
//
|
||||
// Created by Vlad on 10/8/2025.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
@@ -1,32 +0,0 @@
|
||||
//
|
||||
// Created by Vlad on 10/7/2025.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
|
||||
namespace omath::system::pe
|
||||
{
|
||||
struct DosHeader final
|
||||
{
|
||||
std::uint16_t e_magic;
|
||||
std::uint16_t e_cblp;
|
||||
std::uint16_t e_cp;
|
||||
std::uint16_t e_crlc;
|
||||
std::uint16_t e_cparhdr;
|
||||
std::uint16_t e_minalloc;
|
||||
std::uint16_t e_maxalloc;
|
||||
std::uint16_t e_ss;
|
||||
std::uint16_t e_sp;
|
||||
std::uint16_t e_csum;
|
||||
std::uint16_t e_ip;
|
||||
std::uint16_t e_cs;
|
||||
std::uint16_t e_lfarlc;
|
||||
std::uint16_t e_ovno;
|
||||
std::uint16_t e_res[4];
|
||||
std::uint16_t e_oemid;
|
||||
std::uint16_t e_oeminfo;
|
||||
std::uint16_t e_res2[10];
|
||||
std::uint32_t e_lfanew;
|
||||
};
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
//
|
||||
// Created by Vlad on 10/7/2025.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
|
||||
namespace omath::system::pe
|
||||
{
|
||||
enum class MachineId : std::uint16_t
|
||||
{
|
||||
UNKNOWN = 0x0000,
|
||||
TARGET_HOST = 0x0001, // Useful for indicating we want to interact with the host and not a WoW guest.
|
||||
I386 = 0x014C, // Intel 386.
|
||||
R3000 = 0x0162, // MIPS little-endian, 0x160 big-endian
|
||||
R4000 = 0x0166, // MIPS little-endian
|
||||
R10000 = 0x0168, // MIPS little-endian
|
||||
WCEMIPSV2 = 0x0169, // MIPS little-endian WCE v2
|
||||
ALPHA = 0x0184, // Alpha_AXP
|
||||
SH3 = 0x01A2, // SH3 little-endian
|
||||
SH3DSP = 0x01A3,
|
||||
SH3E = 0x01A4, // SH3E little-endian
|
||||
SH4 = 0x01A6, // SH4 little-endian
|
||||
SH5 = 0x01A8, // SH5
|
||||
ARM = 0x01C0, // ARM Little-Endian
|
||||
THUMB = 0x01C2, // ARM Thumb/Thumb-2 Little-Endian
|
||||
ARMNT = 0x01C4, // ARM Thumb-2 Little-Endian
|
||||
AM33 = 0x01D3,
|
||||
POWERPC = 0x01F0, // IBM PowerPC Little-Endian
|
||||
POWERPCP = 0x01F1,
|
||||
IA64 = 0x0200, // Intel 64
|
||||
MIPS16 = 0x0266, // MIPS
|
||||
ALPHA64 = 0x0284, // ALPHA64
|
||||
MIPSFPU = 0x0366, // MIPS
|
||||
MIPSFPU16 = 0x0466, // MIPS
|
||||
AXP64 = 0x0284,
|
||||
TRICORE = 0x0520, // Infineon
|
||||
CEF = 0x0CEF,
|
||||
EBC = 0x0EBC, // EFI Byte Code
|
||||
AMD64 = 0x8664, // AMD64 (K8)
|
||||
M32R = 0x9041, // M32R little-endian
|
||||
ARM64 = 0xAA64, // ARM64 Little-Endian
|
||||
CEE = 0xC0EE,
|
||||
};
|
||||
|
||||
struct FileHeader final
|
||||
{
|
||||
MachineId machine;
|
||||
uint16_t num_sections;
|
||||
uint32_t timedate_stamp;
|
||||
uint32_t ptr_symbols;
|
||||
uint32_t num_symbols;
|
||||
uint16_t size_optional_header;
|
||||
std::uint16_t characteristics;
|
||||
};
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
//
|
||||
// Created by Vlad on 10/9/2025.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
#include "file_header.hpp"
|
||||
#include "optional_header.hpp"
|
||||
|
||||
namespace omath::system::pe
|
||||
{
|
||||
enum class NtArchitecture
|
||||
{
|
||||
x32_bit,
|
||||
x64_bit,
|
||||
};
|
||||
template<NtArchitecture architecture>
|
||||
struct ImageNtHeaders final
|
||||
{
|
||||
std::uint32_t signature;
|
||||
FileHeader file_header;
|
||||
OptionalHeader<architecture == NtArchitecture::x64_bit> optional_header;
|
||||
};
|
||||
} // namespace omath::system::pe
|
||||
@@ -1,118 +0,0 @@
|
||||
//
|
||||
// Created by Vlad on 10/8/2025.
|
||||
//
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
|
||||
namespace omath::system::pe
|
||||
{
|
||||
static constexpr std::uint16_t opt_hdr32_magic = 0x010B;
|
||||
static constexpr std::uint16_t opt_hdr64_magic = 0x020B;
|
||||
enum class SubsystemId : std::uint16_t
|
||||
{
|
||||
unknown = 0x0000,
|
||||
native = 0x0001,
|
||||
windows_gui = 0x0002,
|
||||
windows_cui = 0x0003,
|
||||
os2_cui = 0x0005,
|
||||
posix_cui = 0x0007,
|
||||
native_windows = 0x0008,
|
||||
windows_ce_gui = 0x0009,
|
||||
efi_application = 0x000A,
|
||||
efi_boot_service_driver = 0x000B,
|
||||
efi_runtime_driver = 0x000C,
|
||||
efi_rom = 0x000D,
|
||||
xbox = 0x000E,
|
||||
windows_boot_application = 0x0010,
|
||||
xbox_code_catalog = 0x0011,
|
||||
};
|
||||
|
||||
struct DataDirectory final
|
||||
{
|
||||
std::uint32_t rva;
|
||||
std::uint32_t size;
|
||||
};
|
||||
struct OptionalHeaderX64 final
|
||||
{
|
||||
// Standard fields.
|
||||
std::uint16_t magic;
|
||||
std::uint16_t linker_version;
|
||||
|
||||
std::uint32_t size_code;
|
||||
std::uint32_t size_init_data;
|
||||
std::uint32_t size_uninit_data;
|
||||
|
||||
std::uint32_t entry_point;
|
||||
std::uint32_t base_of_code;
|
||||
|
||||
// NT additional fields.
|
||||
std::uint64_t image_base;
|
||||
std::uint32_t section_alignment;
|
||||
std::uint32_t file_alignment;
|
||||
|
||||
std::uint32_t os_version;
|
||||
std::uint32_t img_version;
|
||||
std::uint32_t subsystem_version;
|
||||
std::uint32_t win32_version_value;
|
||||
|
||||
std::uint32_t size_image;
|
||||
std::uint32_t size_headers;
|
||||
|
||||
std::uint32_t checksum;
|
||||
SubsystemId subsystem;
|
||||
std::uint16_t characteristics;
|
||||
|
||||
std::uint64_t size_stack_reserve;
|
||||
std::uint64_t size_stack_commit;
|
||||
std::uint64_t size_heap_reserve;
|
||||
std::uint64_t size_heap_commit;
|
||||
|
||||
std::uint32_t ldr_flags;
|
||||
|
||||
std::uint32_t num_data_directories;
|
||||
DataDirectory data_directories[16];
|
||||
};
|
||||
struct OptionalHeaderX86 final
|
||||
{
|
||||
// Standard fields.
|
||||
uint16_t magic;
|
||||
uint16_t linker_version;
|
||||
|
||||
uint32_t size_code;
|
||||
uint32_t size_init_data;
|
||||
uint32_t size_uninit_data;
|
||||
|
||||
uint32_t entry_point;
|
||||
uint32_t base_of_code;
|
||||
uint32_t base_of_data;
|
||||
|
||||
// NT additional fields.
|
||||
uint32_t image_base;
|
||||
uint32_t section_alignment;
|
||||
uint32_t file_alignment;
|
||||
|
||||
std::uint32_t os_version;
|
||||
std::uint32_t img_version;
|
||||
std::uint32_t subsystem_version;
|
||||
uint32_t win32_version_value;
|
||||
|
||||
uint32_t size_image;
|
||||
uint32_t size_headers;
|
||||
|
||||
uint32_t checksum;
|
||||
SubsystemId subsystem;
|
||||
std::uint16_t characteristics;
|
||||
|
||||
uint32_t size_stack_reserve;
|
||||
uint32_t size_stack_commit;
|
||||
uint32_t size_heap_reserve;
|
||||
uint32_t size_heap_commit;
|
||||
|
||||
uint32_t ldr_flags;
|
||||
|
||||
uint32_t num_data_directories;
|
||||
DataDirectory data_directories[16];
|
||||
};
|
||||
template<bool x64 = true>
|
||||
using OptionalHeader = std::conditional_t<x64, OptionalHeaderX64, OptionalHeaderX86>;
|
||||
} // namespace omath::system::pe
|
||||
@@ -1,32 +0,0 @@
|
||||
//
|
||||
// Created by Vlad on 10/8/2025.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
|
||||
// Section header
|
||||
//
|
||||
namespace omath::system::pe
|
||||
{
|
||||
struct SectionHeader final
|
||||
{
|
||||
char name[8];
|
||||
union
|
||||
{
|
||||
std::uint32_t physical_address;
|
||||
std::uint32_t virtual_size;
|
||||
};
|
||||
std::uint32_t virtual_address;
|
||||
|
||||
std::uint32_t size_raw_data;
|
||||
std::uint32_t ptr_raw_data;
|
||||
|
||||
std::uint32_t ptr_relocs;
|
||||
std::uint32_t ptr_line_numbers;
|
||||
std::uint32_t num_relocs;
|
||||
std::uint32_t num_line_numbers;
|
||||
|
||||
std::uint32_t characteristics;
|
||||
};
|
||||
}
|
||||
@@ -2,11 +2,8 @@
|
||||
// Created by Vlad on 10/7/2025.
|
||||
//
|
||||
#include "omath/utility/pe_pattern_scan.hpp"
|
||||
#include "omath/system/pe/image_nt_headers.hpp"
|
||||
#include "omath/system/pe/section_header.hpp"
|
||||
#include "omath/utility/pattern_scan.hpp"
|
||||
#include <fstream>
|
||||
#include <omath/system/pe/dos_header.hpp>
|
||||
#include <span>
|
||||
#include <stdexcept>
|
||||
#include <variant>
|
||||
@@ -14,22 +11,190 @@
|
||||
#include <Windows.h>
|
||||
#endif
|
||||
|
||||
using namespace omath::system::pe;
|
||||
namespace
|
||||
{
|
||||
constexpr std::uint16_t opt_hdr32_magic = 0x010B;
|
||||
constexpr std::uint16_t opt_hdr64_magic = 0x020B;
|
||||
|
||||
// Standard fields.
|
||||
// ReSharper disable CppDeclaratorNeverUsed
|
||||
struct DataDirectory final
|
||||
{
|
||||
std::uint32_t rva;
|
||||
std::uint32_t size;
|
||||
};
|
||||
struct OptionalHeaderX64 final
|
||||
{
|
||||
|
||||
std::uint16_t magic;
|
||||
|
||||
std::uint16_t linker_version;
|
||||
|
||||
std::uint32_t size_code;
|
||||
std::uint32_t size_init_data;
|
||||
std::uint32_t size_uninit_data;
|
||||
|
||||
std::uint32_t entry_point;
|
||||
std::uint32_t base_of_code;
|
||||
|
||||
// NT additional fields.
|
||||
std::uint64_t image_base;
|
||||
std::uint32_t section_alignment;
|
||||
std::uint32_t file_alignment;
|
||||
|
||||
std::uint32_t os_version;
|
||||
std::uint32_t img_version;
|
||||
std::uint32_t subsystem_version;
|
||||
std::uint32_t win32_version_value;
|
||||
|
||||
std::uint32_t size_image;
|
||||
std::uint32_t size_headers;
|
||||
|
||||
std::uint32_t checksum;
|
||||
std::uint16_t subsystem;
|
||||
std::uint16_t characteristics;
|
||||
|
||||
std::uint64_t size_stack_reserve;
|
||||
std::uint64_t size_stack_commit;
|
||||
std::uint64_t size_heap_reserve;
|
||||
std::uint64_t size_heap_commit;
|
||||
|
||||
std::uint32_t ldr_flags;
|
||||
|
||||
std::uint32_t num_data_directories;
|
||||
DataDirectory data_directories[16];
|
||||
};
|
||||
struct OptionalHeaderX86 final
|
||||
{
|
||||
// Standard fields.
|
||||
std::uint16_t magic{};
|
||||
std::uint16_t linker_version{};
|
||||
|
||||
std::uint32_t size_code{};
|
||||
std::uint32_t size_init_data{};
|
||||
std::uint32_t size_uninit_data{};
|
||||
|
||||
std::uint32_t entry_point{};
|
||||
std::uint32_t base_of_code{};
|
||||
std::uint32_t base_of_data{};
|
||||
|
||||
// NT additional fields.
|
||||
std::uint32_t image_base{};
|
||||
std::uint32_t section_alignment{};
|
||||
std::uint32_t file_alignment{};
|
||||
|
||||
std::uint32_t os_version{};
|
||||
std::uint32_t img_version{};
|
||||
std::uint32_t subsystem_version{};
|
||||
std::uint32_t win32_version_value{};
|
||||
|
||||
std::uint32_t size_image{};
|
||||
std::uint32_t size_headers{};
|
||||
|
||||
std::uint32_t checksum{};
|
||||
std::uint16_t subsystem{};
|
||||
std::uint16_t characteristics{};
|
||||
|
||||
std::uint32_t size_stack_reserve{};
|
||||
std::uint32_t size_stack_commit{};
|
||||
std::uint32_t size_heap_reserve{};
|
||||
std::uint32_t size_heap_commit{};
|
||||
|
||||
std::uint32_t ldr_flags{};
|
||||
|
||||
std::uint32_t num_data_directories{};
|
||||
DataDirectory data_directories[16]{};
|
||||
};
|
||||
template<bool x64 = true>
|
||||
using OptionalHeader = std::conditional_t<x64, OptionalHeaderX64, OptionalHeaderX86>;
|
||||
|
||||
struct FileHeader final
|
||||
{
|
||||
std::uint16_t machine;
|
||||
std::uint16_t num_sections;
|
||||
std::uint32_t timedate_stamp;
|
||||
std::uint32_t ptr_symbols;
|
||||
std::uint32_t num_symbols;
|
||||
std::uint16_t size_optional_header;
|
||||
std::uint16_t characteristics;
|
||||
};
|
||||
|
||||
struct DosHeader final
|
||||
{
|
||||
std::uint16_t e_magic;
|
||||
std::uint16_t e_cblp;
|
||||
std::uint16_t e_cp;
|
||||
std::uint16_t e_crlc;
|
||||
std::uint16_t e_cparhdr;
|
||||
std::uint16_t e_minalloc;
|
||||
std::uint16_t e_maxalloc;
|
||||
std::uint16_t e_ss;
|
||||
std::uint16_t e_sp;
|
||||
std::uint16_t e_csum;
|
||||
std::uint16_t e_ip;
|
||||
std::uint16_t e_cs;
|
||||
std::uint16_t e_lfarlc;
|
||||
std::uint16_t e_ovno;
|
||||
std::uint16_t e_res[4];
|
||||
std::uint16_t e_oemid;
|
||||
std::uint16_t e_oeminfo;
|
||||
std::uint16_t e_res2[10];
|
||||
std::uint32_t e_lfanew;
|
||||
};
|
||||
|
||||
enum class NtArchitecture
|
||||
{
|
||||
x32_bit,
|
||||
x64_bit,
|
||||
};
|
||||
template<NtArchitecture architecture>
|
||||
struct ImageNtHeaders final
|
||||
{
|
||||
std::uint32_t signature;
|
||||
FileHeader file_header;
|
||||
OptionalHeader<architecture == NtArchitecture::x64_bit> optional_header;
|
||||
};
|
||||
|
||||
struct SectionHeader final
|
||||
{
|
||||
char name[8];
|
||||
union
|
||||
{
|
||||
std::uint32_t physical_address;
|
||||
std::uint32_t virtual_size;
|
||||
};
|
||||
std::uint32_t virtual_address;
|
||||
|
||||
std::uint32_t size_raw_data;
|
||||
std::uint32_t ptr_raw_data;
|
||||
|
||||
std::uint32_t ptr_relocs;
|
||||
std::uint32_t ptr_line_numbers;
|
||||
std::uint32_t num_relocs;
|
||||
std::uint32_t num_line_numbers;
|
||||
|
||||
std::uint32_t characteristics;
|
||||
};
|
||||
// ReSharper restore CppDeclaratorNeverUsed
|
||||
}
|
||||
using NtHeaderVariant = std::variant<ImageNtHeaders<NtArchitecture::x64_bit>, ImageNtHeaders<NtArchitecture::x32_bit>>;
|
||||
|
||||
namespace
|
||||
{
|
||||
[[nodiscard]]
|
||||
NtHeaderVariant get_nt_header_from_file(std::fstream& file, const DosHeader& dos_header)
|
||||
std::optional<NtHeaderVariant> get_nt_header_from_file(std::fstream& file, const DosHeader& dos_header)
|
||||
{
|
||||
ImageNtHeaders<NtArchitecture::x32_bit> x86_headers;
|
||||
ImageNtHeaders<NtArchitecture::x32_bit> x86_headers{};
|
||||
file.seekg(dos_header.e_lfanew, std::ios::beg);
|
||||
file.read(reinterpret_cast<char*>(&x86_headers), sizeof(x86_headers));
|
||||
|
||||
if (x86_headers.optional_header.magic == opt_hdr32_magic)
|
||||
return x86_headers;
|
||||
|
||||
ImageNtHeaders<NtArchitecture::x64_bit> x64_headers;
|
||||
if (x86_headers.optional_header.magic != opt_hdr64_magic)
|
||||
return std::nullopt;
|
||||
|
||||
ImageNtHeaders<NtArchitecture::x64_bit> x64_headers{};
|
||||
file.seekg(dos_header.e_lfanew, std::ios::beg);
|
||||
file.read(reinterpret_cast<char*>(&x64_headers), sizeof(x64_headers));
|
||||
|
||||
@@ -72,6 +237,7 @@ namespace omath
|
||||
|
||||
const auto scan_range = std::span{reinterpret_cast<std::byte*>(base_address) + start, scan_size};
|
||||
|
||||
// ReSharper disable once CppTooWideScopeInitStatement
|
||||
const auto result = PatternScanner::scan_for_pattern(scan_range, pattern);
|
||||
|
||||
if (result != scan_range.cend())
|
||||
@@ -120,7 +286,10 @@ namespace omath
|
||||
|
||||
const auto nt_headers = get_nt_header_from_file(file, dos_header);
|
||||
|
||||
if (invalid_nt_header_file(nt_headers)) [[unlikely]]
|
||||
if (!nt_headers)
|
||||
return std::nullopt;
|
||||
|
||||
if (invalid_nt_header_file(nt_headers.value())) [[unlikely]]
|
||||
return std::nullopt;
|
||||
|
||||
return std::visit(
|
||||
@@ -153,6 +322,6 @@ namespace omath
|
||||
}
|
||||
return std::nullopt;
|
||||
},
|
||||
nt_headers);
|
||||
nt_headers.value());
|
||||
}
|
||||
} // namespace omath
|
||||
@@ -16,5 +16,4 @@ set_target_properties(${PROJECT_NAME} PROPERTIES
|
||||
|
||||
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE gtest gtest_main omath::omath)
|
||||
|
||||
gtest_discover_tests(${PROJECT_NAME})
|
||||
Reference in New Issue
Block a user