diff options
author | Malfurious <m@lfurio.us> | 2022-07-08 00:04:02 -0400 |
---|---|---|
committer | Malfurious <m@lfurio.us> | 2022-09-12 20:15:35 -0400 |
commit | 51d92be1f5eb0ec188b635366d588f61f5f3bca4 (patch) | |
tree | 3d0dc7e75774b51d38b9813ae0e38268cb49f00c | |
parent | 9759d731da4787ea0679ebe9700d72397ec788b2 (diff) | |
download | lib-des-gnux-51d92be1f5eb0ec188b635366d588f61f5f3bca4.tar.gz lib-des-gnux-51d92be1f5eb0ec188b635366d588f61f5f3bca4.zip |
sploit: payload: Clean up automatic symbol naming
This is just a slight code reduction, but will make any future code
simpler as well. Explicit comparision to None is more correct as well;
centralizing this for reuse better justifies the wordier if statement.
Signed-off-by: Malfurious <m@lfurio.us>
Signed-off-by: dusoleil <howcansocksbereal@gmail.com>
-rw-r--r-- | tools/sploit/sploit/payload.py | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/tools/sploit/sploit/payload.py b/tools/sploit/sploit/payload.py index 0bbf463..0e32975 100644 --- a/tools/sploit/sploit/payload.py +++ b/tools/sploit/sploit/payload.py @@ -18,7 +18,8 @@ class Payload: raise Exception(f'Payload: bad bytes in content: {found}') return self.payload - def __name(self, kind): + def __name(self, kind, sym): + if sym is not None: return sym try: ctr = self.ctrs[kind] except: ctr = 0 self.ctrs[kind] = ctr + 1 @@ -36,32 +37,32 @@ class Payload: return self def bin(self, *values, sym=None): - return self.__append(b''.join(values), sym or self.__name('bin')) + return self.__append(b''.join(values), sym=self.__name('bin', sym)) def str(self, *values, sym=None): values = [ v.encode() + b'\x00' for v in values ] - return self.bin(*values, sym=(sym or self.__name('str'))) + return self.bin(*values, sym=self.__name('str', sym)) def int(self, *values, sym=None, signed=False): values = [ itob(v, signed=signed) for v in values ] - return self.bin(*values, sym=(sym or self.__name('int'))) + return self.bin(*values, sym=self.__name('int', sym)) def ret(self, *values, sym=None): - return self.int(*values, sym=(sym or self.__name('ret'))) + return self.int(*values, sym=self.__name('ret', sym)) def sbp(self, *values, sym=None): if len(values) == 0: - return self.rep(self.MAGIC, arch.wordsize, sym or self.__name('sbp')) - return self.int(*values, sym=(sym or self.__name('sbp'))) + return self.rep(self.MAGIC, arch.wordsize, sym=self.__name('sbp', sym)) + return self.int(*values, sym=self.__name('sbp', sym)) def rep(self, value, size, sym=None): - return self.bin(self.__rep_helper(value, size), sym=(sym or self.__name('rep'))) + return self.bin(self.__rep_helper(value, size), sym=self.__name('rep', sym)) def pad(self, size, value=None, sym=None): - return self.bin(self.__pad_helper(size, value), sym=(sym or self.__name('pad'))) + return self.bin(self.__pad_helper(size, value), sym=self.__name('pad', sym)) def pad_front(self, size, value=None, sym=None): - return self.__prepend(self.__pad_helper(size, value), sym or self.__name('pad')) + return self.__prepend(self.__pad_helper(size, value), sym=self.__name('pad', sym)) def __rep_helper(self, value, size, *, explain=''): if size < 0: |