From c9f5d7113c6f977fb31fd7699bd2d5a5869954ad Mon Sep 17 00:00:00 2001 From: Malfurious Date: Wed, 15 Mar 2023 17:12:31 -0400 Subject: rev: Add rop gadget description class This new class is intended to be used to return data from gadget searches, and is able to be nested within object Symtbls. Signed-off-by: Malfurious Signed-off-by: dusoleil --- sploit/rev/__init__.py | 4 ++-- sploit/rev/gadget.py | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 sploit/rev/gadget.py diff --git a/sploit/rev/__init__.py b/sploit/rev/__init__.py index 43cee7b..0d0dc9b 100644 --- a/sploit/rev/__init__.py +++ b/sploit/rev/__init__.py @@ -1,6 +1,6 @@ from . import ( + elf, + gadget, ldd, r2, - elf, ) - diff --git a/sploit/rev/gadget.py b/sploit/rev/gadget.py new file mode 100644 index 0000000..a2564c0 --- /dev/null +++ b/sploit/rev/gadget.py @@ -0,0 +1,36 @@ +from dataclasses import dataclass, field + +@dataclass +class Gadget: + """ + Basic gadget description object + + offset (int): The location this gadget is found at. What `offset` is + relative to depends on context. + + asm (list[re.Match]): A list of assembly instructions matched by the gadget + search query. + """ + + offset: int = 0 + asm: list = field(default_factory=list) + + def __index__(self): + """Convert object to integer using offset value.""" + return self.offset + + def __add__(self, x): + """Return new object with adjusted offset.""" + return Gadget(self.offset + x, self.asm) + + def __sub__(self, x): + """Return new object with adjusted offset.""" + return self + (-x) + + def __repr__(self): + """Return human-readable Gadget.""" + s = hex(self.offset) + if len(self.asm) > 0: + asm = "; ".join([ m.string for m in self.asm ]) + s += f", '{asm}'" + return f"Gadget({s})" -- cgit v1.2.3