-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[FEAT] XAPK Support - Support Resource Decompilation in XAPK | @null in XML Resources When Decompiling XAPK Base APK #3806
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I'm trying it on 'Opera browser beta' with the same problem. Problem is the following: base.apk has AndroidManifest.xml and resources.arsc Let's see AndroidManifest.xml in Android Studio (Analyze APK option): Let's see base.apk's resources.arsc. This symbol is available for xxhdpi resolution in another APK package (split_config.xxhdpi.apk): It has got a name drawable/notification_smali Solution: Currently this is not allowed. For decompilation, add the possibility to specify more APK packages from which resource IDs will be derived. resources.arsc to be loaded from these additional APK packages and IDs to be put inside of res/values/public.xml properly. AndroidManifest.xml should be decompiled then. Thanks for this great project by the way. |
Yes this is a challenge Apktool has not yet handled. Apktool frameworks handle this somewhat well, but that goes under assumption that pkgId is different for loading for all. As you can tell in your split setups - they all share the private package id (0x7f) but have chunks of their own resources. This has bubbled up in a few times in some applications that have similar behavior without being a split - say this ticket where Twitter has 7f-7g - #2514 Or this one - #3364 Its just a bit difficult to identify the fix here between quite a few things.
|
Short-Term Solution
Long-Term Vision
Summary
I guess, this approach would help Apktool support split APKs more effectively while reducing the complexity for users |
Make it load resource IDs from multiple APK files. Initially APK tool has been designed to work with only one APK file. This approach is no longer valid, most importantly for resources. At least the resource IDs should be loaded from (primary APK file + several other APK files). Solution: Currently this is not allowed. For decompilation, add the possibility to specify more APK packages from which resource IDs will be derived. resources.arsc to be loaded from these additional APK packages and IDs to be put inside of res/values/public.xml properly. AndroidManifest.xml should be decompiled later. @iBotPeaches, how about implementing it in this way? This doesn't sound that hard to do, although it can take few hours possibly. |
I mean if you feel you can implement that in a few hours - go for it. That feels like 20-30 hours of work for me. |
I can possibly think about implementing it soon, can do a pull request then. I'm using your tool in my project (fastman92 APK modifier) that handles standalone/split APK files (APK/APKM/APKS/XAPK), so I can see some challenges that come with it. You have made a great tool overall. Today I've been working on handling the problem of decompilation of DEX files from 'assets' directory and compilation by APKtool. It doesn't work properly in APKtool. have designed a workaround in my tool for this, so that additional DEX files can be compiled properly and put into correct location into APK file (back into assets). This is something that I would like to see fixed in APKtool. I could possibly add a pull request for this. I haven't worked with source code of APK tool yet, so my time estimate may be a bit off. For me the time to implement it might be longer because I don't have such a good understanding of APK tool's source code as you do (may need some to learn few things how it works). Anyway, I'll see what I can do. May add a pull request later. |
What I've discovered while my tool, dummy mode in APK tool can handle split APKs properly. So now my tool can convert any bundle to standalone APK, managed to implement a tricky move of resources between base APK and other APK files including their names. This was quite a lot of work, but I did it finally. I recommend everyone to use the following setting: -resm dummy |
That was (merging the bundles into a single apk file), already an option!? -- With APKEditor, so why YOUR TOOL is specific for this case, and you didn't have to implement a tricky move for that? (Correct me if I missed something please)
That's not the point there;
When you have that option, I guess you cannot get a working app recompiled (I guess -- There is a great chance I'm missing here -- Correct me if so) And, let's take if it does somehow replace dummy resource locations with actual ones on recompilation, but, does it decompile the actual resources as well or skip them? If this option doesn't do these (reallocate actual files, and decompile all the resources), in dummy mode, this's not a solution at all!? Cause for example, the Wattpad XAPK, has only config.xxhdpi.apk and the base apk (wp.wattpad.apk), so how can we edit resources then? Again, I really don't know about the -resm dummy flag. So I could be completely wrong. Kindly correct me. |
Right. APK editor allows to merge the bundle into a single APK file. I'm building my own tool that also does it and many other things like renaming the package including everything that's related to package name. Let's explain the thing about resources now. resources.arsc contains a list of IDs and their values for several different configurations (default, :
Here it can be seen: Anyway, what matters it can be empty. For bundles (using split APKs) it's possible that there will be a resource ID declared, where all configurations have an unset value in certain APK file. Let's take a look at this: There exists a resource ID 0x7f080378 in this base APK, but its value is not set for any configuration (default, sw600dp, television...). It's empty. APK tool, when decompiling this base APK will consider it a missing resource (empty value in all configurations). With "dummy" mode it will properly create an entry for this in the following files: The APK can be recompiled this way properly. Now in other file like config.xxhdpi.apk things look a bit differently, As it can be seen, for this ID there's a value for at least one config specified. APK tool will not create a dummy element for this. It will extract the file to "{decompiledDir}\res\drawable-xxhdpi". There will be two things: The definition for xxhdpi config. In this case the PNG file will be created: "so how can we edit resources then?" Resource IDs are common, but the definitions for certain configs may be in any of split APK files. You edit resources in APK packages, where they reside. Can refer to resource IDs that may have their definitions in other APK files (must have empty dummy entry for at least one config in such a case in file such as drawables.xml so that APK tool does not abort the compilation and does not tell "public symbol not defined"). I had to think quite a bit about this problem as I'm developing my tool. |
Ah, I see, that approach seems feasible. Therefore, perhaps you could integrate this feature; once implemented in your tool, it would offer increased efficiency? |
I want to do this. I still need to understand the problem fully in order to make this functionality work flawlessly. |
Looking forward for it |
Done. Download the newest version of "fastman92 APK modifier" https://gtaforums.com/topic/979211-fastman92-apk-modifier/ Load bundle (APK/APKS/APKM/XAPK/directory) Check the option "Only fix resources, don't add APK modifier's code". Click Save button. You can save as a bundle or standalone APK. Look for modified files in tmp directory, where you have extracted APK modifier. You might want to copy these files to another location. They are being deleted, when APK modifier is being shut down. These files are better in a way, also modified to allow a compilation in cases, where APK tool's code would fail to compile resources (also fixing the problem of private resources). So, what's important to know about split APKs: make sure to decompile them with "-resm dummy" option in APKtool. This way APKtool won't output @null in place of actual references, but it will create empty entries that can be referenced properly. |
Oh my... I was thinking that you were going to contribute back to this project when you said you could do it and @iBotPeaches said "go for it". 😯 And it's not opensource? Anyway, I personally appreciate the work you've done! Should checkout. |
I may add some improvements to APKtool later. I have never worked with APKtool's source code though, so it can take me some time to figure out what I can do with this. APKtool's is focused on decompilation and recompilation of a single APK file and it works quite well for this task (although there are some problems with this, noticeable in case of certain APKs). Now my project is focused on working with packages or bundles (multiple APKs), possibly adding some good changes automatically (like AndUnpr directory to be used instead of Android, solves Android 10+ problem of limited access to /sdcard/Android, these changes can be disabled in GUI) and their recompilation, possibly conversion to standalone APK. |
Ah, I see.
Impressive, indeed.
Ah, right. |
Thanks for the reply. I'd recommend my project to anyone who wants to modify an application to provide an easy access to files (/sdcard/AndUnpr instead of /sdcard/Android, people who want to modify game files). My project works with multiple packages, it offers many features, makes lots of changes. Note that it depends on APKtool to decompile and compile each single APK. That being said, APKtool is an important project to handle a single APK. |
Uh oh!
There was an error while loading. Please reload this page.
Information
apktool -version
) - 2.11.0 | 2.11.0-7-f5c226b5-SNAPSHOTjava --version
) - 23.0.1 | 2024-10-15ADB Stacktrace/Logcat
Steps to Reproduce
apktool d wp.wattpad.apk
apktool b -o wp.wattpad.apk
adb install-multiple app1.apk app2.apk ...
ORCreate a zip folder containing all the apks, icon.png, manifest.json
Frameworks
Not from a framework
APK
https://apkcombo.app/wattpad/wp.wattpad/download/phone-10.95.0-apk
Questions to ask before submission
apktool d
,apktool b
without changing anything? - YesUpdate: I don't get any error (or warning) when decompiling or recompiling. So I've included adb's logcat here.
Additional Information
Not a issue with the original xapk itself. I could successfully install the original xapk (and with adb too).
When the wp.wattpad.apk (base apk) is decompiled, it contains a lot of @null values, like
and in many more. (This's from AndroidManifest.xml)
There're apks for multiple resolutions:
config.hdpi.apk, config.ldpi.apk, config.mdpi.apk, config.tvdpi.apk, config.xhdpi.apk, config.xxhdpi.apk, config.xxhdpi.apk
, so could it be that apktool replaces original resources with @null as they're not available in the base apk?Furthermore, the target Android version seemed to be 15, which's more interesting.
The text was updated successfully, but these errors were encountered: