crabstone 3.0.3 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (347) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGES.md +45 -42
  3. data/README.md +16 -33
  4. data/lib/crabstone.rb +5 -557
  5. data/lib/crabstone/arch.rb +37 -0
  6. data/lib/{arch → crabstone/arch/3}/arm.rb +28 -49
  7. data/lib/crabstone/arch/3/arm64.rb +124 -0
  8. data/lib/{arch → crabstone/arch/3}/arm64_const.rb +45 -86
  9. data/lib/{arch → crabstone/arch/3}/arm_const.rb +19 -47
  10. data/lib/crabstone/arch/3/mips.rb +57 -0
  11. data/lib/{arch → crabstone/arch/3}/mips_const.rb +18 -38
  12. data/lib/crabstone/arch/3/ppc.rb +73 -0
  13. data/lib/{arch → crabstone/arch/3}/ppc_const.rb +27 -43
  14. data/lib/crabstone/arch/3/sparc.rb +60 -0
  15. data/lib/{arch → crabstone/arch/3}/sparc_const.rb +49 -67
  16. data/lib/crabstone/arch/3/sysz.rb +67 -0
  17. data/lib/{arch → crabstone/arch/3}/sysz_const.rb +11 -25
  18. data/lib/crabstone/arch/3/x86.rb +82 -0
  19. data/lib/{arch → crabstone/arch/3}/x86_const.rb +15 -36
  20. data/lib/crabstone/arch/3/xcore.rb +59 -0
  21. data/lib/{arch → crabstone/arch/3}/xcore_const.rb +10 -22
  22. data/lib/crabstone/arch/4/arm.rb +110 -0
  23. data/lib/crabstone/arch/4/arm64.rb +125 -0
  24. data/lib/crabstone/arch/4/arm64_const.rb +1016 -0
  25. data/lib/crabstone/arch/4/arm_const.rb +785 -0
  26. data/lib/crabstone/arch/4/evm.rb +20 -0
  27. data/lib/crabstone/arch/4/evm_const.rb +161 -0
  28. data/lib/crabstone/arch/4/m680x.rb +106 -0
  29. data/lib/crabstone/arch/4/m680x_const.rb +426 -0
  30. data/lib/crabstone/arch/4/m68k.rb +129 -0
  31. data/lib/crabstone/arch/4/m68k_const.rb +496 -0
  32. data/lib/crabstone/arch/4/mips.rb +57 -0
  33. data/lib/crabstone/arch/4/mips_const.rb +869 -0
  34. data/lib/crabstone/arch/4/ppc.rb +73 -0
  35. data/lib/crabstone/arch/4/ppc_const.rb +1375 -0
  36. data/lib/crabstone/arch/4/sparc.rb +60 -0
  37. data/lib/crabstone/arch/4/sparc_const.rb +439 -0
  38. data/lib/crabstone/arch/4/sysz.rb +67 -0
  39. data/lib/crabstone/arch/4/sysz_const.rb +763 -0
  40. data/lib/crabstone/arch/4/tms320c64x.rb +87 -0
  41. data/lib/crabstone/arch/4/tms320c64x_const.rb +287 -0
  42. data/lib/crabstone/arch/4/x86.rb +91 -0
  43. data/lib/crabstone/arch/4/x86_const.rb +1972 -0
  44. data/lib/crabstone/arch/4/xcore.rb +59 -0
  45. data/lib/crabstone/arch/4/xcore_const.rb +171 -0
  46. data/lib/crabstone/arch/extension.rb +27 -0
  47. data/lib/crabstone/arch/register.rb +36 -0
  48. data/lib/crabstone/binding.rb +60 -0
  49. data/lib/crabstone/binding/3/detail.rb +36 -0
  50. data/lib/crabstone/binding/3/instruction.rb +23 -0
  51. data/lib/crabstone/binding/4/detail.rb +40 -0
  52. data/lib/crabstone/binding/4/instruction.rb +23 -0
  53. data/lib/crabstone/binding/structs.rb +32 -0
  54. data/lib/crabstone/constants.rb +110 -0
  55. data/lib/crabstone/cs_version.rb +49 -0
  56. data/lib/crabstone/disassembler.rb +153 -0
  57. data/lib/crabstone/error.rb +60 -0
  58. data/lib/crabstone/instruction.rb +183 -0
  59. data/lib/crabstone/version.rb +5 -0
  60. metadata +128 -324
  61. data/MANIFEST +0 -312
  62. data/Rakefile +0 -27
  63. data/bin/genconst +0 -66
  64. data/bin/genreg +0 -99
  65. data/crabstone.gemspec +0 -27
  66. data/examples/hello_world.rb +0 -43
  67. data/lib/arch/arm64.rb +0 -167
  68. data/lib/arch/arm64_registers.rb +0 -295
  69. data/lib/arch/arm_registers.rb +0 -149
  70. data/lib/arch/mips.rb +0 -78
  71. data/lib/arch/mips_registers.rb +0 -208
  72. data/lib/arch/ppc.rb +0 -90
  73. data/lib/arch/ppc_registers.rb +0 -209
  74. data/lib/arch/sparc.rb +0 -79
  75. data/lib/arch/sparc_registers.rb +0 -121
  76. data/lib/arch/systemz.rb +0 -79
  77. data/lib/arch/sysz_registers.rb +0 -66
  78. data/lib/arch/x86.rb +0 -107
  79. data/lib/arch/x86_registers.rb +0 -265
  80. data/lib/arch/xcore.rb +0 -78
  81. data/lib/arch/xcore_registers.rb +0 -57
  82. data/test/MC/AArch64/basic-a64-instructions.s.cs +0 -2014
  83. data/test/MC/AArch64/gicv3-regs.s.cs +0 -111
  84. data/test/MC/AArch64/neon-2velem.s.cs +0 -113
  85. data/test/MC/AArch64/neon-3vdiff.s.cs +0 -143
  86. data/test/MC/AArch64/neon-aba-abd.s.cs +0 -28
  87. data/test/MC/AArch64/neon-across.s.cs +0 -40
  88. data/test/MC/AArch64/neon-add-pairwise.s.cs +0 -11
  89. data/test/MC/AArch64/neon-add-sub-instructions.s.cs +0 -21
  90. data/test/MC/AArch64/neon-bitwise-instructions.s.cs +0 -17
  91. data/test/MC/AArch64/neon-compare-instructions.s.cs +0 -136
  92. data/test/MC/AArch64/neon-crypto.s.cs +0 -15
  93. data/test/MC/AArch64/neon-extract.s.cs +0 -3
  94. data/test/MC/AArch64/neon-facge-facgt.s.cs +0 -13
  95. data/test/MC/AArch64/neon-frsqrt-frecp.s.cs +0 -7
  96. data/test/MC/AArch64/neon-halving-add-sub.s.cs +0 -25
  97. data/test/MC/AArch64/neon-max-min-pairwise.s.cs +0 -37
  98. data/test/MC/AArch64/neon-max-min.s.cs +0 -37
  99. data/test/MC/AArch64/neon-mla-mls-instructions.s.cs +0 -19
  100. data/test/MC/AArch64/neon-mov.s.cs +0 -74
  101. data/test/MC/AArch64/neon-mul-div-instructions.s.cs +0 -24
  102. data/test/MC/AArch64/neon-perm.s.cs +0 -43
  103. data/test/MC/AArch64/neon-rounding-halving-add.s.cs +0 -13
  104. data/test/MC/AArch64/neon-rounding-shift.s.cs +0 -15
  105. data/test/MC/AArch64/neon-saturating-add-sub.s.cs +0 -29
  106. data/test/MC/AArch64/neon-saturating-rounding-shift.s.cs +0 -15
  107. data/test/MC/AArch64/neon-saturating-shift.s.cs +0 -15
  108. data/test/MC/AArch64/neon-scalar-abs.s.cs +0 -8
  109. data/test/MC/AArch64/neon-scalar-add-sub.s.cs +0 -3
  110. data/test/MC/AArch64/neon-scalar-by-elem-mla.s.cs +0 -13
  111. data/test/MC/AArch64/neon-scalar-by-elem-mul.s.cs +0 -13
  112. data/test/MC/AArch64/neon-scalar-by-elem-saturating-mla.s.cs +0 -15
  113. data/test/MC/AArch64/neon-scalar-by-elem-saturating-mul.s.cs +0 -18
  114. data/test/MC/AArch64/neon-scalar-compare.s.cs +0 -12
  115. data/test/MC/AArch64/neon-scalar-cvt.s.cs +0 -34
  116. data/test/MC/AArch64/neon-scalar-dup.s.cs +0 -23
  117. data/test/MC/AArch64/neon-scalar-extract-narrow.s.cs +0 -10
  118. data/test/MC/AArch64/neon-scalar-fp-compare.s.cs +0 -21
  119. data/test/MC/AArch64/neon-scalar-mul.s.cs +0 -13
  120. data/test/MC/AArch64/neon-scalar-neg.s.cs +0 -6
  121. data/test/MC/AArch64/neon-scalar-recip.s.cs +0 -11
  122. data/test/MC/AArch64/neon-scalar-reduce-pairwise.s.cs +0 -3
  123. data/test/MC/AArch64/neon-scalar-rounding-shift.s.cs +0 -3
  124. data/test/MC/AArch64/neon-scalar-saturating-add-sub.s.cs +0 -25
  125. data/test/MC/AArch64/neon-scalar-saturating-rounding-shift.s.cs +0 -9
  126. data/test/MC/AArch64/neon-scalar-saturating-shift.s.cs +0 -9
  127. data/test/MC/AArch64/neon-scalar-shift-imm.s.cs +0 -42
  128. data/test/MC/AArch64/neon-scalar-shift.s.cs +0 -3
  129. data/test/MC/AArch64/neon-shift-left-long.s.cs +0 -13
  130. data/test/MC/AArch64/neon-shift.s.cs +0 -22
  131. data/test/MC/AArch64/neon-simd-copy.s.cs +0 -42
  132. data/test/MC/AArch64/neon-simd-ldst-multi-elem.s.cs +0 -197
  133. data/test/MC/AArch64/neon-simd-ldst-one-elem.s.cs +0 -129
  134. data/test/MC/AArch64/neon-simd-misc.s.cs +0 -213
  135. data/test/MC/AArch64/neon-simd-post-ldst-multi-elem.s.cs +0 -107
  136. data/test/MC/AArch64/neon-simd-shift.s.cs +0 -151
  137. data/test/MC/AArch64/neon-tbl.s.cs +0 -21
  138. data/test/MC/AArch64/trace-regs.s.cs +0 -383
  139. data/test/MC/ARM/arm-aliases.s.cs +0 -7
  140. data/test/MC/ARM/arm-arithmetic-aliases.s.cs +0 -50
  141. data/test/MC/ARM/arm-it-block.s.cs +0 -2
  142. data/test/MC/ARM/arm-memory-instructions.s.cs +0 -138
  143. data/test/MC/ARM/arm-shift-encoding.s.cs +0 -50
  144. data/test/MC/ARM/arm-thumb-trustzone.s.cs +0 -3
  145. data/test/MC/ARM/arm-trustzone.s.cs +0 -3
  146. data/test/MC/ARM/arm_addrmode2.s.cs +0 -15
  147. data/test/MC/ARM/arm_addrmode3.s.cs +0 -9
  148. data/test/MC/ARM/arm_instructions.s.cs +0 -25
  149. data/test/MC/ARM/basic-arm-instructions-v8.s.cs +0 -10
  150. data/test/MC/ARM/basic-arm-instructions.s.cs +0 -997
  151. data/test/MC/ARM/basic-thumb-instructions.s.cs +0 -130
  152. data/test/MC/ARM/basic-thumb2-instructions-v8.s.cs +0 -1
  153. data/test/MC/ARM/basic-thumb2-instructions.s.cs +0 -1242
  154. data/test/MC/ARM/crc32-thumb.s.cs +0 -7
  155. data/test/MC/ARM/crc32.s.cs +0 -7
  156. data/test/MC/ARM/dot-req.s.cs +0 -3
  157. data/test/MC/ARM/fp-armv8.s.cs +0 -52
  158. data/test/MC/ARM/idiv-thumb.s.cs +0 -3
  159. data/test/MC/ARM/idiv.s.cs +0 -3
  160. data/test/MC/ARM/load-store-acquire-release-v8-thumb.s.cs +0 -15
  161. data/test/MC/ARM/load-store-acquire-release-v8.s.cs +0 -15
  162. data/test/MC/ARM/mode-switch.s.cs +0 -7
  163. data/test/MC/ARM/neon-abs-encoding.s.cs +0 -15
  164. data/test/MC/ARM/neon-absdiff-encoding.s.cs +0 -39
  165. data/test/MC/ARM/neon-add-encoding.s.cs +0 -119
  166. data/test/MC/ARM/neon-bitcount-encoding.s.cs +0 -15
  167. data/test/MC/ARM/neon-bitwise-encoding.s.cs +0 -126
  168. data/test/MC/ARM/neon-cmp-encoding.s.cs +0 -88
  169. data/test/MC/ARM/neon-convert-encoding.s.cs +0 -27
  170. data/test/MC/ARM/neon-crypto.s.cs +0 -16
  171. data/test/MC/ARM/neon-dup-encoding.s.cs +0 -13
  172. data/test/MC/ARM/neon-minmax-encoding.s.cs +0 -57
  173. data/test/MC/ARM/neon-mov-encoding.s.cs +0 -76
  174. data/test/MC/ARM/neon-mul-accum-encoding.s.cs +0 -39
  175. data/test/MC/ARM/neon-mul-encoding.s.cs +0 -72
  176. data/test/MC/ARM/neon-neg-encoding.s.cs +0 -15
  177. data/test/MC/ARM/neon-pairwise-encoding.s.cs +0 -47
  178. data/test/MC/ARM/neon-reciprocal-encoding.s.cs +0 -13
  179. data/test/MC/ARM/neon-reverse-encoding.s.cs +0 -13
  180. data/test/MC/ARM/neon-satshift-encoding.s.cs +0 -75
  181. data/test/MC/ARM/neon-shift-encoding.s.cs +0 -238
  182. data/test/MC/ARM/neon-shiftaccum-encoding.s.cs +0 -97
  183. data/test/MC/ARM/neon-shuffle-encoding.s.cs +0 -59
  184. data/test/MC/ARM/neon-sub-encoding.s.cs +0 -82
  185. data/test/MC/ARM/neon-table-encoding.s.cs +0 -9
  186. data/test/MC/ARM/neon-v8.s.cs +0 -38
  187. data/test/MC/ARM/neon-vld-encoding.s.cs +0 -213
  188. data/test/MC/ARM/neon-vst-encoding.s.cs +0 -120
  189. data/test/MC/ARM/neon-vswp.s.cs +0 -3
  190. data/test/MC/ARM/neont2-abs-encoding.s.cs +0 -15
  191. data/test/MC/ARM/neont2-absdiff-encoding.s.cs +0 -39
  192. data/test/MC/ARM/neont2-add-encoding.s.cs +0 -65
  193. data/test/MC/ARM/neont2-bitcount-encoding.s.cs +0 -15
  194. data/test/MC/ARM/neont2-bitwise-encoding.s.cs +0 -15
  195. data/test/MC/ARM/neont2-cmp-encoding.s.cs +0 -17
  196. data/test/MC/ARM/neont2-convert-encoding.s.cs +0 -19
  197. data/test/MC/ARM/neont2-dup-encoding.s.cs +0 -19
  198. data/test/MC/ARM/neont2-minmax-encoding.s.cs +0 -57
  199. data/test/MC/ARM/neont2-mov-encoding.s.cs +0 -58
  200. data/test/MC/ARM/neont2-mul-accum-encoding.s.cs +0 -41
  201. data/test/MC/ARM/neont2-mul-encoding.s.cs +0 -31
  202. data/test/MC/ARM/neont2-neg-encoding.s.cs +0 -15
  203. data/test/MC/ARM/neont2-pairwise-encoding.s.cs +0 -43
  204. data/test/MC/ARM/neont2-reciprocal-encoding.s.cs +0 -13
  205. data/test/MC/ARM/neont2-reverse-encoding.s.cs +0 -13
  206. data/test/MC/ARM/neont2-satshift-encoding.s.cs +0 -75
  207. data/test/MC/ARM/neont2-shift-encoding.s.cs +0 -80
  208. data/test/MC/ARM/neont2-shiftaccum-encoding.s.cs +0 -97
  209. data/test/MC/ARM/neont2-shuffle-encoding.s.cs +0 -23
  210. data/test/MC/ARM/neont2-sub-encoding.s.cs +0 -23
  211. data/test/MC/ARM/neont2-table-encoding.s.cs +0 -9
  212. data/test/MC/ARM/neont2-vld-encoding.s.cs +0 -51
  213. data/test/MC/ARM/neont2-vst-encoding.s.cs +0 -48
  214. data/test/MC/ARM/simple-fp-encoding.s.cs +0 -157
  215. data/test/MC/ARM/thumb-fp-armv8.s.cs +0 -51
  216. data/test/MC/ARM/thumb-hints.s.cs +0 -12
  217. data/test/MC/ARM/thumb-neon-crypto.s.cs +0 -16
  218. data/test/MC/ARM/thumb-neon-v8.s.cs +0 -38
  219. data/test/MC/ARM/thumb-shift-encoding.s.cs +0 -19
  220. data/test/MC/ARM/thumb.s.cs +0 -19
  221. data/test/MC/ARM/thumb2-b.w-encodingT4.s.cs +0 -2
  222. data/test/MC/ARM/thumb2-branches.s.cs +0 -85
  223. data/test/MC/ARM/thumb2-mclass.s.cs +0 -41
  224. data/test/MC/ARM/thumb2-narrow-dp.ll.cs +0 -379
  225. data/test/MC/ARM/thumb2-pldw.s.cs +0 -2
  226. data/test/MC/ARM/vfp4-thumb.s.cs +0 -13
  227. data/test/MC/ARM/vfp4.s.cs +0 -13
  228. data/test/MC/ARM/vpush-vpop-thumb.s.cs +0 -9
  229. data/test/MC/ARM/vpush-vpop.s.cs +0 -9
  230. data/test/MC/Mips/hilo-addressing.s.cs +0 -4
  231. data/test/MC/Mips/micromips-alu-instructions-EB.s.cs +0 -33
  232. data/test/MC/Mips/micromips-alu-instructions.s.cs +0 -33
  233. data/test/MC/Mips/micromips-branch-instructions-EB.s.cs +0 -11
  234. data/test/MC/Mips/micromips-branch-instructions.s.cs +0 -11
  235. data/test/MC/Mips/micromips-expansions.s.cs +0 -20
  236. data/test/MC/Mips/micromips-jump-instructions-EB.s.cs +0 -5
  237. data/test/MC/Mips/micromips-jump-instructions.s.cs +0 -6
  238. data/test/MC/Mips/micromips-loadstore-instructions-EB.s.cs +0 -9
  239. data/test/MC/Mips/micromips-loadstore-instructions.s.cs +0 -9
  240. data/test/MC/Mips/micromips-loadstore-unaligned-EB.s.cs +0 -5
  241. data/test/MC/Mips/micromips-loadstore-unaligned.s.cs +0 -5
  242. data/test/MC/Mips/micromips-movcond-instructions-EB.s.cs +0 -5
  243. data/test/MC/Mips/micromips-movcond-instructions.s.cs +0 -5
  244. data/test/MC/Mips/micromips-multiply-instructions-EB.s.cs +0 -5
  245. data/test/MC/Mips/micromips-multiply-instructions.s.cs +0 -5
  246. data/test/MC/Mips/micromips-shift-instructions-EB.s.cs +0 -9
  247. data/test/MC/Mips/micromips-shift-instructions.s.cs +0 -9
  248. data/test/MC/Mips/micromips-trap-instructions-EB.s.cs +0 -13
  249. data/test/MC/Mips/micromips-trap-instructions.s.cs +0 -13
  250. data/test/MC/Mips/mips-alu-instructions.s.cs +0 -53
  251. data/test/MC/Mips/mips-control-instructions-64.s.cs +0 -33
  252. data/test/MC/Mips/mips-control-instructions.s.cs +0 -33
  253. data/test/MC/Mips/mips-coprocessor-encodings.s.cs +0 -17
  254. data/test/MC/Mips/mips-dsp-instructions.s.cs +0 -43
  255. data/test/MC/Mips/mips-expansions.s.cs +0 -20
  256. data/test/MC/Mips/mips-fpu-instructions.s.cs +0 -93
  257. data/test/MC/Mips/mips-jump-instructions.s.cs +0 -1
  258. data/test/MC/Mips/mips-memory-instructions.s.cs +0 -17
  259. data/test/MC/Mips/mips-register-names.s.cs +0 -33
  260. data/test/MC/Mips/mips64-alu-instructions.s.cs +0 -47
  261. data/test/MC/Mips/mips64-instructions.s.cs +0 -3
  262. data/test/MC/Mips/mips64-register-names.s.cs +0 -33
  263. data/test/MC/Mips/mips_directives.s.cs +0 -12
  264. data/test/MC/Mips/nabi-regs.s.cs +0 -12
  265. data/test/MC/Mips/set-at-directive.s.cs +0 -6
  266. data/test/MC/Mips/test_2r.s.cs +0 -16
  267. data/test/MC/Mips/test_2rf.s.cs +0 -33
  268. data/test/MC/Mips/test_3r.s.cs +0 -243
  269. data/test/MC/Mips/test_3rf.s.cs +0 -83
  270. data/test/MC/Mips/test_bit.s.cs +0 -49
  271. data/test/MC/Mips/test_cbranch.s.cs +0 -11
  272. data/test/MC/Mips/test_ctrlregs.s.cs +0 -33
  273. data/test/MC/Mips/test_elm.s.cs +0 -16
  274. data/test/MC/Mips/test_elm_insert.s.cs +0 -4
  275. data/test/MC/Mips/test_elm_insve.s.cs +0 -5
  276. data/test/MC/Mips/test_i10.s.cs +0 -5
  277. data/test/MC/Mips/test_i5.s.cs +0 -45
  278. data/test/MC/Mips/test_i8.s.cs +0 -11
  279. data/test/MC/Mips/test_lsa.s.cs +0 -5
  280. data/test/MC/Mips/test_mi10.s.cs +0 -24
  281. data/test/MC/Mips/test_vec.s.cs +0 -8
  282. data/test/MC/PowerPC/ppc64-encoding-bookII.s.cs +0 -25
  283. data/test/MC/PowerPC/ppc64-encoding-bookIII.s.cs +0 -35
  284. data/test/MC/PowerPC/ppc64-encoding-ext.s.cs +0 -535
  285. data/test/MC/PowerPC/ppc64-encoding-fp.s.cs +0 -110
  286. data/test/MC/PowerPC/ppc64-encoding-vmx.s.cs +0 -170
  287. data/test/MC/PowerPC/ppc64-encoding.s.cs +0 -202
  288. data/test/MC/PowerPC/ppc64-operands.s.cs +0 -32
  289. data/test/MC/README +0 -6
  290. data/test/MC/Sparc/sparc-alu-instructions.s.cs +0 -47
  291. data/test/MC/Sparc/sparc-atomic-instructions.s.cs +0 -7
  292. data/test/MC/Sparc/sparc-ctrl-instructions.s.cs +0 -11
  293. data/test/MC/Sparc/sparc-fp-instructions.s.cs +0 -59
  294. data/test/MC/Sparc/sparc-mem-instructions.s.cs +0 -25
  295. data/test/MC/Sparc/sparc-vis.s.cs +0 -2
  296. data/test/MC/Sparc/sparc64-alu-instructions.s.cs +0 -13
  297. data/test/MC/Sparc/sparc64-ctrl-instructions.s.cs +0 -102
  298. data/test/MC/Sparc/sparcv8-instructions.s.cs +0 -7
  299. data/test/MC/Sparc/sparcv9-instructions.s.cs +0 -1
  300. data/test/MC/SystemZ/insn-good-z196.s.cs +0 -589
  301. data/test/MC/SystemZ/insn-good.s.cs +0 -2265
  302. data/test/MC/SystemZ/regs-good.s.cs +0 -45
  303. data/test/MC/X86/3DNow.s.cs +0 -29
  304. data/test/MC/X86/address-size.s.cs +0 -5
  305. data/test/MC/X86/avx512-encodings.s.cs +0 -12
  306. data/test/MC/X86/intel-syntax-encoding.s.cs +0 -30
  307. data/test/MC/X86/x86-32-avx.s.cs +0 -833
  308. data/test/MC/X86/x86-32-fma3.s.cs +0 -169
  309. data/test/MC/X86/x86-32-ms-inline-asm.s.cs +0 -27
  310. data/test/MC/X86/x86_64-avx-clmul-encoding.s.cs +0 -11
  311. data/test/MC/X86/x86_64-avx-encoding.s.cs +0 -1058
  312. data/test/MC/X86/x86_64-bmi-encoding.s.cs +0 -51
  313. data/test/MC/X86/x86_64-encoding.s.cs +0 -59
  314. data/test/MC/X86/x86_64-fma3-encoding.s.cs +0 -169
  315. data/test/MC/X86/x86_64-fma4-encoding.s.cs +0 -98
  316. data/test/MC/X86/x86_64-hle-encoding.s.cs +0 -3
  317. data/test/MC/X86/x86_64-imm-widths.s.cs +0 -27
  318. data/test/MC/X86/x86_64-rand-encoding.s.cs +0 -13
  319. data/test/MC/X86/x86_64-rtm-encoding.s.cs +0 -4
  320. data/test/MC/X86/x86_64-sse4a.s.cs +0 -1
  321. data/test/MC/X86/x86_64-tbm-encoding.s.cs +0 -40
  322. data/test/MC/X86/x86_64-xop-encoding.s.cs +0 -152
  323. data/test/README +0 -6
  324. data/test/test.rb +0 -205
  325. data/test/test.rb.SPEC +0 -235
  326. data/test/test_arm.rb +0 -202
  327. data/test/test_arm.rb.SPEC +0 -275
  328. data/test/test_arm64.rb +0 -150
  329. data/test/test_arm64.rb.SPEC +0 -116
  330. data/test/test_detail.rb +0 -228
  331. data/test/test_detail.rb.SPEC +0 -322
  332. data/test/test_exhaustive.rb +0 -80
  333. data/test/test_mips.rb +0 -118
  334. data/test/test_mips.rb.SPEC +0 -91
  335. data/test/test_ppc.rb +0 -137
  336. data/test/test_ppc.rb.SPEC +0 -84
  337. data/test/test_sanity.rb +0 -83
  338. data/test/test_skipdata.rb +0 -111
  339. data/test/test_skipdata.rb.SPEC +0 -58
  340. data/test/test_sparc.rb +0 -113
  341. data/test/test_sparc.rb.SPEC +0 -116
  342. data/test/test_sysz.rb +0 -111
  343. data/test/test_sysz.rb.SPEC +0 -61
  344. data/test/test_x86.rb +0 -189
  345. data/test/test_x86.rb.SPEC +0 -579
  346. data/test/test_xcore.rb +0 -100
  347. data/test/test_xcore.rb.SPEC +0 -75
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: acf2c718e307944c7535140d1048d7bff42e35d3
4
- data.tar.gz: 60877a5b5d2cbc318431ae9c6019dcdd24e6b75b
2
+ SHA256:
3
+ metadata.gz: 140a7d4cf44612a3205d95039371d243db5f7eabf5cc218eaafd6ac30a348846
4
+ data.tar.gz: 13bda9437d26890e825cfea3f661c12a50673fffc9710333fc04b025a5f0059c
5
5
  SHA512:
6
- metadata.gz: 5fc96a476ee596c02d0c60805e27348503aba244a910c3aa4fc8596590c1e9c337a5a8cebd9cb9df8551352f95d07b3d6f957b578b0f4620b25d3a5f6fb734ac
7
- data.tar.gz: 4821da92a28077e91a03759c8cf986d4b7bd68ff56df30f2d760189d50a0af1f0b6e216a7cca62134b01dbe7647261d8b8319bf2048e96a5cfb6b16a9eeba319
6
+ metadata.gz: bdb675faa5efd7eb608ac44d21b8b39e8e3cdbf3592a72df42ac4364b956c1c43463200cf5381556ccd532b3ed20e884a0505eb62d558a12e82156ba26135218
7
+ data.tar.gz: a38739c9b5a190673b29b1ccc0defcc27cbdf0d4a08fccc45822a3d3ae9bf80447c9ef5647167d1421cc5ab09300cbc0aaab9b43ed8e16b42f28746687cf6287
data/CHANGES.md CHANGED
@@ -1,23 +1,40 @@
1
- ## 0.0.1
2
- * Alpha release.
1
+ ## 4.0.0
2
+ * Supported *both* Capstone 3.x and 4.x.
3
+ * Supported 4 new architectures: M68K, M680X, TMS320C64x, and EVM.
4
+ * Added `cs_regs_access` API (wrapped as `Instruction#regs_access` in Crabstone).
5
+ * Changed some internal constants and methods.
6
+ * Fixed tons of bugs.
7
+ * For more details, see https://github.com/david942j/crabstone/pull/2
3
8
 
4
- ## 0.0.2
5
- * Update tests, add syntax sugar
9
+ ## 3.0.3-rc1
10
+ * Internal binding updates, updated some test specs.
6
11
 
7
- ## 0.0.3
8
- * Refactoring and cosmetics
12
+ ## 3.0
13
+ * See https://github.com/aquynh/capstone/wiki/ChangeLog-since-3.0-rc3
14
+ * Shouldn't be breaking, most changes are internal.
9
15
 
10
- ## 0.0.4
11
- * Verify MIPS support, tests, slight API changes
16
+ ## 3.0rc3
17
+ * Generic groups ( CS_GRP_JUMP, CS_GRP_CALL etc)
18
+ * Mips 32R6 + MICRO
19
+ * Many constant changes
20
+ * PPC CRX operand
21
+ * X86: added prefixed symbols
22
+ * THIS IS A BREAKING CHANGE ( even from rc1 )
12
23
 
13
- ## 0.0.5
14
- * API changes including cs_errno.
24
+ ## 3.0rc1
25
+ * Update for C side changes
26
+ * Add support for Xcore
27
+ * ARM, ARM64 and X86 passing, rest waiting for upstream
15
28
 
16
- ## 0.0.6
17
- * Final set of API changes before public beta.
29
+ ## 2.2.0
30
+ * Add support for Sparc and SystemZ
18
31
 
19
- ## 1.0.0
20
- * Move to new github repo
32
+ ## 2.1rc1
33
+ * Many constant changes
34
+ * disasm CAN now return an Array, with a slightly scary built-in finalizer
35
+
36
+ ## 2.0.1
37
+ * Update X86 constants
21
38
 
22
39
  ## 2.0.0
23
40
  * Add PPC support
@@ -25,37 +42,23 @@
25
42
  * disasm can now ONLY be used with a block ( hopefully fix later )
26
43
  * THIS IS A BREAKING CHANGE
27
44
 
28
- ## 2.0.1
29
- * Update X86 constants
30
-
31
- ## 2.1rc1
32
- * Many constant changes
33
- * disasm CAN now return an Array, with a slightly scary built-in finalizer
45
+ ## 1.0.0
46
+ * Move to new github repo
34
47
 
35
- ## 2.1.0
36
- * Full compliance with 2.1 API
37
- * Better error handling for diet mode
38
- * Internally change cs_close() signature, so closed handles can't be used
48
+ ## 0.0.6
49
+ * Final set of API changes before public beta.
39
50
 
40
- ## 2.2.0
41
- * Add support for Sparc and SystemZ
51
+ ## 0.0.5
52
+ * API changes including cs_errno.
42
53
 
43
- ## 3.0rc1
44
- * Update for C side changes
45
- * Add support for Xcore
46
- * ARM, ARM64 and X86 passing, rest waiting for upstream
54
+ ## 0.0.4
55
+ * Verify MIPS support, tests, slight API changes
47
56
 
48
- ## 3.0rc3
49
- * Generic groups ( CS_GRP_JUMP, CS_GRP_CALL etc)
50
- * Mips 32R6 + MICRO
51
- * Many constant changes
52
- * PPC CRX operand
53
- * X86: added prefixed symbols
54
- * THIS IS A BREAKING CHANGE ( even from rc1 )
57
+ ## 0.0.3
58
+ * Refactoring and cosmetics
55
59
 
56
- ## 3.0
57
- * See https://github.com/aquynh/capstone/wiki/ChangeLog-since-3.0-rc3
58
- * Shouldn't be breaking, most changes are internal.
60
+ ## 0.0.2
61
+ * Update tests, add syntax sugar
59
62
 
60
- ## 3.0.3-rc1
61
- * Internal binding updates, updated some test specs.
63
+ ## 0.0.1
64
+ * Alpha release.
data/README.md CHANGED
@@ -1,12 +1,7 @@
1
1
  crabstone
2
2
  ====
3
3
 
4
- STATUS
5
- ===
6
-
7
- Hopefully working.
8
-
9
- Current Library binding: 3.0.3-rc1
4
+ Current library support: 4.0.1
10
5
  ----
11
6
 
12
7
  ( FROM THE CAPSTONE README )
@@ -41,55 +36,43 @@ To install:
41
36
  First install the capstone library from either https://github.com/aquynh/capstone
42
37
  or http://www.capstone-engine.org
43
38
 
44
- Then (until we publish a gem) clone the repo, then do this:
39
+ Then:
45
40
 
46
41
  ```bash
47
- gem build crabstone.gemspec
48
- gem install crabstone-3.0.3.gem
49
- rake test
42
+ gem install crabstone
50
43
  ```
51
44
 
52
45
  To write code:
53
46
  ----
54
47
 
55
- Check the tests for more examples. Here is "Hello World":
48
+ Check the tests in [Capstone](https://github.com/aquynh/capstone) for more examples. Here is "Hello World":
56
49
  ```ruby
50
+
57
51
  require 'crabstone'
58
52
  include Crabstone
59
-
60
- arm = (
61
- "\xED\xFF\xFF\xEB\x04\xe0\x2d\xe5\x00\x00\x00\x00\xe0\x83\x22" <<
53
+ arm =
54
+ "\xED\xFF\xFF\xEB\x04\xe0\x2d\xe5\x00\x00\x00\x00\xe0\x83\x22" \
62
55
  "\xe5\xf1\x02\x03\x0e\x00\x00\xa0\xe3\x02\x30\xc1\xe7\x00\x00\x53\xe3"
63
- )
64
56
 
65
57
  begin
66
-
67
58
  cs = Disassembler.new(ARCH_ARM, MODE_ARM)
68
- puts "Hello from Capstone v #{cs.version.join('.')}!"
69
- puts "Disasm:"
59
+ puts "Hello from Capstone v#{cs.version.join('.')}!"
60
+ puts 'Disasm:'
70
61
 
71
62
  begin
72
- cs.disasm(arm, 0x1000).each {|i|
73
- printf("0x%x:\t%s\t\t%s\n",i.address, i.mnemonic, i.op_str)
74
- }
75
- rescue
76
- fail "Disassembly error: #{$!}"
63
+ cs.disasm(arm, 0x1000).each do |i|
64
+ printf("0x%x:\t%s\t\t%s\n", i.address, i.mnemonic, i.op_str)
65
+ end
66
+ rescue StandardError => e
67
+ raise "Disassembly error: #{e.message}"
77
68
  ensure
78
69
  cs.close
79
70
  end
80
-
81
- rescue
82
- fail "Unable to open engine: #{$!}"
71
+ rescue StandardError => e
72
+ raise "Unable to open engine: #{e.message}"
83
73
  end
84
74
  ```
85
75
 
86
- Interpreter Support:
87
- ----
88
-
89
- I test with JRuby >= 1.7.8, MRI >= 2.0.0. If it doesn't work with any of those
90
- it's a bug. If it doesn't work with like Rubinius or REE or 1.8 or whatever then
91
- "patches welcome". ( AFAIK it does, actually, work with rbx )
92
-
93
76
  Contributing:
94
77
  ----
95
78
 
@@ -1,564 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Library by Nguyen Anh Quynh
2
4
  # Original binding by Nguyen Anh Quynh and Tan Sheng Di
3
5
  # Additional binding work by Ben Nagy
4
6
  # (c) 2013 COSEINC. All Rights Reserved.
5
7
 
6
- require 'ffi'
7
-
8
- require_relative 'arch/x86'
9
- require_relative 'arch/x86_registers'
10
- require_relative 'arch/arm'
11
- require_relative 'arch/arm_registers'
12
- require_relative 'arch/arm64'
13
- require_relative 'arch/arm64_registers'
14
- require_relative 'arch/mips'
15
- require_relative 'arch/mips_registers'
16
- require_relative 'arch/ppc'
17
- require_relative 'arch/ppc_registers'
18
- require_relative 'arch/sparc'
19
- require_relative 'arch/sparc_registers'
20
- require_relative 'arch/systemz'
21
- require_relative 'arch/sysz_registers'
22
- require_relative 'arch/xcore'
23
- require_relative 'arch/xcore_registers'
24
-
25
8
  module Crabstone
26
-
27
- VERSION = '3.0.3'
28
-
29
- # API version
30
- BINDING_MAJ = 3
31
- BINDING_MIN = 0
32
-
33
- # architectures
34
- ARCH_ARM = 0
35
- ARCH_ARM64 = 1
36
- ARCH_MIPS = 2
37
- ARCH_X86 = 3
38
- ARCH_PPC = 4
39
- ARCH_SPARC = 5
40
- ARCH_SYSZ = 6
41
- ARCH_XCORE = 7
42
- ARCH_MAX = 8
43
- ARCH_ALL = 0xFFFF
44
-
45
- # disasm mode
46
- MODE_LITTLE_ENDIAN = 0 # little-endian mode (default mode)
47
- MODE_ARM = 0 # 32-bit ARM
48
- MODE_16 = 1 << 1 # 16-bit mode (X86)
49
- MODE_32 = 1 << 2 # 32-bit mode (X86)
50
- MODE_64 = 1 << 3 # 64-bit mode (X86, PPC)
51
- MODE_THUMB = 1 << 4 # ARM's Thumb mode, including Thumb-2
52
- MODE_MCLASS = 1 << 5 # ARM's Cortex-M series
53
- MODE_V8 = 1 << 6 # ARMv8 A32 encodings for ARM
54
- MODE_MICRO = 1 << 4 # MicroMips mode (MIPS)
55
- MODE_MIPS3 = 1 << 5 # Mips III ISA
56
- MODE_MIPS32R6 = 1 << 6 # Mips32r6 ISA
57
- MODE_MIPSGP64 = 1 << 7 # General Purpose Registers are 64-bit wide (MIPS)
58
- MODE_V9 = 1 << 4 # SparcV9 mode (Sparc)
59
- MODE_BIG_ENDIAN = 1 << 31 # big-endian mode
60
- MODE_MIPS32 = MODE_32 # Mips32 ISA (Mips)
61
- MODE_MIPS64 = MODE_64 # Mips64 ISA (Mips)
62
-
63
-
64
- # Capstone option type
65
- OPT_SYNTAX = 1 # Intel X86 asm syntax (ARCH_X86 arch)
66
- OPT_DETAIL = 2 # Break down instruction structure into details
67
- OPT_MODE = 3 # Change engine's mode at run-time
68
- OPT_MEM = 4 # Change engine's mode at run-time
69
- OPT_SKIPDATA = 5 # Skip data when disassembling
70
- OPT_SKIPDATA_SETUP = 6 # Setup user-defined function for SKIPDATA option
71
-
72
- # Capstone option value
73
- OPT_OFF = 0 # Turn OFF an option - default option of OPT_DETAIL
74
- OPT_ON = 3 # Turn ON an option (OPT_DETAIL)
75
-
76
- # Common instruction operand types - to be consistent across all architectures.
77
- OP_INVALID = 0
78
- OP_REG = 1
79
- OP_IMM = 2
80
- OP_MEM = 3
81
- OP_FP = 4
82
-
83
- # Common instruction groups - to be consistent across all architectures.
84
- GRP_INVALID = 0 # uninitialized/invalid group.
85
- GRP_JUMP = 1 # all jump instructions (conditional+direct+indirect jumps)
86
- GRP_CALL = 2 # all call instructions
87
- GRP_RET = 3 # all return instructions
88
- GRP_INT = 4 # all interrupt instructions (int+syscall)
89
- GRP_IRET = 5 # all interrupt return instructions
90
-
91
- # Capstone syntax value
92
- OPT_SYNTAX_DEFAULT = 0 # Default assembly syntax of all platforms (OPT_SYNTAX)
93
- OPT_SYNTAX_INTEL = 1 # Intel X86 asm syntax - default syntax on X86 (OPT_SYNTAX, ARCH_X86)
94
- OPT_SYNTAX_ATT = 2 # ATT asm syntax (OPT_SYNTAX, ARCH_X86)
95
- OPT_SYNTAX_NOREGNAME = 3 # Asm syntax prints register name with only number - (OPT_SYNTAX, ARCH_PPC, ARCH_ARM)
96
-
97
- # query id for cs_support()
98
- SUPPORT_DIET = ARCH_ALL + 1
99
- SUPPORT_X86_REDUCE = ARCH_ALL + 2
100
-
101
- SYNTAX = {
102
- :intel => 1,
103
- :att => 2,
104
- :no_regname => 3 # for PPC only
105
- }
106
-
107
- DETAIL = {
108
- true => 3, #trololol
109
- false => 0
110
- }
111
-
112
- SKIPDATA = {
113
- true => 3, #trololol
114
- false => 0
115
- }
116
-
117
- class ErrArch < StandardError; end
118
- class ErrCsh < StandardError; end
119
- class ErrHandle < StandardError; end
120
- class ErrMem < StandardError; end
121
- class ErrMode < StandardError; end
122
- class ErrOK < StandardError; end
123
- class ErrOption < StandardError; end
124
- class ErrDetail < StandardError; end
125
- class ErrMemSetup < StandardError; end
126
- class ErrVersion < StandardError; end
127
- class ErrDiet < StandardError; end
128
- class ErrSkipData < StandardError; end
129
- class ErrX86ATT < StandardError; end
130
- class ErrX86Intel < StandardError; end
131
-
132
- ERRNO = {
133
- 0 => ErrOK,
134
- 1 => ErrMem,
135
- 2 => ErrArch,
136
- 3 => ErrHandle,
137
- 4 => ErrCsh,
138
- 5 => ErrMode,
139
- 6 => ErrOption,
140
- 7 => ErrDetail,
141
- 8 => ErrMemSetup,
142
- 9 => ErrVersion,
143
- 10 => ErrDiet,
144
- 11 => ErrSkipData,
145
- 12 => ErrX86ATT,
146
- 13 => ErrX86Intel,
147
- }
148
-
149
- ERRNO_KLASS = ERRNO.invert
150
-
151
- def self.raise_errno errno
152
- err_klass = ERRNO[errno]
153
- raise RuntimeError, "Internal Error: Tried to raise unknown errno" unless err_klass
154
- err_str = Binding.cs_strerror(errno)
155
- raise err_klass, err_str
156
- end
157
-
158
- module Binding
159
-
160
- extend FFI::Library
161
- ffi_lib ['capstone', 'libcapstone.so.3']
162
-
163
- # This is because JRuby FFI on x64 Windows thinks size_t is 32 bit
164
- case FFI::Platform::ADDRESS_SIZE
165
- when 64
166
- typedef :ulong_long, :size_t
167
- when 32
168
- typedef :ulong, :size_t
169
- else
170
- fail "Unsupported native address size"
171
- end
172
-
173
- typedef :size_t, :csh
174
- typedef :size_t, :cs_opt_value
175
- typedef :uint, :cs_opt_type
176
- typedef :uint, :cs_err
177
- typedef :uint, :cs_arch
178
- typedef :uint, :cs_mode
179
-
180
- class Architecture < FFI::Union
181
- layout(
182
- :arm, ARM::Instruction,
183
- :arm64, ARM64::Instruction,
184
- :mips, MIPS::Instruction,
185
- :x86, X86::Instruction,
186
- :ppc, PPC::Instruction,
187
- :sparc, Sparc::Instruction,
188
- :sysz, SysZ::Instruction,
189
- :xcore, XCore::Instruction
190
- )
191
- end
192
-
193
- class Detail < FFI::Struct
194
- layout(
195
- :regs_read, [:uint8, 12],
196
- :regs_read_count, :uint8,
197
- :regs_write, [:uint8, 20],
198
- :regs_write_count, :uint8,
199
- :groups, [:uint8, 8],
200
- :groups_count, :uint8,
201
- :arch, Architecture
202
- )
203
- end
204
-
205
- class Instruction < FFI::ManagedStruct
206
- layout(
207
- :id, :uint,
208
- :address, :ulong_long,
209
- :size, :uint16,
210
- :bytes, [:uchar, 16],
211
- :mnemonic, [:char, 32],
212
- :op_str, [:char, 160],
213
- :detail, Detail.by_ref
214
- )
215
-
216
- def self.release(ptr)
217
- detail_ptr = ptr.+(Instruction.offset_of(:detail)).read_ptr
218
- Binding.free(detail_ptr)
219
- Binding.free(ptr)
220
- end
221
- end
222
-
223
- callback :skipdata_cb, [:pointer, :size_t, :size_t, :pointer], :size_t
224
-
225
- class SkipdataConfig < FFI::Struct
226
- layout(
227
- :mnemonic, :pointer,
228
- :callback, :skipdata_cb,
229
- :unused, :pointer
230
- )
231
- end
232
-
233
- attach_function(
234
- :cs_disasm,
235
- [:csh, :pointer, :size_t, :ulong_long, :size_t, :pointer],
236
- :size_t
237
- )
238
- attach_function :cs_close, [:pointer], :cs_err
239
- attach_function :cs_errno, [:csh], :cs_err
240
- attach_function :cs_group_name, [:csh, :uint], :string
241
- attach_function :cs_insn_group, [:csh, Instruction, :uint], :bool
242
- attach_function :cs_insn_name, [:csh, :uint], :string
243
- attach_function :cs_op_count, [:csh, Instruction, :uint], :cs_err
244
- attach_function :cs_open, [:cs_arch, :cs_mode, :pointer], :cs_err
245
- attach_function :cs_option, [:csh, :cs_opt_type, :cs_opt_value], :cs_err
246
- attach_function :cs_reg_name, [:csh, :uint], :string
247
- attach_function :cs_reg_read, [:csh, Instruction, :uint], :bool
248
- attach_function :cs_reg_write, [:csh, Instruction, :uint], :bool
249
- attach_function :cs_strerror, [:cs_err], :string
250
- attach_function :cs_support, [:cs_arch], :bool
251
- attach_function :cs_version, [:pointer, :pointer], :uint
252
- attach_function :memcpy, [:pointer, :pointer, :size_t], :pointer
253
- attach_function :malloc, [:size_t], :pointer
254
- attach_function :free, [:pointer], :void
255
-
256
- end # Binding
257
-
258
- # This is a C engine build option, so we can set it here, not when we
259
- # instantiate a new Disassembler.
260
- DIET_MODE = Binding.cs_support SUPPORT_DIET
261
- # Diet mode means:
262
- # - No op_str or mnemonic in Instruction
263
- # - No regs_read, regs_write or groups ( even with detail on )
264
- # - No reg_name or insn_name id2str convenience functions
265
- # - detail mode CAN still be on - so the arch insn operands MAY be available
266
-
267
- class Instruction
268
-
269
- attr_reader :arch, :csh, :raw_insn
270
-
271
- ARCHS = {
272
- arm: ARCH_ARM,
273
- arm64: ARCH_ARM64,
274
- x86: ARCH_X86,
275
- mips: ARCH_MIPS,
276
- ppc: ARCH_PPC,
277
- sparc: ARCH_SPARC,
278
- sysz: ARCH_SYSZ,
279
- xcore: ARCH_XCORE
280
- }.invert
281
-
282
- ARCH_CLASSES = {
283
- ARCH_ARM => ARM,
284
- ARCH_ARM64 => ARM64,
285
- ARCH_X86 => X86,
286
- ARCH_MIPS => MIPS,
287
- ARCH_PPC => PPC,
288
- ARCH_SPARC => Sparc,
289
- ARCH_SYSZ => SysZ,
290
- ARCH_XCORE => XCore
291
- }
292
-
293
- def initialize csh, insn, arch
294
- @arch = arch
295
- @csh = csh
296
- @raw_insn = insn
297
- if detailed?
298
- @detail = insn[:detail]
299
- @arch_insn = @detail[:arch][ARCHS[arch]]
300
- @regs_read = @detail[:regs_read].first( @detail[:regs_read_count] )
301
- @regs_write = @detail[:regs_write].first( @detail[:regs_write_count] )
302
- @groups = @detail[:groups].first( @detail[:groups_count] )
303
- end
304
- end
305
-
306
- def name
307
- raise_if_diet
308
- name = Binding.cs_insn_name(csh, id)
309
- Crabstone.raise_errno( ERRNO_KLASS[ErrCsh] ) unless name
310
- name
311
- end
312
-
313
- def group_name grp
314
- raise_if_diet
315
- name = Binding.cs_group_name(csh, Integer(grp))
316
- Crabstone.raise_errno( ERRNO_KLASS[ErrCsh] ) unless name
317
- name
318
- end
319
-
320
- # It's more informative to raise if CS_DETAIL is off than just return nil
321
- def detailed?
322
- not @raw_insn[:detail].pointer.null?
323
- end
324
-
325
- def detail
326
- raise_unless_detailed
327
- @detail
328
- end
329
-
330
- def regs_read
331
- raise_unless_detailed
332
- raise_if_diet
333
- @regs_read
334
- end
335
-
336
- def regs_write
337
- raise_unless_detailed
338
- raise_if_diet
339
- @regs_write
340
- end
341
-
342
- def groups
343
- raise_unless_detailed
344
- raise_if_diet
345
- @groups
346
- end
347
-
348
- def group? groupid
349
- raise_unless_detailed
350
- raise_if_diet
351
- Binding.cs_insn_group csh, raw_insn, groupid
352
- end
353
-
354
- def reads_reg? reg
355
- raise_unless_detailed
356
- raise_if_diet
357
- Binding.cs_reg_read csh, raw_insn, ARCH_CLASSES[arch].register( reg )
358
- end
359
-
360
- def writes_reg? reg
361
- raise_unless_detailed
362
- raise_if_diet
363
- Binding.cs_reg_write csh, raw_insn, ARCH_CLASSES[arch].register( reg )
364
- end
365
-
366
- def mnemonic
367
- raise_if_diet
368
- raw_insn[:mnemonic]
369
- end
370
-
371
- def op_str
372
- raise_if_diet
373
- raw_insn[:op_str]
374
- end
375
-
376
- def op_count op_type=nil
377
- raise_unless_detailed
378
- if op_type
379
- Binding.cs_op_count csh, raw_insn, op_type
380
- else
381
- self.operands.size
382
- end
383
- end
384
-
385
- def bytes
386
- raw_insn[:bytes].first raw_insn[:size]
387
- end
388
-
389
- # So an Instruction should respond to all the methods in Instruction, and
390
- # all the methods in the Arch specific Instruction class. The methods /
391
- # members that have special handling for detail mode or diet mode are
392
- # handled above. The rest is dynamically dispatched below.
393
- def method_missing meth, *args
394
- if raw_insn.members.include? meth
395
- # Dispatch to toplevel Instruction class ( this file )
396
- raw_insn[meth]
397
- else
398
- # Nothing else is available without details.
399
- if not detailed?
400
- raise(
401
- NoMethodError,
402
- "Either CS_DETAIL is off, or #{self.class} doesn't implement #{meth}"
403
- )
404
- end
405
- # Dispatch to the architecture specific Instruction ( in arch/ )
406
- if @arch_insn.respond_to? meth
407
- @arch_insn.send meth, *args
408
- elsif @arch_insn.members.include? meth
409
- @arch_insn[meth]
410
- else
411
- raise NoMethodError, "Unknown method #{meth} for #{self.class}"
412
- end
413
- end
414
- end
415
-
416
- private
417
-
418
- def raise_unless_detailed
419
- Crabstone.raise_errno( Crabstone::ERRNO_KLASS[ErrDetail] ) unless detailed?
420
- end
421
-
422
- def raise_if_diet
423
- Crabstone.raise_errno( Crabstone::ERRNO_KLASS[ErrDiet] ) if DIET_MODE
424
- end
425
-
426
- end
427
-
428
-
429
- class Disassembler
430
-
431
- attr_reader :arch, :mode, :csh, :syntax, :decomposer
432
-
433
- def initialize arch, mode
434
-
435
- maj, min = version
436
- if maj != BINDING_MAJ || min != BINDING_MIN
437
- raise "FATAL: Binding for #{BINDING_MAJ}.#{BINDING_MIN}, found #{maj}.#{min}"
438
- end
439
-
440
- @arch = arch
441
- @mode = mode
442
- p_size_t = FFI::MemoryPointer.new :ulong_long
443
- @p_csh = FFI::MemoryPointer.new p_size_t
444
- if ( res = Binding.cs_open( arch, mode, @p_csh )).nonzero?
445
- Crabstone.raise_errno res
446
- end
447
-
448
- @csh = @p_csh.read_ulong_long
449
-
450
- end
451
-
452
- # After you close the engine, don't use it anymore. Can't believe I even
453
- # have to write this.
454
- def close
455
- if ( res = Binding.cs_close(@p_csh) ).nonzero?
456
- Crabstone.raise_errno res
457
- end
458
- end
459
-
460
- def syntax= new_stx
461
- Crabstone.raise_errno( Crabstone::ERRNO_KLASS[ErrOption] ) unless SYNTAX[new_stx]
462
- res = Binding.cs_option(csh, OPT_SYNTAX, SYNTAX[new_stx])
463
- Crabstone.raise_errno res if res.nonzero?
464
- @syntax = new_stx
465
- end
466
-
467
- def decomposer= new_val
468
- res = Binding.cs_option(csh, OPT_DETAIL, DETAIL[!!(new_val)])
469
- Crabstone.raise_errno res if res.nonzero?
470
- @decomposer = !!(new_val)
471
- end
472
-
473
- def version
474
- maj = FFI::MemoryPointer.new(:int)
475
- min = FFI::MemoryPointer.new(:int)
476
- Binding.cs_version maj, min
477
- [ maj.read_int, min.read_int ]
478
- end
479
-
480
- def diet?
481
- DIET_MODE
482
- end
483
-
484
- def errno
485
- Binding.cs_errno(csh)
486
- end
487
-
488
- def skipdata mnemonic='.byte'
489
-
490
- cfg = Binding::SkipdataConfig.new
491
- cfg[:mnemonic] = FFI::MemoryPointer.from_string String(mnemonic)
492
-
493
- if block_given?
494
-
495
- real_cb = FFI::Function.new(
496
- :size_t,
497
- [:pointer, :size_t, :size_t, :pointer]
498
- ) {|code, sz, offset, _|
499
-
500
- code = code.read_array_of_uchar(sz).pack('c*')
501
- begin
502
- res = yield code, offset
503
- Integer(res)
504
- rescue
505
- warn "Error in skipdata callback: #{$!}"
506
- # It will go on to crash, but now at least there's more info :)
507
- end
508
- }
509
-
510
- cfg[:callback] = real_cb
511
-
512
- end
513
-
514
- res = Binding.cs_option(csh, OPT_SKIPDATA_SETUP, cfg.pointer.address)
515
- Crabstone.raise_errno res if res.nonzero?
516
- res = Binding.cs_option(csh, OPT_SKIPDATA, SKIPDATA[true])
517
- Crabstone.raise_errno res if res.nonzero?
518
- end
519
-
520
- def skipdata_off
521
- res = Binding.cs_option(csh, OPT_SKIPDATA, SKIPDATA[false])
522
- Crabstone.raise_errno res if res.nonzero?
523
- end
524
-
525
- def reg_name regid
526
- Crabstone.raise_errno( Crabstone::ERRNO_KLASS[ErrDiet] ) if DIET_MODE
527
- name = Binding.cs_reg_name(csh, regid)
528
- Crabstone.raise_errno( Crabstone::ERRNO_KLASS[ErrCsh] ) unless name
529
- name
530
- end
531
-
532
- def disasm code, offset, count = 0
533
- return [] if code.empty?
534
-
535
- insn_ptr = FFI::MemoryPointer.new :pointer
536
- insn_count = Binding.cs_disasm(
537
- @csh,
538
- code,
539
- code.bytesize,
540
- offset,
541
- count,
542
- insn_ptr
543
- )
544
- Crabstone.raise_errno(errno) if insn_count.zero?
545
-
546
- insns = (0...insn_count * Binding::Instruction.size).step(Binding::Instruction.size).map do |off|
547
- cs_insn_ptr = Binding.malloc Binding::Instruction.size
548
- cs_insn = Binding::Instruction.new cs_insn_ptr
549
- Binding.memcpy(cs_insn_ptr, insn_ptr.read_pointer + off, Binding::Instruction.size)
550
- Instruction.new @csh, cs_insn, @arch
551
- end
552
-
553
- Binding.free(insn_ptr.read_pointer)
554
-
555
- insns
556
- end
557
-
558
- def set_raw_option opt, val
559
- res = Binding.cs_option csh, opt, val
560
- Crabstone.raise_errno res if res.nonzero?
561
- end
562
-
563
- end
564
9
  end
10
+
11
+ require 'crabstone/disassembler'
12
+ require 'crabstone/version'