smallworld-re 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- smallworld/__init__.py +35 -0
- smallworld/analyses/__init__.py +14 -0
- smallworld/analyses/analysis.py +88 -0
- smallworld/analyses/code_coverage.py +31 -0
- smallworld/analyses/colorizer.py +682 -0
- smallworld/analyses/colorizer_summary.py +100 -0
- smallworld/analyses/field_detection/__init__.py +14 -0
- smallworld/analyses/field_detection/field_analysis.py +536 -0
- smallworld/analyses/field_detection/guards.py +26 -0
- smallworld/analyses/field_detection/hints.py +133 -0
- smallworld/analyses/field_detection/malloc.py +211 -0
- smallworld/analyses/forced_exec/__init__.py +3 -0
- smallworld/analyses/forced_exec/forced_exec.py +87 -0
- smallworld/analyses/underlays/__init__.py +4 -0
- smallworld/analyses/underlays/basic.py +13 -0
- smallworld/analyses/underlays/underlay.py +31 -0
- smallworld/analyses/unstable/__init__.py +4 -0
- smallworld/analyses/unstable/angr/__init__.py +0 -0
- smallworld/analyses/unstable/angr/base.py +12 -0
- smallworld/analyses/unstable/angr/divergence.py +274 -0
- smallworld/analyses/unstable/angr/model.py +383 -0
- smallworld/analyses/unstable/angr/nwbt.py +63 -0
- smallworld/analyses/unstable/angr/typedefs.py +170 -0
- smallworld/analyses/unstable/angr/utils.py +25 -0
- smallworld/analyses/unstable/angr/visitor.py +315 -0
- smallworld/analyses/unstable/angr_nwbt.py +106 -0
- smallworld/analyses/unstable/code_coverage.py +54 -0
- smallworld/analyses/unstable/code_reachable.py +44 -0
- smallworld/analyses/unstable/control_flow_tracer.py +71 -0
- smallworld/analyses/unstable/pointer_finder.py +90 -0
- smallworld/arch/__init__.py +0 -0
- smallworld/arch/aarch64_arch.py +286 -0
- smallworld/arch/amd64_arch.py +86 -0
- smallworld/arch/i386_arch.py +44 -0
- smallworld/emulators/__init__.py +14 -0
- smallworld/emulators/angr/__init__.py +7 -0
- smallworld/emulators/angr/angr.py +1652 -0
- smallworld/emulators/angr/default.py +15 -0
- smallworld/emulators/angr/exceptions.py +7 -0
- smallworld/emulators/angr/exploration/__init__.py +9 -0
- smallworld/emulators/angr/exploration/bounds.py +27 -0
- smallworld/emulators/angr/exploration/default.py +17 -0
- smallworld/emulators/angr/exploration/terminate.py +22 -0
- smallworld/emulators/angr/factory.py +55 -0
- smallworld/emulators/angr/machdefs/__init__.py +35 -0
- smallworld/emulators/angr/machdefs/aarch64.py +292 -0
- smallworld/emulators/angr/machdefs/amd64.py +192 -0
- smallworld/emulators/angr/machdefs/arm.py +387 -0
- smallworld/emulators/angr/machdefs/i386.py +221 -0
- smallworld/emulators/angr/machdefs/machdef.py +138 -0
- smallworld/emulators/angr/machdefs/mips.py +184 -0
- smallworld/emulators/angr/machdefs/mips64.py +189 -0
- smallworld/emulators/angr/machdefs/ppc.py +101 -0
- smallworld/emulators/angr/machdefs/riscv.py +261 -0
- smallworld/emulators/angr/machdefs/xtensa.py +255 -0
- smallworld/emulators/angr/memory/__init__.py +7 -0
- smallworld/emulators/angr/memory/default.py +10 -0
- smallworld/emulators/angr/memory/fixups.py +43 -0
- smallworld/emulators/angr/memory/memtrack.py +105 -0
- smallworld/emulators/angr/scratch.py +43 -0
- smallworld/emulators/angr/simos.py +53 -0
- smallworld/emulators/angr/utils.py +70 -0
- smallworld/emulators/emulator.py +1013 -0
- smallworld/emulators/hookable.py +252 -0
- smallworld/emulators/panda/__init__.py +5 -0
- smallworld/emulators/panda/machdefs/__init__.py +28 -0
- smallworld/emulators/panda/machdefs/aarch64.py +93 -0
- smallworld/emulators/panda/machdefs/amd64.py +71 -0
- smallworld/emulators/panda/machdefs/arm.py +89 -0
- smallworld/emulators/panda/machdefs/i386.py +36 -0
- smallworld/emulators/panda/machdefs/machdef.py +86 -0
- smallworld/emulators/panda/machdefs/mips.py +94 -0
- smallworld/emulators/panda/machdefs/mips64.py +91 -0
- smallworld/emulators/panda/machdefs/ppc.py +79 -0
- smallworld/emulators/panda/panda.py +575 -0
- smallworld/emulators/unicorn/__init__.py +13 -0
- smallworld/emulators/unicorn/machdefs/__init__.py +28 -0
- smallworld/emulators/unicorn/machdefs/aarch64.py +310 -0
- smallworld/emulators/unicorn/machdefs/amd64.py +326 -0
- smallworld/emulators/unicorn/machdefs/arm.py +321 -0
- smallworld/emulators/unicorn/machdefs/i386.py +137 -0
- smallworld/emulators/unicorn/machdefs/machdef.py +117 -0
- smallworld/emulators/unicorn/machdefs/mips.py +202 -0
- smallworld/emulators/unicorn/unicorn.py +684 -0
- smallworld/exceptions/__init__.py +5 -0
- smallworld/exceptions/exceptions.py +85 -0
- smallworld/exceptions/unstable/__init__.py +1 -0
- smallworld/exceptions/unstable/exceptions.py +25 -0
- smallworld/extern/__init__.py +4 -0
- smallworld/extern/ctypes.py +94 -0
- smallworld/extern/unstable/__init__.py +1 -0
- smallworld/extern/unstable/ghidra.py +129 -0
- smallworld/helpers.py +107 -0
- smallworld/hinting/__init__.py +8 -0
- smallworld/hinting/hinting.py +214 -0
- smallworld/hinting/hints.py +427 -0
- smallworld/hinting/unstable/__init__.py +2 -0
- smallworld/hinting/utils.py +19 -0
- smallworld/instructions/__init__.py +18 -0
- smallworld/instructions/aarch64.py +20 -0
- smallworld/instructions/arm.py +18 -0
- smallworld/instructions/bsid.py +67 -0
- smallworld/instructions/instructions.py +258 -0
- smallworld/instructions/mips.py +21 -0
- smallworld/instructions/x86.py +100 -0
- smallworld/logging.py +90 -0
- smallworld/platforms.py +95 -0
- smallworld/py.typed +0 -0
- smallworld/state/__init__.py +6 -0
- smallworld/state/cpus/__init__.py +32 -0
- smallworld/state/cpus/aarch64.py +563 -0
- smallworld/state/cpus/amd64.py +676 -0
- smallworld/state/cpus/arm.py +630 -0
- smallworld/state/cpus/cpu.py +71 -0
- smallworld/state/cpus/i386.py +239 -0
- smallworld/state/cpus/mips.py +374 -0
- smallworld/state/cpus/mips64.py +372 -0
- smallworld/state/cpus/powerpc.py +229 -0
- smallworld/state/cpus/riscv.py +357 -0
- smallworld/state/cpus/xtensa.py +80 -0
- smallworld/state/memory/__init__.py +7 -0
- smallworld/state/memory/code.py +70 -0
- smallworld/state/memory/elf/__init__.py +3 -0
- smallworld/state/memory/elf/elf.py +564 -0
- smallworld/state/memory/elf/rela/__init__.py +32 -0
- smallworld/state/memory/elf/rela/aarch64.py +27 -0
- smallworld/state/memory/elf/rela/amd64.py +32 -0
- smallworld/state/memory/elf/rela/arm.py +51 -0
- smallworld/state/memory/elf/rela/i386.py +32 -0
- smallworld/state/memory/elf/rela/mips.py +45 -0
- smallworld/state/memory/elf/rela/ppc.py +45 -0
- smallworld/state/memory/elf/rela/rela.py +63 -0
- smallworld/state/memory/elf/rela/riscv64.py +27 -0
- smallworld/state/memory/elf/rela/xtensa.py +15 -0
- smallworld/state/memory/elf/structs.py +55 -0
- smallworld/state/memory/heap.py +85 -0
- smallworld/state/memory/memory.py +181 -0
- smallworld/state/memory/stack/__init__.py +31 -0
- smallworld/state/memory/stack/aarch64.py +22 -0
- smallworld/state/memory/stack/amd64.py +42 -0
- smallworld/state/memory/stack/arm.py +66 -0
- smallworld/state/memory/stack/i386.py +22 -0
- smallworld/state/memory/stack/mips.py +34 -0
- smallworld/state/memory/stack/mips64.py +34 -0
- smallworld/state/memory/stack/ppc.py +34 -0
- smallworld/state/memory/stack/riscv.py +22 -0
- smallworld/state/memory/stack/stack.py +127 -0
- smallworld/state/memory/stack/xtensa.py +34 -0
- smallworld/state/models/__init__.py +6 -0
- smallworld/state/models/mmio.py +186 -0
- smallworld/state/models/model.py +163 -0
- smallworld/state/models/posix.py +455 -0
- smallworld/state/models/x86/__init__.py +2 -0
- smallworld/state/models/x86/microsoftcdecl.py +35 -0
- smallworld/state/models/x86/systemv.py +240 -0
- smallworld/state/state.py +962 -0
- smallworld/state/unstable/__init__.py +0 -0
- smallworld/state/unstable/elf.py +393 -0
- smallworld/state/x86_registers.py +30 -0
- smallworld/utils.py +935 -0
- smallworld_re-1.0.0.dist-info/LICENSE.txt +21 -0
- smallworld_re-1.0.0.dist-info/METADATA +189 -0
- smallworld_re-1.0.0.dist-info/RECORD +166 -0
- smallworld_re-1.0.0.dist-info/WHEEL +5 -0
- smallworld_re-1.0.0.dist-info/entry_points.txt +2 -0
- smallworld_re-1.0.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,138 @@
|
|
1
|
+
import abc
|
2
|
+
import typing
|
3
|
+
|
4
|
+
import angr
|
5
|
+
import archinfo
|
6
|
+
|
7
|
+
from .... import exceptions, platforms, utils
|
8
|
+
|
9
|
+
|
10
|
+
class AngrMachineDef:
|
11
|
+
"""Container class for angr architecture-specific definitions"""
|
12
|
+
|
13
|
+
@property
|
14
|
+
@abc.abstractmethod
|
15
|
+
def arch(self) -> platforms.Architecture:
|
16
|
+
"""The architecture ID"""
|
17
|
+
raise NotImplementedError("This is an abstract method.")
|
18
|
+
|
19
|
+
@property
|
20
|
+
@abc.abstractmethod
|
21
|
+
def byteorder(self) -> platforms.Byteorder:
|
22
|
+
"""The byte order"""
|
23
|
+
raise NotImplementedError("This is an abstract method.")
|
24
|
+
|
25
|
+
@property
|
26
|
+
@abc.abstractmethod
|
27
|
+
def angr_arch(self) -> archinfo.arch.Arch:
|
28
|
+
"""The angr architecture to use"""
|
29
|
+
raise NotImplementedError("This is an abstract method.")
|
30
|
+
|
31
|
+
@property
|
32
|
+
@abc.abstractmethod
|
33
|
+
def pc_reg(self) -> str:
|
34
|
+
"""The program counter register name"""
|
35
|
+
return ""
|
36
|
+
|
37
|
+
# Is this thumb?
|
38
|
+
# Almost always no, but angr needs to ask.
|
39
|
+
is_thumb: bool = False
|
40
|
+
|
41
|
+
# The angr execution engine.
|
42
|
+
# Setting this to "none" uses the default Vex engine.
|
43
|
+
# This only needs to be overridden if you're a pcode machine.
|
44
|
+
angr_engine: typing.Optional[typing.Type[angr.engines.UberEnginePcode]] = None
|
45
|
+
|
46
|
+
# Does angr support single-instruction stepping for this ISA.
|
47
|
+
#
|
48
|
+
# Instructions with delay slots cannot be lifted into VEX
|
49
|
+
# without also lifting the instruction in the delay slot.
|
50
|
+
#
|
51
|
+
# This flag indicates that this machine uses such instructions,
|
52
|
+
# and is not safe to step in this manner.
|
53
|
+
supports_single_step: bool = True
|
54
|
+
|
55
|
+
_registers: typing.Dict[str, str]
|
56
|
+
|
57
|
+
def angr_reg(self, name: str) -> typing.Tuple[int, int]:
|
58
|
+
"""Find the offset and size of a register in the angr state's register file."""
|
59
|
+
if name not in self._registers:
|
60
|
+
raise KeyError(f"Unknown register for {self.arch}:{self.byteorder}: {name}")
|
61
|
+
name = self._registers[name]
|
62
|
+
|
63
|
+
if name not in self.angr_arch.registers:
|
64
|
+
raise exceptions.UnsupportedRegisterError(
|
65
|
+
f"Register {name} not recognized by angr for {self.arch}:{self.byteorder}"
|
66
|
+
)
|
67
|
+
return self.angr_arch.registers[name]
|
68
|
+
|
69
|
+
def successors(self, state: angr.SimState, **kwargs) -> typing.Any:
|
70
|
+
"""Compute successor states for this architecture
|
71
|
+
|
72
|
+
This allows a particular machine definition
|
73
|
+
to compensate for cases where the default
|
74
|
+
successor computation produces inaccurate results.
|
75
|
+
|
76
|
+
For the overwhelming majority of machine models,
|
77
|
+
the default should be sufficient.
|
78
|
+
|
79
|
+
The biggest case to date is to handle
|
80
|
+
user-defined operations in pcode.
|
81
|
+
These are treated as illegal ops by angr,
|
82
|
+
and there is currently no way to intercept their processing.
|
83
|
+
|
84
|
+
Arguments:
|
85
|
+
state: The angr state for which to compute successors
|
86
|
+
kwargs: See AngrObjectFactory.successors()
|
87
|
+
|
88
|
+
Returns:
|
89
|
+
The successor states of `state`.
|
90
|
+
"""
|
91
|
+
if state.project is None:
|
92
|
+
raise exceptions.ConfigurationError("Angr state had no project.")
|
93
|
+
return state.project.factory.successors(state, **kwargs)
|
94
|
+
|
95
|
+
@classmethod
|
96
|
+
def for_platform(cls, platform: platforms.Platform):
|
97
|
+
"""Find the appropriate MachineDef for your architecture
|
98
|
+
|
99
|
+
Arguments:
|
100
|
+
arch: The architecture ID you want
|
101
|
+
mode: The mode ID you want
|
102
|
+
byteorder: The byteorderness you want
|
103
|
+
|
104
|
+
Returns:
|
105
|
+
An instance of the appropriate MachineDef
|
106
|
+
|
107
|
+
Raises:
|
108
|
+
ValueError: If no MachineDef subclass matches your request
|
109
|
+
"""
|
110
|
+
try:
|
111
|
+
return utils.find_subclass(
|
112
|
+
cls,
|
113
|
+
lambda x: x.arch == platform.architecture
|
114
|
+
and x.byteorder == platform.byteorder,
|
115
|
+
)
|
116
|
+
except:
|
117
|
+
raise ValueError(f"No machine model for {platform}")
|
118
|
+
|
119
|
+
|
120
|
+
class PcodeMachineDef(AngrMachineDef):
|
121
|
+
"""Container class for pcode-dependent angr architecture-specific definitions"""
|
122
|
+
|
123
|
+
@property
|
124
|
+
@abc.abstractmethod
|
125
|
+
def pcode_language(self) -> str:
|
126
|
+
"""The pcode language ID string"""
|
127
|
+
return ""
|
128
|
+
|
129
|
+
@property
|
130
|
+
def angr_arch(self) -> archinfo.arch.Arch:
|
131
|
+
return self._angr_arch
|
132
|
+
|
133
|
+
angr_engine: typing.Optional[
|
134
|
+
typing.Type[angr.engines.UberEnginePcode]
|
135
|
+
] = angr.engines.UberEnginePcode
|
136
|
+
|
137
|
+
def __init__(self):
|
138
|
+
self._angr_arch = archinfo.ArchPcode(self.pcode_language)
|
@@ -0,0 +1,184 @@
|
|
1
|
+
import archinfo
|
2
|
+
|
3
|
+
from ....platforms import Architecture, Byteorder
|
4
|
+
from .machdef import AngrMachineDef
|
5
|
+
|
6
|
+
|
7
|
+
class MIPSMachineDef(AngrMachineDef):
|
8
|
+
arch = Architecture.MIPS32
|
9
|
+
|
10
|
+
pc_reg = "pc"
|
11
|
+
|
12
|
+
# NOTE: MIPS registers have a name and a number
|
13
|
+
# angr's machine state doesn't use the number,
|
14
|
+
# so... name.
|
15
|
+
_registers = {
|
16
|
+
# *** General-Purpose Registers ***
|
17
|
+
# Assembler-Temporary Register
|
18
|
+
"at": "at",
|
19
|
+
"1": "at",
|
20
|
+
# Return Value Registers
|
21
|
+
"v0": "v0",
|
22
|
+
"2": "v0",
|
23
|
+
"v1": "v1",
|
24
|
+
"3": "v3",
|
25
|
+
# Argument Registers
|
26
|
+
"a0": "a0",
|
27
|
+
"4": "a0",
|
28
|
+
"a1": "a1",
|
29
|
+
"5": "a1",
|
30
|
+
"a2": "a2",
|
31
|
+
"6": "a2",
|
32
|
+
"a3": "a3",
|
33
|
+
"7": "a3",
|
34
|
+
# Temporary Registers
|
35
|
+
"t0": "t0",
|
36
|
+
"8": "t0",
|
37
|
+
"t1": "t1",
|
38
|
+
"9": "t1",
|
39
|
+
"t2": "t2",
|
40
|
+
"10": "t2",
|
41
|
+
"t3": "t3",
|
42
|
+
"11": "t3",
|
43
|
+
"t4": "t4",
|
44
|
+
"12": "t4",
|
45
|
+
"t5": "t5",
|
46
|
+
"13": "t5",
|
47
|
+
"t6": "t6",
|
48
|
+
"14": "t6",
|
49
|
+
"t7": "t7",
|
50
|
+
"15": "t7",
|
51
|
+
# NOTE: These numbers aren't out of order.
|
52
|
+
# t8 and t9 are later in the register file than t0 - t7.
|
53
|
+
"t8": "t8",
|
54
|
+
"24": "t8",
|
55
|
+
"t9": "t9",
|
56
|
+
"25": "t9",
|
57
|
+
# Saved Registers
|
58
|
+
"s0": "s0",
|
59
|
+
"16": "s0",
|
60
|
+
"s1": "s1",
|
61
|
+
"17": "s1",
|
62
|
+
"s2": "s2",
|
63
|
+
"18": "s2",
|
64
|
+
"s3": "s3",
|
65
|
+
"19": "s3",
|
66
|
+
"s4": "s4",
|
67
|
+
"20": "s4",
|
68
|
+
"s5": "s5",
|
69
|
+
"21": "s5",
|
70
|
+
"s6": "s6",
|
71
|
+
"22": "s6",
|
72
|
+
"s7": "s7",
|
73
|
+
"23": "s7",
|
74
|
+
# NOTE: Register #30 was originally the Frame Pointer.
|
75
|
+
# It's been re-aliased as s8, since many ABIs don't use the frame pointer.
|
76
|
+
# Unicorn and Sleigh prefer to use the alias s8,
|
77
|
+
# so it should be the base register.
|
78
|
+
"s8": "s8",
|
79
|
+
"fp": "fp",
|
80
|
+
"30": "fp",
|
81
|
+
# Kernel-reserved Registers
|
82
|
+
"k0": "k0",
|
83
|
+
"26": "k0",
|
84
|
+
"k1": "k1",
|
85
|
+
"27": "k1",
|
86
|
+
# *** Pointer Registers ***
|
87
|
+
# Zero register
|
88
|
+
"zero": "zero",
|
89
|
+
"0": "zero",
|
90
|
+
# Global Offset Pointer
|
91
|
+
"gp": "gp",
|
92
|
+
"28": "gp",
|
93
|
+
# Stack Pointer
|
94
|
+
"sp": "sp",
|
95
|
+
"29": "sp",
|
96
|
+
# Return Address
|
97
|
+
"ra": "ra",
|
98
|
+
"31": "ra",
|
99
|
+
# Program Counter
|
100
|
+
"pc": "pc",
|
101
|
+
# Floating Point Registers
|
102
|
+
"f0": "f0",
|
103
|
+
"f1": "f1",
|
104
|
+
"f2": "f2",
|
105
|
+
"f3": "f3",
|
106
|
+
"f4": "f4",
|
107
|
+
"f5": "f5",
|
108
|
+
"f6": "f6",
|
109
|
+
"f7": "f7",
|
110
|
+
"f8": "f8",
|
111
|
+
"f9": "f9",
|
112
|
+
"f10": "f10",
|
113
|
+
"f11": "f11",
|
114
|
+
"f12": "f12",
|
115
|
+
"f13": "f13",
|
116
|
+
"f14": "f14",
|
117
|
+
"f15": "f15",
|
118
|
+
"f16": "f16",
|
119
|
+
"f17": "f17",
|
120
|
+
"f18": "f18",
|
121
|
+
"f19": "f19",
|
122
|
+
"f20": "f20",
|
123
|
+
"f21": "f21",
|
124
|
+
"f22": "f22",
|
125
|
+
"f23": "f23",
|
126
|
+
"f24": "f24",
|
127
|
+
"f25": "f25",
|
128
|
+
"f26": "f26",
|
129
|
+
"f27": "f27",
|
130
|
+
"f28": "f28",
|
131
|
+
"f29": "f29",
|
132
|
+
"f30": "f30",
|
133
|
+
"f31": "f31",
|
134
|
+
# *** Floating Point Control Registers ***
|
135
|
+
"fir": "fir",
|
136
|
+
"fcsr": "fcsr",
|
137
|
+
"fexr": "fexr",
|
138
|
+
"fenr": "fenr",
|
139
|
+
"fccr": "fccr",
|
140
|
+
# *** Accumulator Registers ***
|
141
|
+
# MIPS uses these to implement 64-bit results
|
142
|
+
# from 32-bit multiplication, amongst others.
|
143
|
+
"ac0": "ac0",
|
144
|
+
"hi0": "hi0",
|
145
|
+
"lo0": "lo0",
|
146
|
+
"ac1": "ac1",
|
147
|
+
"hi1": "hi1",
|
148
|
+
"lo1": "lo1",
|
149
|
+
"ac2": "ac2",
|
150
|
+
"hi2": "hi2",
|
151
|
+
"lo2": "lo2",
|
152
|
+
"ac3": "ac3",
|
153
|
+
"hi3": "hi3",
|
154
|
+
"lo3": "lo3",
|
155
|
+
}
|
156
|
+
|
157
|
+
_delay_slot_opcodes = {
|
158
|
+
"j",
|
159
|
+
"jal",
|
160
|
+
"jalx",
|
161
|
+
"jalr",
|
162
|
+
"jr",
|
163
|
+
"beq",
|
164
|
+
"beqz",
|
165
|
+
"bne" "bnez",
|
166
|
+
"bgez",
|
167
|
+
"bgezal",
|
168
|
+
"bgtz",
|
169
|
+
"blez",
|
170
|
+
"bltz",
|
171
|
+
"bltzal",
|
172
|
+
}
|
173
|
+
|
174
|
+
supports_single_step = False
|
175
|
+
|
176
|
+
|
177
|
+
class MIPSELMachineDef(MIPSMachineDef):
|
178
|
+
byteorder = Byteorder.LITTLE
|
179
|
+
angr_arch = archinfo.ArchMIPS32(archinfo.Endness.LE)
|
180
|
+
|
181
|
+
|
182
|
+
class MIPSBEMachineDef(MIPSMachineDef):
|
183
|
+
byteorder = Byteorder.BIG
|
184
|
+
angr_arch = archinfo.ArchMIPS32(archinfo.Endness.BE)
|
@@ -0,0 +1,189 @@
|
|
1
|
+
import archinfo
|
2
|
+
|
3
|
+
from ....platforms import Architecture, Byteorder
|
4
|
+
from .machdef import AngrMachineDef
|
5
|
+
|
6
|
+
|
7
|
+
class MIPS64MachineDef(AngrMachineDef):
|
8
|
+
arch = Architecture.MIPS64
|
9
|
+
|
10
|
+
pc_reg = "pc"
|
11
|
+
|
12
|
+
# NOTE: MIPS registers have a name and a number
|
13
|
+
# angr's machine state doesn't use the number,
|
14
|
+
# so... name.
|
15
|
+
# NOTE: angr's register names are wrong.
|
16
|
+
# It follows Wikipedia's definition of the 64-bit ABI,
|
17
|
+
# which has a4 - a7 and t0 - t3 overlapping.
|
18
|
+
_registers = {
|
19
|
+
# *** General-Purpose Registers ***
|
20
|
+
# Assembler-Temporary Register
|
21
|
+
"at": "at",
|
22
|
+
"1": "at",
|
23
|
+
# Return Value Registers
|
24
|
+
"v0": "v0",
|
25
|
+
"2": "v0",
|
26
|
+
"v1": "v1",
|
27
|
+
"3": "v1",
|
28
|
+
# Argument Registers
|
29
|
+
"a0": "a0",
|
30
|
+
"4": "a0",
|
31
|
+
"a1": "a1",
|
32
|
+
"5": "a1",
|
33
|
+
"a2": "a2",
|
34
|
+
"6": "a2",
|
35
|
+
"a3": "a3",
|
36
|
+
"7": "a3",
|
37
|
+
"a4": "a4",
|
38
|
+
"8": "a4",
|
39
|
+
"a5": "a5",
|
40
|
+
"9": "a5",
|
41
|
+
"a6": "a6",
|
42
|
+
"10": "a6",
|
43
|
+
"a7": "a7",
|
44
|
+
"11": "a7",
|
45
|
+
# Temporary Registers
|
46
|
+
# NOTE: angr names registers 12 - 15 incorrectly.
|
47
|
+
# Be very careful if accessing angr's state directly.
|
48
|
+
"t0": "t4",
|
49
|
+
"12": "t4",
|
50
|
+
"t1": "t5",
|
51
|
+
"13": "t5",
|
52
|
+
"t2": "t6",
|
53
|
+
"14": "t6",
|
54
|
+
"t3": "t7",
|
55
|
+
"15": "t7",
|
56
|
+
# NOTE: These numbers aren't out of order.
|
57
|
+
# t8 and t9 are later in the register file than t0 - t7.
|
58
|
+
"t8": "t8",
|
59
|
+
"24": "t8",
|
60
|
+
"t9": "t9",
|
61
|
+
"25": "t9",
|
62
|
+
# Saved Registers
|
63
|
+
"s0": "s0",
|
64
|
+
"16": "s0",
|
65
|
+
"s1": "s1",
|
66
|
+
"17": "s1",
|
67
|
+
"s2": "s2",
|
68
|
+
"18": "s2",
|
69
|
+
"s3": "s3",
|
70
|
+
"19": "s3",
|
71
|
+
"s4": "s4",
|
72
|
+
"20": "s4",
|
73
|
+
"s5": "s5",
|
74
|
+
"21": "s5",
|
75
|
+
"s6": "s6",
|
76
|
+
"22": "s6",
|
77
|
+
"s7": "s7",
|
78
|
+
"23": "s7",
|
79
|
+
# NOTE: Register #30 was originally the Frame Pointer.
|
80
|
+
# It's been re-aliased as s8, since many ABIs don't use the frame pointer.
|
81
|
+
# Unicorn and Sleigh prefer to use the alias s8,
|
82
|
+
# so it should be the base register.
|
83
|
+
"s8": "s8",
|
84
|
+
"fp": "fp",
|
85
|
+
"30": "fp",
|
86
|
+
# Kernel-reserved Registers
|
87
|
+
"k0": "k0",
|
88
|
+
"26": "k0",
|
89
|
+
"k1": "k1",
|
90
|
+
"27": "k1",
|
91
|
+
# *** Pointer Registers ***
|
92
|
+
# Zero register
|
93
|
+
"zero": "zero",
|
94
|
+
"0": "zero",
|
95
|
+
# Global Offset Pointer
|
96
|
+
"gp": "gp",
|
97
|
+
"28": "gp",
|
98
|
+
# Stack Pointer
|
99
|
+
"sp": "sp",
|
100
|
+
"29": "sp",
|
101
|
+
# Return Address
|
102
|
+
"ra": "ra",
|
103
|
+
"31": "ra",
|
104
|
+
# Program Counter
|
105
|
+
"pc": "pc",
|
106
|
+
# Floating Point Registers
|
107
|
+
"f0": "f0",
|
108
|
+
"f1": "f1",
|
109
|
+
"f2": "f2",
|
110
|
+
"f3": "f3",
|
111
|
+
"f4": "f4",
|
112
|
+
"f5": "f5",
|
113
|
+
"f6": "f6",
|
114
|
+
"f7": "f7",
|
115
|
+
"f8": "f8",
|
116
|
+
"f9": "f9",
|
117
|
+
"f10": "f10",
|
118
|
+
"f11": "f11",
|
119
|
+
"f12": "f12",
|
120
|
+
"f13": "f13",
|
121
|
+
"f14": "f14",
|
122
|
+
"f15": "f15",
|
123
|
+
"f16": "f16",
|
124
|
+
"f17": "f17",
|
125
|
+
"f18": "f18",
|
126
|
+
"f19": "f19",
|
127
|
+
"f20": "f20",
|
128
|
+
"f21": "f21",
|
129
|
+
"f22": "f22",
|
130
|
+
"f23": "f23",
|
131
|
+
"f24": "f24",
|
132
|
+
"f25": "f25",
|
133
|
+
"f26": "f26",
|
134
|
+
"f27": "f27",
|
135
|
+
"f28": "f28",
|
136
|
+
"f29": "f29",
|
137
|
+
"f30": "f30",
|
138
|
+
"f31": "f31",
|
139
|
+
# *** Floating Point Control Registers ***
|
140
|
+
"fir": "fir",
|
141
|
+
"fcsr": "fcsr",
|
142
|
+
"fexr": "fexr",
|
143
|
+
"fenr": "fenr",
|
144
|
+
"fccr": "fccr",
|
145
|
+
# *** Accumulator Registers ***
|
146
|
+
# MIPS uses these to implement 64-bit results
|
147
|
+
# from 32-bit multiplication, amongst others.
|
148
|
+
"ac0": "ac0",
|
149
|
+
"hi0": "hi0",
|
150
|
+
"lo0": "lo0",
|
151
|
+
"ac1": "ac1",
|
152
|
+
"hi1": "hi1",
|
153
|
+
"lo1": "lo1",
|
154
|
+
"ac2": "ac2",
|
155
|
+
"hi2": "hi2",
|
156
|
+
"lo2": "lo2",
|
157
|
+
"ac3": "ac3",
|
158
|
+
"hi3": "hi3",
|
159
|
+
"lo3": "lo3",
|
160
|
+
}
|
161
|
+
|
162
|
+
_delay_slot_opcodes = {
|
163
|
+
"j",
|
164
|
+
"jal",
|
165
|
+
"jalx",
|
166
|
+
"jalr",
|
167
|
+
"jr",
|
168
|
+
"beq",
|
169
|
+
"beqz",
|
170
|
+
"bne" "bnez",
|
171
|
+
"bgez",
|
172
|
+
"bgezal",
|
173
|
+
"bgtz",
|
174
|
+
"blez",
|
175
|
+
"bltz",
|
176
|
+
"bltzal",
|
177
|
+
}
|
178
|
+
|
179
|
+
supports_single_step = False
|
180
|
+
|
181
|
+
|
182
|
+
class MIPS64ELMachineDef(MIPS64MachineDef):
|
183
|
+
byteorder = Byteorder.LITTLE
|
184
|
+
angr_arch = archinfo.ArchMIPS64(archinfo.Endness.LE)
|
185
|
+
|
186
|
+
|
187
|
+
class MIPS64BEMachineDef(MIPS64MachineDef):
|
188
|
+
byteorder = Byteorder.BIG
|
189
|
+
angr_arch = archinfo.ArchMIPS64(archinfo.Endness.BE)
|
@@ -0,0 +1,101 @@
|
|
1
|
+
import archinfo
|
2
|
+
|
3
|
+
from ....platforms import Architecture, Byteorder
|
4
|
+
from .machdef import AngrMachineDef
|
5
|
+
|
6
|
+
|
7
|
+
class PowerPCMachineDef(AngrMachineDef):
|
8
|
+
byteorder = Byteorder.BIG
|
9
|
+
|
10
|
+
pc_reg = "pc"
|
11
|
+
|
12
|
+
_registers = {
|
13
|
+
"r0": "r0",
|
14
|
+
"r1": "r1",
|
15
|
+
"sp": "sp",
|
16
|
+
"r2": "r2",
|
17
|
+
"r3": "r3",
|
18
|
+
"r4": "r4",
|
19
|
+
"r5": "r5",
|
20
|
+
"r6": "r6",
|
21
|
+
"r7": "r7",
|
22
|
+
"r8": "r8",
|
23
|
+
"r9": "r9",
|
24
|
+
"r10": "r10",
|
25
|
+
"r11": "r11",
|
26
|
+
"r12": "r12",
|
27
|
+
"r13": "r13",
|
28
|
+
"r14": "r14",
|
29
|
+
"r15": "r15",
|
30
|
+
"r16": "r16",
|
31
|
+
"r17": "r17",
|
32
|
+
"r18": "r18",
|
33
|
+
"r19": "r19",
|
34
|
+
"r20": "r20",
|
35
|
+
"r21": "r21",
|
36
|
+
"r22": "r22",
|
37
|
+
"r23": "r23",
|
38
|
+
"r24": "r24",
|
39
|
+
"r25": "r25",
|
40
|
+
"r26": "r26",
|
41
|
+
"r27": "r27",
|
42
|
+
"r28": "r28",
|
43
|
+
"r29": "r29",
|
44
|
+
"r30": "r30",
|
45
|
+
"r31": "r31",
|
46
|
+
"pc": "pc",
|
47
|
+
"lr": "lr",
|
48
|
+
"ctr": "ctr",
|
49
|
+
"cr0": "cr0",
|
50
|
+
"cr1": "cr1",
|
51
|
+
"cr2": "cr2",
|
52
|
+
"cr3": "cr3",
|
53
|
+
"cr4": "cr4",
|
54
|
+
"cr5": "cr5",
|
55
|
+
"cr6": "cr6",
|
56
|
+
"cr7": "cr7",
|
57
|
+
"f0": "fpr0",
|
58
|
+
"f1": "fpr1",
|
59
|
+
"f2": "fpr2",
|
60
|
+
"f3": "fpr3",
|
61
|
+
"f4": "fpr4",
|
62
|
+
"f5": "fpr5",
|
63
|
+
"f6": "fpr6",
|
64
|
+
"f7": "fpr7",
|
65
|
+
"f8": "fpr8",
|
66
|
+
"f9": "fpr9",
|
67
|
+
"f10": "fpr10",
|
68
|
+
"f11": "fpr11",
|
69
|
+
"f12": "fpr12",
|
70
|
+
"f13": "fpr13",
|
71
|
+
"f14": "fpr14",
|
72
|
+
"f15": "fpr15",
|
73
|
+
"f16": "fpr16",
|
74
|
+
"f17": "fpr17",
|
75
|
+
"f18": "fpr18",
|
76
|
+
"f19": "fpr19",
|
77
|
+
"f20": "fpr20",
|
78
|
+
"f21": "fpr21",
|
79
|
+
"f22": "fpr22",
|
80
|
+
"f23": "fpr23",
|
81
|
+
"f24": "fpr24",
|
82
|
+
"f25": "fpr25",
|
83
|
+
"f26": "fpr26",
|
84
|
+
"f27": "fpr27",
|
85
|
+
"f28": "fpr28",
|
86
|
+
"f29": "fpr29",
|
87
|
+
"f30": "fpr30",
|
88
|
+
"f31": "fpr31",
|
89
|
+
"xer": "",
|
90
|
+
"fpscr": "",
|
91
|
+
}
|
92
|
+
|
93
|
+
|
94
|
+
class PowerPC32MachineDef(PowerPCMachineDef):
|
95
|
+
arch = Architecture.POWERPC32
|
96
|
+
angr_arch = archinfo.arch_ppc32.ArchPPC32(archinfo.Endness.BE)
|
97
|
+
|
98
|
+
|
99
|
+
class PowerPC64MachineDef(PowerPCMachineDef):
|
100
|
+
arch = Architecture.POWERPC64
|
101
|
+
angr_arch = archinfo.arch_ppc64.ArchPPC64(archinfo.Endness.BE)
|