Closed GoogleCodeExporter closed 9 years ago
Same here. LG G3 running official Lolipop. I was trying to decompile QRemote
(IR blaster app), both lge_res.apk and framework_res.apk were installed.
Log: http://pastebin.com/SfJcjdvw
Original comment by jaros...@dronsky.ru
on 28 Nov 2014 at 6:59
You can grab all mentioned APK's here. I tried to decompile "base.apk".
https://drive.google.com/folderview?id=0B2t3Ypff6A6dX3VCY3U3R2JIRzg&usp=sharing
Original comment by jaros...@dronsky.ru
on 28 Nov 2014 at 7:21
I duplicate. Multiple issues here.
lge-res.apk is being installed as 0.apk when its package id is 2.
base.apk & target apk both are package id of 127, but share resources
This causes the attributes to be undefined, hint "could not decode attr
errors". Will investigate.
Original comment by connor.tumbleson
on 30 Nov 2014 at 1:03
[deleted comment]
Assigning lge-res.apk being installed improperly as #713-1 and base & target
sharing same package id as #713-2.
#713-1 makes no sense. Apktool is doing nothing wrong, the APK has shown in a
hex output (http://i.imgur.com/o2oRkgK.png) has the package ID (which is right
before package name) as 00.
So I took a look at AOSP documentation.
https://github.com/android/platform_frameworks_base/blob/master/include/androidf
w/ResourceTypes.h#L833
> // If this is a base package, its ID. Package IDs start
> // at 1 (corresponding to the value of the package bits in a
> // resource identifier). 0 means this is not a base package.
> uint32_t id;
So maybe lge-res.apk is not a base package or maybe its some new fancy method
of obfuscation / fancy OEM tricks. Since the error message of #713-2 doesn't
have a package ID of 0x00 or 0x02, then its probably safe to say this isn't the
problem.
Investigation of #713-2 is as follows. Using the pattern of installing the
frameworks. The APKs included from comment #2 showed.
i) com.lge.qremote.apk - no issue decoding
ii) com.lge.app.floating.res.apk - no issue decoding
iii) com.lge.sui.widget.apk - failed (ResBoolValue cannot be cast to ResAttr)
iv) LGFormManager.apk - no issue decoding
v) LGSettings.apk - failed (Undefined 0x7f attributes)
vi) LGSystemServer.apk - no issue decoding
vii) LGSystemUI.apk - failed (Same as v)
viii) QuicksetSDK.apk - no issue decoding
ix) UnifiedEULA.apk - failed (Same as v)
So basically (iii) is a completely non-related bug. The apks of interest are
(v), (vii) and (ix).
Original comment by connor.tumbleson
on 22 Dec 2014 at 12:24
As a quick follow-up. All the missing resources in (ix) are found in the apk.
> ibotpeaches@raganok:~/Downloads/Apktool/Bug713$ aapt d resources
UnifiedEULA.apk | grep '0x7f080000'
... 40 lines
> ibotpeaches@raganok:~/Downloads/Apktool/Bug713$ aapt d resources
UnifiedEULA.apk | grep '0x7f02000c'
... 9 lines
> ibotpeaches@raganok:~/Downloads/Apktool/Bug713$ aapt d resources
UnifiedEULA.apk | grep '0x7f08001e'
... 30 lines
All return results. This points towards an improper decoding and assigning of
resources on Apktool's side. This is better than having to attempt a merge of a
resource pool between alike package ids. The culprit seems to be apktool's
resource decoding.
Original comment by connor.tumbleson
on 22 Dec 2014 at 12:28
So the problem has been found, the solution has not been started.
We have attributes that have references to internal resources (0x7F), so ie you
have attr="@0x7F080000" etc. We try to follow this reference, but it hasn't
been decoded yet so we encounter an UndefinedRes error.
I need to add support for delayed loading of attributes. These attributes are
present after the APK is fully loaded, but since we decode as we load we
encounter errors. We should decode all resources, but tag the attrs that need
to be decoded later.
Usually this hasn't been a problem since attrs are first or the attr is from a
shared public framework.
Original comment by connor.tumbleson
on 22 Dec 2014 at 1:22
Yeah this is a problem in the current design of Apktool. Say we write the files
using the unresolved name (ie @0x7F08000), then we have that in the file and
stored in an array saying it needs to be resolved.
Unfortunately re-locating this reference in the file is quite difficult. We
would have to reparse the XML files and then crawl them looking for our
reference to change. This is damn slow, especially if we need to do it for 100+
files. I need to adapt apktool to delay writing of files if it has unresolved
resources.
However, apktool isn't multi-threaded so things go in turns and simply cannot
be paused as that will prevent the next file from being decoded and thus a
deadlock since we have a circle of waiting.
This is a big undertaking. I'm going to take a few days and talk to some people
and try and figure out a good plan of attack for this, as I fear more apks/oems
will be affected soon.
----------------------
This exact problem happened before with missing name/value pairs in the
manifest. Except these missing attrs were public (0x01), so I could simply
reference the framework for the resource. This I believe was bug #512.
Original comment by connor.tumbleson
on 22 Dec 2014 at 10:04
Okay back to #713-1. A packageId of 0 indicates a shared library resource. This
means the packageId is assigned at runtime. However, the resources internally
are still assigned a packageId that is not zero so mapping can occur.
/**
* A shared library package-id to package name entry.
*/
struct ResTable_lib_entry
{
// The package-id this shared library was assigned at build time.
// We use a uint32 to keep the structure aligned on a uint32 boundary.
uint32_t packageId;
// The package name of the shared library. \0 terminated.
char16_t packageName[128];
};
This block of code shows the mapping of the package name to ID. However, this
struct is found no-where in the offending resources.arsc. You can find the
first package name of "com lge" for the ResTable_package struct, but none other
so finding the true packageId is unknown to me still.
I've been looking at the related commits which introduced shared packages
https://github.com/android/platform_frameworks_base/commit/de898ff42912bd7ca1bfb
099cd439562496765a4
https://github.com/android/platform_frameworks_base/commit/6022debdbcc4498736580
640c6287b57872617a2
Though no luck. Enjoy the holidays. Will research more soon.
Original comment by connor.tumbleson
on 24 Dec 2014 at 2:25
https://github.com/iBotPeaches/Apktool/commit/e9d21f84af8522ef797a4016b0266f394b
9a5650
RC4 / 2.0 Gold will contain fix.
Original comment by connor.tumbleson
on 25 Dec 2014 at 8:31
I still cannot decompile it.
My code:
apktool if framework-res.apk
apktool if lge-res.apk
now in java based on the github repo:
ApkDecoder decoder = new ApkDecoder();
decoder.setApkFile(new File("C:\\Users\\Yoav\\Downloads\\android\\LGSystemUI.apk"));
decoder.setApi(21);
decoder.setOutDir(new File("C:\\Users\\Yoav\\Downloads\\android\\lgsystemui\\"));
decoder.decode();
Log:
דצמ 26, 2014 9:31:02 AM brut.androlib.ApkDecoder decode
INFO: Using Apktool 2.0.0-dirty on LGSystemUI.apk
דצמ 26, 2014 9:31:02 AM brut.androlib.res.AndrolibResources loadMainPkg
INFO: Loading resource table...
דצמ 26, 2014 9:31:02 AM brut.androlib.res.decoder.ARSCDecoder readLibraryType
INFO: Decoding Shared Library (com.lge), pkgId: 2
דצמ 26, 2014 9:31:04 AM brut.androlib.res.AndrolibResources decode
INFO: Decoding AndroidManifest.xml with resources...
דצמ 26, 2014 9:31:04 AM brut.androlib.res.AndrolibResources loadFrameworkPkg
INFO: Loading resource table from file: C:\Users\Yoav\apktool\framework\1.apk
דצמ 26, 2014 9:31:05 AM brut.androlib.res.decoder.AXmlResourceParser
getAttributeValue
WARNING: Could not decode attr value, using undecoded value instead:
ns=android, name=versionCode, value=0x00000015
brut.androlib.AndrolibException: Expected pkg of id: 1, got: 2
at brut.androlib.res.AndrolibResources.loadFrameworkPkg(AndrolibResources.java:139)
at brut.androlib.res.data.ResTable.getPackage(ResTable.java:74)
at brut.androlib.res.data.ResTable.getResSpec(ResTable.java:57)
at brut.androlib.res.data.ResTable.getResSpec(ResTable.java:53)
at brut.androlib.res.decoder.ResAttrDecoder.decode(ResAttrDecoder.java:36)
at brut.androlib.res.decoder.AXmlResourceParser.getAttributeValue(AXmlResourceParser.java:369)
at org.xmlpull.v1.wrapper.classic.XmlPullParserDelegate.getAttributeValue(XmlPullParserDelegate.java:69)
at brut.androlib.res.decoder.XmlPullStreamDecoder$1.parseManifest(XmlPullStreamDecoder.java:97)
at brut.androlib.res.decoder.XmlPullStreamDecoder$1.event(XmlPullStreamDecoder.java:65)
at brut.androlib.res.decoder.XmlPullStreamDecoder.decode(XmlPullStreamDecoder.java:141)
at brut.androlib.res.decoder.XmlPullStreamDecoder.decodeManifest(XmlPullStreamDecoder.java:153)
at brut.androlib.res.decoder.ResFileDecoder.decodeManifest(ResFileDecoder.java:134)
at brut.androlib.res.AndrolibResources.decode(AndrolibResources.java:296)
at brut.androlib.Androlib.decodeResourcesFull(Androlib.java:131)
at brut.androlib.ApkDecoder.decode(ApkDecoder.java:101)
at com.company.Main.main(Main.java:18)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
דצמ 26, 2014 9:31:05 AM brut.androlib.res.AndrolibResources loadFrameworkPkg
INFO: Loading resource table from file: C:\Users\Yoav\apktool\framework\1.apk
דצמ 26, 2014 9:31:06 AM brut.androlib.res.decoder.AXmlResourceParser
getAttributeValue
WARNING: Could not decode attr value, using undecoded value instead:
ns=android, name=versionName, value=0x00000030
brut.androlib.AndrolibException: Expected pkg of id: 1, got: 2
at brut.androlib.res.AndrolibResources.loadFrameworkPkg(AndrolibResources.java:139)
at brut.androlib.res.data.ResTable.getPackage(ResTable.java:74)
at brut.androlib.res.data.ResTable.getResSpec(ResTable.java:57)
at brut.androlib.res.data.ResTable.getResSpec(ResTable.java:53)
at brut.androlib.res.decoder.ResAttrDecoder.decode(ResAttrDecoder.java:36)
at brut.androlib.res.decoder.AXmlResourceParser.getAttributeValue(AXmlResourceParser.java:369)
at org.xmlpull.v1.wrapper.classic.XmlPullParserDelegate.getAttributeValue(XmlPullParserDelegate.java:69)
at brut.androlib.res.decoder.XmlPullStreamDecoder$1.parseManifest(XmlPullStreamDecoder.java:99)
at brut.androlib.res.decoder.XmlPullStreamDecoder$1.event(XmlPullStreamDecoder.java:65)
at brut.androlib.res.decoder.XmlPullStreamDecoder.decode(XmlPullStreamDecoder.java:141)
at brut.androlib.res.decoder.XmlPullStreamDecoder.decodeManifest(XmlPullStreamDecoder.java:153)
at brut.androlib.res.decoder.ResFileDecoder.decodeManifest(ResFileDecoder.java:134)
at brut.androlib.res.AndrolibResources.decode(AndrolibResources.java:296)
at brut.androlib.Androlib.decodeResourcesFull(Androlib.java:131)
at brut.androlib.ApkDecoder.decode(ApkDecoder.java:101)
at com.company.Main.main(Main.java:18)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
דצמ 26, 2014 9:31:06 AM brut.androlib.res.AndrolibResources loadFrameworkPkg
INFO: Loading resource table from file: C:\Users\Yoav\apktool\framework\1.apk
דצמ 26, 2014 9:31:08 AM brut.androlib.res.decoder.AXmlResourceParser
getAttributeValue
WARNING: Could not decode attr value, using undecoded value instead:
ns=android, name=sharedUserId, value=0x0000002e
brut.androlib.AndrolibException: Expected pkg of id: 1, got: 2
at brut.androlib.res.AndrolibResources.loadFrameworkPkg(AndrolibResources.java:139)
at brut.androlib.res.data.ResTable.getPackage(ResTable.java:74)
at brut.androlib.res.data.ResTable.getResSpec(ResTable.java:57)
at brut.androlib.res.data.ResTable.getResSpec(ResTable.java:53)
at brut.androlib.res.decoder.ResAttrDecoder.decode(ResAttrDecoder.java:36)
at brut.androlib.res.decoder.AXmlResourceParser.getAttributeValue(AXmlResourceParser.java:369)
at org.xmlpull.v1.wrapper.classic.XmlPullParserDelegate.getAttributeValue(XmlPullParserDelegate.java:69)
at org.xmlpull.v1.wrapper.classic.StaticXmlSerializerWrapper.writeStartTag(StaticXmlSerializerWrapper.java:267)
at org.xmlpull.v1.wrapper.classic.StaticXmlSerializerWrapper.event(StaticXmlSerializerWrapper.java:211)
at brut.androlib.res.decoder.XmlPullStreamDecoder$1.event(XmlPullStreamDecoder.java:83)
at brut.androlib.res.decoder.XmlPullStreamDecoder.decode(XmlPullStreamDecoder.java:141)
at brut.androlib.res.decoder.XmlPullStreamDecoder.decodeManifest(XmlPullStreamDecoder.java:153)
at brut.androlib.res.decoder.ResFileDecoder.decodeManifest(ResFileDecoder.java:134)
at brut.androlib.res.AndrolibResources.decode(AndrolibResources.java:296)
at brut.androlib.Androlib.decodeResourcesFull(Androlib.java:131)
at brut.androlib.ApkDecoder.decode(ApkDecoder.java:101)
at com.company.Main.main(Main.java:18)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
Exception in thread "main" java.lang.NullPointerException
at java.io.Writer.write(Writer.java:157)
at brut.androlib.res.util.ExtMXSerializer.writeAttributeValue(ExtMXSerializer.java:38)
at org.xmlpull.mxp1_serializer.MXSerializer.attribute(MXSerializer.java:696)
at org.xmlpull.v1.wrapper.classic.XmlSerializerDelegate.attribute(XmlSerializerDelegate.java:106)
at org.xmlpull.v1.wrapper.classic.StaticXmlSerializerWrapper.writeStartTag(StaticXmlSerializerWrapper.java:267)
at org.xmlpull.v1.wrapper.classic.StaticXmlSerializerWrapper.event(StaticXmlSerializerWrapper.java:211)
at brut.androlib.res.decoder.XmlPullStreamDecoder$1.event(XmlPullStreamDecoder.java:83)
at brut.androlib.res.decoder.XmlPullStreamDecoder.decode(XmlPullStreamDecoder.java:141)
at brut.androlib.res.decoder.XmlPullStreamDecoder.decodeManifest(XmlPullStreamDecoder.java:153)
at brut.androlib.res.decoder.ResFileDecoder.decodeManifest(ResFileDecoder.java:134)
at brut.androlib.res.AndrolibResources.decode(AndrolibResources.java:296)
at brut.androlib.Androlib.decodeResourcesFull(Androlib.java:131)
at brut.androlib.ApkDecoder.decode(ApkDecoder.java:101)
at com.company.Main.main(Main.java:18)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
Process finished with exit code 1
Original comment by yoav.g...@gmail.com
on 26 Dec 2014 at 7:32
Update:
I had to play with the naming of 0.apk and 1.apk in order to make it work. it
should be 1 and 2 (don't remember which is which).
Original comment by yoav.g...@gmail.com
on 26 Dec 2014 at 7:35
Original issue reported on code.google.com by
szecsl...@gmail.com
on 28 Nov 2014 at 4:17