| 1 | # apkparser |
| 2 | |
| 3 | [](https://godoc.org/github.com/avast/apkparser) |
| 4 | [](https://travis-ci.org/avast/apkparser) |
| 5 | |
| 6 | APK AndroidManifest.xml and resources.arsc parsing. |
| 7 | |
| 8 | **Works with Go 1.8 or higher.** |
| 9 | |
| 10 | Documentation on [GoDoc](https://godoc.org/github.com/avast/apkparser) |
| 11 | |
| 12 | go get github.com/avast/apkparser |
| 13 | |
| 14 | ## ZipReader |
| 15 | Because Android can handle even broken ZIP archives, this packages has it's own zip reader, |
| 16 | based on archive/zip. |
| 17 | |
| 18 | ## axml2xml |
| 19 | A tool to extract AndroidManifest.xml and verify APK signature is also part of this repo. |
| 20 | |
| 21 | go get github.com/avast/apkparser |
| 22 | go install github.com/avast/apkparser/axml2xml |
| 23 | ./axml2xml -v application.apk |
| 24 | |
| 25 | ## Example |
| 26 | |
| 27 | ```go |
| 28 | package main |
| 29 | |
| 30 | import ( |
| 31 | "encoding/xml" |
| 32 | "fmt" |
| 33 | "github.com/avast/apkparser" |
| 34 | "os" |
| 35 | ) |
| 36 | |
| 37 | func main() { |
| 38 | enc := xml.NewEncoder(os.Stdout) |
| 39 | enc.Indent("", "\t") |
| 40 | zipErr, resErr, manErr := apkparser.ParseApk(os.Args[1], enc) |
| 41 | if zipErr != nil { |
| 42 | fmt.Fprintf(os.Stderr, "Failed to open the APK: %s", zipErr.Error()) |
| 43 | os.Exit(1) |
| 44 | return |
| 45 | } |
| 46 | |
| 47 | if resErr != nil { |
| 48 | fmt.Fprintf(os.Stderr, "Failed to parse resources: %s", resErr.Error()) |
| 49 | } |
| 50 | if manErr != nil { |
| 51 | fmt.Fprintf(os.Stderr, "Failed to parse AndroidManifest.xml: %s", manErr.Error()) |
| 52 | os.Exit(1) |
| 53 | return |
| 54 | } |
| 55 | fmt.Println() |
| 56 | } |
| 57 | ``` |