示例#1
0
// ReadInstruction fetches bytes from the provided address space at the given
//  address and parses them into a single instruction instance.
func (dis *GapstoneDisassembler) ReadInstruction(as AS.AddressSpace, va AS.VA) (gapstone.Instruction, error) {
	d, e := as.MemRead(va, uint64(MAX_INSN_SIZE))
	if e != nil {
		logrus.Warnf("read instruction invalid: %s 0x%x", va, MAX_INSN_SIZE)
	}
	check(e)
	if e != nil {
		return gapstone.Instruction{}, AS.ErrInvalidMemoryRead
	}

	n := gapstone.Engine(*dis)
	insns, e := n.Disasm(d, uint64(va), 1)
	check(e)
	if e != nil {
		return gapstone.Instruction{}, ErrFailedToDisassembleInstruction
	}

	if len(insns) == 0 {
		return gapstone.Instruction{}, ErrFailedToDisassembleInstruction
	}

	insn := insns[0]
	return insn, nil
}
示例#2
0
func (dis *GapstoneDisassembler) Close() error {
	n := gapstone.Engine(*dis)
	n.Close()
	return nil
}