Coder Social home page Coder Social logo

go-arm64's Introduction

go-arm64 [WIP] ๐Ÿšง

Go PkgGoDev License

Pure Go AARCH64 architecture disassembler


Install

$ go get github.com/blacktop/go-arm64

Getting Started

package main

import (
	"bytes"
	"fmt"

	"github.com/blacktop/go-arm64"
	"github.com/blacktop/go-macho"
)

func main() {
	m, err := macho.Open("hello-mte")
	if err != nil {
		panic(err)
	}

	symAddr, err := m.FindSymbolAddress("_test")
	if err != nil {
		panic(err)
	}

	fn, err := m.GetFunctionForVMAddr(symAddr)
	if err != nil {
		panic(err)
	}

	data, err := m.GetFunctionData(fn)
	if err != nil {
		panic(err)
	}

	options := arm64.Options{
		StartAddress: int64(symAddr),
	}

	fmt.Println("_test:")
	for i := range arm64.Disassemble(bytes.NewReader(data), options) {
		fmt.Printf("%#08x:  %s\t%s\t%s\n",
			i.Instruction.Address(),
			i.Instruction.OpCodes(),
			i.Instruction.Operation(),
			i.Instruction.OpStr())
	}
}
_test:
0x100007e58:  7f 23 03 d5       pacibsp
0x100007e5c:  ff c3 02 d1       sub             sp, sp, #0xb0
0x100007e60:  fd 7b 0a a9       stp             x29, x30, [sp, #0xa0]
0x100007e64:  fd 83 02 91       add             x29, sp, #0xa0
0x100007e68:  08 00 00 b0       adrp            x8, #0x100008000
0x100007e6c:  08 09 40 f9       ldr             x8, [x8, #0x10]
0x100007e70:  08 01 40 f9       ldr             x8, [x8]
0x100007e74:  a8 83 1f f8       stur            x8, [x29, #-0x8]
0x100007e78:  08 00 80 d2       mov             x8, #0x0
0x100007e7c:  e8 13 c8 9a       irg             x8, sp, x8
0x100007e80:  08 01 81 91       addg            x8, x8, #0x10, #0x0
0x100007e84:  08 69 a0 d9       st2g            x8, [x8, #0x60]
0x100007e88:  08 49 a0 d9       st2g            x8, [x8, #0x40]
0x100007e8c:  08 29 a0 d9       st2g            x8, [x8, #0x20]
0x100007e90:  08 09 a0 d9       st2g            x8, [x8]
0x100007e94:  09 00 80 52       mov             w9, #0x0
0x100007e98:  09 01 04 39       strb            w9, [x8, #0x100]
0x100007e9c:  09 fd 43 39       ldrb            w9, [x8, #0xff]
0x100007ea0:  ff 7b a0 d9       st2g            sp, [sp, #0x70]
0x100007ea4:  ff 5b a0 d9       st2g            sp, [sp, #0x50]
0x100007ea8:  ff 3b a0 d9       st2g            sp, [sp, #0x30]
0x100007eac:  ff 1b a0 d9       st2g            sp, [sp, #0x10]
0x100007eb0:  08 00 00 b0       adrp            x8, #0x100008000
0x100007eb4:  08 09 40 f9       ldr             x8, [x8, #0x10]
0x100007eb8:  08 01 40 f9       ldr             x8, [x8]
0x100007ebc:  aa 83 5f f8       ldur            x10, [x29, #-0x8]
0x100007ec0:  08 01 0a eb       subs            x8, x8, x10
0x100007ec4:  e9 0f 00 b9       str             w9, [sp, #0xc]
0x100007ec8:  e1 00 00 54       b.ne            #0x100007ee4
0x100007ecc:  01 00 00 14       b               #0x100007ed0
0x100007ed0:  e8 0f 40 b9       ldr             w8, [sp, #0xc]
0x100007ed4:  00 1d 00 12       and             w0, w8, #0xff
0x100007ed8:  fd 7b 4a a9       ldp             x29, x30, [sp, #0xa0]
0x100007edc:  ff c3 02 91       add             sp, sp, #0xb0
0x100007ee0:  ff 0f 5f d6       retab           xzr
0x100007ee4:  2c 00 00 94       bl              #0x100007f94
0x100007ee8:  20 00 20 d4       brk             #0x1

TODO

  • fix ๐Ÿ›๐Ÿ›๐Ÿ›
  • standize on error types
  • add option for dec/hex immediates
  • display opcodes like 7f 23 03 d5
  • benchmarks ๐Ÿƒโ€โ™‚๏ธ๐Ÿ’จ

Credit

This is a complete Go re-write of Vector35/arch-arm64

License

MIT Copyright (c) 2020 blacktop

go-arm64's People

Contributors

blacktop avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.