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.
Files changed (166) hide show
  1. smallworld/__init__.py +35 -0
  2. smallworld/analyses/__init__.py +14 -0
  3. smallworld/analyses/analysis.py +88 -0
  4. smallworld/analyses/code_coverage.py +31 -0
  5. smallworld/analyses/colorizer.py +682 -0
  6. smallworld/analyses/colorizer_summary.py +100 -0
  7. smallworld/analyses/field_detection/__init__.py +14 -0
  8. smallworld/analyses/field_detection/field_analysis.py +536 -0
  9. smallworld/analyses/field_detection/guards.py +26 -0
  10. smallworld/analyses/field_detection/hints.py +133 -0
  11. smallworld/analyses/field_detection/malloc.py +211 -0
  12. smallworld/analyses/forced_exec/__init__.py +3 -0
  13. smallworld/analyses/forced_exec/forced_exec.py +87 -0
  14. smallworld/analyses/underlays/__init__.py +4 -0
  15. smallworld/analyses/underlays/basic.py +13 -0
  16. smallworld/analyses/underlays/underlay.py +31 -0
  17. smallworld/analyses/unstable/__init__.py +4 -0
  18. smallworld/analyses/unstable/angr/__init__.py +0 -0
  19. smallworld/analyses/unstable/angr/base.py +12 -0
  20. smallworld/analyses/unstable/angr/divergence.py +274 -0
  21. smallworld/analyses/unstable/angr/model.py +383 -0
  22. smallworld/analyses/unstable/angr/nwbt.py +63 -0
  23. smallworld/analyses/unstable/angr/typedefs.py +170 -0
  24. smallworld/analyses/unstable/angr/utils.py +25 -0
  25. smallworld/analyses/unstable/angr/visitor.py +315 -0
  26. smallworld/analyses/unstable/angr_nwbt.py +106 -0
  27. smallworld/analyses/unstable/code_coverage.py +54 -0
  28. smallworld/analyses/unstable/code_reachable.py +44 -0
  29. smallworld/analyses/unstable/control_flow_tracer.py +71 -0
  30. smallworld/analyses/unstable/pointer_finder.py +90 -0
  31. smallworld/arch/__init__.py +0 -0
  32. smallworld/arch/aarch64_arch.py +286 -0
  33. smallworld/arch/amd64_arch.py +86 -0
  34. smallworld/arch/i386_arch.py +44 -0
  35. smallworld/emulators/__init__.py +14 -0
  36. smallworld/emulators/angr/__init__.py +7 -0
  37. smallworld/emulators/angr/angr.py +1652 -0
  38. smallworld/emulators/angr/default.py +15 -0
  39. smallworld/emulators/angr/exceptions.py +7 -0
  40. smallworld/emulators/angr/exploration/__init__.py +9 -0
  41. smallworld/emulators/angr/exploration/bounds.py +27 -0
  42. smallworld/emulators/angr/exploration/default.py +17 -0
  43. smallworld/emulators/angr/exploration/terminate.py +22 -0
  44. smallworld/emulators/angr/factory.py +55 -0
  45. smallworld/emulators/angr/machdefs/__init__.py +35 -0
  46. smallworld/emulators/angr/machdefs/aarch64.py +292 -0
  47. smallworld/emulators/angr/machdefs/amd64.py +192 -0
  48. smallworld/emulators/angr/machdefs/arm.py +387 -0
  49. smallworld/emulators/angr/machdefs/i386.py +221 -0
  50. smallworld/emulators/angr/machdefs/machdef.py +138 -0
  51. smallworld/emulators/angr/machdefs/mips.py +184 -0
  52. smallworld/emulators/angr/machdefs/mips64.py +189 -0
  53. smallworld/emulators/angr/machdefs/ppc.py +101 -0
  54. smallworld/emulators/angr/machdefs/riscv.py +261 -0
  55. smallworld/emulators/angr/machdefs/xtensa.py +255 -0
  56. smallworld/emulators/angr/memory/__init__.py +7 -0
  57. smallworld/emulators/angr/memory/default.py +10 -0
  58. smallworld/emulators/angr/memory/fixups.py +43 -0
  59. smallworld/emulators/angr/memory/memtrack.py +105 -0
  60. smallworld/emulators/angr/scratch.py +43 -0
  61. smallworld/emulators/angr/simos.py +53 -0
  62. smallworld/emulators/angr/utils.py +70 -0
  63. smallworld/emulators/emulator.py +1013 -0
  64. smallworld/emulators/hookable.py +252 -0
  65. smallworld/emulators/panda/__init__.py +5 -0
  66. smallworld/emulators/panda/machdefs/__init__.py +28 -0
  67. smallworld/emulators/panda/machdefs/aarch64.py +93 -0
  68. smallworld/emulators/panda/machdefs/amd64.py +71 -0
  69. smallworld/emulators/panda/machdefs/arm.py +89 -0
  70. smallworld/emulators/panda/machdefs/i386.py +36 -0
  71. smallworld/emulators/panda/machdefs/machdef.py +86 -0
  72. smallworld/emulators/panda/machdefs/mips.py +94 -0
  73. smallworld/emulators/panda/machdefs/mips64.py +91 -0
  74. smallworld/emulators/panda/machdefs/ppc.py +79 -0
  75. smallworld/emulators/panda/panda.py +575 -0
  76. smallworld/emulators/unicorn/__init__.py +13 -0
  77. smallworld/emulators/unicorn/machdefs/__init__.py +28 -0
  78. smallworld/emulators/unicorn/machdefs/aarch64.py +310 -0
  79. smallworld/emulators/unicorn/machdefs/amd64.py +326 -0
  80. smallworld/emulators/unicorn/machdefs/arm.py +321 -0
  81. smallworld/emulators/unicorn/machdefs/i386.py +137 -0
  82. smallworld/emulators/unicorn/machdefs/machdef.py +117 -0
  83. smallworld/emulators/unicorn/machdefs/mips.py +202 -0
  84. smallworld/emulators/unicorn/unicorn.py +684 -0
  85. smallworld/exceptions/__init__.py +5 -0
  86. smallworld/exceptions/exceptions.py +85 -0
  87. smallworld/exceptions/unstable/__init__.py +1 -0
  88. smallworld/exceptions/unstable/exceptions.py +25 -0
  89. smallworld/extern/__init__.py +4 -0
  90. smallworld/extern/ctypes.py +94 -0
  91. smallworld/extern/unstable/__init__.py +1 -0
  92. smallworld/extern/unstable/ghidra.py +129 -0
  93. smallworld/helpers.py +107 -0
  94. smallworld/hinting/__init__.py +8 -0
  95. smallworld/hinting/hinting.py +214 -0
  96. smallworld/hinting/hints.py +427 -0
  97. smallworld/hinting/unstable/__init__.py +2 -0
  98. smallworld/hinting/utils.py +19 -0
  99. smallworld/instructions/__init__.py +18 -0
  100. smallworld/instructions/aarch64.py +20 -0
  101. smallworld/instructions/arm.py +18 -0
  102. smallworld/instructions/bsid.py +67 -0
  103. smallworld/instructions/instructions.py +258 -0
  104. smallworld/instructions/mips.py +21 -0
  105. smallworld/instructions/x86.py +100 -0
  106. smallworld/logging.py +90 -0
  107. smallworld/platforms.py +95 -0
  108. smallworld/py.typed +0 -0
  109. smallworld/state/__init__.py +6 -0
  110. smallworld/state/cpus/__init__.py +32 -0
  111. smallworld/state/cpus/aarch64.py +563 -0
  112. smallworld/state/cpus/amd64.py +676 -0
  113. smallworld/state/cpus/arm.py +630 -0
  114. smallworld/state/cpus/cpu.py +71 -0
  115. smallworld/state/cpus/i386.py +239 -0
  116. smallworld/state/cpus/mips.py +374 -0
  117. smallworld/state/cpus/mips64.py +372 -0
  118. smallworld/state/cpus/powerpc.py +229 -0
  119. smallworld/state/cpus/riscv.py +357 -0
  120. smallworld/state/cpus/xtensa.py +80 -0
  121. smallworld/state/memory/__init__.py +7 -0
  122. smallworld/state/memory/code.py +70 -0
  123. smallworld/state/memory/elf/__init__.py +3 -0
  124. smallworld/state/memory/elf/elf.py +564 -0
  125. smallworld/state/memory/elf/rela/__init__.py +32 -0
  126. smallworld/state/memory/elf/rela/aarch64.py +27 -0
  127. smallworld/state/memory/elf/rela/amd64.py +32 -0
  128. smallworld/state/memory/elf/rela/arm.py +51 -0
  129. smallworld/state/memory/elf/rela/i386.py +32 -0
  130. smallworld/state/memory/elf/rela/mips.py +45 -0
  131. smallworld/state/memory/elf/rela/ppc.py +45 -0
  132. smallworld/state/memory/elf/rela/rela.py +63 -0
  133. smallworld/state/memory/elf/rela/riscv64.py +27 -0
  134. smallworld/state/memory/elf/rela/xtensa.py +15 -0
  135. smallworld/state/memory/elf/structs.py +55 -0
  136. smallworld/state/memory/heap.py +85 -0
  137. smallworld/state/memory/memory.py +181 -0
  138. smallworld/state/memory/stack/__init__.py +31 -0
  139. smallworld/state/memory/stack/aarch64.py +22 -0
  140. smallworld/state/memory/stack/amd64.py +42 -0
  141. smallworld/state/memory/stack/arm.py +66 -0
  142. smallworld/state/memory/stack/i386.py +22 -0
  143. smallworld/state/memory/stack/mips.py +34 -0
  144. smallworld/state/memory/stack/mips64.py +34 -0
  145. smallworld/state/memory/stack/ppc.py +34 -0
  146. smallworld/state/memory/stack/riscv.py +22 -0
  147. smallworld/state/memory/stack/stack.py +127 -0
  148. smallworld/state/memory/stack/xtensa.py +34 -0
  149. smallworld/state/models/__init__.py +6 -0
  150. smallworld/state/models/mmio.py +186 -0
  151. smallworld/state/models/model.py +163 -0
  152. smallworld/state/models/posix.py +455 -0
  153. smallworld/state/models/x86/__init__.py +2 -0
  154. smallworld/state/models/x86/microsoftcdecl.py +35 -0
  155. smallworld/state/models/x86/systemv.py +240 -0
  156. smallworld/state/state.py +962 -0
  157. smallworld/state/unstable/__init__.py +0 -0
  158. smallworld/state/unstable/elf.py +393 -0
  159. smallworld/state/x86_registers.py +30 -0
  160. smallworld/utils.py +935 -0
  161. smallworld_re-1.0.0.dist-info/LICENSE.txt +21 -0
  162. smallworld_re-1.0.0.dist-info/METADATA +189 -0
  163. smallworld_re-1.0.0.dist-info/RECORD +166 -0
  164. smallworld_re-1.0.0.dist-info/WHEEL +5 -0
  165. smallworld_re-1.0.0.dist-info/entry_points.txt +2 -0
  166. 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)