Skip to content

Commit

Permalink
更换了 解析
Browse files Browse the repository at this point in the history
  • Loading branch information
jicheng1014 committed May 13, 2024
1 parent 1d6b6da commit a5e9e79
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 74 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/go_fir_cli_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
steps:
- uses: actions/checkout@v3

- uses: wangyoucao577/go-release-action@v1.34
- uses: wangyoucao577/go-release-action@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
goos: ${{ matrix.goos }}
Expand Down
74 changes: 24 additions & 50 deletions analysis/apk.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package analysis

import (
"bytes"
"encoding/xml"
"fmt"
"image"
"os"
"strconv"

"github.com/avast/apkparser"
"github.com/shogo82148/androidbinary/apk"
)

Expand All @@ -22,6 +19,28 @@ func (a *ApkApp) GetIcon() image.Image {
return icon
}

func ApkInfo(file string) (appInfo *AppFileInfo, err error) {
appInfo = &AppFileInfo{}
pkg, _ := apk.OpenFile(file)
defer pkg.Close()
icon, _ := pkg.Icon(nil) // returns the icon of APK as image.Image

manifest := pkg.Manifest()

appInfo.Icon = icon
appInfo.Name, _ = pkg.Label(nil)
appInfo.BundleId = manifest.Package.MustString()
appInfo.Version = manifest.VersionName.MustString()
appInfo.Build = strconv.Itoa(int(manifest.VersionCode.MustInt32()))

fmt.Print("appInfo: ", appInfo)

appInfo.Type = "android"
appInfo.ReleaseType = "inhouse"

return appInfo, nil
}

func ApkIcon(apkfile string) image.Image {
pkg, _ := apk.OpenFile(apkfile)
defer pkg.Close()
Expand All @@ -33,54 +52,9 @@ func ApkIcon(apkfile string) image.Image {

func Apk(file string) (appInfo *AppFileInfo, err error) {

b := bytes.Buffer{}

enc := xml.NewEncoder(&b)
enc.Indent("", "\t")
zipErr, resErr, manErr := apkparser.ParseApk(file, enc)

if zipErr != nil {
fmt.Fprintf(os.Stderr, "Failed to open the APK: %s", zipErr.Error())
os.Exit(1)
return
}

if resErr != nil {
fmt.Fprintf(os.Stderr, "Failed to parse resources: %s", resErr.Error())
}
if manErr != nil {
fmt.Fprintf(os.Stderr, "Failed to parse AndroidManifest.xml: %s", manErr.Error())
os.Exit(1)
return
}

type androidLabel struct {
XMLName xml.Name `xml:"application"`
Label string `xml:"label,attr"`
}
var manifestData struct {
XMLName xml.Name `xml:"manifest"`
Package string `xml:"package,attr"`
VersionName string `xml:"versionName,attr"`
VersionCode string `xml:"versionCode,attr"`
Application androidLabel `xml:"application"`
}
// fmt.Println(b.String())

err = xml.Unmarshal(b.Bytes(), &manifestData)
if err != nil {
panic(err)
}
appInfo = &AppFileInfo{}
appInfo.BundleId = manifestData.Package
appInfo.Version = manifestData.VersionName
appInfo.Build = manifestData.VersionCode
appInfo.Name = manifestData.Application.Label
appInfo.Type = "android"
appInfo.ReleaseType = "inhouse"

icon := ApkIcon(file)
appInfo.Icon = icon
appInfo, _ = ApkInfo(file)

return appInfo, nil
}
2 changes: 1 addition & 1 deletion constants/constants.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package constants

const VERSION = "0.0.9"
const VERSION = "0.0.10"
const USER_AGENT = "go-fir-" + VERSION
11 changes: 3 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,19 @@ go 1.19

require (
github.com/andrianbdn/iospng v0.0.0-20180730113000-dccef1992541
github.com/avast/apkparser v0.0.0-20221110131626-bc2b7ccc9d3e
github.com/cheggaaa/pb v1.0.29
github.com/go-resty/resty/v2 v2.7.0
github.com/shogo82148/androidbinary v1.0.3
github.com/shogo82148/androidbinary v1.0.5
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
gopkg.in/urfave/cli.v1 v1.20.0
howett.net/plist v1.0.0
)

require (
github.com/VividCortex/ewma v1.1.1 // indirect
github.com/cheggaaa/pb v1.0.29 // indirect
github.com/cheggaaa/pb/v3 v3.1.0 // indirect
github.com/fatih/color v1.10.0 // indirect
github.com/klauspost/compress v1.15.12 // indirect
github.com/mattn/go-colorable v0.1.8 // indirect
github.com/mattn/go-isatty v0.0.12 // indirect
github.com/mattn/go-runewidth v0.0.12 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e // indirect
golang.org/x/net v0.0.0-20211029224645-99673261e6eb // indirect
golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6 // indirect
)
16 changes: 2 additions & 14 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
github.com/VividCortex/ewma v1.1.1 h1:MnEK4VOv6n0RSY4vtRe3h11qjxL3+t0B8yOL8iMXdcM=
github.com/VividCortex/ewma v1.1.1/go.mod h1:2Tkkvm3sRDVXaiyucHiACn4cqf7DpdyLvmxzcbUokwA=
github.com/andrianbdn/iospng v0.0.0-20180730113000-dccef1992541 h1:PlePBgD++64Pjmo5HtrBuBxt1oWTUkc0PzrrLk822uA=
github.com/andrianbdn/iospng v0.0.0-20180730113000-dccef1992541/go.mod h1:Ct7Kf2zP3u3uzYRRwayZEwtAQGJ2leVXiR6DQI9IqPo=
github.com/avast/apkparser v0.0.0-20221110131626-bc2b7ccc9d3e h1:xlEHmOdmkZSseNewD+HiR6HIgJ1NHoVyiapTtSaHPFo=
github.com/avast/apkparser v0.0.0-20221110131626-bc2b7ccc9d3e/go.mod h1:Q9VJUqVyJjIsFm+2rS5ongUUeHjoTG4b0LanUo7A2yk=
github.com/cheggaaa/pb v1.0.29 h1:FckUN5ngEk2LpvuG0fw1GEFx6LtyY2pWI/Z2QgCnEYo=
github.com/cheggaaa/pb v1.0.29/go.mod h1:W40334L7FMC5JKWldsTWbdGjLo0RxUKK73K+TuPxX30=
github.com/cheggaaa/pb/v3 v3.1.0 h1:3uouEsl32RL7gTiQsuaXD4Bzbfl5tGztXGUvXbs4O04=
github.com/cheggaaa/pb/v3 v3.1.0/go.mod h1:YjrevcBqadFDaGQKRdmZxTY42pXEqda48Ea3lt0K/BE=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU=
github.com/fatih/color v1.10.0 h1:s36xzo75JdqLaaWoiEHk767eHiwo0598uUxyfiPkDsg=
github.com/fatih/color v1.10.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM=
github.com/go-resty/resty/v2 v2.7.0 h1:me+K9p3uhSmXtrBZ4k9jcEAfJmuC8IivWHwaLZwPrFY=
github.com/go-resty/resty/v2 v2.7.0/go.mod h1:9PWDzw47qPphMRFfhsyk0NnSgvluHcljSMVIq3w7q0I=
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/klauspost/compress v1.15.12 h1:YClS/PImqYbn+UILDnqxQCZ3RehC9N318SU3kElDUEM=
github.com/klauspost/compress v1.15.12/go.mod h1:QPwzmACJjUTFsnSHH934V6woptycfrDDJnH7hvFVbGM=
github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
github.com/mattn/go-colorable v0.1.8 h1:c1ghPdyEDarC70ftn0y+A/Ee++9zz8ljHG1b13eJ0s8=
github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
Expand All @@ -27,15 +18,13 @@ github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Ky
github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
github.com/mattn/go-runewidth v0.0.12 h1:Y41i/hVW3Pgwr8gV+J23B9YEY0zxjptBuCWEaxmAOow=
github.com/mattn/go-runewidth v0.0.12/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/shogo82148/androidbinary v1.0.3 h1:0E9bBCcDVwb2xJP3NwDkdfkxtOrys3DK/NjxnUq+bNI=
github.com/shogo82148/androidbinary v1.0.3/go.mod h1:TZXT25KBG2LxEC+kh7v2qvmwXfMwC/FNxKt7uTf8tJc=
github.com/shogo82148/androidbinary v1.0.5 h1:7afvcNw+vT84R0ugrL/u/DIrGYylC66yNvt0Y0j7rrM=
github.com/shogo82148/androidbinary v1.0.5/go.mod h1:FzpR5bLAXR3VsAUG4BRCFaUm0WV6YD4Ldu+m05tr9Vk=
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e h1:MRM5ITcdelLK2j1vwZ3Je0FKVCfqOLp5zO6trqMLYs0=
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e/go.mod h1:XV66xRDqSt+GTGFMVlhk3ULuV0y9ZmzeVGR4mloJI3M=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
golang.org/x/net v0.0.0-20211029224645-99673261e6eb h1:pirldcYWx7rx7kE5r+9WsOXPXK0+WH5+uZ7uPmJ44uM=
golang.org/x/net v0.0.0-20211029224645-99673261e6eb/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
Expand All @@ -53,6 +42,5 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8
gopkg.in/urfave/cli.v1 v1.20.0 h1:NdAVW6RYxDif9DhDHaAortIu956m2c0v+09AZBPTbE0=
gopkg.in/urfave/cli.v1 v1.20.0/go.mod h1:vuBzUtMdQeixQj8LVd+/98pzhxNGQoyuPBlsXHOQNO0=
gopkg.in/yaml.v1 v1.0.0-20140924161607-9f9df34309c0/go.mod h1:WDnlLJ4WF5VGsH/HVa3CI79GS0ol3YnhVnKP89i0kNg=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
howett.net/plist v1.0.0 h1:7CrbWYbPPO/PyNy38b2EB/+gYbjCe2DXBxgtOOZbSQM=
howett.net/plist v1.0.0/go.mod h1:lqaXoTrLY4hg8tnEzNru53gicrbv7rrk+2xJA/7hw9g=
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,3 +297,5 @@ func buildDownloadUrl(apiAppInfo *api.ApiAppInfo, includeRelease bool) string {
}
return fmt.Sprintf("http://%s/%s", apiAppInfo.DownloadDomain, apiAppInfo.Short)
}

// 直接运行

0 comments on commit a5e9e79

Please sign in to comment.