forked from lunny/axmlParser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse.go
59 lines (50 loc) · 902 Bytes
/
parse.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package axmlParser
import (
"archive/zip"
"io/ioutil"
)
func ParseApk(apkpath string, listener Listener) (*Parser, error) {
r, err := zip.OpenReader(apkpath)
if err != nil {
return nil, err
}
defer r.Close()
var xmlf *zip.File
for _, f := range r.File {
if f.Name != "AndroidManifest.xml" {
continue
}
xmlf = f
break
}
if xmlf == nil {
return nil, err
}
rc, err := xmlf.Open()
if err != nil {
return nil, err
}
defer rc.Close()
bs, err := ioutil.ReadAll(rc)
if err != nil {
return nil, err
}
parser := New(listener)
err = parser.Parse(bs)
if err != nil {
return nil, err
}
return parser, nil
}
func ParseAxml(axmlpath string, listener Listener) (*Parser, error) {
bs, err := ioutil.ReadFile(axmlpath)
if err != nil {
return nil, err
}
parser := New(listener)
err = parser.Parse(bs)
if err != nil {
return nil, err
}
return parser, nil
}