forked from FutureWorkshops/steps-sign-apk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
apk_info.go
43 lines (35 loc) · 1.05 KB
/
apk_info.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package main
import (
"bytes"
"encoding/xml"
"fmt"
"github.com/avast/apkparser"
)
type manifest struct {
XMLName xml.Name `xml:"manifest"`
Application application
}
type application struct {
XMLName xml.Name `xml:"application"`
ExtractNativeLibs bool `xml:"extractNativeLibs,attr"` // defaults to false
}
func parseAPKextractNativeLibs(apkPath string) (bool, error) {
var manifestContent bytes.Buffer
enc := xml.NewEncoder(&manifestContent)
enc.Indent("", "\t")
zipErr, resErr, manErr := apkparser.ParseApk(apkPath, enc)
if zipErr != nil {
return false, fmt.Errorf("failed to unzip the APK: %s", zipErr)
}
if resErr != nil {
return false, fmt.Errorf("failed to parse resources: %s", zipErr)
}
if manErr != nil {
return false, fmt.Errorf("failed to parse AndroidManifest.xml: %s", zipErr)
}
var manifest manifest
if err := xml.Unmarshal(manifestContent.Bytes(), &manifest); err != nil {
return false, fmt.Errorf("failed to unmarshal AndroidManifest.xml: %s", err)
}
return manifest.Application.ExtractNativeLibs, nil
}