summaryrefslogtreecommitdiffstats
path: root/sploit/arch.py
blob: e5de2ce07ff5af18c3a1b6535f275cd843923bb7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
from collections import namedtuple as nt

def btoi(b, signed=False):
    return int.from_bytes(b, arch.endianness, signed=signed)

def itob(i, signed=False):
    return i.to_bytes(arch.wordsize, arch.endianness, signed=signed)

Arch = nt("Arch", "wordsize  endianness  alignment  nopcode")
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')

class __ActiveArch__:
    __arch = x86_64
    def __getattr__(self,k):
        return getattr(self.__arch,k)
    def set(self,a):
        self.__arch = a
arch = __ActiveArch__()