google / smali

Other
213 stars 35 forks source link

Fix incorrect DEX version for Android 10 (API 29) #2 #56

Closed IgorEisberg closed 6 months ago

IgorEisberg commented 6 months ago

See https://github.com/google/smali/pull/55

Android 10+ use DEX version 039 with Hidden API restrictions. Converting DEX version 039 to API 29 instead of 28 is mandatory, otherwise: Hidden API restrictions are only supported on api 29 and above.

iBotPeaches commented 6 months ago

Thanks - I'm guessing this will fix https://github.com/google/smali/issues/46 also

IgorEisberg commented 6 months ago

Thanks - I'm guessing this will fix #46 also

Indeed, we're talking about the same thing. JAR cannot be recompiled back unless API explicitly specified simply due to that. That issue was inherited from JesusFreke's defunct smali repo, when it should have been updated once DEX 040 was introduced. https://github.com/JesusFreke/smali/blob/master/dexlib2/src/main/java/org/jf/dexlib2/VersionMap.java#L45

sgjesse commented 6 months ago

Not sure we can just map DEX format 039 to API level 29. DEX_FILE_MAGIC states that version 039 is supported form API level 28 to allow instructions const-method-handle and const-method-type.

Looks more like the place reporting Hidden API restrictions are only supported on api 29 and above. needs to have its checking relaxed or rely on a more precise API level provided by the user instead of inferring it from the DEX format version.

IgorEisberg commented 6 months ago

Not sure we can just map DEX format 039 to API level 29. DEX_FILE_MAGIC states that version 039 is supported form API level 28 to allow instructions const-method-handle and const-method-type.

Looks more like the place reporting Hidden API restrictions are only supported on api 29 and above. needs to have its checking relaxed or rely on a more precise API level provided by the user instead of inferring it from the DEX format version.

Then that statement is contradictory to what mapDexVersionToApi does. mapDexVersionToApi maps DEX version to the last API level before a new DEX version is introduced:

DEX version 35 introduced in ancient times, mapped to API 23. DEX version 37 introduced in API 24, mapped to API 25. DEX version 38 introduced in API 26, mapped to API 27. ... DEX version 40 introduced in API 30, mapped to API 34. DEX version 41 introduced in API 35, mapped to API 35. (no newer API levels yet to update the mapping)

According to this pattern, it only makes perfect sense to fill in the blank with the missing range: DEX version 39 introduced in API 28, mapped to API 29.

sgjesse commented 6 months ago

Yes, I see you point. This mapping seems quite odd to me, but your change is consistent with the mapping of the other values.

IgorEisberg commented 6 months ago

Yes, I see you point. This mapping seems quite odd to me, but your change is consistent with the mapping of the other values.

It actually makes sense. Both Android 9 and Android 10 used 039, but Android 10 utilized Hidden API restrictions without having to introduce a new DEX version. However, those DEX files are backward-compatible with Android 9, where Hidden API restrictions would most likely simply be ignored. That's why specifying the last API version is so important.