From 0b7f6eba62c93c53c0adc9eda6c8fffb507b8fdd Mon Sep 17 00:00:00 2001 From: dusoleil Date: Mon, 13 Mar 2023 09:18:41 -0400 Subject: arch: refactor byte/int conversions The built in int's to_bytes and from_bytes functions have some weird behavior with the signed parameter. Rather than expecting the user to properly give btoi/itob the right signed value to pass through to to_bytes/from_btyes, it makes more sense to just always convert an unsigned number. Using the new int conversions, this can always be unambiguous with respect to the width of the int. There may also be situations where a user would like to truncate/sign extend an int to a certain length other than the configured architecture wordsize or convert to a different endianness. These are now parameterized. There is no need to parameterize the width for btoi because you will now always get an unsigned int back (and because of python, the width is ambiguous). The user can convert it to whatever width/sign they want after the fact with the new int conversion methods. This also means that payload's int() does not need to take a signed argument either. Whatever sign of int you give it, when it calls itob, it will get the correct bytearray at the width of the configured architecture's wordsize. Signed-off-by: dusoleil Reviewed-by: Malfurious --- sploit/payload.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'sploit/payload.py') diff --git a/sploit/payload.py b/sploit/payload.py index 1775ceb..1ece105 100644 --- a/sploit/payload.py +++ b/sploit/payload.py @@ -43,8 +43,8 @@ class Payload: values = [ v.encode() + b'\x00' for v in values ] 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 ] + def int(self, *values, sym=None): + values = [ itob(v) for v in values ] return self.bin(*values, sym=self._name('int', sym)) def ret(self, *values, sym=None): -- cgit v1.2.3