class Metasm::DecodedInstruction

holds information for decoded instructions: the original opcode, a pointer to the InstructionBlock, etc

update DecodedInstr.to_s to include instr length

Attributes

address[RW]

the address of the instruction's first byte in memory

backtrace_binding[RW]

a cache of the binding used by the backtracker to emulate this instruction

bin_length[RW]

our, length in bytes

block[RW]

the instance of InstructionBlock this di is into

block_offset[RW]

our offset (in bytes) from the start of the block, used only for hexdump

comment[RW]

array of arbitrary strings

instruction[RW]

the disassembled data

misc[RW]

arbitrary data used during decoding, architecture-specific

opcode[RW]

the disassembled data

raw_data[RW]

used during fixed-size instruction decoding to hold the decoded raw opcode

Public Class Methods

new(arg, addr=nil) click to toggle source

create a new DecodedInstruction with an Instruction whose cpu is the argument can take an existing Instruction as argument

# File metasm/disassemble.rb, line 34
def initialize(arg, addr=nil)
        case arg
        when Instruction
                @instruction = arg
                @opcode = @instruction.cpu.opcode_list.find { |op| op.name == @instruction.opname } if @instruction.cpu
        else @instruction = Instruction.new(arg)
        end
        @bin_length = 0
        @address = addr if addr
end

Public Instance Methods

add_comment(c) click to toggle source
# File metasm/disassemble.rb, line 77
def add_comment(c)
        @comment ||= []
        @comment |= [c]
end
block_head?() click to toggle source

checks if this instruction is the first of its IBlock

# File metasm/disassemble_api.rb, line 128
def block_head?
        self == @block.list.first
end
dup() click to toggle source

returns a copy of the DecInstr, with duplicated instruction (“deep_copy”)

Calls superclass method
# File metasm/disassemble.rb, line 83
def dup
        new = super()
        new.instruction = @instruction.dup
        new
end
next_addr() click to toggle source
# File metasm/disassemble.rb, line 46
def next_addr
        (@next_addr ||= nil) || (address + @bin_length) if address
end
next_addr=(a) click to toggle source
# File metasm/disassemble.rb, line 45
def next_addr=(a) @next_addr = a end
render() click to toggle source
# File metasm/disassemble.rb, line 63
def render
        ret = []
        ret << Expression[address] << ' ' if address
        ret << @instruction
        if comment
                ret << ' ; '
                @comment.each { |c|
                        ret << c << ' '
                }
                ret.pop
        end
        ret
end
show() click to toggle source
# File metasm/disassemble.rb, line 50
def show
        if block
                bin = @block.edata.data[@block.edata_ptr+@block_offset, @bin_length].unpack('C*').map { |c| '%02x' % c }.join
                if @bin_length > 12
                        bin = bin[0, 20] + "..<+#{@bin_length-10}>"
                end
                "    #{@instruction.to_s.ljust(44)} ; @#{Expression[address]}  #{bin}  #{@comment.sort[0,6].join(' ') if comment}"
        else
                "#{@instruction}#{' ; ' + @comment.join(' ') if comment}"
        end
end
to_s() click to toggle source
# File samples/dasm-plugins/deobfuscate.rb, line 240
def to_s ; "#{Metasm::Expression[address] if address} +#{bin_length} #{instruction}" end