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 | e0c0ac8cf9fb7bab5619cbd9171ba3e1b76c5051 (patch) | |
tree | bce0516cedd569e93551e2b9d2994662e4f290ed | |
parent | e2e19ae710abdb77e232e5e3eb2aec503cbaacad (diff) | |
download | sploit-e0c0ac8cf9fb7bab5619cbd9171ba3e1b76c5051.tar.gz sploit-e0c0ac8cf9fb7bab5619cbd9171ba3e1b76c5051.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-- | sploit/payload.py | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/sploit/payload.py b/sploit/payload.py index 0bbf463..0e32975 100644 --- a/sploit/payload.py +++ b/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: |