Skip to content

Commit 16eb2e9

Browse files
committed
accept nil ResTableConfig
1 parent ed83440 commit 16eb2e9

2 files changed

Lines changed: 24 additions & 5 deletions

File tree

apk/apk.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ import (
1616
"github.com/shogo82148/androidbinary"
1717
)
1818

19-
var DefaultResTableConfig = &androidbinary.ResTableConfig{}
20-
2119
type Apk struct {
2220
f *os.File
2321
zipreader *zip.Reader
@@ -143,9 +141,6 @@ func (k *Apk) parseResources() (err error) {
143141
}
144142

145143
func (k *Apk) getResource(id string, resConfig *androidbinary.ResTableConfig) string {
146-
if resConfig == nil {
147-
resConfig = DefaultResTableConfig
148-
}
149144
var resId uint32
150145
_, err := fmt.Sscanf(id, "@0x%x", &resId)
151146
if err != nil {

table.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,15 @@ func readTableTypeSpec(sr *io.SectionReader) ([]uint32, error) {
399399
}
400400

401401
func (c *ResTableConfig) IsMoreSpecificThan(o *ResTableConfig) bool {
402+
// non-nill ResTableConfig is always more specific than nil ResTableConfig
403+
if c != nil && o == nil {
404+
return true
405+
}
406+
407+
if c == o {
408+
return false
409+
}
410+
402411
// imsi
403412
if c.Mcc != o.Mcc {
404413
if c.Mcc == 0 {
@@ -630,6 +639,14 @@ func (c *ResTableConfig) IsBetterThan(o *ResTableConfig, r *ResTableConfig) bool
630639
return c.IsMoreSpecificThan(o)
631640
}
632641

642+
if c != nil {
643+
if o == nil || c == o {
644+
return false
645+
}
646+
} else {
647+
return o != nil
648+
}
649+
633650
// imsi
634651
if c.Mcc != 0 || c.Mnc != 0 || o.Mcc != 0 || o.Mnc != 0 {
635652
if c.Mcc != o.Mcc && r.Mcc != 0 {
@@ -830,6 +847,13 @@ func (c *ResTableConfig) IsBetterThan(o *ResTableConfig, r *ResTableConfig) bool
830847
}
831848

832849
func (c *ResTableConfig) Match(settings *ResTableConfig) bool {
850+
// nil ResTableConfig always matches.
851+
if settings == nil {
852+
return true
853+
} else if c == nil {
854+
return *settings == ResTableConfig{}
855+
}
856+
833857
// match imsi
834858
if settings.Mcc == 0 {
835859
if c.Mcc != 0 {

0 commit comments

Comments
 (0)