You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Theodosius/include/decomp/symbol.hpp

59 lines
1.9 KiB

#pragma once
#include <coff/image.hpp>
#include <cstdint>
#include <recomp/reloc.hpp>
#include <string>
#include <vector>
namespace theo::decomp {
/// <summary>
/// meta symbol type. this is an abstraction upon the coff symbol storage/class
/// type.
/// </summary>
enum sym_type_t { function, instruction, data, section };
/// <summary>
/// symbol_t is an abstraction upon the coff symbol. this allows for easier
/// manipulation of the symbol. symbols can be different things, sections,
/// functions, and even instructions (when functions are broken down).
///
/// this class is used throughout theodosius and is a keystone of the project.
/// </summary>
class symbol_t {
public:
explicit symbol_t(coff::image_t* img,
std::string name,
std::uintptr_t offset,
std::vector<std::uint8_t> data,
coff::section_header_t* scn = {},
coff::symbol_t* sym = {},
std::vector<recomp::reloc_t> relocs = {},
sym_type_t dcmp_type = {});
std::string name() const;
std::uintptr_t offset() const;
std::uintptr_t allocated_at() const;
std::uint32_t size() const;
coff::section_header_t* scn() const;
coff::image_t* img() const;
std::vector<std::uint8_t>& data();
coff::symbol_t* sym() const;
sym_type_t type() const;
std::vector<recomp::reloc_t>& relocs();
void allocated_at(std::uintptr_t allocated_at);
std::size_t hash();
static std::size_t hash(const std::string& sym);
static std::string name(const coff::image_t* img, coff::symbol_t* sym);
private:
std::string m_name;
std::uintptr_t m_offset, m_allocated_at;
std::vector<std::uint8_t> m_data;
coff::section_header_t* m_scn;
std::vector<recomp::reloc_t> m_relocs;
sym_type_t m_sym_type;
coff::symbol_t* m_sym;
coff::image_t* m_img;
};
} // namespace theo::decomp