Skip to content

Commit

Permalink
feat: add GetInstructions func
Browse files Browse the repository at this point in the history
  • Loading branch information
blacktop committed Aug 8, 2021
1 parent 538f878 commit d52a5fd
Show file tree
Hide file tree
Showing 2 changed files with 1,196 additions and 0 deletions.
29 changes: 29 additions & 0 deletions disassemble/disassemble.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"encoding/binary"
"encoding/json"
"fmt"
"io"
"unsafe"
)

Expand Down Expand Up @@ -521,6 +522,34 @@ func Decompose(addr uint64, instructionValue uint32, results *[1024]byte) (*Inst
return i, nil
}

// GetInstructions returns an array of arm64 instruction pointers for a given start address and data blob
func GetInstructions(startAddr uint64, data []byte) ([]*Instruction, error) {
var resutls [1024]byte
var instrValue uint32
var instructions []*Instruction

r := bytes.NewReader(data)

for {
err := binary.Read(r, binary.LittleEndian, &instrValue)
if err == io.EOF {
break
} else if err != nil {
return nil, fmt.Errorf("failed to read 32-bit instruction value: %v", err)
}

if instruction, err := Decompose(startAddr, instrValue, &resutls); err != nil {
return nil, err
} else {
instructions = append(instructions, instruction)
}

startAddr += uint64(binary.Size(uint32(0)))
}

return instructions, nil
}

// goInstruction converts the cgo version into Go vesrion
func goInstruction(instr *C.Instruction) *Instruction {

Expand Down
Loading

0 comments on commit d52a5fd

Please sign in to comment.