From 81f8130fa479fd827bc84354ee9a72b80c9cde02 Mon Sep 17 00:00:00 2001
From: Malfurious <m@lfurio.us>
Date: Wed, 6 Jul 2022 23:30:49 -0400
Subject: sploit: mem: Allow Symtbl base to be modified

Allow a Symtbl's base to be modified in-place, without mapping into a
new object.  This is useful when working with the Symtbl aspect of a
Payload.

This includes setting a non-zero base on construction.  As usual, when
defining base on construction, any additional kwargs symbols are
interpreted relative to the given base.  The order of arguments does not
matter.

Signed-off-by: Malfurious <m@lfurio.us>
Signed-off-by: dusoleil <howcansocksbereal@gmail.com>
---
 tools/sploit/sploit/mem.py | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

(limited to 'tools')

diff --git a/tools/sploit/sploit/mem.py b/tools/sploit/sploit/mem.py
index 3fee92f..9ae0575 100644
--- a/tools/sploit/sploit/mem.py
+++ b/tools/sploit/sploit/mem.py
@@ -1,8 +1,8 @@
 import types
 
 class Symtbl:
-    def __init__(self, **kwargs):
-        object.__setattr__(self, '_namesp', types.SimpleNamespace(base=0,sym={},sub={}))
+    def __init__(self, *, base=0, **kwargs):
+        object.__setattr__(self, '_namesp', types.SimpleNamespace(base=base,sym={},sub={}))
         for k, v in {**kwargs}.items():
             setattr(self, k, v)
 
@@ -15,11 +15,13 @@ class Symtbl:
 
     def __setattr__(self, ident, value):
         if ident in dir(self): raise Exception(f'Symtbl: assignment would shadow non-symbol "{ident}"')
-        if ident == 'base': raise Exception('Symtbl: may not redefine symbol "base"')
         self = self._namesp
-        if type(value) is tuple: self.sub[ident], off = value
-        else: off = value
-        self.sym[ident] = off - self.base
+        if ident == 'base':
+            self.base = value
+        else:
+            if type(value) is tuple: self.sub[ident], off = value
+            else: off = value
+            self.sym[ident] = off - self.base
 
     def map(self, addr, off=0):
         self = self._namesp
-- 
cgit v1.2.3