2022-03-27 18:32:19 +02:00
|
|
|
//---------------------------------------------------------------------------//
|
|
|
|
// 1100101 |_ mov #0, r4 __ //
|
|
|
|
// 11 |_ <0xb380 %5c4> / _|_ _____ ___ //
|
|
|
|
// 0110 |_ 3.50 -> 3.60 | _\ \ / _ (_-< //
|
|
|
|
// |_ base# + offset |_| /_\_\___/__/ //
|
|
|
|
//---------------------------------------------------------------------------//
|
|
|
|
// fxos/symbols: User-extensible naming scheme for OS objects
|
|
|
|
//
|
|
|
|
// This header provides tools to define symbols, ie. names attached to fixed or
|
|
|
|
// symbolic addresses. Currently supported:
|
|
|
|
// - Address: the name maps to a fixed 32-bit virtual address.
|
|
|
|
// - Syscall: the name maps to a syscall number resolved by OS analysis.
|
|
|
|
//
|
|
|
|
// The SymbolTable structure manages a set of symbols, usually all the symbols
|
|
|
|
// in a given virtual space.
|
2020-02-15 18:42:14 +01:00
|
|
|
//---
|
|
|
|
|
2022-03-27 18:32:19 +02:00
|
|
|
#ifndef FXOS_SYMBOLS_H
|
|
|
|
#define FXOS_SYMBOLS_H
|
2020-02-15 18:42:14 +01:00
|
|
|
|
|
|
|
#include <optional>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2022-03-27 18:32:19 +02:00
|
|
|
namespace FxOS {
|
2022-03-04 12:29:33 +01:00
|
|
|
|
2020-02-15 18:42:14 +01:00
|
|
|
/* A named symbol that can be substituted to literal values in the code. */
|
|
|
|
struct Symbol
|
|
|
|
{
|
2022-04-14 13:30:43 +02:00
|
|
|
enum Type { Syscall = 1, Address = 2 };
|
2020-02-15 18:42:14 +01:00
|
|
|
|
2022-03-27 18:32:19 +02:00
|
|
|
enum Type type;
|
|
|
|
uint32_t value;
|
2020-02-15 18:42:14 +01:00
|
|
|
|
2022-03-27 18:32:19 +02:00
|
|
|
/* Symbol name, no particular conventions */
|
|
|
|
std::string name;
|
2022-12-22 21:11:16 +01:00
|
|
|
|
|
|
|
bool operator<(const FxOS::Symbol &right) const
|
|
|
|
{
|
|
|
|
return (type < right.type) || (value < right.value);
|
|
|
|
}
|
2020-02-15 18:42:14 +01:00
|
|
|
};
|
|
|
|
|
2022-03-27 18:32:19 +02:00
|
|
|
/* A symbol table, usually the set of symbols of a virtual space */
|
|
|
|
struct SymbolTable
|
2020-02-15 18:42:14 +01:00
|
|
|
{
|
2022-03-27 18:32:19 +02:00
|
|
|
SymbolTable();
|
2022-03-04 12:29:33 +01:00
|
|
|
|
2022-03-27 18:32:19 +02:00
|
|
|
/* Allow move but disable copy */
|
|
|
|
SymbolTable(SymbolTable const &other) = delete;
|
|
|
|
SymbolTable(SymbolTable &&other) = default;
|
2020-02-15 18:42:14 +01:00
|
|
|
|
2022-03-27 18:32:19 +02:00
|
|
|
std::string table_name;
|
|
|
|
std::vector<Symbol> symbols;
|
2020-06-13 11:23:46 +02:00
|
|
|
|
2022-03-27 18:32:19 +02:00
|
|
|
/* Add a symbol to the table */
|
|
|
|
void add(Symbol s);
|
|
|
|
/* Query a value for a certain type of symbol */
|
|
|
|
std::optional<std::string> query(Symbol::Type type, uint32_t value) const;
|
|
|
|
/* Lookup the symbol behind a given name */
|
|
|
|
std::optional<Symbol> lookup(std::string name) const;
|
2020-02-15 18:42:14 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
} /* namespace FxOS */
|
|
|
|
|
2022-03-27 18:32:19 +02:00
|
|
|
#endif /* FXOS_SYMBOLS_H */
|