From 6be0169515cc0cfc3bed4800c2276f0ed7237d97 Mon Sep 17 00:00:00 2001 From: dusoleil Date: Mon, 13 Mar 2023 05:40:15 -0400 Subject: arch: Add docstrings Signed-off-by: dusoleil Reviewed-by: Malfurious --- sploit/arch.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/sploit/arch.py b/sploit/arch.py index 5575b05..ac8ac14 100644 --- a/sploit/arch.py +++ b/sploit/arch.py @@ -1,3 +1,24 @@ +""" +Architecture-aware utilities and global architecture config + +It is common within sploit and for users of sploit to need different behavior +depending on the architecture of the target. This module encapsulates those +behaviors and bases them on a global architecture that is also configured here. + +Users can set the global arch with arch.set() and all of the methods in this +module will honor it. An architecture can be defined through the Arch dataclass +and there are also several predefined architecture constants that can be used. + +arch (Arch): the architecture config that sploit will use whenever it needs to +know the architecture of the target + +predefined architectures: + x86 + x86_64 + ARM + THUMB +""" + from dataclasses import dataclass def btoi(b, signed=False): @@ -8,11 +29,23 @@ def itob(i, signed=False): @dataclass(frozen=True) class Arch: + """ + Dataclass of information about a target architecture + + wordsize (int): the width, in bytes, of the natural unit of data + endianness (str): byte order. either "little" or "big" + alignment (int): the multiple, in bytes, that return addresses must exist + on the stack + nopcode (bytes): the exact bytes of a "do nothing" instruction + """ + wordsize: int endianness: str alignment: int nopcode: bytes + def set(self,k): + """Copy the given Arch into this instance.""" self.__dict__.update(k.__dict__) x86 = Arch( 4, 'little', 16, b'\x90') -- cgit v1.2.3