From 88fb92aa6cfdcc35f9baa9fd9bcc7c1e7ebfc3cb Mon Sep 17 00:00:00 2001 From: Malfurious Date: Sat, 11 Mar 2023 08:58:26 -0500 Subject: symtbl: Overload __getitem__ for translating raw offsets Can now use Symtbl subscript syntax to obtain the mapped address of a foreign offset (not a defined symbol) without having to modify the object or add a new symbol entry. Assuming a base value of 10, tbl[15] will return 25, for example. We now assert that the defined table keys are strings, to prevent the creation of entries that are now un-readable by this patch. However, this always should have been the case. Signed-off-by: Malfurious Signed-off-by: dusoleil --- sploit/symtbl.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/sploit/symtbl.py b/sploit/symtbl.py index ce57277..3babd96 100644 --- a/sploit/symtbl.py +++ b/sploit/symtbl.py @@ -143,17 +143,20 @@ class SymtblImpl: return len(self.__entries__) def __getitem__(self, symbol): - """Return symbol offset or subtable via subscript""" + """Return symbol offset, subtable, or translated offset via subscript""" if symbol == "base": return self.base - return self.__entries__[symbol] + (self.base + self.__adjust__) + offset = symbol if type(symbol) is int else self.__entries__[symbol] + return offset + (self.base + self.__adjust__) def __setitem__(self, symbol, value): """Set symbol offset or subtable via subscript""" if symbol == "base": object.__setattr__(self, "base", int(value)) elif symbol in dir(self): - raise KeyError(f"Symtbl: name '{symbol}' is reserved") + raise KeyError(f"Symtbl: key is reserved: {symbol}") + elif type(symbol) is not str: + raise KeyError(f"Symtbl: key must be a string: {symbol}") else: self.__entries__[symbol] = value - (self.base + self.__adjust__) -- cgit v1.2.3