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,139 @@
1
+ from ....c99 import (
2
+ Memchr,
3
+ Memcmp,
4
+ Memcpy,
5
+ Memmove,
6
+ Memset,
7
+ Strcat,
8
+ Strchr,
9
+ Strcmp,
10
+ Strcoll,
11
+ Strcpy,
12
+ Strcspn,
13
+ Strerror,
14
+ Strlen,
15
+ Strncat,
16
+ Strncmp,
17
+ Strncpy,
18
+ Strpbrk,
19
+ Strrchr,
20
+ Strspn,
21
+ Strstr,
22
+ Strtok,
23
+ Strxfrm,
24
+ )
25
+ from ..systemv import MIPSELSysVModel
26
+
27
+
28
+ class MIPSELSysVMemcpy(Memcpy, MIPSELSysVModel):
29
+ pass
30
+
31
+
32
+ class MIPSELSysVMemmove(Memmove, MIPSELSysVModel):
33
+ pass
34
+
35
+
36
+ class MIPSELSysVStrcpy(Strcpy, MIPSELSysVModel):
37
+ pass
38
+
39
+
40
+ class MIPSELSysVStrncpy(Strncpy, MIPSELSysVModel):
41
+ pass
42
+
43
+
44
+ class MIPSELSysVStrcat(Strcat, MIPSELSysVModel):
45
+ pass
46
+
47
+
48
+ class MIPSELSysVStrncat(Strncat, MIPSELSysVModel):
49
+ pass
50
+
51
+
52
+ class MIPSELSysVMemcmp(Memcmp, MIPSELSysVModel):
53
+ pass
54
+
55
+
56
+ class MIPSELSysVStrncmp(Strncmp, MIPSELSysVModel):
57
+ pass
58
+
59
+
60
+ class MIPSELSysVStrcmp(Strcmp, MIPSELSysVModel):
61
+ pass
62
+
63
+
64
+ class MIPSELSysVStrcoll(Strcoll, MIPSELSysVModel):
65
+ pass
66
+
67
+
68
+ class MIPSELSysVStrxfrm(Strxfrm, MIPSELSysVModel):
69
+ pass
70
+
71
+
72
+ class MIPSELSysVMemchr(Memchr, MIPSELSysVModel):
73
+ pass
74
+
75
+
76
+ class MIPSELSysVStrchr(Strchr, MIPSELSysVModel):
77
+ pass
78
+
79
+
80
+ class MIPSELSysVStrcspn(Strcspn, MIPSELSysVModel):
81
+ pass
82
+
83
+
84
+ class MIPSELSysVStrpbrk(Strpbrk, MIPSELSysVModel):
85
+ pass
86
+
87
+
88
+ class MIPSELSysVStrrchr(Strrchr, MIPSELSysVModel):
89
+ pass
90
+
91
+
92
+ class MIPSELSysVStrspn(Strspn, MIPSELSysVModel):
93
+ pass
94
+
95
+
96
+ class MIPSELSysVStrstr(Strstr, MIPSELSysVModel):
97
+ pass
98
+
99
+
100
+ class MIPSELSysVStrtok(Strtok, MIPSELSysVModel):
101
+ pass
102
+
103
+
104
+ class MIPSELSysVMemset(Memset, MIPSELSysVModel):
105
+ pass
106
+
107
+
108
+ class MIPSELSysVStrerror(Strerror, MIPSELSysVModel):
109
+ pass
110
+
111
+
112
+ class MIPSELSysVStrlen(Strlen, MIPSELSysVModel):
113
+ pass
114
+
115
+
116
+ __all__ = [
117
+ "MIPSELSysVMemcpy",
118
+ "MIPSELSysVMemmove",
119
+ "MIPSELSysVStrcpy",
120
+ "MIPSELSysVStrncpy",
121
+ "MIPSELSysVStrcat",
122
+ "MIPSELSysVStrncat",
123
+ "MIPSELSysVMemcmp",
124
+ "MIPSELSysVStrncmp",
125
+ "MIPSELSysVStrcmp",
126
+ "MIPSELSysVStrcoll",
127
+ "MIPSELSysVStrxfrm",
128
+ "MIPSELSysVMemchr",
129
+ "MIPSELSysVStrchr",
130
+ "MIPSELSysVStrcspn",
131
+ "MIPSELSysVStrpbrk",
132
+ "MIPSELSysVStrrchr",
133
+ "MIPSELSysVStrspn",
134
+ "MIPSELSysVStrstr",
135
+ "MIPSELSysVStrtok",
136
+ "MIPSELSysVMemset",
137
+ "MIPSELSysVStrerror",
138
+ "MIPSELSysVStrlen",
139
+ ]
@@ -0,0 +1,61 @@
1
+ from ....c99 import (
2
+ Asctime,
3
+ Clock,
4
+ Ctime,
5
+ Difftime,
6
+ Gmtime,
7
+ Localtime,
8
+ Mktime,
9
+ Strftime,
10
+ Time,
11
+ )
12
+ from ..systemv import MIPSELSysVModel
13
+
14
+
15
+ class MIPSELSysVTime(Time, MIPSELSysVModel):
16
+ pass
17
+
18
+
19
+ class MIPSELSysVLocaltime(Localtime, MIPSELSysVModel):
20
+ pass
21
+
22
+
23
+ class MIPSELSysVGmtime(Gmtime, MIPSELSysVModel):
24
+ pass
25
+
26
+
27
+ class MIPSELSysVCtime(Ctime, MIPSELSysVModel):
28
+ pass
29
+
30
+
31
+ class MIPSELSysVAsctime(Asctime, MIPSELSysVModel):
32
+ pass
33
+
34
+
35
+ class MIPSELSysVStrftime(Strftime, MIPSELSysVModel):
36
+ pass
37
+
38
+
39
+ class MIPSELSysVDifftime(Difftime, MIPSELSysVModel):
40
+ pass
41
+
42
+
43
+ class MIPSELSysVMktime(Mktime, MIPSELSysVModel):
44
+ pass
45
+
46
+
47
+ class MIPSELSysVClock(Clock, MIPSELSysVModel):
48
+ pass
49
+
50
+
51
+ __all__ = [
52
+ "MIPSELSysVTime",
53
+ "MIPSELSysVLocaltime",
54
+ "MIPSELSysVGmtime",
55
+ "MIPSELSysVCtime",
56
+ "MIPSELSysVAsctime",
57
+ "MIPSELSysVStrftime",
58
+ "MIPSELSysVDifftime",
59
+ "MIPSELSysVMktime",
60
+ "MIPSELSysVClock",
61
+ ]
@@ -0,0 +1,6 @@
1
+ from .libgen import * # noqa: F401, F403
2
+ from .libgen import __all__ as __libgen__
3
+ from .signal import * # noqa: F401, F403
4
+ from .signal import __all__ as __signal__
5
+
6
+ __all__ = __libgen__ + __signal__
@@ -0,0 +1,16 @@
1
+ from ....posix.libgen import Basename, Dirname
2
+ from ..systemv import MIPSELSysVModel
3
+
4
+
5
+ class MIPSELSysVBasename(Basename, MIPSELSysVModel):
6
+ pass
7
+
8
+
9
+ class MIPSELSysVDirname(Dirname, MIPSELSysVModel):
10
+ pass
11
+
12
+
13
+ __all__ = [
14
+ "MIPSELSysVBasename",
15
+ "MIPSELSysVDirname",
16
+ ]
@@ -0,0 +1,157 @@
1
+ from ....posix.signal import (
2
+ BsdSignal,
3
+ Kill,
4
+ Killpg,
5
+ PthreadKill,
6
+ PthreadSigmask,
7
+ Sigaction,
8
+ Sigaddset,
9
+ Sigaltstack,
10
+ Sigdelset,
11
+ Sigemptyset,
12
+ Sigfillset,
13
+ Sighold,
14
+ Sigignore,
15
+ Siginterrupt,
16
+ Sigismember,
17
+ Sigpause,
18
+ Sigpending,
19
+ Sigprocmask,
20
+ Sigqueue,
21
+ Sigrelse,
22
+ Sigset,
23
+ Sigsuspend,
24
+ Sigtimedwait,
25
+ Sigwait,
26
+ Sigwaitinfo,
27
+ )
28
+ from ..systemv import MIPSELSysVModel
29
+
30
+
31
+ class MIPSELSysVBsdSignal(BsdSignal, MIPSELSysVModel):
32
+ pass
33
+
34
+
35
+ class MIPSELSysVKill(Kill, MIPSELSysVModel):
36
+ pass
37
+
38
+
39
+ class MIPSELSysVKillpg(Killpg, MIPSELSysVModel):
40
+ pass
41
+
42
+
43
+ class MIPSELSysVPthreadKill(PthreadKill, MIPSELSysVModel):
44
+ pass
45
+
46
+
47
+ class MIPSELSysVPthreadSigmask(PthreadSigmask, MIPSELSysVModel):
48
+ pass
49
+
50
+
51
+ class MIPSELSysVSigaction(Sigaction, MIPSELSysVModel):
52
+ pass
53
+
54
+
55
+ class MIPSELSysVSigaddset(Sigaddset, MIPSELSysVModel):
56
+ pass
57
+
58
+
59
+ class MIPSELSysVSigaltstack(Sigaltstack, MIPSELSysVModel):
60
+ pass
61
+
62
+
63
+ class MIPSELSysVSigdelset(Sigdelset, MIPSELSysVModel):
64
+ pass
65
+
66
+
67
+ class MIPSELSysVSigemptyset(Sigemptyset, MIPSELSysVModel):
68
+ pass
69
+
70
+
71
+ class MIPSELSysVSigfillset(Sigfillset, MIPSELSysVModel):
72
+ pass
73
+
74
+
75
+ class MIPSELSysVSighold(Sighold, MIPSELSysVModel):
76
+ pass
77
+
78
+
79
+ class MIPSELSysVSigignore(Sigignore, MIPSELSysVModel):
80
+ pass
81
+
82
+
83
+ class MIPSELSysVSiginterrupt(Siginterrupt, MIPSELSysVModel):
84
+ pass
85
+
86
+
87
+ class MIPSELSysVSigismember(Sigismember, MIPSELSysVModel):
88
+ pass
89
+
90
+
91
+ class MIPSELSysVSigpause(Sigpause, MIPSELSysVModel):
92
+ pass
93
+
94
+
95
+ class MIPSELSysVSigpending(Sigpending, MIPSELSysVModel):
96
+ pass
97
+
98
+
99
+ class MIPSELSysVSigprocmask(Sigprocmask, MIPSELSysVModel):
100
+ pass
101
+
102
+
103
+ class MIPSELSysVSigqueue(Sigqueue, MIPSELSysVModel):
104
+ pass
105
+
106
+
107
+ class MIPSELSysVSigrelse(Sigrelse, MIPSELSysVModel):
108
+ pass
109
+
110
+
111
+ class MIPSELSysVSigset(Sigset, MIPSELSysVModel):
112
+ pass
113
+
114
+
115
+ class MIPSELSysVSigsuspend(Sigsuspend, MIPSELSysVModel):
116
+ pass
117
+
118
+
119
+ class MIPSELSysVSigtimedwait(Sigtimedwait, MIPSELSysVModel):
120
+ pass
121
+
122
+
123
+ class MIPSELSysVSigwait(Sigwait, MIPSELSysVModel):
124
+ pass
125
+
126
+
127
+ class MIPSELSysVSigwaitinfo(Sigwaitinfo, MIPSELSysVModel):
128
+ pass
129
+
130
+
131
+ __all__ = [
132
+ "MIPSELSysVBsdSignal",
133
+ "MIPSELSysVKill",
134
+ "MIPSELSysVKillpg",
135
+ "MIPSELSysVPthreadKill",
136
+ "MIPSELSysVPthreadSigmask",
137
+ "MIPSELSysVSigaction",
138
+ "MIPSELSysVSigaddset",
139
+ "MIPSELSysVSigaltstack",
140
+ "MIPSELSysVSigdelset",
141
+ "MIPSELSysVSigemptyset",
142
+ "MIPSELSysVSigfillset",
143
+ "MIPSELSysVSighold",
144
+ "MIPSELSysVSigignore",
145
+ "MIPSELSysVSiginterrupt",
146
+ "MIPSELSysVSigismember",
147
+ "MIPSELSysVSigpause",
148
+ "MIPSELSysVSigpending",
149
+ "MIPSELSysVSigprocmask",
150
+ "MIPSELSysVSigqueue",
151
+ "MIPSELSysVSigrelse",
152
+ "MIPSELSysVSigset",
153
+ "MIPSELSysVSigsuspend",
154
+ "MIPSELSysVSigtimedwait",
155
+ "MIPSELSysVSigwait",
156
+ "MIPSELSysVSigwaitinfo",
157
+ ]
@@ -0,0 +1,78 @@
1
+ import struct
2
+
3
+ from ..... import emulators, platforms
4
+ from ...cstd import ArgumentType, CStdModel
5
+
6
+
7
+ class MIPSELSysVModel(CStdModel):
8
+ """Base class for C models using the MIPS o32 ABI"""
9
+
10
+ platform = platforms.Platform(
11
+ platforms.Architecture.MIPS32, platforms.Byteorder.LITTLE
12
+ )
13
+ abi = platforms.ABI.SYSTEMV
14
+
15
+ _int_sign_mask = 0x80000000
16
+ _int_inv_mask = 0xFFFFFFFF
17
+ _long_sign_mask = 0x80000000
18
+ _long_inv_mask = 0xFFFFFFFF
19
+ _long_long_sign_mask = 0x8000000000000000
20
+ _long_long_inv_mask = 0xFFFFFFFFFFFFFFFF
21
+
22
+ _four_byte_types = {
23
+ ArgumentType.INT,
24
+ ArgumentType.UINT,
25
+ ArgumentType.LONG,
26
+ ArgumentType.ULONG,
27
+ ArgumentType.SIZE_T,
28
+ ArgumentType.SSIZE_T,
29
+ ArgumentType.POINTER,
30
+ }
31
+
32
+ _eight_byte_types = {
33
+ ArgumentType.LONGLONG,
34
+ ArgumentType.ULONGLONG,
35
+ }
36
+
37
+ _four_byte_arg_regs = ["a0", "a1", "a2", "a3"]
38
+ _eight_byte_arg_regs = ["a0", "a1", "a2", "a3"]
39
+
40
+ _soft_float = True
41
+ _variadic_soft_float = True
42
+ _floats_are_doubles = False
43
+ _float_arg_regs = []
44
+ _double_arg_regs = []
45
+
46
+ _init_stack_offset = 16
47
+ _align_stack = True
48
+ _eight_byte_reg_size = 2
49
+ _double_reg_size = 2
50
+ _four_byte_stack_size = 4
51
+ _eight_byte_stack_size = 8
52
+ _float_stack_size = 4
53
+ _double_stack_size = 8
54
+
55
+ def _return_4_byte(self, emulator: emulators.Emulator, val: int) -> None:
56
+ emulator.write_register("v0", val)
57
+
58
+ def _return_8_byte(self, emulator: emulators.Emulator, val: int) -> None:
59
+ lo = val & self._int_inv_mask
60
+ hi = (val >> 32) & self._int_inv_mask
61
+
62
+ emulator.write_register("v0", lo)
63
+ emulator.write_register("v1", hi)
64
+
65
+ def _return_float(self, emulator: emulators.Emulator, val: float) -> None:
66
+ data = struct.pack("<f", val)
67
+ intval = int.from_bytes(data, "little")
68
+ emulator.write_register("f0", intval)
69
+
70
+ def _return_double(self, emulator: emulators.Emulator, val: float) -> None:
71
+ data = struct.pack("<d", val)
72
+ intval = int.from_bytes(data, "little")
73
+
74
+ lo = intval & self._int_inv_mask
75
+ hi = (intval >> 32) & self._int_inv_mask
76
+
77
+ emulator.write_register("f0", lo)
78
+ emulator.write_register("f1", hi)
@@ -40,7 +40,6 @@ class Hook(state.Stateful):
40
40
 
41
41
 
42
42
  class Breakpoint(Hook):
43
-
44
43
  """An interactive breakpoint.
45
44
 
46
45
  Stops execution at the specified address and opens an interactive
@@ -85,13 +84,24 @@ class Model(Hook):
85
84
  function, e.g., libc `fread`. It is the responsibility of the
86
85
  model to read arguments and generate reasonable return values.
87
86
 
87
+ Some models require static scratch space to operate.
88
+ The quantity is stored in the 'static_space_required' attribute.
89
+ If true, the harness must set the 'static_buffer_address' property
90
+ of this model object. The model will take care of mapping
91
+ a buffer of the appropriate size at that address.
92
+
93
+ A harness doesn't need to include a `Memory` object
94
+ for a static buffer. A harness can include such an object
95
+ if it wants to initialize that memory with a specific value, or if it
96
+ wants to inspect the contents of that buffer via `Machine.extract()`
97
+
88
98
  Arguments:
89
99
  address: The address to model.
90
-
91
100
  """
92
101
 
93
102
  def __init__(self, address: int):
94
103
  super().__init__(address=address, function=self.model)
104
+ self.static_buffer_address: typing.Optional[int] = None
95
105
 
96
106
  @property
97
107
  @abc.abstractmethod
@@ -111,6 +121,8 @@ class Model(Hook):
111
121
  """The ABI according to which this model works."""
112
122
  pass
113
123
 
124
+ static_space_required: int = 0
125
+
114
126
  @classmethod
115
127
  def lookup(
116
128
  cls, name: str, platform: platforms.Platform, abi: platforms.ABI, address: int
@@ -137,7 +149,20 @@ class Model(Hook):
137
149
 
138
150
  def apply(self, emulator: emulators.Emulator) -> None:
139
151
  logger.debug(f"Hooking Model {self} {self._address:x}")
152
+
153
+ if self.static_space_required != 0:
154
+ # We need a static buffer.
155
+ if self.static_buffer_address is None:
156
+ # Harness author forgot to reserve us one
157
+ raise exceptions.ConfigurationError(
158
+ f"No static buffer address provided for {self.name}"
159
+ )
160
+ emulator.map_memory(self.static_buffer_address, self.static_space_required)
161
+
162
+ # Map just enough memory to jump to the model address without faulting.
140
163
  emulator.map_memory(self._address, 16)
164
+
165
+ # Add the function hook to the emulator
141
166
  if not isinstance(emulator, emulators.FunctionHookable):
142
167
  raise exceptions.ConfigurationError("Emulator cannot hook functions")
143
168
  emulator.hook_function(self._address, self._function)
@@ -0,0 +1,6 @@
1
+ from .libgen import * # noqa: F401, F403
2
+ from .libgen import __all__ as __libgen__
3
+ from .signal import * # noqa: F401, F403
4
+ from .signal import __all__ as __signal__
5
+
6
+ __all__ = __libgen__ + __signal__
@@ -0,0 +1,123 @@
1
+ from .... import emulators
2
+ from ..c99.utils import _emu_strlen
3
+ from ..cstd import ArgumentType, CStdModel
4
+
5
+
6
+ class Basename(CStdModel):
7
+ name = "basename"
8
+
9
+ # NOTE: There are two versions of basename().
10
+ #
11
+ # POSIX and GNU have competing specifications.
12
+ # They have the following differences:
13
+ #
14
+ # - GNU always uses a static buffer for its returns
15
+ # - GNU returns "" in case of trailing separators
16
+ # - GNU returns "" in case of the root path
17
+
18
+ # char *basename(char *path);
19
+ argument_types = [ArgumentType.POINTER]
20
+ return_type = ArgumentType.POINTER
21
+
22
+ # Use the GNU memory semantics
23
+ static_space_required = 0x1000
24
+
25
+ def __init__(self, address: int):
26
+ super().__init__(address)
27
+
28
+ # Override this to change how you parse paths
29
+ self.separator = b"/"
30
+
31
+ def model(self, emulator: emulators.Emulator) -> None:
32
+ super().model(emulator)
33
+
34
+ pathptr = self.get_arg1(emulator)
35
+
36
+ assert isinstance(pathptr, int)
37
+
38
+ # Not actually a loop; I just want to use break.
39
+ while True:
40
+ if pathptr == 0:
41
+ # Case: pathptr is NULL; return a static buffer containing '.'
42
+ path = b"."
43
+ break
44
+
45
+ pathlen = _emu_strlen(emulator, pathptr)
46
+ path = emulator.read_memory(pathptr, pathlen)
47
+
48
+ if path == self.separator:
49
+ # Case: Path is the root path: Return itself
50
+ break
51
+
52
+ if path[-1] == self.separator[0]:
53
+ # Case: Path ends in separator: Delete the trailing separator
54
+ path = path[0:-1]
55
+
56
+ if self.separator not in path:
57
+ # Case: no path separator: Return copy of path
58
+ break
59
+
60
+ # Case: Path has a separator in it: Return the trailing substring of path
61
+ idx = path.rindex(self.separator)
62
+ path = path[idx + 1 :]
63
+ break
64
+
65
+ assert self.static_buffer_address is not None
66
+
67
+ emulator.write_memory(self.static_buffer_address, path + b"\0")
68
+ self.set_return_value(emulator, self.static_buffer_address)
69
+
70
+
71
+ class Dirname(CStdModel):
72
+ name = "dirname"
73
+
74
+ # char *dirname(char *path);
75
+ argument_types = [ArgumentType.POINTER]
76
+ return_type = ArgumentType.POINTER
77
+
78
+ def __init__(self, address: int):
79
+ super().__init__(address)
80
+
81
+ # Override this to change how you parse paths
82
+ self.separator = b"/"
83
+
84
+ def model(self, emulator: emulators.Emulator) -> None:
85
+ super().model(emulator)
86
+
87
+ pathptr = self.get_arg1(emulator)
88
+
89
+ assert isinstance(pathptr, int)
90
+
91
+ if pathptr == 0:
92
+ # Case: pathptr is NULL; return a static buffer containing '.'
93
+ raise NotImplementedError("Requires a static buffer")
94
+
95
+ pathlen = _emu_strlen(emulator, pathptr)
96
+ path = emulator.read_memory(pathptr, pathlen)
97
+
98
+ if path == self.separator:
99
+ # Case: Path is '/': Return itself
100
+ print("Root case")
101
+ self.set_return_value(emulator, pathptr)
102
+ return
103
+
104
+ if self.separator not in path:
105
+ # Case: No path separator; return '.'
106
+ emulator.write_memory(pathptr, b".\0")
107
+ self.set_return_value(emulator, pathptr)
108
+ return
109
+
110
+ if path[-1] == self.separator[0]:
111
+ path = path[:-2]
112
+
113
+ idx = path.rindex(self.separator)
114
+ if idx == 0:
115
+ # Case: Path's lowest '/' is the root path; return '/'
116
+ emulator.write_memory(pathptr + idx + 1, b"\0")
117
+ else:
118
+ # Case: Path has a '/' in it. Replace it with \0 and return original pointer
119
+ emulator.write_memory(pathptr + idx, b"\0")
120
+ self.set_return_value(emulator, pathptr)
121
+
122
+
123
+ __all__ = ["Basename", "Dirname"]