metasm/cpu/mips/decode.rb in metasm-1.0.3 vs metasm/cpu/mips/decode.rb in metasm-1.0.4
- old
+ new
@@ -124,16 +124,10 @@
end
di
end
- # hash opname => lambda { |di, *sym_args| binding }
- def backtrace_binding
- @backtrace_binding ||= init_backtrace_binding
- end
- def backtrace_binding=(b) @backtrace_binding = b end
-
def init_backtrace_binding
@backtrace_binding ||= {}
opcode_list.map { |ol| ol.name }.uniq.each { |op|
binding = case op
when 'break'
@@ -165,38 +159,34 @@
when 'mult', 'multu'; lambda { |di, a0, a1| { :hi => Expression[[a0, :*, a1], :>>, 32], :lo => Expression[[a0, :*, a1], :&, 0xffff_ffff] } }
when 'div', 'divu'; lambda { |di, a0, a1| { :hi => Expression[a0, :%, a1], :lo => Expression[a0, :/, a1] } }
when 'jal', 'jalr'; lambda { |di, a0| { :$ra => Expression[Expression[di.address, :+, 2*di.bin_length].reduce] } }
when 'li', 'mov'; lambda { |di, a0, a1| { a0 => Expression[a1] } }
when 'syscall'; lambda { |di, *a| { :$v0 => Expression::Unknown } }
+ when /^b/; lambda { |di, *a| {} }
end
@backtrace_binding[op] ||= binding if binding
}
@backtrace_binding
end
def get_backtrace_binding(di)
a = di.instruction.args.map { |arg|
case arg
- when Memref; arg.symbolic(di.address)
+ when Memref; arg.symbolic(di)
when Reg; arg.symbolic
else arg
end
}
- binding = if binding = backtrace_binding[di.instruction.opname]
- binding[di, *a]
+ if binding = backtrace_binding[di.instruction.opname]
+ bd = binding[di, *a]
+ bd.delete 0 # allow add $zero, 42 => nop
+ bd
else
- if di.instruction.opname[0] == ?b and di.opcode.props[:setip]
- else
- puts "unknown instruction to emu #{di}" if $VERBOSE
- end
- {}
+ puts "unhandled instruction to backtrace: #{di}" if $VERBOSE
+ {:incomplete_binding => Expression[1]}
end
-
- binding.delete 0 # allow add $zero, 42 => nop
-
- binding
end
def get_xrefs_x(dasm, di)
return [] if not di.opcode.props[:setip]