2024-09-07 22:56:20 +06:00
|
|
|
#pragma once
|
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
2024-09-08 08:32:31 +06:00
|
|
|
#include <set>
|
2024-09-07 22:56:20 +06:00
|
|
|
#include <expected>
|
2024-09-08 08:32:31 +06:00
|
|
|
#include <section.h>
|
|
|
|
#include "symbol_table.h"
|
2024-09-07 22:56:20 +06:00
|
|
|
|
|
|
|
struct Image
|
|
|
|
{
|
|
|
|
std::unique_ptr<uint8_t[]> data{};
|
|
|
|
size_t base{};
|
|
|
|
uint32_t size{};
|
|
|
|
|
|
|
|
size_t entry_point{};
|
2024-09-08 08:32:31 +06:00
|
|
|
std::set<Section, SectionComparer> sections{};
|
|
|
|
SymbolTable symbols{};
|
2024-09-07 22:56:20 +06:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Map data to image by RVA
|
|
|
|
* \param name Name of section
|
|
|
|
* \param base Section RVA
|
|
|
|
* \param size Section Size
|
|
|
|
* \param flags Section Flags, enum SectionFlags
|
|
|
|
* \param data Section data
|
|
|
|
*/
|
|
|
|
void Map(const std::string_view& name, size_t base, uint32_t size, uint8_t flags, uint8_t* data);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \param address Virtual Address
|
|
|
|
* \return Pointer to image owned data
|
|
|
|
*/
|
|
|
|
const void* Find(size_t address) const;
|
|
|
|
|
2024-09-11 21:21:23 +06:00
|
|
|
/**
|
|
|
|
* \param name Name of section
|
|
|
|
* \return Section
|
|
|
|
*/
|
|
|
|
const Section* Find(const std::string_view& name) const;
|
|
|
|
|
2024-09-07 22:56:20 +06:00
|
|
|
/**
|
|
|
|
* \brief Parse given data to an image, reallocates with ownership
|
|
|
|
* \param data Pointer to data
|
|
|
|
* \param size Size of data
|
|
|
|
* \return Parsed image
|
|
|
|
*/
|
|
|
|
static std::expected<Image, int> ParseImage(const uint8_t* data, size_t size);
|
|
|
|
};
|
|
|
|
|
|
|
|
Image ElfLoadImage(const uint8_t* data, size_t size);
|