Add X_RUNTIME_FUNCTION

This commit is contained in:
Sajid 2024-09-11 21:21:23 +06:00
parent 6e48ca31ab
commit 9d6c760ab9
4 changed files with 39 additions and 8 deletions

View File

@ -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 &section;
}
}
return nullptr;
}
std::expected<Image, int> Image::ParseImage(const uint8_t* data, size_t size)
{
if (data[0] == ELFMAG0 && data[1] == ELFMAG1 && data[2] == ELFMAG2 && data[3] == ELFMAG3)

View File

@ -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

View File

@ -162,6 +162,24 @@ struct _XLIST_ENTRY;
typedef _XLIST_ENTRY XLIST_ENTRY;
typedef xpointer<XLIST_ENTRY> 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;

View File

@ -90,12 +90,6 @@ typedef struct _XEX_HEADER
be<uint32_t> NumberOfOptionalHeaders;
} XEX_HEADER;
typedef struct _X_RUNTIME_FUNCTION
{
be<DWORD> BeginAddress;
be<DWORD> Flags; // honestly, no idea
} X_RUNTIME_FUNCTION;
template<typename T>
inline static const T* Xex2FindOptionalHeader(const void* base, const XEX_OPTIONAL_HEADER* headers, size_t n, _XEX_OPTIONAL_HEADER_TYPES type)
{