diff options
author | Malfurious <m@lfurio.us> | 2023-03-11 08:58:26 -0500 |
---|---|---|
committer | dusoleil <howcansocksbereal@gmail.com> | 2023-03-14 16:10:47 -0400 |
commit | 88fb92aa6cfdcc35f9baa9fd9bcc7c1e7ebfc3cb (patch) | |
tree | 662b2b17c11245ce264a3553df3b26a175198be0 | |
parent | e568900727d1f6eb47d92d49ee746abf099a7854 (diff) | |
download | sploit-88fb92aa6cfdcc35f9baa9fd9bcc7c1e7ebfc3cb.tar.gz sploit-88fb92aa6cfdcc35f9baa9fd9bcc7c1e7ebfc3cb.zip |
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 <m@lfurio.us>
Signed-off-by: dusoleil <howcansocksbereal@gmail.com>
-rw-r--r-- | sploit/symtbl.py | 9 |
1 files 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__) |