fxos: remove now-unused old "symbols" storage
This is being replaced by: - Binary objects for functions, variables, etc. (WIP) - Hardcoded tables for syscalls and their prototypes. (TODO)
This commit is contained in:
parent
1df2a14c06
commit
9ed14e9fa7
|
@ -46,7 +46,6 @@ set(fxos_core_SOURCES
|
|||
lib/passes/syscall.cpp
|
||||
lib/project.cpp
|
||||
lib/semantics.cpp
|
||||
lib/symbols.cpp
|
||||
lib/view/assembly.cpp
|
||||
lib/vspace.cpp
|
||||
|
||||
|
@ -79,7 +78,6 @@ set(fxos_shell_SOURCES
|
|||
shell/e.cpp
|
||||
shell/h.cpp
|
||||
shell/i.cpp
|
||||
shell/m.cpp
|
||||
shell/p.cpp
|
||||
shell/s.cpp
|
||||
${FLEX_Lexer_OUTPUTS}
|
||||
|
|
|
@ -1,96 +0,0 @@
|
|||
//---------------------------------------------------------------------------//
|
||||
// 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.
|
||||
//---
|
||||
|
||||
#ifndef FXOS_SYMBOLS_H
|
||||
#define FXOS_SYMBOLS_H
|
||||
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <cstdint>
|
||||
|
||||
namespace FxOS {
|
||||
|
||||
/* A named symbol that can be substituted to literal values in the code. */
|
||||
struct Symbol
|
||||
{
|
||||
enum Type { Syscall = 1, Address = 2 };
|
||||
|
||||
enum Type type;
|
||||
uint32_t value;
|
||||
|
||||
/* Symbol name, no particular conventions */
|
||||
std::string name;
|
||||
|
||||
bool operator<(const FxOS::Symbol &right) const
|
||||
{
|
||||
return (type < right.type)
|
||||
|| (value < right.value && type == right.type);
|
||||
}
|
||||
|
||||
bool operator>(const FxOS::Symbol &right) const
|
||||
{
|
||||
return (type > right.type)
|
||||
|| (value > right.value && type == right.type);
|
||||
}
|
||||
|
||||
bool operator==(const FxOS::Symbol &right) const
|
||||
{
|
||||
return value == right.value && type == right.type;
|
||||
}
|
||||
|
||||
bool operator!=(const FxOS::Symbol &right) const
|
||||
{
|
||||
return value != right.value || type != right.type;
|
||||
}
|
||||
|
||||
bool operator>=(const FxOS::Symbol &right) const
|
||||
{
|
||||
return (type > right.type)
|
||||
|| (value >= right.value && type == right.type);
|
||||
}
|
||||
|
||||
bool operator<=(const FxOS::Symbol &right) const
|
||||
{
|
||||
return (type < right.type)
|
||||
|| (value <= right.value && type == right.type);
|
||||
}
|
||||
};
|
||||
|
||||
/* A symbol table, usually the set of symbols of a virtual space */
|
||||
struct SymbolTable
|
||||
{
|
||||
SymbolTable();
|
||||
|
||||
/* Allow move but disable copy */
|
||||
SymbolTable(SymbolTable const &other) = delete;
|
||||
SymbolTable(SymbolTable &&other) = default;
|
||||
|
||||
std::string table_name;
|
||||
std::vector<Symbol> symbols;
|
||||
|
||||
/* 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;
|
||||
};
|
||||
|
||||
} /* namespace FxOS */
|
||||
|
||||
#endif /* FXOS_SYMBOLS_H */
|
|
@ -24,7 +24,6 @@
|
|||
|
||||
#include <fxos/memory.h>
|
||||
#include <fxos/os.h>
|
||||
#include <fxos/symbols.h>
|
||||
#include <fxos/disassembly.h>
|
||||
#include <fxos/util/Buffer.h>
|
||||
#include <fxos/util/Addressable.h>
|
||||
|
@ -127,7 +126,6 @@ public:
|
|||
char const *translate_dynamic(uint32_t addr, int *size) override;
|
||||
|
||||
// TODO: Remove these
|
||||
SymbolTable symbols;
|
||||
Disassembly disasm;
|
||||
private:
|
||||
std::unique_ptr<OS> m_os;
|
||||
|
|
|
@ -1,43 +0,0 @@
|
|||
//---------------------------------------------------------------------------//
|
||||
// 1100101 |_ mov #0, r4 __ //
|
||||
// 11 |_ <0xb380 %5c4> / _|_ _____ ___ //
|
||||
// 0110 |_ 3.50 -> 3.60 | _\ \ / _ (_-< //
|
||||
// |_ base# + offset |_| /_\_\___/__/ //
|
||||
//---------------------------------------------------------------------------//
|
||||
|
||||
#include <fxos/symbols.h>
|
||||
#include <fxos/vspace.h>
|
||||
|
||||
namespace FxOS {
|
||||
|
||||
SymbolTable::SymbolTable()
|
||||
{
|
||||
}
|
||||
|
||||
void SymbolTable::add(Symbol s)
|
||||
{
|
||||
symbols.push_back(s);
|
||||
}
|
||||
|
||||
std::optional<std::string> SymbolTable::query(
|
||||
Symbol::Type type, uint32_t value) const
|
||||
{
|
||||
for(auto &sym: symbols) {
|
||||
if(sym.type == type && sym.value == value)
|
||||
return sym.name;
|
||||
}
|
||||
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
std::optional<Symbol> SymbolTable::lookup(std::string name) const
|
||||
{
|
||||
for(auto &sym: symbols) {
|
||||
if(sym.name == name)
|
||||
return sym;
|
||||
}
|
||||
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
} /* namespace FxOS */
|
45
shell/m.cpp
45
shell/m.cpp
|
@ -1,45 +0,0 @@
|
|||
#include "parser.h"
|
||||
#include "shell.h"
|
||||
#include <fxos/util/log.h>
|
||||
|
||||
//---
|
||||
// ms
|
||||
//---
|
||||
|
||||
static FxOS::Symbol parse_ms(Session &session, Parser &parser)
|
||||
{
|
||||
FxOS::Symbol s;
|
||||
|
||||
if(parser.lookahead().type == T::SYSCALL) {
|
||||
s.type = FxOS::Symbol::Syscall;
|
||||
s.value = parser.expect(T::SYSCALL).value.NUM;
|
||||
}
|
||||
else {
|
||||
s.type = FxOS::Symbol::Address;
|
||||
s.value = parser.expr(session.currentBinary());
|
||||
}
|
||||
|
||||
s.name = parser.symbol();
|
||||
parser.end();
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
void _ms(Session &session, Symbol s)
|
||||
{
|
||||
if(!session.currentBinary())
|
||||
return;
|
||||
FxOS_log(ERR, "Creating new objects is a TODO o(x_x)o\n");
|
||||
// session.current_space->symbols.add(s);
|
||||
}
|
||||
|
||||
static ShellCommand _ms_cmd(
|
||||
"ms", [](Session &s, Parser &p) { _ms(s, parse_ms(s, p)); },
|
||||
[](Session &s, Parser &p) { parse_ms(s, p); }, "Metadata Symbol", R"(
|
||||
ms <address|syscall> <symbol>
|
||||
|
||||
Defines a new symbol at the specified address or syscall number in the current
|
||||
virtual space. If a syscall number is provided, the address is not resolved;
|
||||
the same syscall symbol can be used across multiple OS versions regardless of
|
||||
where the functions are actually located.
|
||||
)");
|
|
@ -145,9 +145,9 @@ public:
|
|||
to query symbol values */
|
||||
long num();
|
||||
long expr(Binary *b);
|
||||
/* Read a range; again $ and symbols are interpreted. If (before) and
|
||||
(after) are both specified, a single value will also be accepted, and
|
||||
the range [value-before, value+after) will be returned. */
|
||||
/* Read a range; again symbols are interpreted. If (before) and (after) are
|
||||
both specified, a single value will also be accepted, and the range
|
||||
[value-before, value+after) will be returned. */
|
||||
Range range(Binary *b, long before=-1, long after=-1);
|
||||
/* Read an expression or a range */
|
||||
std::variant<long, Range> expr_or_range(Binary *b);
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
#include "errors.h"
|
||||
#include "theme.h"
|
||||
|
||||
#include <fxos/symbols.h>
|
||||
#include <fmt/core.h>
|
||||
#include <endian.h>
|
||||
|
||||
|
|
Loading…
Reference in New Issue