shogo82148 / androidbinary

Android binary file parser written in golang
MIT License
241 stars 79 forks source link

parse momo.apk AndroidManifest.xml to apk/apkxml.go struct error #27

Closed codeskyblue closed 4 years ago

codeskyblue commented 4 years ago

The bool filed might be none of "true" or "false", this happends in apk: https://www.immomo.com/download/momo_apk

image

AndroidManifest.xml.txt

Ref: https://github.com/openatx/uiautomator2/issues/393

shogo82148 commented 4 years ago

It is a ResID. You can get the real value by TableFile.GetResource, instead of the apk package.

Any field may be a RedID, so we need a new interface to handle it. But I have no idea. I'm thinking a solution now... 🤔

codeskyblue commented 4 years ago

What about create a new Type BoolField

type BoolField struct {
    value string
}

func (f *BoolField) UnmarshalXMLAttr(attr xml.Attr) error {
    f.value = attr.Value
    return nil
}

func (f *BoolField)  Bool(table *TableFile) (bool, error) {
    if (strings.HasPrefix(f.value, "@") {
        if (table != nil){
            return table.GetResource(f.value)
        }
    }
    return strconv.ParseBool(f.value)
}

func (f *BoolField)  MustBool(table *TableFile) bool {
    v, err := f.Bool()
    if err != nil {
        panic(err)
    }
    return v
}

code is not tested

ref: https://stackoverflow.com/questions/24980166/golang-unmarshalxmlattr-in-encoding-xml

shogo82148 commented 4 years ago

I implemented Proof of Concept for resolving this issue. #28 It looks that it works with momo.apk. could you check it please?

package main

import (
    "fmt"

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

func main() {
    apkFile, err := apk.OpenFile("momo.apk")
    if err != nil {
        panic(err)
    }
    fmt.Println(apkFile.Manifest().App.HardwareAccelerated.Bool())
    // Output:
    // true, nil
}
codeskyblue commented 4 years ago

I tested the it is working. Awesome. There is a method need to implement UnmarshalXMLAttr

The demo can see here: https://play.golang.org/p/IlzpKQ8ehn

shogo82148 commented 4 years ago

released v0.0.2 https://github.com/shogo82148/androidbinary/releases/tag/v0.0.2 try it.

codeskyblue commented 4 years ago

API changes, why not change version to 1.0.0

shogo82148 commented 4 years ago

because androidbinary have not reached v1.0.0 yet. v0.x.y versions may have broken changes.

do you use androidbinary in production? if yes, I will bump up to v1.0.0 soon.

codeskyblue commented 4 years ago

That's fine, v0.0.2 is fine to me, even through I have already used in production. I like this library very much.

shogo82148 commented 4 years ago

Thanks! Released v1.0.0 now https://github.com/shogo82148/androidbinary/releases/tag/v1.0.0

codeskyblue commented 4 years ago

Can you remove tag v0.0.2

codeskyblue commented 4 years ago

Thanks