Skip to content

Commit

Permalink
tools/symdump: Added new tool to dump symbol offsets from ELF executable
Browse files Browse the repository at this point in the history
  • Loading branch information
pgaskin committed Mar 16, 2020
1 parent db826a1 commit 5b5b541
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 5 deletions.
15 changes: 10 additions & 5 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ steps:
"--build-cmd", "
CGO_ENABLED=1 go build -ldflags \"-s -w -linkmode external -X main.version=$(git describe --tags --always)\" -o build/kobopatch-linux-64bit ./kobopatch &&
CGO_ENABLED=1 go build -ldflags \"-s -w -linkmode external -X main.version=$(git describe --tags --always)\" -o build/kobopatch-apply-linux-64bit ./tools/kobopatch-apply &&
CGO_ENABLED=1 go build -ldflags \"-s -w -linkmode external -X main.version=$(git describe --tags --always)\" -o build/cssextract-linux-64bit ./tools/cssextract",
CGO_ENABLED=1 go build -ldflags \"-s -w -linkmode external -X main.version=$(git describe --tags --always)\" -o build/cssextract-linux-64bit ./tools/cssextract &&
CGO_ENABLED=1 go build -ldflags \"-s -w -linkmode external -X main.version=$(git describe --tags --always)\" -o build/symdump-linux-64bit ./tools/symdump",
]
- name: build-linux-386
image: docker.elastic.co/beats-dev/golang-crossbuild:1.13.6-main
Expand All @@ -62,7 +63,8 @@ steps:
"--build-cmd", "
CGO_ENABLED=1 go build -ldflags \"-s -w -linkmode external -X main.version=$(git describe --tags --always)\" -o build/kobopatch-linux-32bit ./kobopatch &&
CGO_ENABLED=1 go build -ldflags \"-s -w -linkmode external -X main.version=$(git describe --tags --always)\" -o build/kobopatch-apply-linux-32bit ./tools/kobopatch-apply &&
CGO_ENABLED=1 go build -ldflags \"-s -w -linkmode external -X main.version=$(git describe --tags --always)\" -o build/cssextract-linux-32bit ./tools/cssextract",
CGO_ENABLED=1 go build -ldflags \"-s -w -linkmode external -X main.version=$(git describe --tags --always)\" -o build/cssextract-linux-32bit ./tools/cssextract &&
CGO_ENABLED=1 go build -ldflags \"-s -w -linkmode external -X main.version=$(git describe --tags --always)\" -o build/symdump-linux-32bit ./tools/symdump",
]
- name: build-linux-arm
image: docker.elastic.co/beats-dev/golang-crossbuild:1.13.6-arm
Expand All @@ -71,7 +73,8 @@ steps:
"--build-cmd", "
CGO_ENABLED=1 go build -ldflags \"-s -w -linkmode external -X main.version=$(git describe --tags --always)\" -o build/kobopatch-linux-arm ./kobopatch &&
CGO_ENABLED=1 go build -ldflags \"-s -w -linkmode external -X main.version=$(git describe --tags --always)\" -o build/kobopatch-apply-linux-arm ./tools/kobopatch-apply &&
CGO_ENABLED=1 go build -ldflags \"-s -w -linkmode external -X main.version=$(git describe --tags --always)\" -o build/cssextract-linux-arm ./tools/cssextract",
CGO_ENABLED=1 go build -ldflags \"-s -w -linkmode external -X main.version=$(git describe --tags --always)\" -o build/cssextract-linux-arm ./tools/cssextract &&
CGO_ENABLED=1 go build -ldflags \"-s -w -linkmode external -X main.version=$(git describe --tags --always)\" -o build/symdump-linux-arm ./tools/symdump",
]
- name: build-windows-386
image: docker.elastic.co/beats-dev/golang-crossbuild:1.13.6-main
Expand All @@ -80,7 +83,8 @@ steps:
"--build-cmd", "
CGO_ENABLED=1 go build -ldflags \"-s -w -linkmode external -X main.version=$(git describe --tags --always) -extldflags -static\" -o build/koboptch-windows.exe ./kobopatch &&
CGO_ENABLED=1 go build -ldflags \"-s -w -linkmode external -X main.version=$(git describe --tags --always) -extldflags -static\" -o build/koboptch-apply-windows.exe ./tools/kobopatch-apply &&
CGO_ENABLED=1 go build -ldflags \"-s -w -linkmode external -X main.version=$(git describe --tags --always) -extldflags -static\" -o build/cssextract-windows.exe ./tools/cssextract",
CGO_ENABLED=1 go build -ldflags \"-s -w -linkmode external -X main.version=$(git describe --tags --always) -extldflags -static\" -o build/cssextract-windows.exe ./tools/cssextract &&
CGO_ENABLED=1 go build -ldflags \"-s -w -linkmode external -X main.version=$(git describe --tags --always) -extldflags -static\" -o build/symdump-windows.exe ./tools/symdump",
]
- name: build-darwin-amd64
image: docker.elastic.co/beats-dev/golang-crossbuild:1.13.6-darwin
Expand All @@ -89,7 +93,8 @@ steps:
"--build-cmd", "
CGO_ENABLED=1 go build -ldflags \"-s -w -linkmode external -X main.version=$(git describe --tags --always)\" -o build/kobopatch-darwin-64bit ./kobopatch &&
CGO_ENABLED=1 go build -ldflags \"-s -w -linkmode external -X main.version=$(git describe --tags --always)\" -o build/kobopatch-apply-darwin-64bit ./tools/kobopatch-apply &&
CGO_ENABLED=1 go build -ldflags \"-s -w -linkmode external -X main.version=$(git describe --tags --always)\" -o build/cssextract-darwin-64bit ./tools/cssextract",
CGO_ENABLED=1 go build -ldflags \"-s -w -linkmode external -X main.version=$(git describe --tags --always)\" -o build/cssextract-darwin-64bit ./tools/cssextract &&
CGO_ENABLED=1 go build -ldflags \"-s -w -linkmode external -X main.version=$(git describe --tags --always)\" -o build/symdump-darwin-64bit ./tools/symdump",
]
- name: list
image: golang:1.13-buster
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ cssextract extracts zlib-compressed from a binary file
Usage: cssextract BINARY_FILE
```

```
symdump dumps symbol addresses from an ARMv6+ 32-bit ELF executable
Usage: symdump BINARY_FILE
```

```
Usage: kobopatch-apply [OPTIONS]
Expand Down
48 changes: 48 additions & 0 deletions tools/symdump/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package main

import (
"encoding/json"
"fmt"
"io/ioutil"
"os"

"github.com/geek1011/kobopatch/patchlib"
)

func main() {
if len(os.Args) != 2 {
fmt.Fprintln(os.Stderr, "symdump dumps symbol addresses from an ARMv6+ 32-bit ELF executable")
fmt.Fprintln(os.Stderr, "Usage: symdump BINARY_FILE")
os.Exit(1)
}

buf, err := ioutil.ReadFile(os.Args[1])
if err != nil {
panic(err)
}

pt := patchlib.NewPatcher(buf)

ds, err := pt.ExtractDynsyms(true)
if err != nil {
panic(err)
}

f, err := os.Create("symdump.out.json")
if err != nil {
panic(err)
}

fmt.Fprintf(f, "[\n")
for i, s := range ds {
if i != 0 {
fmt.Fprintf(f, ",\n")
}
buf, _ := json.Marshal(s)
f.Write(buf)
}
fmt.Fprintf(f, "]\n")

f.Close()
os.Exit(0)
}

1 comment on commit 5b5b541

@pgaskin
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this tool works well on all of the other shared libs too, not just libnickel. It should also work with non-kobo libs compiled with different toolchains, but I haven't tested that extensively.

Please sign in to comment.