smallworld-re 1.0.2__py3-none-any.whl → 2.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 (306) hide show
  1. smallworld/analyses/__init__.py +8 -0
  2. smallworld/analyses/analysis.py +8 -67
  3. smallworld/analyses/code_coverage.py +1 -2
  4. smallworld/analyses/colorizer.py +301 -534
  5. smallworld/analyses/colorizer_def_use.py +217 -0
  6. smallworld/analyses/colorizer_summary.py +173 -83
  7. smallworld/analyses/field_detection/field_analysis.py +7 -8
  8. smallworld/analyses/field_detection/hints.py +1 -1
  9. smallworld/analyses/field_detection/malloc.py +2 -2
  10. smallworld/analyses/trace_execution.py +160 -0
  11. smallworld/analyses/trace_execution_types.py +42 -0
  12. smallworld/analyses/unstable/angr/divergence.py +1 -2
  13. smallworld/analyses/unstable/angr/model.py +5 -6
  14. smallworld/analyses/unstable/angr_nwbt.py +3 -4
  15. smallworld/analyses/unstable/code_coverage.py +2 -3
  16. smallworld/analyses/unstable/code_reachable.py +2 -3
  17. smallworld/analyses/unstable/control_flow_tracer.py +2 -3
  18. smallworld/analyses/unstable/pointer_finder.py +2 -3
  19. smallworld/analyses/unstable/utils/tui.py +71 -0
  20. smallworld/emulators/__init__.py +3 -1
  21. smallworld/emulators/angr/angr.py +30 -9
  22. smallworld/emulators/angr/machdefs/__init__.py +2 -0
  23. smallworld/emulators/angr/machdefs/aarch64.py +1 -1
  24. smallworld/emulators/angr/machdefs/amd64.py +0 -4
  25. smallworld/emulators/angr/machdefs/arm.py +0 -2
  26. smallworld/emulators/angr/machdefs/i386.py +0 -2
  27. smallworld/emulators/angr/machdefs/loongarch.py +340 -0
  28. smallworld/emulators/angr/machdefs/machdef.py +1 -8
  29. smallworld/emulators/angr/machdefs/mips.py +0 -2
  30. smallworld/emulators/angr/machdefs/mips64.py +0 -2
  31. smallworld/emulators/angr/machdefs/ppc.py +1 -2
  32. smallworld/emulators/angr/machdefs/riscv.py +8 -10
  33. smallworld/emulators/angr/machdefs/xtensa.py +7 -4
  34. smallworld/emulators/emulator.py +22 -0
  35. smallworld/emulators/ghidra/__init__.py +37 -0
  36. smallworld/emulators/ghidra/ghidra.py +513 -0
  37. smallworld/emulators/ghidra/machdefs/__init__.py +31 -0
  38. smallworld/emulators/ghidra/machdefs/aarch64.py +289 -0
  39. smallworld/emulators/ghidra/machdefs/amd64.py +185 -0
  40. smallworld/emulators/ghidra/machdefs/arm.py +370 -0
  41. smallworld/emulators/ghidra/machdefs/i386.py +109 -0
  42. smallworld/emulators/ghidra/machdefs/loongarch.py +162 -0
  43. smallworld/emulators/ghidra/machdefs/machdef.py +81 -0
  44. smallworld/emulators/ghidra/machdefs/mips.py +163 -0
  45. smallworld/emulators/ghidra/machdefs/mips64.py +186 -0
  46. smallworld/emulators/ghidra/machdefs/ppc.py +98 -0
  47. smallworld/emulators/ghidra/machdefs/riscv.py +208 -0
  48. smallworld/emulators/ghidra/machdefs/xtensa.py +21 -0
  49. smallworld/emulators/ghidra/typing.py +28 -0
  50. smallworld/emulators/hookable.py +18 -4
  51. smallworld/emulators/panda/machdefs/__init__.py +2 -2
  52. smallworld/emulators/panda/machdefs/aarch64.py +186 -11
  53. smallworld/emulators/panda/machdefs/amd64.py +103 -11
  54. smallworld/emulators/panda/machdefs/arm.py +216 -20
  55. smallworld/emulators/panda/machdefs/i386.py +30 -7
  56. smallworld/emulators/panda/machdefs/machdef.py +9 -16
  57. smallworld/emulators/panda/machdefs/mips.py +49 -5
  58. smallworld/emulators/panda/machdefs/mips64.py +57 -5
  59. smallworld/emulators/panda/machdefs/ppc.py +38 -13
  60. smallworld/emulators/panda/panda.py +146 -44
  61. smallworld/emulators/unicorn/__init__.py +2 -0
  62. smallworld/emulators/unicorn/machdefs/aarch64.py +253 -264
  63. smallworld/emulators/unicorn/machdefs/amd64.py +254 -259
  64. smallworld/emulators/unicorn/machdefs/arm.py +200 -212
  65. smallworld/emulators/unicorn/machdefs/i386.py +84 -90
  66. smallworld/emulators/unicorn/machdefs/machdef.py +2 -23
  67. smallworld/emulators/unicorn/machdefs/mips.py +127 -135
  68. smallworld/emulators/unicorn/unicorn.py +52 -13
  69. smallworld/helpers.py +4 -19
  70. smallworld/hinting/hinting.py +22 -192
  71. smallworld/hinting/hints.py +50 -18
  72. smallworld/instructions/bsid.py +8 -8
  73. smallworld/logging.py +4 -2
  74. smallworld/platforms/__init__.py +12 -0
  75. smallworld/platforms/defs/__init__.py +36 -0
  76. smallworld/platforms/defs/aarch64.py +450 -0
  77. smallworld/platforms/defs/amd64.py +463 -0
  78. smallworld/platforms/defs/arm.py +519 -0
  79. smallworld/platforms/defs/i386.py +258 -0
  80. smallworld/platforms/defs/loongarch.py +270 -0
  81. smallworld/platforms/defs/mips.py +321 -0
  82. smallworld/platforms/defs/mips64.py +313 -0
  83. smallworld/platforms/defs/platformdef.py +97 -0
  84. smallworld/platforms/defs/powerpc.py +259 -0
  85. smallworld/platforms/defs/riscv.py +257 -0
  86. smallworld/platforms/defs/xtensa.py +96 -0
  87. smallworld/{platforms.py → platforms/platforms.py} +3 -0
  88. smallworld/state/cpus/__init__.py +2 -0
  89. smallworld/state/cpus/aarch64.py +0 -9
  90. smallworld/state/cpus/amd64.py +6 -28
  91. smallworld/state/cpus/arm.py +0 -11
  92. smallworld/state/cpus/cpu.py +0 -11
  93. smallworld/state/cpus/i386.py +0 -7
  94. smallworld/state/cpus/loongarch.py +299 -0
  95. smallworld/state/cpus/mips.py +4 -47
  96. smallworld/state/cpus/mips64.py +18 -58
  97. smallworld/state/cpus/powerpc.py +2 -9
  98. smallworld/state/cpus/riscv.py +1 -11
  99. smallworld/state/cpus/xtensa.py +0 -5
  100. smallworld/state/memory/code.py +44 -2
  101. smallworld/state/memory/elf/__init__.py +5 -1
  102. smallworld/state/memory/elf/coredump/__init__.py +3 -0
  103. smallworld/state/memory/elf/coredump/coredump.py +46 -0
  104. smallworld/state/memory/elf/coredump/prstatus/__init__.py +27 -0
  105. smallworld/state/memory/elf/coredump/prstatus/aarch64.py +46 -0
  106. smallworld/state/memory/elf/coredump/prstatus/amd64.py +40 -0
  107. smallworld/state/memory/elf/coredump/prstatus/arm.py +53 -0
  108. smallworld/state/memory/elf/coredump/prstatus/i386.py +30 -0
  109. smallworld/state/memory/elf/coredump/prstatus/mips.py +55 -0
  110. smallworld/state/memory/elf/coredump/prstatus/mips64.py +57 -0
  111. smallworld/state/memory/elf/coredump/prstatus/ppc.py +82 -0
  112. smallworld/state/memory/elf/coredump/prstatus/prstatus.py +129 -0
  113. smallworld/state/memory/elf/elf.py +225 -61
  114. smallworld/state/memory/elf/register_state.py +36 -0
  115. smallworld/state/memory/elf/rela/__init__.py +2 -0
  116. smallworld/state/memory/elf/rela/aarch64.py +3 -1
  117. smallworld/state/memory/elf/rela/amd64.py +4 -2
  118. smallworld/state/memory/elf/rela/arm.py +4 -2
  119. smallworld/state/memory/elf/rela/i386.py +4 -2
  120. smallworld/state/memory/elf/rela/loongarch.py +32 -0
  121. smallworld/state/memory/elf/rela/mips.py +39 -18
  122. smallworld/state/memory/elf/rela/ppc.py +31 -14
  123. smallworld/state/memory/elf/structs.py +3 -0
  124. smallworld/state/memory/heap.py +2 -2
  125. smallworld/state/memory/memory.py +18 -0
  126. smallworld/state/memory/pe/__init__.py +3 -0
  127. smallworld/state/memory/pe/pe.py +361 -0
  128. smallworld/state/memory/pe/structs.py +60 -0
  129. smallworld/state/memory/stack/__init__.py +2 -0
  130. smallworld/state/memory/stack/loongarch.py +26 -0
  131. smallworld/state/models/__init__.py +29 -2
  132. smallworld/state/models/aarch64/__init__.py +1 -0
  133. smallworld/state/models/aarch64/systemv/__init__.py +6 -0
  134. smallworld/state/models/aarch64/systemv/c99/__init__.py +12 -0
  135. smallworld/state/models/aarch64/systemv/c99/signal.py +16 -0
  136. smallworld/state/models/aarch64/systemv/c99/stdio.py +265 -0
  137. smallworld/state/models/aarch64/systemv/c99/stdlib.py +169 -0
  138. smallworld/state/models/aarch64/systemv/c99/string.py +139 -0
  139. smallworld/state/models/aarch64/systemv/c99/time.py +61 -0
  140. smallworld/state/models/aarch64/systemv/posix/__init__.py +6 -0
  141. smallworld/state/models/aarch64/systemv/posix/libgen.py +16 -0
  142. smallworld/state/models/aarch64/systemv/posix/signal.py +157 -0
  143. smallworld/state/models/aarch64/systemv/systemv.py +80 -0
  144. smallworld/state/models/amd64/__init__.py +1 -0
  145. smallworld/state/models/amd64/systemv/__init__.py +6 -0
  146. smallworld/state/models/amd64/systemv/c99/__init__.py +12 -0
  147. smallworld/state/models/amd64/systemv/c99/signal.py +16 -0
  148. smallworld/state/models/amd64/systemv/c99/stdio.py +265 -0
  149. smallworld/state/models/amd64/systemv/c99/stdlib.py +169 -0
  150. smallworld/state/models/amd64/systemv/c99/string.py +139 -0
  151. smallworld/state/models/amd64/systemv/c99/time.py +61 -0
  152. smallworld/state/models/amd64/systemv/posix/__init__.py +6 -0
  153. smallworld/state/models/amd64/systemv/posix/libgen.py +16 -0
  154. smallworld/state/models/amd64/systemv/posix/signal.py +157 -0
  155. smallworld/state/models/amd64/systemv/systemv.py +78 -0
  156. smallworld/state/models/armel/__init__.py +1 -0
  157. smallworld/state/models/armel/systemv/__init__.py +6 -0
  158. smallworld/state/models/armel/systemv/c99/__init__.py +12 -0
  159. smallworld/state/models/armel/systemv/c99/signal.py +16 -0
  160. smallworld/state/models/armel/systemv/c99/stdio.py +265 -0
  161. smallworld/state/models/armel/systemv/c99/stdlib.py +169 -0
  162. smallworld/state/models/armel/systemv/c99/string.py +139 -0
  163. smallworld/state/models/armel/systemv/c99/time.py +61 -0
  164. smallworld/state/models/armel/systemv/posix/__init__.py +6 -0
  165. smallworld/state/models/armel/systemv/posix/libgen.py +16 -0
  166. smallworld/state/models/armel/systemv/posix/signal.py +157 -0
  167. smallworld/state/models/armel/systemv/systemv.py +82 -0
  168. smallworld/state/models/armhf/__init__.py +1 -0
  169. smallworld/state/models/armhf/systemv/__init__.py +6 -0
  170. smallworld/state/models/armhf/systemv/c99/__init__.py +12 -0
  171. smallworld/state/models/armhf/systemv/c99/signal.py +16 -0
  172. smallworld/state/models/armhf/systemv/c99/stdio.py +265 -0
  173. smallworld/state/models/armhf/systemv/c99/stdlib.py +169 -0
  174. smallworld/state/models/armhf/systemv/c99/string.py +139 -0
  175. smallworld/state/models/armhf/systemv/c99/time.py +61 -0
  176. smallworld/state/models/armhf/systemv/posix/__init__.py +6 -0
  177. smallworld/state/models/armhf/systemv/posix/libgen.py +16 -0
  178. smallworld/state/models/armhf/systemv/posix/signal.py +157 -0
  179. smallworld/state/models/armhf/systemv/systemv.py +77 -0
  180. smallworld/state/models/c99/__init__.py +12 -0
  181. smallworld/state/models/c99/fmt_print.py +915 -0
  182. smallworld/state/models/c99/fmt_scan.py +864 -0
  183. smallworld/state/models/c99/math.py +362 -0
  184. smallworld/state/models/c99/signal.py +71 -0
  185. smallworld/state/models/c99/stdio.py +1305 -0
  186. smallworld/state/models/c99/stdlib.py +595 -0
  187. smallworld/state/models/c99/string.py +674 -0
  188. smallworld/state/models/c99/time.py +340 -0
  189. smallworld/state/models/c99/utils.py +89 -0
  190. smallworld/state/models/cstd.py +759 -0
  191. smallworld/state/models/errno.py +581 -0
  192. smallworld/state/models/filedesc.py +515 -0
  193. smallworld/state/models/i386/__init__.py +1 -0
  194. smallworld/state/models/i386/systemv/__init__.py +6 -0
  195. smallworld/state/models/i386/systemv/c99/__init__.py +12 -0
  196. smallworld/state/models/i386/systemv/c99/signal.py +16 -0
  197. smallworld/state/models/i386/systemv/c99/stdio.py +265 -0
  198. smallworld/state/models/i386/systemv/c99/stdlib.py +169 -0
  199. smallworld/state/models/i386/systemv/c99/string.py +139 -0
  200. smallworld/state/models/i386/systemv/c99/time.py +61 -0
  201. smallworld/state/models/i386/systemv/posix/__init__.py +6 -0
  202. smallworld/state/models/i386/systemv/posix/libgen.py +16 -0
  203. smallworld/state/models/i386/systemv/posix/signal.py +157 -0
  204. smallworld/state/models/i386/systemv/systemv.py +71 -0
  205. smallworld/state/models/loongarch64/__init__.py +1 -0
  206. smallworld/state/models/loongarch64/systemv/__init__.py +6 -0
  207. smallworld/state/models/loongarch64/systemv/c99/__init__.py +12 -0
  208. smallworld/state/models/loongarch64/systemv/c99/signal.py +16 -0
  209. smallworld/state/models/loongarch64/systemv/c99/stdio.py +265 -0
  210. smallworld/state/models/loongarch64/systemv/c99/stdlib.py +169 -0
  211. smallworld/state/models/loongarch64/systemv/c99/string.py +139 -0
  212. smallworld/state/models/loongarch64/systemv/c99/time.py +61 -0
  213. smallworld/state/models/loongarch64/systemv/posix/__init__.py +6 -0
  214. smallworld/state/models/loongarch64/systemv/posix/libgen.py +16 -0
  215. smallworld/state/models/loongarch64/systemv/posix/signal.py +157 -0
  216. smallworld/state/models/loongarch64/systemv/systemv.py +83 -0
  217. smallworld/state/models/mips/__init__.py +1 -0
  218. smallworld/state/models/mips/systemv/__init__.py +6 -0
  219. smallworld/state/models/mips/systemv/c99/__init__.py +12 -0
  220. smallworld/state/models/mips/systemv/c99/signal.py +16 -0
  221. smallworld/state/models/mips/systemv/c99/stdio.py +265 -0
  222. smallworld/state/models/mips/systemv/c99/stdlib.py +169 -0
  223. smallworld/state/models/mips/systemv/c99/string.py +139 -0
  224. smallworld/state/models/mips/systemv/c99/time.py +61 -0
  225. smallworld/state/models/mips/systemv/posix/__init__.py +6 -0
  226. smallworld/state/models/mips/systemv/posix/libgen.py +16 -0
  227. smallworld/state/models/mips/systemv/posix/signal.py +157 -0
  228. smallworld/state/models/mips/systemv/systemv.py +78 -0
  229. smallworld/state/models/mips64/__init__.py +1 -0
  230. smallworld/state/models/mips64/systemv/__init__.py +6 -0
  231. smallworld/state/models/mips64/systemv/c99/__init__.py +12 -0
  232. smallworld/state/models/mips64/systemv/c99/signal.py +16 -0
  233. smallworld/state/models/mips64/systemv/c99/stdio.py +265 -0
  234. smallworld/state/models/mips64/systemv/c99/stdlib.py +169 -0
  235. smallworld/state/models/mips64/systemv/c99/string.py +139 -0
  236. smallworld/state/models/mips64/systemv/c99/time.py +61 -0
  237. smallworld/state/models/mips64/systemv/posix/__init__.py +6 -0
  238. smallworld/state/models/mips64/systemv/posix/libgen.py +16 -0
  239. smallworld/state/models/mips64/systemv/posix/signal.py +157 -0
  240. smallworld/state/models/mips64/systemv/systemv.py +98 -0
  241. smallworld/state/models/mips64el/__init__.py +1 -0
  242. smallworld/state/models/mips64el/systemv/__init__.py +6 -0
  243. smallworld/state/models/mips64el/systemv/c99/__init__.py +12 -0
  244. smallworld/state/models/mips64el/systemv/c99/signal.py +16 -0
  245. smallworld/state/models/mips64el/systemv/c99/stdio.py +265 -0
  246. smallworld/state/models/mips64el/systemv/c99/stdlib.py +169 -0
  247. smallworld/state/models/mips64el/systemv/c99/string.py +139 -0
  248. smallworld/state/models/mips64el/systemv/c99/time.py +61 -0
  249. smallworld/state/models/mips64el/systemv/posix/__init__.py +6 -0
  250. smallworld/state/models/mips64el/systemv/posix/libgen.py +16 -0
  251. smallworld/state/models/mips64el/systemv/posix/signal.py +157 -0
  252. smallworld/state/models/mips64el/systemv/systemv.py +96 -0
  253. smallworld/state/models/mipsel/__init__.py +1 -0
  254. smallworld/state/models/mipsel/systemv/__init__.py +6 -0
  255. smallworld/state/models/mipsel/systemv/c99/__init__.py +12 -0
  256. smallworld/state/models/mipsel/systemv/c99/signal.py +16 -0
  257. smallworld/state/models/mipsel/systemv/c99/stdio.py +265 -0
  258. smallworld/state/models/mipsel/systemv/c99/stdlib.py +169 -0
  259. smallworld/state/models/mipsel/systemv/c99/string.py +139 -0
  260. smallworld/state/models/mipsel/systemv/c99/time.py +61 -0
  261. smallworld/state/models/mipsel/systemv/posix/__init__.py +6 -0
  262. smallworld/state/models/mipsel/systemv/posix/libgen.py +16 -0
  263. smallworld/state/models/mipsel/systemv/posix/signal.py +157 -0
  264. smallworld/state/models/mipsel/systemv/systemv.py +78 -0
  265. smallworld/state/models/model.py +27 -2
  266. smallworld/state/models/posix/__init__.py +6 -0
  267. smallworld/state/models/posix/libgen.py +123 -0
  268. smallworld/state/models/posix/signal.py +690 -0
  269. smallworld/state/models/powerpc/__init__.py +1 -0
  270. smallworld/state/models/powerpc/systemv/__init__.py +6 -0
  271. smallworld/state/models/powerpc/systemv/c99/__init__.py +12 -0
  272. smallworld/state/models/powerpc/systemv/c99/signal.py +16 -0
  273. smallworld/state/models/powerpc/systemv/c99/stdio.py +265 -0
  274. smallworld/state/models/powerpc/systemv/c99/stdlib.py +169 -0
  275. smallworld/state/models/powerpc/systemv/c99/string.py +139 -0
  276. smallworld/state/models/powerpc/systemv/c99/time.py +61 -0
  277. smallworld/state/models/powerpc/systemv/posix/__init__.py +6 -0
  278. smallworld/state/models/powerpc/systemv/posix/libgen.py +16 -0
  279. smallworld/state/models/powerpc/systemv/posix/signal.py +157 -0
  280. smallworld/state/models/powerpc/systemv/systemv.py +93 -0
  281. smallworld/state/models/riscv64/__init__.py +1 -0
  282. smallworld/state/models/riscv64/systemv/__init__.py +6 -0
  283. smallworld/state/models/riscv64/systemv/c99/__init__.py +12 -0
  284. smallworld/state/models/riscv64/systemv/c99/signal.py +16 -0
  285. smallworld/state/models/riscv64/systemv/c99/stdio.py +265 -0
  286. smallworld/state/models/riscv64/systemv/c99/stdlib.py +169 -0
  287. smallworld/state/models/riscv64/systemv/c99/string.py +139 -0
  288. smallworld/state/models/riscv64/systemv/c99/time.py +61 -0
  289. smallworld/state/models/riscv64/systemv/posix/__init__.py +6 -0
  290. smallworld/state/models/riscv64/systemv/posix/libgen.py +16 -0
  291. smallworld/state/models/riscv64/systemv/posix/signal.py +157 -0
  292. smallworld/state/models/riscv64/systemv/systemv.py +85 -0
  293. smallworld/state/state.py +65 -24
  294. smallworld/state/unstable/elf.py +16 -31
  295. smallworld/utils.py +6 -1
  296. {smallworld_re-1.0.2.dist-info → smallworld_re-2.0.0.dist-info}/METADATA +76 -43
  297. smallworld_re-2.0.0.dist-info/RECORD +374 -0
  298. {smallworld_re-1.0.2.dist-info → smallworld_re-2.0.0.dist-info}/WHEEL +1 -1
  299. smallworld/state/models/x86/__init__.py +0 -2
  300. smallworld/state/models/x86/microsoftcdecl.py +0 -35
  301. smallworld/state/models/x86/systemv.py +0 -240
  302. smallworld_re-1.0.2.dist-info/RECORD +0 -166
  303. /smallworld/state/models/{posix.py → _posix.py} +0 -0
  304. {smallworld_re-1.0.2.dist-info → smallworld_re-2.0.0.dist-info}/entry_points.txt +0 -0
  305. {smallworld_re-1.0.2.dist-info → smallworld_re-2.0.0.dist-info/licenses}/LICENSE.txt +0 -0
  306. {smallworld_re-1.0.2.dist-info → smallworld_re-2.0.0.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,81 @@
1
+ import abc
2
+ import typing
3
+
4
+ from ghidra.app.plugin.processors.sleigh import SleighLanguageProvider
5
+ from ghidra.program.model.lang import Language, LanguageID, Register
6
+
7
+ from .... import exceptions, platforms, utils
8
+
9
+
10
+ class GhidraMachineDef:
11
+ """Container class for ghdra 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 language_id(self) -> str:
28
+ """The Pcode language ID"""
29
+ raise NotImplementedError("This is an abstract method")
30
+
31
+ # Does Pcode support single-instruction stepping for this ISA.
32
+ #
33
+ # Instructions with delay slots can't be lifted into Pcode
34
+ # without also lifting the instruction in the delay slot.
35
+ #
36
+ # This flag indicates that this machine uses such instructions,
37
+ # and is not safe to step in this manner
38
+ supports_single_step: bool = True
39
+
40
+ _registers: typing.Dict[str, typing.Optional[str]]
41
+
42
+ def __init__(self):
43
+ # Load the Pcode language definition
44
+ slp = SleighLanguageProvider.getSleighLanguageProvider()
45
+ langID = LanguageID(self.language_id)
46
+ self.language: Language = slp.getLanguage(langID)
47
+ assert self.language is not None
48
+
49
+ def pcode_reg(self, name: str) -> Register:
50
+ if name not in self._registers:
51
+ raise KeyError(f"Unknown register for {self.arch}:{self.byteorder}: {name}")
52
+ if self._registers[name] is None:
53
+ raise exceptions.UnsupportedRegisterError(
54
+ f"Register {name} not recognized by pcode for {self.arch}:{self.byteorder}"
55
+ )
56
+ reg = self.language.getRegister(self._registers[name])
57
+ assert reg is not None, name
58
+ return reg
59
+
60
+ @classmethod
61
+ def for_platform(cls, platform: platforms.Platform):
62
+ """Find the appropriate MachineDef for your architecture
63
+
64
+ Arguments:
65
+ arch: The architecture ID you want
66
+ byteorder: The byteorderness you want
67
+
68
+ Returns:
69
+ An instance of the appropriate MachineDef
70
+
71
+ Raises:
72
+ ValueError: If no MachineDef subclass matches your request
73
+ """
74
+ try:
75
+ return utils.find_subclass(
76
+ cls,
77
+ lambda x: x.arch == platform.architecture
78
+ and x.byteorder == platform.byteorder,
79
+ )
80
+ except:
81
+ raise ValueError(f"No machine model for {platform}")
@@ -0,0 +1,163 @@
1
+ from ....platforms import Architecture, Byteorder
2
+ from .machdef import GhidraMachineDef
3
+
4
+
5
+ class MIPSMachineDef(GhidraMachineDef):
6
+ arch = Architecture.MIPS32
7
+
8
+ # NOTE: MIPS registers have a name and a number
9
+ # angr's machine state doesn't use the number,
10
+ # so... name.
11
+ _registers = {
12
+ # *** General-Purpose Registers ***
13
+ # Assembler-Temporary Register
14
+ "at": "at",
15
+ "1": "at",
16
+ # Return Value Registers
17
+ "v0": "v0",
18
+ "2": "v0",
19
+ "v1": "v1",
20
+ "3": "v1",
21
+ # Argument Registers
22
+ "a0": "a0",
23
+ "4": "a0",
24
+ "a1": "a1",
25
+ "5": "a1",
26
+ "a2": "a2",
27
+ "6": "a2",
28
+ "a3": "a3",
29
+ "7": "a3",
30
+ # Temporary Registers
31
+ "t0": "t0",
32
+ "8": "t0",
33
+ "t1": "t1",
34
+ "9": "t1",
35
+ "t2": "t2",
36
+ "10": "t2",
37
+ "t3": "t3",
38
+ "11": "t3",
39
+ "t4": "t4",
40
+ "12": "t4",
41
+ "t5": "t5",
42
+ "13": "t5",
43
+ "t6": "t6",
44
+ "14": "t6",
45
+ "t7": "t7",
46
+ "15": "t7",
47
+ # NOTE: These numbers aren't out of order.
48
+ # t8 and t9 are later in the register file than t0 - t7.
49
+ "t8": "t8",
50
+ "24": "t8",
51
+ "t9": "t9",
52
+ "25": "t9",
53
+ # Saved Registers
54
+ "s0": "s0",
55
+ "16": "s0",
56
+ "s1": "s1",
57
+ "17": "s1",
58
+ "s2": "s2",
59
+ "18": "s2",
60
+ "s3": "s3",
61
+ "19": "s3",
62
+ "s4": "s4",
63
+ "20": "s4",
64
+ "s5": "s5",
65
+ "21": "s5",
66
+ "s6": "s6",
67
+ "22": "s6",
68
+ "s7": "s7",
69
+ "23": "s7",
70
+ # NOTE: Register #30 was originally the Frame Pointer.
71
+ # It's been re-aliased as s8, since many ABIs don't use the frame pointer.
72
+ # Unicorn and Sleigh prefer to use the alias s8,
73
+ # so it should be the base register.
74
+ "s8": "s8",
75
+ "fp": "s8",
76
+ "30": "s8",
77
+ # Kernel-reserved Registers
78
+ "k0": "k0",
79
+ "26": "k0",
80
+ "k1": "k1",
81
+ "27": "k1",
82
+ # *** Pointer Registers ***
83
+ # Zero register
84
+ "zero": "zero",
85
+ "0": "zero",
86
+ # Global Offset Pointer
87
+ "gp": "gp",
88
+ "28": "gp",
89
+ # Stack Pointer
90
+ "sp": "sp",
91
+ "29": "sp",
92
+ # Return Address
93
+ "ra": "ra",
94
+ "31": "ra",
95
+ # Program Counter
96
+ "pc": "pc",
97
+ # Floating Point Registers
98
+ "f0": "f0",
99
+ "f1": "f1",
100
+ "f2": "f2",
101
+ "f3": "f3",
102
+ "f4": "f4",
103
+ "f5": "f5",
104
+ "f6": "f6",
105
+ "f7": "f7",
106
+ "f8": "f8",
107
+ "f9": "f9",
108
+ "f10": "f10",
109
+ "f11": "f11",
110
+ "f12": "f12",
111
+ "f13": "f13",
112
+ "f14": "f14",
113
+ "f15": "f15",
114
+ "f16": "f16",
115
+ "f17": "f17",
116
+ "f18": "f18",
117
+ "f19": "f19",
118
+ "f20": "f20",
119
+ "f21": "f21",
120
+ "f22": "f22",
121
+ "f23": "f23",
122
+ "f24": "f24",
123
+ "f25": "f25",
124
+ "f26": "f26",
125
+ "f27": "f27",
126
+ "f28": "f28",
127
+ "f29": "f29",
128
+ "f30": "f30",
129
+ "f31": "f31",
130
+ # *** Floating Point Control Registers ***
131
+ "fir": "fir",
132
+ "fcsr": "fcsr",
133
+ "fexr": "fexr",
134
+ "fenr": "fenr",
135
+ "fccr": "fccr",
136
+ # *** Accumulator Registers ***
137
+ # MIPS uses these to implement 64-bit results
138
+ # from 32-bit multiplication, amongst others.
139
+ "ac0": None,
140
+ "hi0": None,
141
+ "lo0": None,
142
+ "ac1": None,
143
+ "hi1": None,
144
+ "lo1": None,
145
+ "ac2": None,
146
+ "hi2": None,
147
+ "lo2": None,
148
+ "ac3": None,
149
+ "hi3": None,
150
+ "lo3": None,
151
+ }
152
+
153
+ supports_single_step = True
154
+
155
+
156
+ class MIPSELMachineDef(MIPSMachineDef):
157
+ byteorder = Byteorder.LITTLE
158
+ language_id = "MIPS:LE:32:default"
159
+
160
+
161
+ class MIPSBEMachineDef(MIPSMachineDef):
162
+ byteorder = Byteorder.BIG
163
+ language_id = "MIPS:BE:32:default"
@@ -0,0 +1,186 @@
1
+ from ....platforms import Architecture, Byteorder
2
+ from .machdef import GhidraMachineDef
3
+
4
+
5
+ class MIPS64MachineDef(GhidraMachineDef):
6
+ arch = Architecture.MIPS64
7
+
8
+ # NOTE: MIPS registers have a name and a number
9
+ # angr's machine state doesn't use the number,
10
+ # so... name.
11
+ # NOTE: angr's register names are wrong.
12
+ # It follows Wikipedia's definition of the 64-bit ABI,
13
+ # which has a4 - a7 and t0 - t3 overlapping.
14
+ _registers = {
15
+ # *** General-Purpose Registers ***
16
+ # NOTE: Ghidra uses the O64 ABI (rather, it reuses the O32 names for both)
17
+ # SmallWorld uses the N64 ABI for mips64,
18
+ # so the argument and temporary registers will appear wrong
19
+ # Assembler-Temporary Register
20
+ "at": "at",
21
+ "1": "at",
22
+ # Return Value Registers
23
+ "v0": "v0",
24
+ "2": "v0",
25
+ "v1": "v1",
26
+ "3": "v1",
27
+ # Argument Registers
28
+ "a0": "a0",
29
+ "4": "a0",
30
+ "a1": "a1",
31
+ "5": "a1",
32
+ "a2": "a2",
33
+ "6": "a2",
34
+ "a3": "a3",
35
+ "7": "a3",
36
+ "a4": "t0",
37
+ "8": "t0",
38
+ "a5": "t1",
39
+ "9": "t1",
40
+ "a6": "t2",
41
+ "10": "t2",
42
+ "a7": "t3",
43
+ "11": "t3",
44
+ # Temporary Registers
45
+ "t0": "t4",
46
+ "12": "t4",
47
+ "t1": "t5",
48
+ "13": "t5",
49
+ "t2": "t6",
50
+ "14": "t6",
51
+ "t3": "t7",
52
+ "15": "t7",
53
+ # NOTE: These numbers aren't out of order.
54
+ # t8 and t9 are later in the register file than t0 - t7.
55
+ "t8": "t8",
56
+ "24": "t8",
57
+ "t9": "t9",
58
+ "25": "t9",
59
+ # Saved Registers
60
+ "s0": "s0",
61
+ "16": "s0",
62
+ "s1": "s1",
63
+ "17": "s1",
64
+ "s2": "s2",
65
+ "18": "s2",
66
+ "s3": "s3",
67
+ "19": "s3",
68
+ "s4": "s4",
69
+ "20": "s4",
70
+ "s5": "s5",
71
+ "21": "s5",
72
+ "s6": "s6",
73
+ "22": "s6",
74
+ "s7": "s7",
75
+ "23": "s7",
76
+ # NOTE: Register #30 was originally the Frame Pointer.
77
+ # It's been re-aliased as s8, since many ABIs don't use the frame pointer.
78
+ # Unicorn and Sleigh prefer to use the alias s8,
79
+ # so it should be the base register.
80
+ "s8": "s8",
81
+ "fp": "s8",
82
+ "30": "s8",
83
+ # Kernel-reserved Registers
84
+ "k0": "k0",
85
+ "26": "k0",
86
+ "k1": "k1",
87
+ "27": "k1",
88
+ # *** Pointer Registers ***
89
+ # Zero register
90
+ "zero": "zero",
91
+ "0": "zero",
92
+ # Global Offset Pointer
93
+ "gp": "gp",
94
+ "28": "gp",
95
+ # Stack Pointer
96
+ "sp": "sp",
97
+ "29": "sp",
98
+ # Return Address
99
+ "ra": "ra",
100
+ "31": "ra",
101
+ # Program Counter
102
+ "pc": "pc",
103
+ # Floating Point Registers
104
+ "f0": "f0",
105
+ "f1": "f1",
106
+ "f2": "f2",
107
+ "f3": "f3",
108
+ "f4": "f4",
109
+ "f5": "f5",
110
+ "f6": "f6",
111
+ "f7": "f7",
112
+ "f8": "f8",
113
+ "f9": "f9",
114
+ "f10": "f10",
115
+ "f11": "f11",
116
+ "f12": "f12",
117
+ "f13": "f13",
118
+ "f14": "f14",
119
+ "f15": "f15",
120
+ "f16": "f16",
121
+ "f17": "f17",
122
+ "f18": "f18",
123
+ "f19": "f19",
124
+ "f20": "f20",
125
+ "f21": "f21",
126
+ "f22": "f22",
127
+ "f23": "f23",
128
+ "f24": "f24",
129
+ "f25": "f25",
130
+ "f26": "f26",
131
+ "f27": "f27",
132
+ "f28": "f28",
133
+ "f29": "f29",
134
+ "f30": "f30",
135
+ "f31": "f31",
136
+ # *** Floating Point Control Registers ***
137
+ "fir": "fir",
138
+ "fcsr": "fcsr",
139
+ "fexr": "fexr",
140
+ "fenr": "fenr",
141
+ "fccr": "fccr",
142
+ # *** Accumulator Registers ***
143
+ # MIPS uses these to implement 64-bit results
144
+ # from 32-bit multiplication, amongst others.
145
+ "ac0": None,
146
+ "hi0": None,
147
+ "lo0": None,
148
+ "ac1": None,
149
+ "hi1": None,
150
+ "lo1": None,
151
+ "ac2": None,
152
+ "hi2": None,
153
+ "lo2": None,
154
+ "ac3": None,
155
+ "hi3": None,
156
+ "lo3": None,
157
+ }
158
+
159
+ _delay_slot_opcodes = {
160
+ "j",
161
+ "jal",
162
+ "jalx",
163
+ "jalr",
164
+ "jr",
165
+ "beq",
166
+ "beqz",
167
+ "bne" "bnez",
168
+ "bgez",
169
+ "bgezal",
170
+ "bgtz",
171
+ "blez",
172
+ "bltz",
173
+ "bltzal",
174
+ }
175
+
176
+ supports_single_step = True
177
+
178
+
179
+ class MIPS64ELMachineDef(MIPS64MachineDef):
180
+ byteorder = Byteorder.LITTLE
181
+ language_id = "MIPS:LE:64:default"
182
+
183
+
184
+ class MIPS64BEMachineDef(MIPS64MachineDef):
185
+ byteorder = Byteorder.BIG
186
+ language_id = "MIPS:BE:64:default"
@@ -0,0 +1,98 @@
1
+ from ....platforms import Architecture, Byteorder
2
+ from .machdef import GhidraMachineDef
3
+
4
+
5
+ class PowerPCMachineDef(GhidraMachineDef):
6
+ byteorder = Byteorder.BIG
7
+
8
+ _registers = {
9
+ "r0": "r0",
10
+ "r1": "r1",
11
+ "sp": "r1",
12
+ "r2": "r2",
13
+ "r3": "r3",
14
+ "r4": "r4",
15
+ "r5": "r5",
16
+ "r6": "r6",
17
+ "r7": "r7",
18
+ "r8": "r8",
19
+ "r9": "r9",
20
+ "r10": "r10",
21
+ "r11": "r11",
22
+ "r12": "r12",
23
+ "r13": "r13",
24
+ "r14": "r14",
25
+ "r15": "r15",
26
+ "r16": "r16",
27
+ "r17": "r17",
28
+ "r18": "r18",
29
+ "r19": "r19",
30
+ "r20": "r20",
31
+ "r21": "r21",
32
+ "r22": "r22",
33
+ "r23": "r23",
34
+ "r24": "r24",
35
+ "r25": "r25",
36
+ "r26": "r26",
37
+ "r27": "r27",
38
+ "r28": "r28",
39
+ "r29": "r29",
40
+ "r30": "r30",
41
+ "r31": "r31",
42
+ "bp": "r31",
43
+ "pc": "pc",
44
+ "lr": "lr",
45
+ "ctr": "ctr",
46
+ "cr0": "cr0",
47
+ "cr1": "cr1",
48
+ "cr2": "cr2",
49
+ "cr3": "cr3",
50
+ "cr4": "cr4",
51
+ "cr5": "cr5",
52
+ "cr6": "cr6",
53
+ "cr7": "cr7",
54
+ "f0": "f0",
55
+ "f1": "f1",
56
+ "f2": "f2",
57
+ "f3": "f3",
58
+ "f4": "f4",
59
+ "f5": "f5",
60
+ "f6": "f6",
61
+ "f7": "f7",
62
+ "f8": "f8",
63
+ "f9": "f9",
64
+ "f10": "f10",
65
+ "f11": "f11",
66
+ "f12": "f12",
67
+ "f13": "f13",
68
+ "f14": "f14",
69
+ "f15": "f15",
70
+ "f16": "f16",
71
+ "f17": "f17",
72
+ "f18": "f18",
73
+ "f19": "f19",
74
+ "f20": "f20",
75
+ "f21": "f21",
76
+ "f22": "f22",
77
+ "f23": "f23",
78
+ "f24": "f24",
79
+ "f25": "f25",
80
+ "f26": "f26",
81
+ "f27": "f27",
82
+ "f28": "f28",
83
+ "f29": "f29",
84
+ "f30": "f30",
85
+ "f31": "f31",
86
+ "xer": None,
87
+ "fpscr": None,
88
+ }
89
+
90
+
91
+ class PowerPC32MachineDef(PowerPCMachineDef):
92
+ arch = Architecture.POWERPC32
93
+ language_id = "PowerPC:BE:32:default"
94
+
95
+
96
+ class PowerPC64MachineDef(PowerPCMachineDef):
97
+ arch = Architecture.POWERPC64
98
+ language_id = "PowerPC:BE:64:default"