From 9d6c760ab9cce642144051e4e0b71f8441745a20 Mon Sep 17 00:00:00 2001 From: Sajid Date: Wed, 11 Sep 2024 21:21:23 +0600 Subject: [PATCH] Add X_RUNTIME_FUNCTION --- PowerUtils/image.cpp | 13 +++++++++++++ PowerUtils/image.h | 6 ++++++ PowerUtils/xbox.h | 20 +++++++++++++++++++- PowerUtils/xex.h | 8 +------- 4 files changed, 39 insertions(+), 8 deletions(-) diff --git a/PowerUtils/image.cpp b/PowerUtils/image.cpp index 6a9b73c..7a88bd0 100644 --- a/PowerUtils/image.cpp +++ b/PowerUtils/image.cpp @@ -20,6 +20,19 @@ const void* Image::Find(size_t address) const return section->data + (address - section->base); } +const Section* Image::Find(const std::string_view& name) const +{ + for (const auto& section : sections) + { + if (section.name == name) + { + return §ion; + } + } + + return nullptr; +} + std::expected Image::ParseImage(const uint8_t* data, size_t size) { if (data[0] == ELFMAG0 && data[1] == ELFMAG1 && data[2] == ELFMAG2 && data[3] == ELFMAG3) diff --git a/PowerUtils/image.h b/PowerUtils/image.h index ec67922..0c0da91 100644 --- a/PowerUtils/image.h +++ b/PowerUtils/image.h @@ -32,6 +32,12 @@ struct Image */ const void* Find(size_t address) const; + /** + * \param name Name of section + * \return Section + */ + const Section* Find(const std::string_view& name) const; + /** * \brief Parse given data to an image, reallocates with ownership * \param data Pointer to data diff --git a/PowerUtils/xbox.h b/PowerUtils/xbox.h index 8b2785a..0ea6968 100644 --- a/PowerUtils/xbox.h +++ b/PowerUtils/xbox.h @@ -162,6 +162,24 @@ struct _XLIST_ENTRY; typedef _XLIST_ENTRY XLIST_ENTRY; typedef xpointer PXLIST_ENTRY; +typedef struct _X_RUNTIME_FUNCTION +{ + DWORD BeginAddress; + + union + { + DWORD Data; + struct + { + DWORD FunctionType : 2; + DWORD FunctionLength : 22; + DWORD PrologLength : 8; + }; + }; +} X_RUNTIME_FUNCTION; + +static_assert(sizeof(X_RUNTIME_FUNCTION) == 8); + typedef struct _XLIST_ENTRY { XDWORD Flink; @@ -285,4 +303,4 @@ typedef struct _XKSEMAPHORE { XDISPATCHER_HEADER Header; XDWORD Limit; -} XKSEMAPHORE; \ No newline at end of file +} XKSEMAPHORE; diff --git a/PowerUtils/xex.h b/PowerUtils/xex.h index 052eeb0..0ff0a5e 100644 --- a/PowerUtils/xex.h +++ b/PowerUtils/xex.h @@ -90,12 +90,6 @@ typedef struct _XEX_HEADER be NumberOfOptionalHeaders; } XEX_HEADER; -typedef struct _X_RUNTIME_FUNCTION -{ - be BeginAddress; - be Flags; // honestly, no idea -} X_RUNTIME_FUNCTION; - template inline static const T* Xex2FindOptionalHeader(const void* base, const XEX_OPTIONAL_HEADER* headers, size_t n, _XEX_OPTIONAL_HEADER_TYPES type) { @@ -124,4 +118,4 @@ inline static const T* Xex2FindOptionalHeader(const XEX_HEADER* header, _XEX_OPT } struct Image; -Image Xex2LoadImage(const uint8_t* data); \ No newline at end of file +Image Xex2LoadImage(const uint8_t* data);