metasm 1.0.0 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (276) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +3 -0
  4. data/.gitignore +3 -0
  5. data/.hgtags +3 -0
  6. data/Gemfile +3 -0
  7. data/INSTALL +61 -0
  8. data/LICENCE +458 -0
  9. data/README +29 -21
  10. data/Rakefile +10 -0
  11. data/TODO +10 -12
  12. data/doc/code_organisation.txt +3 -1
  13. data/doc/core/DynLdr.txt +247 -0
  14. data/doc/core/ExeFormat.txt +43 -0
  15. data/doc/core/Expression.txt +220 -0
  16. data/doc/core/GNUExports.txt +27 -0
  17. data/doc/core/Ia32.txt +236 -0
  18. data/doc/core/SerialStruct.txt +108 -0
  19. data/doc/core/VirtualString.txt +145 -0
  20. data/doc/core/WindowsExports.txt +61 -0
  21. data/doc/core/index.txt +1 -0
  22. data/doc/style.css +6 -3
  23. data/doc/usage/debugger.txt +327 -0
  24. data/doc/usage/index.txt +1 -0
  25. data/doc/use_cases.txt +2 -2
  26. data/metasm.gemspec +23 -0
  27. data/{lib/metasm.rb → metasm.rb} +15 -3
  28. data/{lib/metasm → metasm}/compile_c.rb +15 -9
  29. data/metasm/cpu/arc.rb +8 -0
  30. data/metasm/cpu/arc/decode.rb +404 -0
  31. data/metasm/cpu/arc/main.rb +191 -0
  32. data/metasm/cpu/arc/opcodes.rb +588 -0
  33. data/metasm/cpu/arm.rb +14 -0
  34. data/{lib/metasm → metasm/cpu}/arm/debug.rb +2 -2
  35. data/{lib/metasm → metasm/cpu}/arm/decode.rb +15 -18
  36. data/{lib/metasm → metasm/cpu}/arm/encode.rb +23 -8
  37. data/{lib/metasm → metasm/cpu}/arm/main.rb +3 -6
  38. data/metasm/cpu/arm/opcodes.rb +324 -0
  39. data/{lib/metasm → metasm/cpu}/arm/parse.rb +25 -13
  40. data/{lib/metasm → metasm/cpu}/arm/render.rb +2 -2
  41. data/metasm/cpu/arm64.rb +15 -0
  42. data/metasm/cpu/arm64/debug.rb +38 -0
  43. data/metasm/cpu/arm64/decode.rb +285 -0
  44. data/metasm/cpu/arm64/encode.rb +41 -0
  45. data/metasm/cpu/arm64/main.rb +105 -0
  46. data/metasm/cpu/arm64/opcodes.rb +232 -0
  47. data/metasm/cpu/arm64/parse.rb +20 -0
  48. data/metasm/cpu/arm64/render.rb +95 -0
  49. data/{lib/metasm/mips/compile_c.rb → metasm/cpu/bpf.rb} +4 -2
  50. data/metasm/cpu/bpf/decode.rb +110 -0
  51. data/metasm/cpu/bpf/main.rb +60 -0
  52. data/metasm/cpu/bpf/opcodes.rb +81 -0
  53. data/metasm/cpu/bpf/render.rb +30 -0
  54. data/{lib/metasm/ppc.rb → metasm/cpu/cy16.rb} +2 -4
  55. data/metasm/cpu/cy16/decode.rb +247 -0
  56. data/metasm/cpu/cy16/main.rb +63 -0
  57. data/metasm/cpu/cy16/opcodes.rb +78 -0
  58. data/metasm/cpu/cy16/render.rb +30 -0
  59. data/metasm/cpu/dalvik.rb +11 -0
  60. data/{lib/metasm → metasm/cpu}/dalvik/decode.rb +34 -34
  61. data/{lib/metasm → metasm/cpu}/dalvik/main.rb +71 -4
  62. data/{lib/metasm → metasm/cpu}/dalvik/opcodes.rb +21 -12
  63. data/{lib/metasm/mips.rb → metasm/cpu/ebpf.rb} +3 -4
  64. data/metasm/cpu/ebpf/debug.rb +61 -0
  65. data/metasm/cpu/ebpf/decode.rb +142 -0
  66. data/metasm/cpu/ebpf/main.rb +58 -0
  67. data/metasm/cpu/ebpf/opcodes.rb +97 -0
  68. data/metasm/cpu/ebpf/render.rb +36 -0
  69. data/metasm/cpu/ia32.rb +17 -0
  70. data/{lib/metasm → metasm/cpu}/ia32/compile_c.rb +23 -9
  71. data/{lib/metasm → metasm/cpu}/ia32/debug.rb +44 -6
  72. data/{lib/metasm → metasm/cpu}/ia32/decode.rb +342 -128
  73. data/{lib/metasm → metasm/cpu}/ia32/decompile.rb +75 -53
  74. data/{lib/metasm → metasm/cpu}/ia32/encode.rb +19 -13
  75. data/{lib/metasm → metasm/cpu}/ia32/main.rb +66 -8
  76. data/metasm/cpu/ia32/opcodes.rb +1424 -0
  77. data/{lib/metasm → metasm/cpu}/ia32/parse.rb +55 -17
  78. data/{lib/metasm → metasm/cpu}/ia32/render.rb +32 -5
  79. data/metasm/cpu/mcs51.rb +8 -0
  80. data/metasm/cpu/mcs51/decode.rb +99 -0
  81. data/metasm/cpu/mcs51/main.rb +87 -0
  82. data/metasm/cpu/mcs51/opcodes.rb +120 -0
  83. data/metasm/cpu/mips.rb +14 -0
  84. data/metasm/cpu/mips/debug.rb +42 -0
  85. data/{lib/metasm → metasm/cpu}/mips/decode.rb +59 -38
  86. data/{lib/metasm → metasm/cpu}/mips/encode.rb +4 -3
  87. data/{lib/metasm → metasm/cpu}/mips/main.rb +13 -6
  88. data/{lib/metasm → metasm/cpu}/mips/opcodes.rb +87 -18
  89. data/{lib/metasm → metasm/cpu}/mips/parse.rb +1 -1
  90. data/{lib/metasm → metasm/cpu}/mips/render.rb +1 -1
  91. data/{lib/metasm/dalvik.rb → metasm/cpu/msp430.rb} +1 -1
  92. data/metasm/cpu/msp430/decode.rb +243 -0
  93. data/metasm/cpu/msp430/main.rb +62 -0
  94. data/metasm/cpu/msp430/opcodes.rb +101 -0
  95. data/metasm/cpu/openrisc.rb +11 -0
  96. data/metasm/cpu/openrisc/debug.rb +106 -0
  97. data/metasm/cpu/openrisc/decode.rb +182 -0
  98. data/metasm/cpu/openrisc/decompile.rb +350 -0
  99. data/metasm/cpu/openrisc/main.rb +70 -0
  100. data/metasm/cpu/openrisc/opcodes.rb +109 -0
  101. data/metasm/cpu/openrisc/render.rb +37 -0
  102. data/{lib/metasm → metasm/cpu}/pic16c/decode.rb +6 -7
  103. data/{lib/metasm → metasm/cpu}/pic16c/main.rb +0 -0
  104. data/{lib/metasm → metasm/cpu}/pic16c/opcodes.rb +1 -1
  105. data/metasm/cpu/ppc.rb +11 -0
  106. data/{lib/metasm → metasm/cpu}/ppc/decode.rb +18 -37
  107. data/{lib/metasm → metasm/cpu}/ppc/decompile.rb +3 -3
  108. data/{lib/metasm → metasm/cpu}/ppc/encode.rb +2 -2
  109. data/{lib/metasm → metasm/cpu}/ppc/main.rb +23 -18
  110. data/{lib/metasm → metasm/cpu}/ppc/opcodes.rb +11 -6
  111. data/metasm/cpu/ppc/parse.rb +55 -0
  112. data/metasm/cpu/python.rb +8 -0
  113. data/metasm/cpu/python/decode.rb +116 -0
  114. data/metasm/cpu/python/main.rb +36 -0
  115. data/metasm/cpu/python/opcodes.rb +180 -0
  116. data/{lib/metasm → metasm/cpu}/sh4.rb +1 -1
  117. data/{lib/metasm → metasm/cpu}/sh4/decode.rb +50 -23
  118. data/{lib/metasm → metasm/cpu}/sh4/main.rb +38 -27
  119. data/{lib/metasm → metasm/cpu}/sh4/opcodes.rb +7 -8
  120. data/metasm/cpu/st20.rb +9 -0
  121. data/metasm/cpu/st20/decode.rb +173 -0
  122. data/metasm/cpu/st20/decompile.rb +283 -0
  123. data/metasm/cpu/st20/main.rb +37 -0
  124. data/metasm/cpu/st20/opcodes.rb +140 -0
  125. data/{lib/metasm/arm.rb → metasm/cpu/webasm.rb} +4 -5
  126. data/metasm/cpu/webasm/debug.rb +31 -0
  127. data/metasm/cpu/webasm/decode.rb +321 -0
  128. data/metasm/cpu/webasm/decompile.rb +386 -0
  129. data/metasm/cpu/webasm/encode.rb +104 -0
  130. data/metasm/cpu/webasm/main.rb +81 -0
  131. data/metasm/cpu/webasm/opcodes.rb +214 -0
  132. data/metasm/cpu/x86_64.rb +15 -0
  133. data/{lib/metasm → metasm/cpu}/x86_64/compile_c.rb +40 -25
  134. data/{lib/metasm → metasm/cpu}/x86_64/debug.rb +4 -4
  135. data/{lib/metasm → metasm/cpu}/x86_64/decode.rb +58 -15
  136. data/{lib/metasm → metasm/cpu}/x86_64/encode.rb +59 -28
  137. data/{lib/metasm → metasm/cpu}/x86_64/main.rb +18 -6
  138. data/metasm/cpu/x86_64/opcodes.rb +138 -0
  139. data/{lib/metasm → metasm/cpu}/x86_64/parse.rb +12 -4
  140. data/metasm/cpu/x86_64/render.rb +35 -0
  141. data/metasm/cpu/z80.rb +9 -0
  142. data/metasm/cpu/z80/decode.rb +286 -0
  143. data/metasm/cpu/z80/main.rb +67 -0
  144. data/metasm/cpu/z80/opcodes.rb +224 -0
  145. data/metasm/cpu/z80/render.rb +48 -0
  146. data/{lib/metasm/os/main.rb → metasm/debug.rb} +201 -407
  147. data/{lib/metasm → metasm}/decode.rb +104 -24
  148. data/{lib/metasm → metasm}/decompile.rb +804 -478
  149. data/{lib/metasm → metasm}/disassemble.rb +385 -170
  150. data/{lib/metasm → metasm}/disassemble_api.rb +684 -105
  151. data/{lib/metasm → metasm}/dynldr.rb +231 -138
  152. data/{lib/metasm → metasm}/encode.rb +20 -5
  153. data/{lib/metasm → metasm}/exe_format/a_out.rb +9 -6
  154. data/{lib/metasm → metasm}/exe_format/autoexe.rb +3 -0
  155. data/{lib/metasm → metasm}/exe_format/bflt.rb +57 -27
  156. data/{lib/metasm → metasm}/exe_format/coff.rb +35 -7
  157. data/{lib/metasm → metasm}/exe_format/coff_decode.rb +70 -23
  158. data/{lib/metasm → metasm}/exe_format/coff_encode.rb +24 -22
  159. data/{lib/metasm → metasm}/exe_format/dex.rb +26 -8
  160. data/{lib/metasm → metasm}/exe_format/dol.rb +1 -0
  161. data/{lib/metasm → metasm}/exe_format/elf.rb +108 -58
  162. data/{lib/metasm → metasm}/exe_format/elf_decode.rb +202 -36
  163. data/{lib/metasm → metasm}/exe_format/elf_encode.rb +126 -32
  164. data/metasm/exe_format/gb.rb +65 -0
  165. data/metasm/exe_format/javaclass.rb +424 -0
  166. data/{lib/metasm → metasm}/exe_format/macho.rb +218 -16
  167. data/{lib/metasm → metasm}/exe_format/main.rb +28 -3
  168. data/{lib/metasm → metasm}/exe_format/mz.rb +2 -0
  169. data/{lib/metasm → metasm}/exe_format/nds.rb +7 -4
  170. data/{lib/metasm → metasm}/exe_format/pe.rb +96 -11
  171. data/metasm/exe_format/pyc.rb +167 -0
  172. data/{lib/metasm → metasm}/exe_format/serialstruct.rb +67 -14
  173. data/{lib/metasm → metasm}/exe_format/shellcode.rb +7 -3
  174. data/metasm/exe_format/shellcode_rwx.rb +114 -0
  175. data/metasm/exe_format/swf.rb +205 -0
  176. data/metasm/exe_format/wasm.rb +402 -0
  177. data/{lib/metasm → metasm}/exe_format/xcoff.rb +7 -7
  178. data/metasm/exe_format/zip.rb +335 -0
  179. data/metasm/gui.rb +13 -0
  180. data/{lib/metasm → metasm}/gui/cstruct.rb +35 -41
  181. data/{lib/metasm → metasm}/gui/dasm_coverage.rb +11 -11
  182. data/{lib/metasm → metasm}/gui/dasm_decomp.rb +177 -114
  183. data/{lib/metasm → metasm}/gui/dasm_funcgraph.rb +0 -0
  184. data/metasm/gui/dasm_graph.rb +1754 -0
  185. data/{lib/metasm → metasm}/gui/dasm_hex.rb +16 -12
  186. data/{lib/metasm → metasm}/gui/dasm_listing.rb +43 -28
  187. data/{lib/metasm → metasm}/gui/dasm_main.rb +360 -77
  188. data/{lib/metasm → metasm}/gui/dasm_opcodes.rb +5 -19
  189. data/{lib/metasm → metasm}/gui/debug.rb +109 -34
  190. data/{lib/metasm → metasm}/gui/gtk.rb +174 -44
  191. data/{lib/metasm → metasm}/gui/qt.rb +14 -4
  192. data/{lib/metasm → metasm}/gui/win32.rb +180 -43
  193. data/{lib/metasm → metasm}/gui/x11.rb +59 -59
  194. data/{lib/metasm → metasm}/main.rb +421 -286
  195. data/metasm/os/emulator.rb +175 -0
  196. data/{lib/metasm/os/remote.rb → metasm/os/gdbremote.rb} +146 -54
  197. data/{lib/metasm → metasm}/os/gnu_exports.rb +1 -1
  198. data/{lib/metasm → metasm}/os/linux.rb +628 -151
  199. data/metasm/os/main.rb +335 -0
  200. data/{lib/metasm → metasm}/os/windows.rb +151 -58
  201. data/{lib/metasm → metasm}/os/windows_exports.rb +141 -0
  202. data/{lib/metasm → metasm}/parse.rb +49 -36
  203. data/{lib/metasm → metasm}/parse_c.rb +405 -246
  204. data/{lib/metasm → metasm}/preprocessor.rb +71 -41
  205. data/{lib/metasm → metasm}/render.rb +14 -38
  206. data/misc/hexdump.rb +4 -3
  207. data/misc/lint.rb +58 -0
  208. data/misc/objdiff.rb +4 -1
  209. data/misc/objscan.rb +1 -1
  210. data/misc/openrisc-parser.rb +79 -0
  211. data/misc/txt2html.rb +9 -7
  212. data/samples/bindiff.rb +3 -4
  213. data/samples/dasm-plugins/bindiff.rb +15 -0
  214. data/samples/dasm-plugins/bookmark.rb +133 -0
  215. data/samples/dasm-plugins/c_constants.rb +57 -0
  216. data/samples/dasm-plugins/colortheme_solarized.rb +125 -0
  217. data/samples/dasm-plugins/cppobj_funcall.rb +60 -0
  218. data/samples/dasm-plugins/dasm_all.rb +70 -0
  219. data/samples/dasm-plugins/demangle_cpp.rb +31 -0
  220. data/samples/dasm-plugins/deobfuscate.rb +251 -0
  221. data/samples/dasm-plugins/dump_text.rb +35 -0
  222. data/samples/dasm-plugins/export_graph_svg.rb +86 -0
  223. data/samples/dasm-plugins/findgadget.rb +75 -0
  224. data/samples/dasm-plugins/hl_opcode.rb +32 -0
  225. data/samples/dasm-plugins/hotfix_gtk_dbg.rb +19 -0
  226. data/samples/dasm-plugins/imm2off.rb +34 -0
  227. data/samples/dasm-plugins/match_libsigs.rb +93 -0
  228. data/samples/dasm-plugins/patch_file.rb +95 -0
  229. data/samples/dasm-plugins/scanfuncstart.rb +36 -0
  230. data/samples/dasm-plugins/scanxrefs.rb +29 -0
  231. data/samples/dasm-plugins/selfmodify.rb +197 -0
  232. data/samples/dasm-plugins/stringsxrefs.rb +28 -0
  233. data/samples/dasmnavig.rb +1 -1
  234. data/samples/dbg-apihook.rb +24 -9
  235. data/samples/dbg-plugins/heapscan.rb +283 -0
  236. data/samples/dbg-plugins/heapscan/compiled_heapscan_lin.c +155 -0
  237. data/samples/dbg-plugins/heapscan/compiled_heapscan_win.c +128 -0
  238. data/samples/dbg-plugins/heapscan/graphheap.rb +616 -0
  239. data/samples/dbg-plugins/heapscan/heapscan.rb +709 -0
  240. data/samples/dbg-plugins/heapscan/winheap.h +174 -0
  241. data/samples/dbg-plugins/heapscan/winheap7.h +307 -0
  242. data/samples/dbg-plugins/trace_func.rb +214 -0
  243. data/samples/disassemble-gui.rb +48 -7
  244. data/samples/disassemble.rb +31 -6
  245. data/samples/dump_upx.rb +24 -12
  246. data/samples/dynamic_ruby.rb +35 -27
  247. data/samples/elfencode.rb +15 -0
  248. data/samples/emubios.rb +251 -0
  249. data/samples/emudbg.rb +127 -0
  250. data/samples/exeencode.rb +6 -5
  251. data/samples/factorize-headers-peimports.rb +1 -1
  252. data/samples/lindebug.rb +186 -391
  253. data/samples/metasm-shell.rb +68 -57
  254. data/samples/peldr.rb +2 -2
  255. data/tests/all.rb +1 -1
  256. data/tests/arc.rb +26 -0
  257. data/tests/dynldr.rb +22 -4
  258. data/tests/expression.rb +57 -0
  259. data/tests/graph_layout.rb +285 -0
  260. data/tests/ia32.rb +80 -26
  261. data/tests/mcs51.rb +27 -0
  262. data/tests/mips.rb +10 -3
  263. data/tests/preprocessor.rb +18 -0
  264. data/tests/x86_64.rb +66 -18
  265. metadata +465 -219
  266. metadata.gz.sig +2 -0
  267. data/lib/metasm/arm/opcodes.rb +0 -177
  268. data/lib/metasm/gui.rb +0 -23
  269. data/lib/metasm/gui/dasm_graph.rb +0 -1354
  270. data/lib/metasm/ia32.rb +0 -14
  271. data/lib/metasm/ia32/opcodes.rb +0 -872
  272. data/lib/metasm/ppc/parse.rb +0 -52
  273. data/lib/metasm/x86_64.rb +0 -12
  274. data/lib/metasm/x86_64/opcodes.rb +0 -118
  275. data/samples/gdbclient.rb +0 -583
  276. data/samples/rubstop.rb +0 -399
@@ -0,0 +1,106 @@
1
+ # This file is part of Metasm, the Ruby assembly manipulation suite
2
+ # Copyright (C) 2006-2009 Yoann GUILLOT
3
+ #
4
+ # Licence is LGPL, see LICENCE in the top-level directory
5
+
6
+
7
+ require 'metasm/cpu/openrisc/opcodes'
8
+
9
+ module Metasm
10
+ class OpenRisc
11
+ def dbg_register_pc
12
+ @dbg_register_pc ||= :pc
13
+ end
14
+ def dbg_register_sp
15
+ @dbg_register_sp ||= :r1
16
+ end
17
+
18
+ def dbg_register_list
19
+ @dbg_register_list ||= (1..31).to_a.map { |i| "r#{i}".to_sym } + [:pc, :nextpc, :flag]
20
+ end
21
+
22
+ def dbg_flag_list
23
+ @dbg_flag_list ||= []
24
+ end
25
+
26
+ def dbg_register_size
27
+ @dbg_register_size ||= Hash.new(32)
28
+ end
29
+
30
+ def get_fwdemu_binding(di, pc_reg=nil, dbg_ctx=nil)
31
+ fbd = di.backtrace_binding ||= get_backtrace_binding(di)
32
+ fbd = fix_fwdemu_binding(di, fbd)
33
+ if pc_reg
34
+ if @delay_slot == 0
35
+ n_a = Expression[pc_reg, :+, 4]
36
+ else
37
+ n_a = Expression[:nextpc, :+, 4]
38
+ end
39
+ if di.opcode.props[:setip]
40
+ xr = get_xrefs_x(nil, di).to_a
41
+ xr |= [n_a] if not di.opcode.props[:stopexec]
42
+ if xr.length == 1
43
+ if @delay_slot == 0
44
+ fbd[pc_reg] = xr[0]
45
+ else
46
+ fbd[pc_reg] = Expression[:nextpc]
47
+ fbd[:nextpc] = xr[0]
48
+ end
49
+ else
50
+ dbg_resolve_pc(di, fbd, pc_reg, dbg_ctx)
51
+ end
52
+ else
53
+ if @delay_slot == 0
54
+ fbd[pc_reg] = n_a
55
+ else
56
+ fbd[pc_reg] = Expression[:nextpc]
57
+ fbd[:nextpc] = n_a
58
+ end
59
+ end
60
+ end
61
+ fbd
62
+ end
63
+
64
+ def dbg_resolve_pc(di, fbd, pc_reg, dbg_ctx)
65
+ a = di.instruction.args.map { |aa| symbolic(aa) }
66
+
67
+ cond = case di.opcode.name
68
+ when 'bf'; dbg_ctx.get_reg_value(:flag) != 0
69
+ when 'bnf'; dbg_ctx.get_reg_value(:flag) == 0
70
+ else return super(di, fbd, pc_reg, dbg_ctx)
71
+ end
72
+
73
+ if cond
74
+ n_a = a.last
75
+ else
76
+ if @delay_slot == 0
77
+ n_a = di.next_addr + 4
78
+ else
79
+ n_a = Expression[:nextpc, :+, 4]
80
+ end
81
+ end
82
+
83
+ if @delay_slot == 0
84
+ fbd[pc_reg] = n_a
85
+ else
86
+ fbd[pc_reg] = Expression[:nextpc]
87
+ fbd[:nextpc] = n_a
88
+ end
89
+ end
90
+
91
+ def dbg_enable_bp(dbg, bp)
92
+ end
93
+
94
+ def dbg_disable_bp(dbg, bp)
95
+ end
96
+
97
+ def dbg_need_stepover(dbg, addr, di)
98
+ if @delay_slot == 0
99
+ di.opcode.props[:saveip]
100
+ else
101
+ ddi = dbg.disassembler.di_at(addr-4)
102
+ ddi and ddi.opcode.props[:saveip]
103
+ end
104
+ end
105
+ end
106
+ end
@@ -0,0 +1,182 @@
1
+ # This file is part of Metasm, the Ruby assembly manipulation suite
2
+ # Copyright (C) 2006-2009 Yoann GUILLOT
3
+ #
4
+ # Licence is LGPL, see LICENCE in the top-level directory
5
+
6
+
7
+ require 'metasm/cpu/openrisc/opcodes'
8
+ require 'metasm/decode'
9
+
10
+ module Metasm
11
+ class OpenRisc
12
+ def build_bin_lookaside
13
+ bl = Array.new(255) { [] }
14
+ opcode_list.each { |op|
15
+ ((op.bin >> 24) .. ((op.bin | op.bin_mask) >> 24)).each { |b|
16
+ if (b | (op.bin_mask >> 24)) == ((op.bin | op.bin_mask) >> 24)
17
+ bl[b] << op
18
+ end
19
+ }
20
+ }
21
+ bl
22
+ end
23
+
24
+ # tries to find the opcode encoded at edata.ptr
25
+ def decode_findopcode(edata)
26
+ return if edata.ptr > edata.data.length-4
27
+ di = DecodedInstruction.new self
28
+ val = edata.decode_imm(:u32, @endianness)
29
+ di.misc = val
30
+ return di if di.opcode = @bin_lookaside[val >> 24].find { |op|
31
+ (op.bin | op.bin_mask) == (val | op.bin_mask)
32
+ }
33
+ end
34
+
35
+ def decode_instr_op(edata, di)
36
+ op = di.opcode
37
+ di.instruction.opname = op.name
38
+ di.bin_length = 4
39
+ val = di.misc
40
+ fld = lambda { |f|
41
+ (val >> @fields_off[f]) & @fields_mask[f]
42
+ }
43
+ sign_fld = lambda { |f, sz|
44
+ Expression.make_signed(Expression[fld[f]], sz).reduce
45
+ }
46
+ fld_smoo = lambda {
47
+ Expression[Expression.make_signed((val & 0x7ff) | ((val >> 10) & 0xF800), 16)]
48
+ }
49
+
50
+ op.args.each { |a|
51
+ di.instruction.args << case a
52
+ when :rA, :rB, :rD; Reg.new(fld[a])
53
+ when :fA; FpReg.new(fld[:rA])
54
+ when :fB; FpReg.new(fld[:rB])
55
+ when :fD; FpReg.new(fld[:rD])
56
+ when :disp26; Expression[sign_fld[a, 26]]
57
+ when :uimm5, :uimm16; Expression[fld[a]]
58
+ when :simm16; Expression[sign_fld[a, 16]]
59
+ when :rA_simm16; Memref.new(Reg.new(fld[:rA]), Expression[sign_fld[:simm16, 16]], di.opcode.props[:memsz])
60
+ when :rA_smoo; Memref.new(Reg.new(fld[:rA]), fld_smoo[], di.opcode.props[:memsz])
61
+ else raise "unhandled arg #{a}"
62
+ end
63
+ }
64
+
65
+ di
66
+ end
67
+
68
+ def decode_instr_interpret(di, addr)
69
+ if di.opcode.props[:setip]
70
+ case di.opcode.name
71
+ when 'j', 'jal', 'bf', 'bnf'
72
+ # abs26 is not absolute, duh
73
+ arg = Expression[addr, :+, [di.instruction.args[-1], :<<, 2]].reduce
74
+ di.instruction.args[-1] = Expression[arg]
75
+ end
76
+ end
77
+
78
+ di
79
+ end
80
+
81
+ # populate the @backtrace_binding hash with default values
82
+ def init_backtrace_binding
83
+ @backtrace_binding ||= {}
84
+
85
+ opcode_list.map { |ol| ol.basename }.uniq.sort.each { |op|
86
+ binding = case op
87
+ when 'movhi'; lambda { |di, a0, a1| { a0 => Expression[a1, :<<, 16] } }
88
+ when 'add'; lambda { |di, a0, a1, a2| { a0 => Expression[a1, :+, a2] } }
89
+ when 'sub'; lambda { |di, a0, a1, a2| { a0 => Expression[a1, :-, a2] } }
90
+ when 'mul'; lambda { |di, a0, a1, a2| { a0 => Expression[a1, :*, a2] } }
91
+ when 'div'; lambda { |di, a0, a1, a2| { a0 => Expression[a1, :/, a2] } }
92
+ when 'and'; lambda { |di, a0, a1, a2| { a0 => Expression[a1, :&, a2] } }
93
+ when 'or'; lambda { |di, a0, a1, a2| { a0 => Expression[a1, :|, a2] } }
94
+ when 'xor'; lambda { |di, a0, a1, a2| { a0 => Expression[a1, :^, a2] } }
95
+ when 'shl'; lambda { |di, a0, a1, a2| { a0 => Expression[[a1, :<<, a2], :&, 0xffff_ffff] } }
96
+ when 'shr'; lambda { |di, a0, a1, a2| { a0 => Expression[[a1, :>>, a2], :&, 0xffff_ffff] } }
97
+ when 'sar'; lambda { |di, a0, a1, a2| { a0 => Expression[[[a1, :>>, a2], :|, [[0xffff_ffff, :<<, a2], :*, [a1, :>>, 31]]], :&, 0xffff_ffff] } }
98
+ when 'ror'; lambda { |di, a0, a1, a2| { a0 => Expression[[[a1, :>>, a2], :|, [a1, :<<, [32, :-, a2]]], :&, 0xffff_ffff] } }
99
+ when 'lwz', 'lbz', 'lhz'; lambda { |di, a0, a1| { a0 => Expression[a1] } }
100
+ when 'lbs'; lambda { |di, a0, a1| { a0 => Expression[Expression.make_signed(a1, 8)] } }
101
+ when 'lhs'; lambda { |di, a0, a1| { a0 => Expression[Expression.make_signed(a1, 16)] } }
102
+ when 'sw', 'sh', 'sb'; lambda { |di, a0, a1| { a0 => Expression[a1] } }
103
+ when 'jal', 'jalr'; lambda { |di, a0| { :r9 => Expression[di.next_addr + delay_slot(di)*4] } }
104
+ when 'jr', 'j', 'bf', 'bnf', 'nop'; lambda { |di, *a| {} }
105
+ when 'sfeq'; lambda { |di, a0, a1| { :flag => Expression[a0, :==, a1] } }
106
+ when 'sfne'; lambda { |di, a0, a1| { :flag => Expression[a0, :!=, a1] } }
107
+ when 'sfgtu'; lambda { |di, a0, a1| { :flag => Expression[[a0, :&, 0xffff_ffff], :>, [a1, :&, 0xffff_ffff]] } }
108
+ when 'sfgeu'; lambda { |di, a0, a1| { :flag => Expression[[a0, :&, 0xffff_ffff], :>=, [a1, :&, 0xffff_ffff]] } }
109
+ when 'sfltu'; lambda { |di, a0, a1| { :flag => Expression[[a0, :&, 0xffff_ffff], :<, [a1, :&, 0xffff_ffff]] } }
110
+ when 'sfleu'; lambda { |di, a0, a1| { :flag => Expression[[a0, :&, 0xffff_ffff], :<=, [a1, :&, 0xffff_ffff]] } }
111
+ when 'sfgts'; lambda { |di, a0, a1| { :flag => Expression[Expression.make_signed(a0, 32), :>, Expression.make_signed(a1, 32)] } }
112
+ when 'sfges'; lambda { |di, a0, a1| { :flag => Expression[Expression.make_signed(a0, 32), :>=, Expression.make_signed(a1, 32)] } }
113
+ when 'sflts'; lambda { |di, a0, a1| { :flag => Expression[Expression.make_signed(a0, 32), :<, Expression.make_signed(a1, 32)] } }
114
+ when 'sfles'; lambda { |di, a0, a1| { :flag => Expression[Expression.make_signed(a0, 32), :<=, Expression.make_signed(a1, 32)] } }
115
+ end
116
+ @backtrace_binding[op] ||= binding if binding
117
+ }
118
+
119
+ @backtrace_binding
120
+ end
121
+
122
+ # returns a DecodedFunction from a parsed C function prototype
123
+ def decode_c_function_prototype(cp, sym, orig=nil)
124
+ sym = cp.toplevel.symbol[sym] if sym.kind_of?(::String)
125
+ df = DecodedFunction.new
126
+ orig ||= Expression[sym.name]
127
+
128
+ new_bt = lambda { |expr, rlen|
129
+ df.backtracked_for << BacktraceTrace.new(expr, orig, expr, rlen ? :r : :x, rlen)
130
+ }
131
+
132
+ # return instr emulation
133
+ if sym.has_attribute 'noreturn' or sym.has_attribute '__noreturn__'
134
+ df.noreturn = true
135
+ else
136
+ new_bt[:r9, nil]
137
+ end
138
+
139
+ [3, 4, 5, 6, 7, 8, 11, 12, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31].each { |r|
140
+ # dirty regs according to ABI
141
+ df.backtrace_binding.update "r#{r}".to_sym => Expression::Unknown
142
+ }
143
+
144
+ # scan args for function pointers
145
+ reg_args = [:r3, :r4, :r5, :r6, :r7, :r8]
146
+ sym.type.args.to_a.zip(reg_args).each { |a, ra|
147
+ break if not a or not ra
148
+ if a.type.untypedef.kind_of?(C::Pointer)
149
+ pt = a.type.untypedef.type.untypedef
150
+ if pt.kind_of?(C::Function)
151
+ new_bt[ra, nil]
152
+ df.backtracked_for.last.detached = true
153
+ elsif pt.kind_of?(C::Struct)
154
+ new_bt[ra, cp.typesize[:ptr]]
155
+ else
156
+ new_bt[ra, cp.sizeof(nil, pt)]
157
+ end
158
+ end
159
+ }
160
+
161
+ df
162
+ end
163
+
164
+ def disassembler_default_func
165
+ df = DecodedFunction.new
166
+ df.backtrace_binding = (1..32).inject({}) { |h, r| h.update "r#{r}".to_sym => Expression["r#{r}".to_sym] }
167
+ [3, 4, 5, 6, 7, 8, 11, 12, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31].each { |r|
168
+ df.backtrace_binding["r#{r}".to_sym] = Expression::Unknown
169
+ }
170
+ df.backtracked_for = [BacktraceTrace.new(Expression[:r9], :default, Expression[:r9], :x)]
171
+ df
172
+ end
173
+
174
+ def backtrace_is_function_return(expr, di=nil)
175
+ Expression[expr].reduce_rec == :r9
176
+ end
177
+
178
+ def backtrace_is_stack_address(expr)
179
+ Expression[expr].expr_externals.include? :r1
180
+ end
181
+ end
182
+ end
@@ -0,0 +1,350 @@
1
+ # This file is part of Metasm, the Ruby assembly manipulation suite
2
+ # Copyright (C) 2006-2009 Yoann GUILLOT
3
+ #
4
+ # Licence is LGPL, see LICENCE in the top-level directory
5
+
6
+
7
+ require 'metasm/cpu/openrisc/main'
8
+
9
+ module Metasm
10
+ class OpenRisc
11
+ # temporarily setup dasm.address_binding so that backtracking
12
+ # stack-related offsets resolve in :frameptr (relative to func start)
13
+ def decompile_makestackvars(dasm, funcstart, blocks)
14
+ oldfuncbd = dasm.address_binding[funcstart]
15
+ dasm.address_binding[funcstart] = { :r1 => :frameptr }
16
+ blocks.each { |block| yield block }
17
+ dasm.address_binding[funcstart] = oldfuncbd if oldfuncbd
18
+ end
19
+
20
+ # add di-specific registry written/accessed
21
+ def decompile_func_finddeps_di(dcmp, func, di, a, w)
22
+ a << abi_funcall[:retval] if di.instruction.to_s == 'jr r9' and (not func.type.kind_of?(C::BaseType) or func.type.type.name != :void) # standard ABI
23
+ end
24
+
25
+ # list of register symbols
26
+ def register_symbols
27
+ @dbg_register_list ||= (1..31).to_a.map { |i| "r#{i}".to_sym }
28
+ end
29
+
30
+ # returns a hash { :retval => r, :changed => [] }
31
+ def abi_funcall
32
+ { :retval => :r11, :changed => [3, 4, 5, 6, 7, 8, 11, 12, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31].map { |n| "r#{n}".to_sym }, :args => [:r3, :r4, :r5, :r6, :r7, :r8] }
33
+ end
34
+
35
+ # list variable dependency for each block, remove useless writes
36
+ # returns { blockaddr => [list of vars that are needed by a following block] }
37
+ def decompile_func_finddeps(dcmp, blocks, func)
38
+ deps_r = {} ; deps_w = {} ; deps_to = {}
39
+ deps_subfunc = {} # things read/written by subfuncs
40
+
41
+ # find read/writes by each block
42
+ blocks.each { |b, to|
43
+ deps_r[b] = [] ; deps_w[b] = [] ; deps_to[b] = to
44
+ deps_subfunc[b] = []
45
+
46
+ blk = dcmp.dasm.decoded[b].block
47
+ blk.list.each { |di|
48
+ a = di.backtrace_binding.values
49
+ w = []
50
+ di.backtrace_binding.keys.each { |k|
51
+ case k
52
+ when ::Symbol; w |= [k]
53
+ else a |= Expression[k].externals # if dword [eax] <- 42, eax is read
54
+ end
55
+ }
56
+ decompile_func_finddeps_di(dcmp, func, di, a, w)
57
+
58
+ deps_r[b] |= a.map { |ee| Expression[ee].externals.grep(::Symbol) }.flatten - [:unknown] - deps_w[b]
59
+ deps_w[b] |= w.map { |ee| Expression[ee].externals.grep(::Symbol) }.flatten - [:unknown]
60
+ }
61
+ subfunccall = false
62
+ blk.each_to_normal { |t|
63
+ t = dcmp.backtrace_target(t, blk.list.last.address)
64
+ next if not t = dcmp.c_parser.toplevel.symbol[t]
65
+ t.type = C::Function.new(C::BaseType.new(:int)) if not t.type.kind_of?(C::Function) # XXX this may seem a bit extreme, and yes, it is.
66
+ subfunccall = true
67
+ t.type.args.to_a.each { |arg|
68
+ if reg = arg.has_attribute('register')
69
+ deps_subfunc[b] |= [reg.to_sym]
70
+ end
71
+ }
72
+ }
73
+ if subfunccall # last block instr == subfunction call
74
+ deps_r[b] |= deps_subfunc[b] - deps_w[b]
75
+ deps_w[b] |= abi_funcall[:changed]
76
+ end
77
+ }
78
+
79
+ bt = blocks.transpose
80
+ roots = bt[0] - bt[1].flatten # XXX jmp 1stblock ?
81
+
82
+ # find regs read and never written (must have been set by caller and are part of the func ABI)
83
+ uninitialized = lambda { |b, r, done|
84
+ if not deps_r[b]
85
+ elsif deps_r[b].include?(r)
86
+ blk = dcmp.dasm.decoded[b].block
87
+ bw = []
88
+ rdi = blk.list.find { |di|
89
+ a = di.backtrace_binding.values
90
+ w = []
91
+ di.backtrace_binding.keys.each { |k|
92
+ case k
93
+ when ::Symbol; w |= [k]
94
+ else a |= Expression[k].externals # if dword [eax] <- 42, eax is read
95
+ end
96
+ }
97
+ decompile_func_finddeps_di(dcmp, func, di, a, w)
98
+
99
+ next true if (a.map { |ee| Expression[ee].externals.grep(::Symbol) }.flatten - [:unknown] - bw).include?(r)
100
+ bw |= w.map { |ee| Expression[ee].externals.grep(::Symbol) }.flatten - [:unknown]
101
+ false
102
+ }
103
+ if decompile_func_abi_fcallret(r, rdi, blk)
104
+ func.type.type = C::BaseType.new(:void)
105
+ false
106
+ elsif rdi and rdi.backtrace_binding[r]
107
+ false # mov al, 42 ; ret -> don't regarg eax
108
+ else
109
+ true
110
+ end
111
+ elsif deps_w[b].include?(r)
112
+ else
113
+ done << b
114
+ (deps_to[b] - done).find { |tb| uninitialized[tb, r, done] }
115
+ end
116
+ }
117
+
118
+ regargs = []
119
+ register_symbols.each { |r|
120
+ if roots.find { |root| uninitialized[root, r, []] }
121
+ regargs << r
122
+ end
123
+ }
124
+
125
+ # TODO honor user-defined prototype if available (eg no, really, eax is not read in this function returning al)
126
+ regargs.sort_by { |r| r.to_s }.each { |r|
127
+ a = C::Variable.new(r.to_s, C::BaseType.new(:int, :unsigned))
128
+ a.add_attribute("register(#{r})")
129
+ func.type.args << a
130
+ }
131
+
132
+ # remove writes from a block if no following block read the value
133
+ dw = {}
134
+ deps_w.each { |b, deps|
135
+ dw[b] = deps.reject { |dep|
136
+ ret = true
137
+ done = []
138
+ todo = deps_to[b].dup
139
+ while a = todo.pop
140
+ next if done.include?(a)
141
+ done << a
142
+ if not deps_r[a] or deps_r[a].include?(dep)
143
+ ret = false
144
+ break
145
+ elsif not deps_w[a].include?(dep)
146
+ todo.concat deps_to[a]
147
+ end
148
+ end
149
+ ret
150
+ }
151
+ }
152
+
153
+ dw
154
+ end
155
+
156
+ # return true if r is the implicit register read made by the subfunction return instruction to symbolize the return value ABI
157
+ def decompile_func_abi_fcallret(r, rdi, blk)
158
+ rdi ||= blk.list[-1-@delay_slot]
159
+ return if not rdi
160
+ r == abi_funcall[:retval] and rdi.instruction.to_s == 'jr r9'
161
+ end
162
+
163
+ def decompile_blocks(dcmp, myblocks, deps, func, nextaddr = nil)
164
+ scope = func.initializer
165
+ func.type.args.each { |a| scope.symbol[a.name] = a }
166
+ stmts = scope.statements
167
+ blocks_toclean = myblocks.dup
168
+ func_entry = myblocks.first[0]
169
+ until myblocks.empty?
170
+ b, to = myblocks.shift
171
+ if l = dcmp.dasm.get_label_at(b)
172
+ stmts << C::Label.new(l)
173
+ end
174
+
175
+ # list of assignments [[dest reg, expr assigned]]
176
+ ops = []
177
+ # reg binding (reg => value, values.externals = regs at block start)
178
+ binding = {}
179
+ # Expr => CExpr
180
+ ce = lambda { |*e| dcmp.decompile_cexpr(Expression[Expression[*e].reduce], scope) }
181
+ # Expr => Expr.bind(binding) => CExpr
182
+ ceb = lambda { |*e| ce[Expression[*e].bind(binding)] }
183
+
184
+ # dumps a CExprs that implements an assignment to a reg (uses ops[], patches op => [reg, nil])
185
+ commit = lambda {
186
+ deps[b].map { |k|
187
+ [k, ops.rindex(ops.reverse.find { |r, v| r == k })]
188
+ }.sort_by { |k, i| i.to_i }.each { |k, i|
189
+ next if not i or not binding[k]
190
+ e = k
191
+ final = []
192
+ ops[0..i].reverse_each { |r, v|
193
+ final << r if not v
194
+ e = Expression[e].bind(r => v).reduce if not final.include?(r)
195
+ }
196
+ ops[i][1] = nil
197
+ binding.delete k
198
+ stmts << ce[k, :'=', e] if k != e
199
+ }
200
+ }
201
+
202
+ # returns an array to use as funcall arguments
203
+ get_func_args = lambda { |di, f|
204
+ # XXX see remarks in #finddeps
205
+ args_todo = f.type.args.to_a.dup
206
+ args = []
207
+ args_abi = abi_funcall[:args].dup
208
+ args_todo.each { |a_|
209
+ if r = a_.has_attribute_var('register')
210
+ args << Expression[r.to_sym]
211
+ args_abi.delete r.to_sym
212
+ else
213
+ args << Expression[args_abi.shift]
214
+ end
215
+ }
216
+
217
+ if f.type.varargs
218
+ nargs = 1
219
+ if f.type.args.last.type.pointer?
220
+ # check if last arg is a fmtstring
221
+ bt = dcmp.dasm.backtrace(args.last, di.block.list.last.address, :snapshot_addr => func_entry, :include_start => true)
222
+ if bt.length == 1 and s = dcmp.dasm.get_section_at(bt.first)
223
+ fmt = s[0].read(512)
224
+ fmt = fmt.unpack('v*').pack('C*') if dcmp.sizeof(f.type.args.last.type.untypedef.type) == 2
225
+ if fmt.index(?\0)
226
+ fmt = fmt[0...fmt.index(?\0)]
227
+ nargs = fmt.gsub('%%', '').count('%') # XXX %.*s etc..
228
+ end
229
+ end
230
+ end
231
+ bt = dcmp.dasm.backtrace(:r1, di.block.list.last.address, :snapshot_addr => func_entry, :include_start => true)
232
+ stackoff = Expression[bt, :-, :r1].bind(:r1 => :frameptr).reduce rescue nil
233
+ if stackoff and nargs > 0
234
+ nargs.times {
235
+ args << Indirection[[:frameptr, :+, stackoff], @size/8]
236
+ stackoff += @size/8
237
+ }
238
+ end
239
+ end
240
+
241
+ args.map { |e| ceb[e] }
242
+ }
243
+
244
+ # go !
245
+ di_list = dcmp.dasm.decoded[b].block.list.dup
246
+ if di_list[-2] and di_list[-2].opcode.props[:setip] and @delay_slot > 0
247
+ di_list[-1], di_list[-2] = di_list[-2], di_list[-1]
248
+ end
249
+ di_list.each { |di|
250
+ if di.opcode.props[:setip] and not di.opcode.props[:stopexec]
251
+ # conditional jump
252
+ commit[]
253
+ n = dcmp.backtrace_target(get_xrefs_x(dcmp.dasm, di).first, di.address)
254
+ if di.opcode.name == /bfeq/
255
+ cc = ceb[:flag]
256
+ else
257
+ cc = ceb[:!, :flag]
258
+ end
259
+ # XXX switch/indirect/multiple jmp
260
+ stmts << C::If.new(C::CExpression[cc], C::Goto.new(n))
261
+ to.delete dcmp.dasm.normalize(n)
262
+ next
263
+ end
264
+
265
+ if di.instruction.to_s == 'jr r9'
266
+ commit[]
267
+ ret = C::CExpression[ceb[abi_funcall[:retval]]] unless func.type.type.kind_of?(C::BaseType) and func.type.type.name == :void
268
+ stmts << C::Return.new(ret)
269
+ elsif di.opcode.name == 'jal' or di.opcode.name == 'jalr'
270
+ n = dcmp.backtrace_target(get_xrefs_x(dcmp.dasm, di).first, di.address)
271
+ args = []
272
+ if f = dcmp.c_parser.toplevel.symbol[n] and f.type.kind_of?(C::Function) and f.type.args
273
+ args = get_func_args[di, f]
274
+ end
275
+ commit[]
276
+ #next if not di.block.to_subfuncret
277
+
278
+ if not n.kind_of?(::String) or (f and not f.type.kind_of?(C::Function))
279
+ # indirect funcall
280
+ fptr = ceb[n]
281
+ binding.delete n
282
+ proto = C::Function.new(C::BaseType.new(:int))
283
+ proto = f.type if f and f.type.kind_of?(C::Function)
284
+ f = C::CExpression[[fptr], C::Pointer.new(proto)]
285
+ elsif not f
286
+ # internal functions are predeclared, so this one is extern
287
+ f = C::Variable.new
288
+ f.name = n
289
+ f.type = C::Function.new(C::BaseType.new(:int))
290
+ if dcmp.recurse > 0
291
+ dcmp.c_parser.toplevel.symbol[n] = f
292
+ dcmp.c_parser.toplevel.statements << C::Declaration.new(f)
293
+ end
294
+ end
295
+ commit[]
296
+ binding.delete abi_funcall[:retval]
297
+ e = C::CExpression[f, :funcall, args]
298
+ e = C::CExpression[ce[abi_funcall[:retval]], :'=', e, f.type.type] if deps[b].include?(abi_funcall[:retval]) and f.type.type != C::BaseType.new(:void)
299
+ stmts << e
300
+ else
301
+ bd = get_fwdemu_binding(di)
302
+ if di.backtrace_binding[:incomplete_binding]
303
+ commit[]
304
+ stmts << C::Asm.new(di.instruction.to_s, nil, nil, nil, nil, nil)
305
+ else
306
+ update = {}
307
+ bd.each { |k, v|
308
+ if k.kind_of?(::Symbol) and not deps[b].include?(k)
309
+ ops << [k, v]
310
+ update[k] = Expression[Expression[v].bind(binding).reduce]
311
+ else
312
+ stmts << ceb[k, :'=', v]
313
+ stmts.pop if stmts.last.kind_of?(C::Variable) # [:eflag_s, :=, :unknown].reduce
314
+ end
315
+ }
316
+ binding.update update
317
+ end
318
+ end
319
+ }
320
+ commit[]
321
+
322
+ case to.length
323
+ when 0
324
+ if not myblocks.empty? and (dcmp.dasm.decoded[b].block.list[-1-@delay_slot].instruction.to_s != 'jr r9' rescue true)
325
+ puts " block #{Expression[b]} has no to and don't end in ret"
326
+ end
327
+ when 1
328
+ if (myblocks.empty? ? nextaddr != to[0] : myblocks.first.first != to[0])
329
+ stmts << C::Goto.new(dcmp.dasm.auto_label_at(to[0], 'unknown_goto'))
330
+ end
331
+ else
332
+ puts " block #{Expression[b]} with multiple to"
333
+ end
334
+ end
335
+
336
+ # cleanup di.bt_binding (we set :frameptr etc in those, this may confuse the dasm)
337
+ blocks_toclean.each { |b_, to_|
338
+ dcmp.dasm.decoded[b_].block.list.each { |di|
339
+ di.backtrace_binding = nil
340
+ }
341
+ }
342
+ end
343
+
344
+ def decompile_check_abi(dcmp, entry, func)
345
+ a = func.type.args || []
346
+ # TODO check abi_funcall[:args], dont delete r4 __unused if r5 is used
347
+ a.delete_if { |arg| arg.has_attribute_var('register') and arg.has_attribute('unused') }
348
+ end
349
+ end
350
+ end