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
smallworld/__init__.py
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
from importlib import metadata as __metadata
|
2
|
+
|
3
|
+
metadata = __metadata.metadata("smallworld")
|
4
|
+
|
5
|
+
__title__ = metadata["name"]
|
6
|
+
__description__ = metadata["Summary"]
|
7
|
+
__author__ = metadata["Author"]
|
8
|
+
__version__ = metadata["version"]
|
9
|
+
|
10
|
+
|
11
|
+
from . import (
|
12
|
+
analyses,
|
13
|
+
emulators,
|
14
|
+
exceptions,
|
15
|
+
extern,
|
16
|
+
hinting,
|
17
|
+
instructions,
|
18
|
+
logging,
|
19
|
+
platforms,
|
20
|
+
state,
|
21
|
+
)
|
22
|
+
from .helpers import * # noqa: F401, F403
|
23
|
+
from .helpers import __all__ as __helpers__
|
24
|
+
|
25
|
+
__all__ = __helpers__ + [
|
26
|
+
"analyses",
|
27
|
+
"emulators",
|
28
|
+
"exceptions",
|
29
|
+
"extern",
|
30
|
+
"hinting",
|
31
|
+
"instructions",
|
32
|
+
"logging",
|
33
|
+
"platforms",
|
34
|
+
"state",
|
35
|
+
]
|
@@ -0,0 +1,14 @@
|
|
1
|
+
from .analysis import * # noqa: F401, F403
|
2
|
+
from .analysis import __all__ as __analysis__
|
3
|
+
from .colorizer import Colorizer
|
4
|
+
from .colorizer_summary import ColorizerSummary
|
5
|
+
from .field_detection import FieldDetectionAnalysis, ForcedFieldDetectionAnalysis
|
6
|
+
from .forced_exec import ForcedExecution
|
7
|
+
|
8
|
+
__all__ = __analysis__ + [
|
9
|
+
"Colorizer",
|
10
|
+
"ColorizerSummary",
|
11
|
+
"FieldDetectionAnalysis",
|
12
|
+
"ForcedFieldDetectionAnalysis",
|
13
|
+
"ForcedExecution",
|
14
|
+
]
|
@@ -0,0 +1,88 @@
|
|
1
|
+
import abc
|
2
|
+
import logging
|
3
|
+
import typing
|
4
|
+
|
5
|
+
from .. import hinting, state, utils
|
6
|
+
|
7
|
+
|
8
|
+
class Analysis(utils.MetadataMixin):
|
9
|
+
"""An analysis that emits some information about some code, possibly to help with harnessing."""
|
10
|
+
|
11
|
+
@abc.abstractmethod
|
12
|
+
def run(self, machine: state.Machine) -> None:
|
13
|
+
"""Run the analysis.
|
14
|
+
|
15
|
+
This function **should not** modify the provided Machine. Instead, it
|
16
|
+
should be coppied before modification.
|
17
|
+
|
18
|
+
Arguments:
|
19
|
+
machine: A machine state object on which this analysis should run.
|
20
|
+
"""
|
21
|
+
|
22
|
+
pass
|
23
|
+
|
24
|
+
|
25
|
+
class Filter(utils.MetadataMixin):
|
26
|
+
"""Analyses that consume and sometimes produce additional hints.
|
27
|
+
|
28
|
+
Filter analyses are analyses that consume some part of the hint
|
29
|
+
stream and possibly emit new higher-level, synthetic hints. These
|
30
|
+
analyses do not inspect machine state directly, they just react to
|
31
|
+
hints from other analyses.
|
32
|
+
|
33
|
+
"""
|
34
|
+
|
35
|
+
def __init__(self):
|
36
|
+
self.listeners = []
|
37
|
+
|
38
|
+
def listen(
|
39
|
+
self,
|
40
|
+
hint: typing.Type[hinting.Hint],
|
41
|
+
method: typing.Callable[[hinting.Hint], None],
|
42
|
+
) -> None:
|
43
|
+
"""Register a listener for a particular hint type on the hint stream.
|
44
|
+
|
45
|
+
Arguments:
|
46
|
+
hint: A hint type that should trigger this listener. Note: All
|
47
|
+
subclasses `hint` will trigger the listener.
|
48
|
+
method: The method to call when the given hint type is observed.
|
49
|
+
"""
|
50
|
+
|
51
|
+
class Handler(logging.Handler):
|
52
|
+
def emit(self, record):
|
53
|
+
method(record.msg)
|
54
|
+
|
55
|
+
handler = Handler()
|
56
|
+
handler.setLevel(logging.DEBUG)
|
57
|
+
handler.addFilter(hinting.HintSubclassFilter(hint))
|
58
|
+
hinting.root.addHandler(handler)
|
59
|
+
|
60
|
+
self.listeners.append(handler)
|
61
|
+
|
62
|
+
@abc.abstractmethod
|
63
|
+
def activate(self) -> None:
|
64
|
+
"""Activate this filter.
|
65
|
+
|
66
|
+
Implementations should make necessary calls to `listen()` here to
|
67
|
+
register hint listener functions. They will be unregistered
|
68
|
+
automatically on destruction or manual call to `deactivate()`.
|
69
|
+
"""
|
70
|
+
|
71
|
+
pass
|
72
|
+
|
73
|
+
def deactivate(self) -> None:
|
74
|
+
"""Deactivate this filter.
|
75
|
+
|
76
|
+
This is done automatically on destruction of this object - you likely
|
77
|
+
shouldn't need to call this manually.
|
78
|
+
"""
|
79
|
+
|
80
|
+
for handler in self.listeners:
|
81
|
+
hinting.root.removeHandler(handler)
|
82
|
+
|
83
|
+
def __del__(self):
|
84
|
+
self.deactivate()
|
85
|
+
# super().__del__()
|
86
|
+
|
87
|
+
|
88
|
+
__all__ = ["Analysis", "Filter"]
|
@@ -0,0 +1,31 @@
|
|
1
|
+
import logging
|
2
|
+
import typing
|
3
|
+
|
4
|
+
from .. import emulators, hinting
|
5
|
+
from . import analysis
|
6
|
+
|
7
|
+
logger = logging.getLogger(__name__)
|
8
|
+
hinter = hinting.get_hinter(__name__)
|
9
|
+
|
10
|
+
|
11
|
+
class CodeCoverage(analysis.Analysis):
|
12
|
+
"""A simple analysis that logs jumps, calls, and returns."""
|
13
|
+
|
14
|
+
name = "code-coverage"
|
15
|
+
description = ""
|
16
|
+
version = "0.0.1"
|
17
|
+
|
18
|
+
def run(self, machine) -> None:
|
19
|
+
emulator = emulators.UnicornEmulator(machine.get_platform())
|
20
|
+
coverage: typing.Dict[int, int] = {}
|
21
|
+
|
22
|
+
for step in machine.step(emulator):
|
23
|
+
cpu = step.get_cpu()
|
24
|
+
pc = cpu.pc.get_content()
|
25
|
+
if pc in coverage:
|
26
|
+
coverage[pc] += 1
|
27
|
+
else:
|
28
|
+
coverage[pc] = 1
|
29
|
+
|
30
|
+
hint = hinting.CoverageHint(message="Coverage for execution", coverage=coverage)
|
31
|
+
hinter.info(hint)
|