smallworld-re 1.0.3__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 +38 -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 +211 -57
  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.3.dist-info → smallworld_re-2.0.0.dist-info}/METADATA +74 -42
  297. smallworld_re-2.0.0.dist-info/RECORD +374 -0
  298. {smallworld_re-1.0.3.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.3.dist-info/RECORD +0 -166
  303. /smallworld/state/models/{posix.py → _posix.py} +0 -0
  304. {smallworld_re-1.0.3.dist-info → smallworld_re-2.0.0.dist-info}/entry_points.txt +0 -0
  305. {smallworld_re-1.0.3.dist-info → smallworld_re-2.0.0.dist-info}/licenses/LICENSE.txt +0 -0
  306. {smallworld_re-1.0.3.dist-info → smallworld_re-2.0.0.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,370 @@
1
+ from ....platforms import Architecture, Byteorder
2
+ from .machdef import GhidraMachineDef
3
+
4
+
5
+ class ARMMachineDef(GhidraMachineDef):
6
+ def __init__(self):
7
+ super().__init__()
8
+ self._registers = {
9
+ # *** General-purpose registers ***
10
+ "r0": "r0",
11
+ "r1": "r1",
12
+ "r2": "r2",
13
+ "r3": "r3",
14
+ "r4": "r4",
15
+ "r5": "r5",
16
+ "r6": "r6",
17
+ "r7": "r7",
18
+ "r8": "r8",
19
+ # r9 doubles as the Static base pointer
20
+ "r9": "r9",
21
+ "sb": "r9",
22
+ # r10 doubles as the Stack Limit pointer
23
+ "r10": "r10",
24
+ "sl": "r10",
25
+ # r11 doubles as the Frame Pointer, if desired.
26
+ "r11": "r11",
27
+ "fp": "r10",
28
+ # r12 doubles as the Intra-call scratch register
29
+ "r12": "r12",
30
+ "ip": "r12",
31
+ "sp": "sp",
32
+ "lr": "lr",
33
+ "pc": "pc",
34
+ }
35
+
36
+
37
+ class ARMMachineMixinM:
38
+ """Mixin for ARM series M CPUs"""
39
+
40
+ def __init__(self):
41
+ super().__init__()
42
+ self._registers.update(
43
+ {
44
+ # *** Special Registers ***
45
+ # Program Status Register
46
+ # NOTE: PSR can be accessed through several masked aliases.
47
+ # These are read-only, so I'm not including them.
48
+ # - apsr: Just the condition flags
49
+ # - ipsr: Just exception information
50
+ # - epsr: Just execution state info
51
+ # - iapsr: apsr | ipsr
52
+ # - eapsr: apsr | epsr
53
+ # - iepsr: ipsr | epsr
54
+ # - xpsr: apsr | ipsr | epsr
55
+ # NOTE: Ghidra has a single ARM32 model that appears to focus on the A series.
56
+ # I'd avoid doing privileged stuff on the M series.
57
+ "psr": "cpsr",
58
+ # Exception Mask Register
59
+ "primask": None,
60
+ # Base Priority Mask Register
61
+ "basepri": None,
62
+ # Fault Mask Register
63
+ "faultmask": None,
64
+ # Control register; includes a lot of flags.
65
+ "control": None,
66
+ # *** Stack Pointer Bank ***
67
+ # sp is actually an alias to one of these two.
68
+ # Exactly which one depends on a bit in control.
69
+ # Emulators that care should be careful when loading state.
70
+ # Main Stack Pointer
71
+ "msp": None,
72
+ # Process Stack Pointer
73
+ "psp": None,
74
+ }
75
+ )
76
+
77
+
78
+ class ARMMachineMixinRA:
79
+ """Mixin for ARM series A and R CPUs"""
80
+
81
+ def __init__(self):
82
+ super().__init__()
83
+ self._registers.update(
84
+ {
85
+ # *** Special Registers ***
86
+ # Current Program Status Register
87
+ # NOTE: CPSR can be accessed through several masked aliases.
88
+ # These are read-only, so I'm not including them.
89
+ # - isetstate: Just includes instruction set control bits
90
+ # - itstate: Just includes state bits for Thumb IT instruction
91
+ "cpsr": "cpsr",
92
+ # Saved Program Status Register
93
+ "spsr": "spsr",
94
+ # *** Register Banks ***
95
+ # sp, lr, and spsr are actually aliases to one of these.
96
+ # Which one they reference depends on execution mode.
97
+ # Emulators that care should be careful when loading state.
98
+ # NOTE: Use User-mode copies of registers unless the mode has its own.
99
+ # User-mode Stack Pointer
100
+ "sp_usr": None,
101
+ # User-mode Link Register
102
+ "lr_usr": None,
103
+ # User-mode r8
104
+ "r8_usr": None,
105
+ # User-mode r9
106
+ "r9_usr": None,
107
+ # User-mode r10
108
+ "r10_usr": None,
109
+ # User-mode r11
110
+ "r11_usr": None,
111
+ # User-mode r12
112
+ "r12_usr": None,
113
+ # Hypervisor Stack Pointer
114
+ "sp_hyp": None,
115
+ # Hypervisor Saved PSR
116
+ "spsr_hyp": None,
117
+ # Hypervisor Exception Link Register
118
+ # NOTE: None,
119
+ "elr_hyp": None,
120
+ # Supervisor Stack Pointer
121
+ "sp_svc": None,
122
+ # Supervisor Link Register
123
+ "lr_svc": None,
124
+ # Supervisor Saved PSR
125
+ "spsr_svc": None,
126
+ # Abort-state Stack Pointer
127
+ "sp_abt": None,
128
+ # Abort-state Link Register
129
+ "lr_abt": None,
130
+ # Abort-state Saved PSR
131
+ "spsr_abt": None,
132
+ # Undefined-mode Stack Pointer
133
+ "sp_und": None,
134
+ # Undefined-mode Link Register
135
+ "lr_und": None,
136
+ # Undefined-mode Saved PSR
137
+ "spsr_und": None,
138
+ # Monitor-mode Stack Pointer
139
+ "sp_mon": None,
140
+ # Monitor-mode Link Register
141
+ "lr_mon": None,
142
+ # Monitor-mode Saved PSR
143
+ "spsr_mon": None,
144
+ # IRQ-mode Stack Pointer
145
+ "sp_irq": None,
146
+ # IRQ-mode Link Register
147
+ "lr_irq": None,
148
+ # IRQ-mode Saved PSR
149
+ "spsr_irq": None,
150
+ # FIQ-mode Stack Pointer
151
+ "sp_fiq": None,
152
+ # FIQ-mode Link Register
153
+ "lr_fiq": None,
154
+ # FIQ-mode Saved PSR
155
+ "spsr_fiq": None,
156
+ # FIQ-mode r8
157
+ "r8_fiq": None,
158
+ # FIQ-mode r9
159
+ "r9_fiq": None,
160
+ # FIQ-mode r10
161
+ "r10_fiq": None,
162
+ # FIQ-mode r11
163
+ "r11_fiq": None,
164
+ # FIQ-mode r12
165
+ "r12_fiq": None,
166
+ }
167
+ )
168
+
169
+
170
+ class ARMMachineMixinFP:
171
+ """Mixin for ARM CPUs with FP extensions
172
+
173
+ This is one kind of floating-point extension
174
+ which offers 64-bit scalar operations.
175
+ """
176
+
177
+ def __init__(self):
178
+ super().__init__()
179
+ self._registers.update(
180
+ {
181
+ # *** Floating point control registers ***
182
+ # Floating-point Status and Control Register
183
+ "fpscr": "fpscr",
184
+ # Floating-point Exception Control Register
185
+ "fpexc": "fpexc",
186
+ # Floating-point System ID Register
187
+ "fpsid": "fpsid",
188
+ # Media and VFP Feature Register 0
189
+ "mvfr0": "mvfr0",
190
+ # Media and VFP Feature Register 1
191
+ "mvfr1": "mvfr1",
192
+ # *** Floating point registers ***
193
+ "d0": "d0",
194
+ "s0": "s0",
195
+ "s1": "s1",
196
+ "d1": "d1",
197
+ "s2": "s2",
198
+ "s3": "s3",
199
+ "d2": "d2",
200
+ "s4": "s4",
201
+ "s5": "s5",
202
+ "d3": "d3",
203
+ "s6": "s6",
204
+ "s7": "s7",
205
+ "d4": "d4",
206
+ "s8": "s8",
207
+ "s9": "s9",
208
+ "d5": "d5",
209
+ "s10": "s10",
210
+ "s11": "s11",
211
+ "d6": "d6",
212
+ "s12": "s12",
213
+ "s13": "s13",
214
+ "d7": "d7",
215
+ "s14": "s14",
216
+ "s15": "s15",
217
+ "d8": "d8",
218
+ "s16": "s16",
219
+ "s17": "s17",
220
+ "d9": "d9",
221
+ "s18": "s18",
222
+ "s19": "s19",
223
+ "d10": "d10",
224
+ "s20": "s20",
225
+ "s21": "s21",
226
+ "d11": "d11",
227
+ "s22": "s22",
228
+ "s23": "s23",
229
+ "d12": "d12",
230
+ "s24": "s24",
231
+ "s25": "s25",
232
+ "d13": "d13",
233
+ "s26": "s26",
234
+ "s27": "s27",
235
+ "d14": "d14",
236
+ "s28": "s28",
237
+ "s29": "s29",
238
+ "d15": "d15",
239
+ "s30": "s30",
240
+ "s31": "s31",
241
+ }
242
+ )
243
+
244
+
245
+ class ARMMachineMixinVFPEL:
246
+ def __init__(self):
247
+ super().__init__()
248
+ self._registers.update(
249
+ {
250
+ # *** Floating-point Control Registers ***
251
+ # Floating-point Status and Control Register
252
+ "fpscr": "fpscr",
253
+ # Floating-point Exception Control Register
254
+ "fpexc": "fpexc",
255
+ # Floating-point System ID Register
256
+ "fpsid": "fpsid",
257
+ # Media and VFP Feature Register 0
258
+ "mvfr0": "mvfr0",
259
+ # Media and VFP Feature Register 1
260
+ "mvfr1": "mvfr1",
261
+ # *** Floating-point Registers ****
262
+ "q0": "q0",
263
+ "d0": "d0",
264
+ "s0": "s0",
265
+ "s1": "s1",
266
+ "d1": "d1",
267
+ "s2": "s2",
268
+ "s3": "s3",
269
+ "q1": "q1",
270
+ "d2": "d2",
271
+ "s4": "s4",
272
+ "s5": "s5",
273
+ "d3": "d3",
274
+ "s6": "s6",
275
+ "s7": "s7",
276
+ "q2": "q2",
277
+ "d4": "d4",
278
+ "s8": "s8",
279
+ "s9": "s9",
280
+ "d5": "d5",
281
+ "s10": "s10",
282
+ "s11": "s11",
283
+ "q3": "q3",
284
+ "d6": "d6",
285
+ "s12": "s12",
286
+ "s13": "s13",
287
+ "d7": "d7",
288
+ "s14": "s14",
289
+ "s15": "s15",
290
+ "q4": "q4",
291
+ "d8": "d8",
292
+ "s16": "s16",
293
+ "s17": "s17",
294
+ "d9": "d9",
295
+ "s18": "s18",
296
+ "s19": "s19",
297
+ "q5": "q5",
298
+ "d10": "d10",
299
+ "s20": "s20",
300
+ "s21": "s21",
301
+ "d11": "d11",
302
+ "s22": "s22",
303
+ "s23": "s23",
304
+ "q6": "q6",
305
+ "d12": "d12",
306
+ "s24": "s24",
307
+ "s25": "s25",
308
+ "d13": "d13",
309
+ "s26": "s26",
310
+ "s27": "s27",
311
+ "q7": "q7",
312
+ "d14": "d14",
313
+ "s28": "s28",
314
+ "s29": "s29",
315
+ "d15": "d15",
316
+ "s30": "s30",
317
+ "s31": "s31",
318
+ # NOTE: This isn't a typo; there are only 32 single-precision sX registers
319
+ # This does mean that only half the VFP register space can be used
320
+ # for single-precision arithmetic.
321
+ "q8": "q8",
322
+ "d16": "d16",
323
+ "d17": "d17",
324
+ "q9": "q9",
325
+ "d18": "d18",
326
+ "d19": "d19",
327
+ "q10": "q10",
328
+ "d20": "d20",
329
+ "d21": "d21",
330
+ "q11": "q11",
331
+ "d22": "d22",
332
+ "d23": "d23",
333
+ "q12": "q12",
334
+ "d24": "d24",
335
+ "d25": "d25",
336
+ "q13": "q13",
337
+ "d26": "d26",
338
+ "d27": "d27",
339
+ "q14": "q14",
340
+ "d28": "d28",
341
+ "d29": "d29",
342
+ "q15": "q15",
343
+ "d30": "d30",
344
+ "d31": "d31",
345
+ }
346
+ )
347
+
348
+
349
+ class ARMv5TMachineDef(ARMMachineMixinM, ARMMachineDef):
350
+ arch = Architecture.ARM_V5T
351
+ byteorder = Byteorder.LITTLE
352
+ language_id = "ARM:LE:32:v5t"
353
+
354
+
355
+ class ARMv6MMachineDef(ARMMachineMixinFP, ARMMachineMixinM, ARMMachineDef):
356
+ arch = Architecture.ARM_V6M
357
+ byteorder = Byteorder.LITTLE
358
+ language_id = "ARM:LE:32:v6"
359
+
360
+
361
+ class ARMv7MMachineDef(ARMMachineMixinFP, ARMMachineMixinM, ARMMachineDef):
362
+ arch = Architecture.ARM_V7M
363
+ byteorder = Byteorder.LITTLE
364
+ language_id = "ARM:LE:32:v7"
365
+
366
+
367
+ class ARMv7AMachineDef(ARMMachineMixinVFPEL, ARMMachineMixinRA, ARMMachineDef):
368
+ arch = Architecture.ARM_V7A
369
+ byteorder = Byteorder.LITTLE
370
+ language_id = "ARM:LE:32:v7"
@@ -0,0 +1,109 @@
1
+ from ....platforms import Architecture, Byteorder
2
+ from .machdef import GhidraMachineDef
3
+
4
+
5
+ class i386MachineDef(GhidraMachineDef):
6
+ arch = Architecture.X86_32
7
+ byteorder = Byteorder.LITTLE
8
+ language_id = "x86:LE:32:default"
9
+
10
+ _registers = {
11
+ # *** General Purpose Registers ***
12
+ "eax": "eax",
13
+ "ax": "ax",
14
+ "al": "al",
15
+ "ah": "ah",
16
+ "ebx": "ebx",
17
+ "bx": "bx",
18
+ "bl": "bl",
19
+ "bh": "bh",
20
+ "ecx": "ecx",
21
+ "cx": "cx",
22
+ "cl": "cl",
23
+ "ch": "ch",
24
+ "edx": "edx",
25
+ "dx": "dx",
26
+ "dl": "dl",
27
+ "dh": "dh",
28
+ "esi": "esi",
29
+ "si": "si",
30
+ "sil": None,
31
+ "edi": "edi",
32
+ "di": "di",
33
+ "dil": None,
34
+ "ebp": "ebp",
35
+ "bp": "bp",
36
+ "bpl": None,
37
+ "esp": "esp",
38
+ "sp": "sp",
39
+ "spl": None,
40
+ # *** Instruction Pointer ***
41
+ "eip": "eip",
42
+ "ip": "ip",
43
+ # *** Segment Registers ***
44
+ "cs": "cs",
45
+ "ds": "ds",
46
+ "es": "es",
47
+ "fs": "fs",
48
+ "gs": "gs",
49
+ "ss": "ss",
50
+ # *** Flags Register ***
51
+ "eflags": "eflags",
52
+ "flags": "flags",
53
+ # *** Control Registers ***
54
+ "cr0": "cr0",
55
+ "cr1": None,
56
+ "cr2": "cr2",
57
+ "cr3": "cr3",
58
+ "cr4": "cr4",
59
+ "cr8": None,
60
+ # *** Debug Registers ***
61
+ "dr0": "dr0",
62
+ "dr1": "dr1",
63
+ "dr2": "dr2",
64
+ "dr3": "dr3",
65
+ "dr6": "dr6",
66
+ "dr7": "dr7",
67
+ # *** Descriptor Table Registers ***
68
+ "gdtr": "gdtr",
69
+ "idtr": "idtr",
70
+ "ldtr": "ldtr",
71
+ # *** Task Register ***
72
+ "tr": "tr",
73
+ # *** x87 Registers ***
74
+ # TODO: Ghidra seems to support x87, but I have no idea how its register file works
75
+ # I can't find most of the control registers,
76
+ # and there don't seem to be separate "fprN" registers; the stack references.
77
+ "fpr0": None,
78
+ "fpr1": None,
79
+ "fpr2": None,
80
+ "fpr3": None,
81
+ "fpr4": None,
82
+ "fpr5": None,
83
+ "fpr6": None,
84
+ "fpr7": None,
85
+ "fctrl": None,
86
+ "fstat": None,
87
+ "ftag": None,
88
+ "fip": None,
89
+ "fdp": None,
90
+ "fop": None,
91
+ # *** MMX Registers ***
92
+ "mm0": "mm0",
93
+ "mm1": "mm1",
94
+ "mm2": "mm2",
95
+ "mm3": "mm3",
96
+ "mm4": "mm4",
97
+ "mm5": "mm5",
98
+ "mm6": "mm6",
99
+ "mm7": "mm7",
100
+ # *** SSE Registers ***
101
+ "xmm0": "xmm0",
102
+ "xmm1": "xmm1",
103
+ "xmm2": "xmm2",
104
+ "xmm3": "xmm3",
105
+ "xmm4": "xmm4",
106
+ "xmm5": "xmm5",
107
+ "xmm6": "xmm6",
108
+ "xmm7": "xmm7",
109
+ }
@@ -0,0 +1,162 @@
1
+ from ....platforms import Architecture, Byteorder
2
+ from .machdef import GhidraMachineDef
3
+
4
+
5
+ class LoongArchMachineDef(GhidraMachineDef):
6
+ byteorder = Byteorder.LITTLE
7
+
8
+ _registers = {
9
+ "pc": "pc",
10
+ # Zero register
11
+ "r0": "zero",
12
+ "zero": "zero",
13
+ # Return address
14
+ "r1": "ra",
15
+ "ra": "ra",
16
+ # TLS pointer
17
+ "r2": "tp",
18
+ "tp": "tp",
19
+ # Stack pointer
20
+ "r3": "sp",
21
+ "sp": "sp",
22
+ # Arguments.
23
+ # a0 and a1 are also the return registers
24
+ "r4": "a0",
25
+ "a0": "a0",
26
+ "v0": "a0",
27
+ "r5": "a1",
28
+ "a1": "a1",
29
+ "v1": "a1",
30
+ "r6": "a2",
31
+ "a2": "a2",
32
+ "r7": "a3",
33
+ "a3": "a3",
34
+ "r8": "a4",
35
+ "a4": "a4",
36
+ "r9": "a5",
37
+ "a5": "a5",
38
+ "r10": "a6",
39
+ "a6": "a6",
40
+ "r11": "a7",
41
+ "a7": "a7",
42
+ # Temporary registers
43
+ "r12": "t0",
44
+ "t0": "t0",
45
+ "r13": "t1",
46
+ "t1": "t1",
47
+ "r14": "t2",
48
+ "t2": "t2",
49
+ "r15": "t3",
50
+ "t3": "t3",
51
+ "r16": "t4",
52
+ "t4": "t4",
53
+ "r17": "t5",
54
+ "t5": "t5",
55
+ "r18": "t6",
56
+ "t6": "t6",
57
+ "r19": "t7",
58
+ "t7": "t7",
59
+ "r20": "t8",
60
+ "t8": "t8",
61
+ # Per-CPU Base Address
62
+ "r21": "r21",
63
+ "u0": "r21",
64
+ # Frame Pointer
65
+ "r22": "fp",
66
+ "fp": "fp",
67
+ # Static registers
68
+ "r23": "s0",
69
+ "s0": "s0",
70
+ "r24": "s1",
71
+ "s1": "s1",
72
+ "r25": "s2",
73
+ "s2": "s2",
74
+ "r26": "s3",
75
+ "s3": "s3",
76
+ "r27": "s4",
77
+ "s4": "s4",
78
+ "r28": "s5",
79
+ "s5": "s5",
80
+ "r29": "s6",
81
+ "s6": "s6",
82
+ "r30": "s7",
83
+ "s7": "s7",
84
+ "r31": "s8",
85
+ "s8": "s8",
86
+ # Floating-point arguments.
87
+ # fa0 and fa1 are also return values
88
+ "f0": "fa0",
89
+ "fa0": "fa0",
90
+ "f1": "fa1",
91
+ "fa1": "fa1",
92
+ "f2": "fa2",
93
+ "fa2": "fa2",
94
+ "f3": "fa3",
95
+ "fa3": "fa3",
96
+ "f4": "fa4",
97
+ "fa4": "fa4",
98
+ "f5": "fa5",
99
+ "fa5": "fa5",
100
+ "f6": "fa6",
101
+ "fa6": "fa6",
102
+ "f7": "fa7",
103
+ "fa7": "fa7",
104
+ # Floating-point temporary registers
105
+ "f8": "ft0",
106
+ "ft0": "ft0",
107
+ "f9": "ft1",
108
+ "ft1": "ft1",
109
+ "f10": "ft2",
110
+ "ft2": "ft2",
111
+ "f11": "ft3",
112
+ "ft3": "ft3",
113
+ "f12": "ft4",
114
+ "ft4": "ft4",
115
+ "f13": "ft5",
116
+ "ft5": "ft5",
117
+ "f14": "ft6",
118
+ "ft6": "ft6",
119
+ "f15": "ft7",
120
+ "ft7": "ft7",
121
+ "f16": "ft8",
122
+ "ft8": "ft8",
123
+ "f17": "ft9",
124
+ "ft9": "ft9",
125
+ "f18": "ft10",
126
+ "ft10": "ft10",
127
+ "f19": "ft11",
128
+ "ft11": "ft11",
129
+ "f20": "ft12",
130
+ "ft12": "ft12",
131
+ "f21": "ft13",
132
+ "ft13": "ft13",
133
+ "f22": "ft14",
134
+ "ft14": "ft14",
135
+ "f23": "ft15",
136
+ "ft15": "ft15",
137
+ # Floating-point static registers
138
+ "f24": "fs0",
139
+ "fs0": "fs0",
140
+ "f25": "fs1",
141
+ "fs1": "fs1",
142
+ "f26": "fs2",
143
+ "fs2": "fs2",
144
+ "f27": "fs3",
145
+ "fs3": "fs3",
146
+ "f28": "fs4",
147
+ "fs4": "fs4",
148
+ "f29": "fs5",
149
+ "fs5": "fs5",
150
+ "f30": "fs6",
151
+ "fs6": "fs6",
152
+ "f31": "fs7",
153
+ "fs7": "fs7",
154
+ }
155
+
156
+
157
+ class LoongArch64MachineDef(LoongArchMachineDef):
158
+ arch = Architecture.LOONGARCH64
159
+ language_id = "Loongarch:LE:64:lp64d"
160
+
161
+
162
+ __all__ = ["LoongArch64MachineDef"]