node/lib/metasm/metasm/cpu/z80/decode.rb
# tries to find the opcode encoded at edata.ptr
# if no match, tries to match a prefix (update di.instruction.prefix)
# on match, edata.ptr points to the first byte of the opcode (after prefixes)
tries to find the opcode encoded at edata.ptr
if no match, tries to match a prefix (update di.instruction.prefix)
on match, edata.ptr points to the first byte of the opcode (after prefixes)
tries to find the opcode encoded at edata . ptr if no match tries to match a prefix ( update di . instruction . prefix ) on match edata . ptr points to the first byte of the opcode ( after prefixes )
def decode_findopcode(edata)
		di = DecodedInstruction.new self
		while edata.ptr < edata.data.length
			byte = edata.data[edata.ptr]
			byte = byte.unpack('C').first if byte.kind_of?(::String)
			return di if di.opcode = @bin_lookaside[byte].find { |op|
				bseq = edata.data[edata.ptr, op.bin.length].unpack('C*')
				op.bin.zip(bseq, op.bin_mask).all? { |b1, b2, m| b2 and ((b1 & m) == (b2 & m)) }
			}
			if decode_prefix(di.instruction, edata.get_byte)
				nb = edata.data[edata.ptr]
				nb = nb.unpack('C').first if nb.kind_of?(::String)
				case nb
				when 0xCB
					di.instruction.prefix |= edata.get_byte	<< 8
					di.bin_length += 2
					opc = edata.data[edata.ptr+1]
					opc = opc.unpack('C').first if opc.kind_of?(::String)
					bseq = [0xCB, opc]
					return di if di.opcode = @bin_lookaside[nb].find { |op|
						op.bin.zip(bseq, op.bin_mask).all? { |b1, b2, m| b2 and ((b1 & m) == (b2 & m)) }
					}
				when 0xED
					di.instruction.prefix = nil
				end
			else
				di.opcode = @unknown_opcode
				return di
			end
			di.bin_length += 1
		end
	end
def decode_findopcode ( edata ) di = DecodedInstruction . new self while edata . ptr < edata . data . length byte = edata . data [ edata . ptr ] byte = byte . unpack ( 'C' ) . first if byte . kind_of? ( :: String ) return di if di . opcode = @bin_lookaside [ byte ] . find { | op | bseq = edata . data [ edata . ptr , op . bin . length ] . unpack ( 'C*' ) op . bin . zip ( bseq , op . bin_mask ) . all? { | b1 , b2 , m | b2 and ( ( b1 & m ) == ( b2 & m ) ) } } if decode_prefix ( di . instruction , edata . get_byte ) nb = edata . data [ edata . ptr ] nb = nb . unpack ( 'C' ) . first if nb . kind_of? ( :: String ) case nb when 0xCB di . instruction . prefix |= edata . get_byte << 8 di . bin_length += 2 opc = edata . data [ edata . ptr + 1 ] opc = opc . unpack ( 'C' ) . first if opc . kind_of? ( :: String ) bseq = [ 0xCB , opc ] return di if di . opcode = @bin_lookaside [ nb ] . find { | op | op . bin . zip ( bseq , op . bin_mask ) . all? { | b1 , b2 , m | b2 and ( ( b1 & m ) == ( b2 & m ) ) } } when 0xED di . instruction . prefix = nil end else di . opcode = @unknown_opcode return di end di . bin_length += 1 end end
tries to find the opcode encoded at edata.ptr
if no match, tries to match a prefix (update di.instruction.prefix)
on match, edata.ptr points to the first byte of the opcode (after prefixes)
tries to find the opcode encoded at edata . ptr if no match tries to match a prefix ( update di . instruction . prefix ) on match edata . ptr points to the first byte of the opcode ( after prefixes )
# fetch the relevant bytes from edata # check against full opcode mask # DD CB <disp8> <opcode_pfxCB> [<args>] # XXX in decode_instr_op, byte[0] is the immediate displacement instead of cb
edata