summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordusoleil <howcansocksbereal@gmail.com>2023-03-16 18:33:23 -0400
committerdusoleil <howcansocksbereal@gmail.com>2023-03-16 18:33:23 -0400
commita28613b5b3df545f5d6ac8c8de59405e2358366e (patch)
tree0e82b015cddb590895592c6f000c6c482d332c69
parentae0e98ce671086617e840719a87635b8f748595e (diff)
downloadsploit-a28613b5b3df545f5d6ac8c8de59405e2358366e.tar.gz
sploit-a28613b5b3df545f5d6ac8c8de59405e2358366e.zip
arch: Move predefined Arch's to top of file
Also added a DEFAULT_ARCH constant. Signed-off-by: dusoleil <howcansocksbereal@gmail.com>
-rw-r--r--sploit/arch.py27
1 files changed, 17 insertions, 10 deletions
diff --git a/sploit/arch.py b/sploit/arch.py
index 2d95493..7355f7e 100644
--- a/sploit/arch.py
+++ b/sploit/arch.py
@@ -8,19 +8,27 @@ 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.
+These are accessible by name at module scope. (i.e. sploit.arch.x86_64)
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
+DEFAULT_ARCH (Arch): the default architecture that arch is set to
"""
from dataclasses import dataclass
+def __define_architectures():
+ # All predefined architectures should be listed here
+ # These will also be added to the module's namespace
+ __arch_list = {
+ 'x86' : Arch( 4, 'little', 16, b'\x90'),
+ 'x86_64' : Arch( 8, 'little', 16, b'\x90'),
+ 'ARM' : Arch( 4, 'little', 8, b'\xe1\xa0\x00\x00'),
+ 'THUMB' : Arch( 4, 'little', 8, b'\x46\xc0')
+ }
+ globals().update(__arch_list)
+
@dataclass(frozen=True)
class Arch:
"""
@@ -43,13 +51,12 @@ class Arch:
if type(new_arch) is not Arch:
raise TypeError(f'arch: new_arch must be an Arch: {new_arch}')
self.__dict__.update(new_arch.__dict__)
+__define_architectures()
+
+DEFAULT_ARCH = x86_64
+arch = Arch(**DEFAULT_ARCH.__dict__)
-x86 = Arch( 4, 'little', 16, b'\x90')
-x86_64 = Arch( 8, 'little', 16, b'\x90')
-ARM = Arch( 4, 'little', 8, b'\xe1\xa0\x00\x00')
-THUMB = Arch( 4, 'little', 8, b'\x46\xc0')
-arch = Arch(**x86_64.__dict__)
def sint(i):