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,208 @@
1
+ from ....platforms import Architecture, Byteorder
2
+ from .machdef import GhidraMachineDef
3
+
4
+
5
+ class RISCV64MachineDef(GhidraMachineDef):
6
+ arch = Architecture.RISCV64
7
+ byteorder = Byteorder.LITTLE
8
+ language_id = "RISCV:LE:64:default"
9
+
10
+ _registers = {
11
+ # *** General-Purpose Registers ***
12
+ # x0 is wired to 0, and aliased as "zero"
13
+ "x0": "zero",
14
+ "zero": "zero",
15
+ # x1 acts as the link register
16
+ # NOTE:ra is the official name; lr might be an angr invention.
17
+ "x1": "ra",
18
+ "ra": "ra",
19
+ # x2 acts as the stack pointer
20
+ "x2": "sp",
21
+ "sp": "sp",
22
+ # x3 acts as the global pointer
23
+ "x3": "gp",
24
+ "gp": "gp",
25
+ # x4 acts as the thread pointer
26
+ "x4": "tp",
27
+ "tp": "tp",
28
+ # x5 is a temporary register
29
+ "x5": "t0",
30
+ "t0": "t0",
31
+ # x6 is a temporary register
32
+ "x6": "t1",
33
+ "t1": "t1",
34
+ # x7 is a temporary register
35
+ "x7": "t2",
36
+ "t2": "t2",
37
+ # x8 is a callee-saved register
38
+ "x8": "s0",
39
+ "s0": "s0",
40
+ # x9 is a callee-saved register
41
+ "x9": "s1",
42
+ "s1": "s1",
43
+ # x10 is argument 0
44
+ "x10": "a0",
45
+ "a0": "a0",
46
+ # x11 is argument 1
47
+ "x11": "a1",
48
+ "a1": "a1",
49
+ # x12 is argument 2
50
+ "x12": "a2",
51
+ "a2": "a2",
52
+ # x13 is argument 3
53
+ "x13": "a3",
54
+ "a3": "a3",
55
+ # x14 is argument 4
56
+ "x14": "a4",
57
+ "a4": "a4",
58
+ # x15 is argument 5
59
+ "x15": "a5",
60
+ "a5": "a5",
61
+ # x16 is argument 6
62
+ "x16": "a6",
63
+ "a6": "a6",
64
+ # x17 is argument 7
65
+ "x17": "a7",
66
+ "a7": "a7",
67
+ # x18 is a callee-saved register
68
+ "x18": "s2",
69
+ "s2": "s2",
70
+ # x19 is a callee-saved register
71
+ "x19": "s3",
72
+ "s3": "s3",
73
+ # x20 is a callee-saved register
74
+ "x20": "s4",
75
+ "s4": "s4",
76
+ # x21 is a callee-saved register
77
+ "x21": "s5",
78
+ "s5": "s5",
79
+ # x22 is a callee-saved register
80
+ "x22": "s6",
81
+ "s6": "s6",
82
+ # x23 is a callee-saved register
83
+ "x23": "s7",
84
+ "s7": "s7",
85
+ # x24 is a callee-saved register
86
+ "x24": "s8",
87
+ "s8": "s8",
88
+ # x25 is a callee-saved register
89
+ "x25": "s9",
90
+ "s9": "s9",
91
+ # x26 is a callee-saved register
92
+ "x26": "s10",
93
+ "s10": "s10",
94
+ # x27 is a callee-saved register
95
+ "x27": "s11",
96
+ "s11": "s11",
97
+ # x28 is a temporary register
98
+ "x28": "t3",
99
+ "t3": "t3",
100
+ # x29 is a temporary register
101
+ "x29": "t4",
102
+ "t4": "t4",
103
+ # x30 is a temporary register
104
+ "x30": "t5",
105
+ "t5": "t5",
106
+ # x31 is a temporary register
107
+ "x31": "t6",
108
+ "t6": "t6",
109
+ # *** Program Counter ***
110
+ "pc": "pc",
111
+ # *** Floating-Point Registers ***
112
+ # f0 is a temporary register
113
+ "f0": "ft0",
114
+ "ft0": "ft0",
115
+ # f1 is a temporary register
116
+ "f1": "ft1",
117
+ "ft1": "ft1",
118
+ # f2 is a temporary register
119
+ "f2": "ft2",
120
+ "ft2": "ft2",
121
+ # f3 is a temporary register
122
+ "f3": "ft3",
123
+ "ft3": "ft3",
124
+ # f4 is a temporary register
125
+ "f4": "ft4",
126
+ "ft4": "ft4",
127
+ # f5 is a temporary register
128
+ "f5": "ft5",
129
+ "ft5": "ft5",
130
+ # f6 is a temporary register
131
+ "f6": "ft6",
132
+ "ft6": "ft6",
133
+ # f7 is a temporary register
134
+ "f7": "ft7",
135
+ "ft7": "ft7",
136
+ # f8 is a callee saved register
137
+ "f8": "fs0",
138
+ "fs0": "fs0",
139
+ # f9 is a callee saved register
140
+ "f9": "fs1",
141
+ "fs1": "fs1",
142
+ # f10 is argument 0
143
+ "f10": "fa0",
144
+ "fa0": "fa0",
145
+ # f11 is argument 1
146
+ "f11": "fa1",
147
+ "fa1": "fa1",
148
+ # f12 is argument 2
149
+ "f12": "fa2",
150
+ "fa2": "fa2",
151
+ # f13 is argument 3
152
+ "f13": "fa3",
153
+ "fa3": "fa3",
154
+ # f14 is argument 4
155
+ "f14": "fa4",
156
+ "fa4": "fa4",
157
+ # f15 is argument 5
158
+ "f15": "fa5",
159
+ "fa5": "fa5",
160
+ # f16 is argument 6
161
+ "f16": "fa6",
162
+ "fa6": "fa6",
163
+ # f7 is argument 7
164
+ "f17": "fa7",
165
+ "fa7": "fa7",
166
+ # f18 is a callee-saved register
167
+ "f18": "fs2",
168
+ "fs2": "fs2",
169
+ # f19 is a callee-saved register
170
+ "f19": "fs3",
171
+ "fs3": "fs3",
172
+ # f20 is a callee-saved register
173
+ "f20": "fs4",
174
+ "fs4": "fs4",
175
+ # f21 is a callee-saved register
176
+ "f21": "fs5",
177
+ "fs5": "fs5",
178
+ # f22 is a callee-saved register
179
+ "f22": "fs6",
180
+ "fs6": "fs6",
181
+ # f23 is a callee-saved register
182
+ "f23": "fs7",
183
+ "fs7": "fs7",
184
+ # f24 is a callee-saved register
185
+ "f24": "fs8",
186
+ "fs8": "fs8",
187
+ # f25 is a callee-saved register
188
+ "f25": "fs9",
189
+ "fs9": "fs9",
190
+ # f26 is a callee-saved register
191
+ "f26": "fs10",
192
+ "fs10": "fs10",
193
+ # f27 is a callee-saved register
194
+ "f27": "fs11",
195
+ "fs11": "fs11",
196
+ # f28 is a temporary register
197
+ "f28": "ft8",
198
+ "ft8": "ft8",
199
+ # f29 is a temporary register
200
+ "f29": "ft9",
201
+ "ft9": "ft9",
202
+ # f30 is a temporary register
203
+ "f30": "ft10",
204
+ "ft10": "ft10",
205
+ # f31 is a temporary register
206
+ "f31": "ft11",
207
+ "ft11": "ft11",
208
+ }
@@ -0,0 +1,21 @@
1
+ import typing
2
+
3
+ from ....platforms import Architecture, Byteorder
4
+ from .machdef import GhidraMachineDef
5
+
6
+
7
+ class XTensaMachineDef(GhidraMachineDef):
8
+ arch = Architecture.XTENSA
9
+ _registers: typing.Dict[str, typing.Optional[str]] = {}
10
+ _registers |= {f"a{i}": f"a{i}" for i in range(0, 16)}
11
+ _registers |= {"pc": "pc", "sar": "sar", "sp": "a1"}
12
+
13
+
14
+ class XTensaELMachineDef(XTensaMachineDef):
15
+ byteorder = Byteorder.LITTLE
16
+ language_id = "Xtensa:LE:32:default"
17
+
18
+
19
+ class XTensaBEMachineDef(XTensaMachineDef):
20
+ byteorder = Byteorder.BIG
21
+ language_id = "Xtensa:BE:32:default"
@@ -0,0 +1,28 @@
1
+ from ..emulator import (
2
+ Emulator,
3
+ FunctionHookable,
4
+ InstructionHookable,
5
+ MemoryReadHookable,
6
+ MemoryWriteHookable,
7
+ )
8
+
9
+
10
+ class AbstractGhidraEmulator(
11
+ Emulator,
12
+ InstructionHookable,
13
+ FunctionHookable,
14
+ MemoryReadHookable,
15
+ MemoryWriteHookable,
16
+ ):
17
+ """Abstract type for GhidraEmulator
18
+
19
+ Normal users of SmallWorld shouldn't need to interact with this class.
20
+
21
+ This is for the convenience of the factory function in `__init__.py`.
22
+ The factory needs to annotate its return type with all the
23
+ interfaces supported by GhidraEmulator,
24
+ but it can't use GhidraEmulator in its signature
25
+ because it's not imported until after the first call to the factory.
26
+ """
27
+
28
+ pass
@@ -142,12 +142,19 @@ class QMemoryReadHookable(MemoryReadHookable):
142
142
  # self.memory_read_hooks.pop(address, None)
143
143
 
144
144
  def is_memory_read_hooked(
145
- self, address: int
145
+ self, address: int, size: int
146
146
  ) -> typing.Optional[
147
147
  typing.Callable[[Emulator, int, int, bytes], typing.Optional[bytes]]
148
148
  ]:
149
+ end = address + size
150
+ access_rng = range(address, end)
149
151
  for rng in self.memory_read_hooks:
150
- if address in rng:
152
+ if (
153
+ address in rng
154
+ or end - 1 in rng
155
+ or rng.start in access_rng
156
+ or rng.stop - 1 in access_rng
157
+ ):
151
158
  return self.memory_read_hooks[rng]
152
159
  return None
153
160
 
@@ -203,10 +210,17 @@ class QMemoryWriteHookable(MemoryWriteHookable):
203
210
  # )
204
211
  # self.memory_write_hooks.pop(address, None)
205
212
  def is_memory_write_hooked(
206
- self, address: int
213
+ self, address: int, size: int
207
214
  ) -> typing.Optional[typing.Callable[[Emulator, int, int, bytes], None]]:
215
+ end = address + size
216
+ access_rng = range(address, end)
208
217
  for rng in self.memory_write_hooks:
209
- if address in rng:
218
+ if (
219
+ address in rng
220
+ or end - 1 in rng
221
+ or rng.start in access_rng
222
+ or rng.stop - 1 in access_rng
223
+ ):
210
224
  return self.memory_write_hooks[rng]
211
225
  return None
212
226
 
@@ -7,7 +7,7 @@ from .arm import ( # ARMv6MMachineDef,; ARMv6MThumbMachineDef,
7
7
  from .i386 import i386MachineDef
8
8
  from .machdef import PandaMachineDef
9
9
  from .mips import MIPSBEMachineDef, MIPSELMachineDef
10
- from .mips64 import MIPS64BEMachineDef # , MIPS64ELMachineDef
10
+ from .mips64 import MIPS64BEMachineDef, MIPS64ELMachineDef
11
11
  from .ppc import PowerPC32MachineDef # , PowerPC64MachineDef
12
12
 
13
13
  __all__ = [
@@ -22,7 +22,7 @@ __all__ = [
22
22
  "MIPSBEMachineDef",
23
23
  "MIPSELMachineDef",
24
24
  "MIPS64BEMachineDef",
25
- # "MIPS64ELMachineDef",
25
+ "MIPS64ELMachineDef",
26
26
  "PowerPC32MachineDef",
27
27
  # "PowerPC64MachineDef",
28
28
  ]
@@ -1,5 +1,3 @@
1
- import capstone
2
-
3
1
  from ....platforms import Architecture, Byteorder
4
2
  from .machdef import PandaMachineDef
5
3
 
@@ -8,13 +6,8 @@ class AArch64MachineDef(PandaMachineDef):
8
6
  arch = Architecture.AARCH64
9
7
  byteorder = Byteorder.LITTLE
10
8
 
11
- cs_arch = capstone.CS_ARCH_ARM64
12
- cs_mode = capstone.CS_MODE_ARM | capstone.CS_MODE_LITTLE_ENDIAN
13
-
14
9
  panda_arch = "aarch64"
15
10
 
16
- # I'm going to define all the ones we are making possible as of now
17
- # I need to submit a PR to change to X86 32 bit and to includ eflags
18
11
  def __init__(self):
19
12
  self._registers = {
20
13
  "x0": "x0",
@@ -35,7 +28,6 @@ class AArch64MachineDef(PandaMachineDef):
35
28
  "w7": "x7",
36
29
  "x8": "xr",
37
30
  "w8": "xr",
38
- "xr": "xr",
39
31
  "x9": "x9",
40
32
  "w9": "x9",
41
33
  "x10": "x10",
@@ -52,13 +44,10 @@ class AArch64MachineDef(PandaMachineDef):
52
44
  "w15": "x15",
53
45
  "x16": "ip0",
54
46
  "w16": "ip0",
55
- "ip0": "ip0",
56
47
  "x17": "ip1",
57
48
  "w17": "ip1",
58
- "ip1": "ip1",
59
49
  "x18": "pr",
60
50
  "w18": "pr",
61
- "pr": "pr",
62
51
  "x19": "x19",
63
52
  "w19": "x19",
64
53
  "x20": "x20",
@@ -88,6 +77,192 @@ class AArch64MachineDef(PandaMachineDef):
88
77
  "pc": "pc",
89
78
  "sp": "sp",
90
79
  "wsp": "sp",
80
+ "wzr": None,
81
+ "xzr": None,
82
+ "fpcr": None,
83
+ "fpsr": None,
84
+ "sp_el0": None,
85
+ "sp_el1": None,
86
+ "sp_el2": None,
87
+ "sp_el3": None,
88
+ "elr_el1": None,
89
+ "elr_el2": None,
90
+ "elr_el3": None,
91
+ "far_el1": None,
92
+ "far_el2": None,
93
+ "far_el3": None,
94
+ "vbar_el1": None,
95
+ "vbar_el0": None,
96
+ "vbar_el2": None,
97
+ "vbar_el3": None,
98
+ "cpacr_el1": None,
99
+ "mair_el1": None,
100
+ "par_el1": None,
101
+ "ttbr0_el1": None,
102
+ "ttbr1_el1": None,
103
+ "tpidr_el0": None,
104
+ "tpidr_el1": None,
105
+ "tpidrro_el0": None,
106
+ "q0": None,
107
+ "d0": None,
108
+ "s0": None,
109
+ "h0": None,
110
+ "b0": None,
111
+ "q1": None,
112
+ "d1": None,
113
+ "s1": None,
114
+ "h1": None,
115
+ "b1": None,
116
+ "q2": None,
117
+ "d2": None,
118
+ "s2": None,
119
+ "h2": None,
120
+ "b2": None,
121
+ "q3": None,
122
+ "d3": None,
123
+ "s3": None,
124
+ "h3": None,
125
+ "b3": None,
126
+ "q4": None,
127
+ "d4": None,
128
+ "s4": None,
129
+ "h4": None,
130
+ "b4": None,
131
+ "q5": None,
132
+ "d5": None,
133
+ "s5": None,
134
+ "h5": None,
135
+ "b5": None,
136
+ "q6": None,
137
+ "d6": None,
138
+ "s6": None,
139
+ "h6": None,
140
+ "b6": None,
141
+ "q7": None,
142
+ "d7": None,
143
+ "s7": None,
144
+ "h7": None,
145
+ "b7": None,
146
+ "q8": None,
147
+ "d8": None,
148
+ "s8": None,
149
+ "h8": None,
150
+ "b8": None,
151
+ "q9": None,
152
+ "d9": None,
153
+ "s9": None,
154
+ "h9": None,
155
+ "b9": None,
156
+ "q10": None,
157
+ "d10": None,
158
+ "s10": None,
159
+ "h10": None,
160
+ "b10": None,
161
+ "q11": None,
162
+ "d11": None,
163
+ "s11": None,
164
+ "h11": None,
165
+ "b11": None,
166
+ "q12": None,
167
+ "d12": None,
168
+ "s12": None,
169
+ "h12": None,
170
+ "b12": None,
171
+ "q13": None,
172
+ "d13": None,
173
+ "s13": None,
174
+ "h13": None,
175
+ "b13": None,
176
+ "q14": None,
177
+ "d14": None,
178
+ "s14": None,
179
+ "h14": None,
180
+ "b14": None,
181
+ "q15": None,
182
+ "d15": None,
183
+ "s15": None,
184
+ "h15": None,
185
+ "b15": None,
186
+ "q16": None,
187
+ "d16": None,
188
+ "s16": None,
189
+ "h16": None,
190
+ "b16": None,
191
+ "q17": None,
192
+ "d17": None,
193
+ "s17": None,
194
+ "h17": None,
195
+ "b17": None,
196
+ "q18": None,
197
+ "d18": None,
198
+ "s18": None,
199
+ "h18": None,
200
+ "b18": None,
201
+ "q19": None,
202
+ "d19": None,
203
+ "s19": None,
204
+ "h19": None,
205
+ "b19": None,
206
+ "q20": None,
207
+ "d20": None,
208
+ "s20": None,
209
+ "h20": None,
210
+ "b20": None,
211
+ "q21": None,
212
+ "d21": None,
213
+ "s21": None,
214
+ "h21": None,
215
+ "b21": None,
216
+ "q22": None,
217
+ "d22": None,
218
+ "s22": None,
219
+ "h22": None,
220
+ "b22": None,
221
+ "q23": None,
222
+ "d23": None,
223
+ "s23": None,
224
+ "h23": None,
225
+ "b23": None,
226
+ "q24": None,
227
+ "d24": None,
228
+ "s24": None,
229
+ "h24": None,
230
+ "b24": None,
231
+ "q25": None,
232
+ "d25": None,
233
+ "s25": None,
234
+ "h25": None,
235
+ "b25": None,
236
+ "q26": None,
237
+ "d26": None,
238
+ "s26": None,
239
+ "h26": None,
240
+ "b26": None,
241
+ "q27": None,
242
+ "d27": None,
243
+ "s27": None,
244
+ "h27": None,
245
+ "b27": None,
246
+ "q28": None,
247
+ "d28": None,
248
+ "s28": None,
249
+ "h28": None,
250
+ "b28": None,
251
+ "q29": None,
252
+ "d29": None,
253
+ "s29": None,
254
+ "h29": None,
255
+ "b29": None,
256
+ "q30": None,
257
+ "d30": None,
258
+ "s30": None,
259
+ "h30": None,
260
+ "b30": None,
261
+ "q31": None,
262
+ "d31": None,
263
+ "s31": None,
264
+ "h31": None,
265
+ "b31": None,
91
266
  }
92
267
 
93
268
  self._registers = {i: j for i, j in self._registers.items()}
@@ -1,5 +1,3 @@
1
- import capstone
2
-
3
1
  from ....platforms import Architecture, Byteorder
4
2
  from .machdef import PandaMachineDef
5
3
 
@@ -10,11 +8,8 @@ class AMD64MachineDef(PandaMachineDef):
10
8
 
11
9
  panda_arch = "x86_64"
12
10
 
13
- cs_arch = capstone.CS_ARCH_X86
14
- cs_mode = capstone.CS_MODE_64
15
-
16
11
  # I'm going to define all the ones we are making possible as of now
17
- # I need to submit a PR to change to X86 32 bit and to includ eflags
12
+ # I need to submit a PR to change to X86 32 bit and to include eflags
18
13
  _registers_64 = {
19
14
  "rax",
20
15
  "rbx",
@@ -34,12 +29,83 @@ class AMD64MachineDef(PandaMachineDef):
34
29
  "r14",
35
30
  "r15",
36
31
  }
37
- _registers_general = {"eax", "ebx", "ecx", "edx", "esi", "edi", "esp", "ebp", "eip"}
38
- _registers_short = {"ax", "bx", "cx", "dx", "si", "di", "sp", "bp"}
39
- _registers_byte = {"al", "bl", "cl", "dl", "ah", "bh", "ch", "dh"}
32
+ _registers_general = {
33
+ "eax",
34
+ "ebx",
35
+ "ecx",
36
+ "edx",
37
+ "esi",
38
+ "edi",
39
+ "esp",
40
+ "ebp",
41
+ "eip",
42
+ "r8d",
43
+ "r9d",
44
+ "r10d",
45
+ "r11d",
46
+ "r12d",
47
+ "r13d",
48
+ "r14d",
49
+ "r15d",
50
+ }
51
+ _registers_short = {
52
+ "ax",
53
+ "bx",
54
+ "cx",
55
+ "dx",
56
+ "si",
57
+ "di",
58
+ "sp",
59
+ "bp",
60
+ "r8w",
61
+ "r9w",
62
+ "r10w",
63
+ "r11w",
64
+ "r12w",
65
+ "r13w",
66
+ "r14w",
67
+ "r15w",
68
+ }
69
+ _registers_byte = {
70
+ "al",
71
+ "bl",
72
+ "cl",
73
+ "dl",
74
+ "r8b",
75
+ "r9b",
76
+ "r10b",
77
+ "r11b",
78
+ "r12b",
79
+ "r13b",
80
+ "r14b",
81
+ "r15b",
82
+ "ah",
83
+ "bh",
84
+ "ch",
85
+ "dh",
86
+ }
87
+ _registers_flags = {"rflags", "eflags", "flags"}
40
88
  _registers_seg = {"es", "cs", "ss", "ds", "fs", "gs"}
41
89
  _registers_control = {"cr0", "cr1", "cr2", "cr3", "cr4"}
90
+ _registers_debug = {f"dr{i}" for i in range(0, 16)} - {"dr4", "dr5"}
42
91
  _registers_mmr = {"gdtr": "gdt", "idtr": "idt", "tr": "tr", "ldtr": "ldt"}
92
+ _registers_x87 = {
93
+ "fpr0",
94
+ "fpr1",
95
+ "fpr2",
96
+ "fpr3",
97
+ "fpr4",
98
+ "fpr5",
99
+ "fpr6",
100
+ "fpr7",
101
+ "fctrl",
102
+ "fstat",
103
+ "ftag",
104
+ "fip",
105
+ "fdp",
106
+ "fop",
107
+ }
108
+ _registers_mmx = {"mm0", "mm1", "mm2", "mm3", "mm4", "mm5", "mm6", "mm7"}
43
109
  _registers_xmm = {
44
110
  "xmm0",
45
111
  "xmm1",
@@ -58,14 +124,40 @@ class AMD64MachineDef(PandaMachineDef):
58
124
  "xmm14",
59
125
  "xmm15",
60
126
  }
61
- _register_pc = {"pc": "rip"}
127
+ _registers_ymm = {
128
+ "ymm0",
129
+ "ymm1",
130
+ "ymm2",
131
+ "ymm3",
132
+ "ymm4",
133
+ "ymm5",
134
+ "ymm6",
135
+ "ymm7",
136
+ "ymm8",
137
+ "ymm9",
138
+ "ymm10",
139
+ "ymm11",
140
+ "ymm12",
141
+ "ymm13",
142
+ "ymm14",
143
+ "ymm15",
144
+ }
145
+ _registers_pc = {"pc": "rip", "eip": "eip", "ip": None}
146
+ _registers_absent = {"dil", "sil", "spl", "bpl", "cr8"}
62
147
 
63
148
  _registers = {}
64
149
  _registers = _registers | {i: i for i in _registers_64}
65
150
  _registers = _registers | {i: i for i in _registers_general}
151
+ _registers = _registers | {i: i for i in _registers_short}
66
152
  _registers = _registers | {i: i for i in _registers_byte}
153
+ _registers = _registers | {i: None for i in _registers_flags}
67
154
  _registers = _registers | {i: i for i in _registers_seg}
68
155
  _registers = _registers | {i: i for i in _registers_control}
156
+ _registers = _registers | {i: None for i in _registers_debug}
69
157
  _registers = _registers | {i: j for i, j in _registers_mmr.items()}
158
+ _registers = _registers | {i: None for i in _registers_x87}
159
+ _registers = _registers | {i: None for i in _registers_mmx}
70
160
  _registers = _registers | {i: i for i in _registers_xmm}
71
- _registers = _registers | {i: j for i, j in _register_pc.items()}
161
+ _registers = _registers | {i: None for i in _registers_ymm}
162
+ _registers = _registers | {i: j for i, j in _registers_pc.items()}
163
+ _registers = _registers | {i: None for i in _registers_absent}