Skip to content

Commit e1efb86

Browse files
committed
Make it public
0 parents  commit e1efb86

15 files changed

Lines changed: 1396 additions & 0 deletions

File tree

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
bin
2+
vendor
3+
third_party
4+
*.log
5+
*.swp

Makefile

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
GO=go
2+
3+
export CGO_CPPFLAGS += -I$(shell pwd)/third_party/keystone/include -I$(shell pwd)/third_party/capstone/include
4+
export CGO_LDFLAGS += -lkeystone -lstdc++ -lm -L$(shell pwd)/third_party/keystone/build/llvm/lib -L$(shell pwd)/third_party/capstone/
5+
6+
KEYSTONE_LIB=./third_party/keystone/build/llvm/lib/libkeystone.a
7+
CAPSTONE_LIB=./third_party/capstone/libcapstone.a
8+
9+
.PHONY: all binch static
10+
11+
all: binch
12+
13+
$(KEYSTONE_LIB):
14+
./build-keystone.sh
15+
16+
$(CAPSTONE_LIB):
17+
./build-capstone.sh
18+
19+
binch: $(KEYSTONE_LIB) $(CAPSTONE_LIB)
20+
$(GO) mod vendor
21+
$(GO) build -mod vendor -o bin/binch ./cmd/binch
22+
23+
static: $(KEYSTONE_LIB) $(CAPSTONE_LIB)
24+
$(GO) mod vendor
25+
$(GO) build -mod vendor -a -tags netgo -ldflags '-w -extldflags "-static"' -o bin/binch ./cmd/binch
26+
strip ./bin/binch

README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# binch
2+
3+
A lightweight ELF binary path tool.
4+
5+
![render1567170049118](https://user-images.githubusercontent.com/7830853/64022926-2e990000-cb72-11e9-9736-5c349cc0618f.gif)
6+
7+
## Installation
8+
9+
Using Install script
10+
```
11+
$ curl https://raw.githubusercontent.com/tunz/binch-go/master/install.sh | sh
12+
```
13+
14+
or, you can download a binary in [releases](https://github.com/tunz/binch-go/releases) page.
15+
16+
## Usage
17+
18+
```
19+
$ ./binch [binary name]
20+
```
21+
22+
### Shortcuts
23+
24+
#### Main View
25+
```
26+
g: Go to a specific address. (if not exists, jump to nearest address)
27+
d: Remove a current line. (Fill with nop)
28+
q: Quit.
29+
s: Save a modified binary to a file.
30+
enter: Modify a current line.
31+
j/k: Move to next/previous instruction.
32+
ctrl+f/b: Move to next/previous page.
33+
```
34+
35+
#### Patch View
36+
```
37+
tab: Switch focusing opcode/instruction.
38+
enter: Apply the patch.
39+
```

build-capstone.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
3+
CS_VERSION=4.0.1
4+
5+
mkdir -p third_party && cd third_party
6+
7+
wget https://github.com/aquynh/capstone/archive/${CS_VERSION}.tar.gz
8+
tar xzf ./${CS_VERSION}.tar.gz
9+
mv ./capstone-${CS_VERSION} ./capstone
10+
cd ./capstone
11+
./make.sh

build-keystone.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash
2+
3+
KS_VERSION=0.9.1
4+
5+
mkdir -p third_party && cd third_party
6+
7+
wget https://github.com/keystone-engine/keystone/archive/${KS_VERSION}.tar.gz
8+
tar xzf ./${KS_VERSION}.tar.gz
9+
mv ./keystone-${KS_VERSION} ./keystone
10+
11+
cd ./keystone
12+
13+
if [[ "$OSTYPE" == "darwin"* ]]; then
14+
# MacOS does not support i386 build anymore.
15+
sed -i -e 's/i386;//' ./make-common.sh
16+
fi
17+
18+
mkdir build
19+
cd build
20+
../make-lib.sh

cmd/binch/main.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package main
2+
3+
import (
4+
"github.com/tunz/binch-go/pkg/io"
5+
"github.com/tunz/binch-go/pkg/view"
6+
kingpin "gopkg.in/alecthomas/kingpin.v2"
7+
"log"
8+
"os"
9+
)
10+
11+
var filename = kingpin.Arg("file", "ELF binary to edit.").Required().String()
12+
var logfile = kingpin.Flag("log", "Log filename.").Default(os.DevNull).String()
13+
14+
func setupLogfile(logfile string) *os.File {
15+
fpLog, err := os.OpenFile(logfile, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
16+
if err != nil {
17+
panic(err)
18+
}
19+
20+
log.SetOutput(fpLog)
21+
return fpLog
22+
}
23+
24+
func main() {
25+
kingpin.Parse()
26+
27+
var logfp *os.File
28+
setupLogfile(*logfile)
29+
defer logfp.Close()
30+
31+
binary := bcio.ReadElf(*filename)
32+
bcview.Run(*filename, binary)
33+
}

go.mod

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module github.com/tunz/binch-go
2+
3+
go 1.12
4+
5+
require (
6+
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect
7+
github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4 // indirect
8+
github.com/bnagy/gapstone v0.0.0-20190822022427-21259e70af33
9+
github.com/jroimartin/gocui v0.4.0
10+
github.com/keystone-engine/beta v0.0.0-20190802134503-c4de98f71f05
11+
github.com/keystone-engine/keystone v0.0.0-20190802134503-c4de98f71f05
12+
github.com/mattn/go-runewidth v0.0.4 // indirect
13+
github.com/nsf/termbox-go v0.0.0-20190817171036-93860e161317 // indirect
14+
gopkg.in/alecthomas/kingpin.v2 v2.2.6
15+
)

go.sum

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 h1:JYp7IbQjafoB+tBA3gMyHYHrpOtNuDiK/uB5uXxq5wM=
2+
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
3+
github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4 h1:Hs82Z41s6SdL1CELW+XaDYmOH4hkBN4/N9og/AsOv7E=
4+
github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
5+
github.com/bnagy/gapstone v0.0.0-20190822022427-21259e70af33 h1:ovLZUFRdN5teEfVkHzC5q2gkSIngtRQFghUkoIGNlEw=
6+
github.com/bnagy/gapstone v0.0.0-20190822022427-21259e70af33/go.mod h1:d1o1fFyYsZmHPaDFsSrWMD1fwRqU/KMZiY0//gtBIdc=
7+
github.com/jroimartin/gocui v0.4.0 h1:52jnalstgmc25FmtGcWqa0tcbMEWS6RpFLsOIO+I+E8=
8+
github.com/jroimartin/gocui v0.4.0/go.mod h1:7i7bbj99OgFHzo7kB2zPb8pXLqMBSQegY7azfqXMkyY=
9+
github.com/keystone-engine/beta v0.0.0-20190802134503-c4de98f71f05 h1:8QUabkb1HmlB6w74Pr4y3yGbptDFDZ2MOZkDqheRT10=
10+
github.com/keystone-engine/beta v0.0.0-20190802134503-c4de98f71f05/go.mod h1:OdglOD0b8EoAy3gfoJ8iESVhBxU628mdCNy5Icd5NhI=
11+
github.com/keystone-engine/keystone v0.0.0-20190802134503-c4de98f71f05 h1:FB0hS1A3zScSF/8TZwe81sveyJLe1BvZ0hdlUxkxfbI=
12+
github.com/keystone-engine/keystone v0.0.0-20190802134503-c4de98f71f05/go.mod h1:x6RBIUBOBxJTcZKLVYb8fgJ5gvADotFWIZNeVVIpZG4=
13+
github.com/mattn/go-runewidth v0.0.4 h1:2BvfKmzob6Bmd4YsL0zygOqfdFnK7GR4QL06Do4/p7Y=
14+
github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
15+
github.com/nsf/termbox-go v0.0.0-20190817171036-93860e161317 h1:hhGN4SFXgXo61Q4Sjj/X9sBjyeSa2kdpaOzCO+8EVQw=
16+
github.com/nsf/termbox-go v0.0.0-20190817171036-93860e161317/go.mod h1:IuKpRQcYE1Tfu+oAQqaLisqDeXgjyyltCfsaoYN18NQ=
17+
gopkg.in/alecthomas/kingpin.v2 v2.2.6 h1:jMFz6MfLP0/4fUyZle81rXUoxOBFi19VUFKVDOQfozc=
18+
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=

install.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
mkdir -p ~/.local/bin
3+
4+
version=v0.1
5+
arch=$(uname -sm)
6+
case "$arch" in
7+
Linux\ *64) wget -O ~/.local/bin/binch https://github.com/tunz/binch-go/releases/download/${version}/binch-linux-x64 ;;
8+
Darwin\ *64) wget -O ~/.local/bin/binch https://github.com/tunz/binch-go/releases/download/${version}/binch-macos ;;
9+
*) echo "This OS is not supported yet. Please report us in https://github.com/tunz/binch-go"; exit 1;;
10+
esac
11+
12+
if [[ "$SHELL" =~ "bash" ]]; then
13+
echo "" >> ~/.bashrc
14+
echo 'export PATH=~/.local/bin:$PATH' >> ~/.bashrc
15+
elif [[ "$SHELL" =~ "zsh" ]]; then
16+
echo "" >> ~/.zsrrc
17+
echo 'export PATH=~/.local/bin:$PATH' >> ~/.zshrc
18+
else
19+
echo "Please add ~/.local/bin to your PATH"
20+
echo ""
21+
echo ' export PATH=~/.local/bin:$PATH'
22+
echo ""
23+
fi
24+
25+
echo "Installation Completed!"

0 commit comments

Comments
 (0)