Время на прочтение
1 мин
Количество просмотров 5.2K
Всем привет. Меня зовут Алексей и я занимаюсь реверсом adnroid-приложений. Многие, кто делал реверс android-приложений, сталкивались с тем, что при обратной сборке с помощью apktool приложение не собиралось и писало об ошибках во время Building resources. Как правило эти ошибки можно исправить вручную в местах их возникновения. Но что делать когда их много? На исправления уйдет не один час. Сегодня я расскажу как бороться с эти за пару минут.
1. Устанавливаем на устройствоэмулятор где будем использовать приложение lucky patcher и патчим устройство.
Toolbox → Patch to Android → и патчим первые 2 пункта как на картинке.
2. Собираем приложение с помощью apktool. Apk не создастся, но если у вас не будет ошибок в smali файлах, то у нас будет собранный .dex файл по адресу папка_приложения → build → apk
3. Открываем с помощью winrar оригинальный apk и кладем туда наш модифицированный dex-файл.
4. Устанавливаем на пропатченное устройствоэмулятор. Profit.
P.S. Однажды я столкнулся с приложением, которое генерировало токен на основе подписи apk. И именно такой способ помог мне выяснить это и удачно начать генерировать токены в своем боте)
I am experiencing very annoying problems with the application apktool problem.
I do not understand what i am doing wrong, or what the problem is.
I tried this on debian , and on linux mint. I used different versions of apktool,
resulting in the same error:
I: Checking whether sources has changed...
I: Checking whether resources has changed...
I: Building resources...
Exception in thread "main" brut.androlib.AndrolibException: brut.common.BrutException: could not exec command: [aapt, p, -F, /tmp/APKTOOL3630495287059303807.tmp, -I, /home/awesomename/apktool/framework/1.apk, -S, /home/awesomename/out/./res, -M, /home/awesomename/out/./AndroidManifest.xml]
at brut.androlib.res.AndrolibResources.aaptPackage(Unknown Source)
at brut.androlib.Androlib.buildResourcesFull(Unknown Source)
at brut.androlib.Androlib.buildResources(Unknown Source)
at brut.androlib.Androlib.build(Unknown Source)
at brut.androlib.Androlib.build(Unknown Source)
at brut.apktool.Main.cmdBuild(Unknown Source)
at brut.apktool.Main.main(Unknown Source)
Caused by: brut.common.BrutException: could not exec command: [aapt, p, -F, /tmp/APKTOOL3630495287059303807.tmp, -I, /home/windows/apktool/framework/1.apk, -S, /home/windows/out/./res, -M, /home/windows/out/./AndroidManifest.xml]
at brut.util.OS.exec(Unknown Source)
... 7 more
Caused by: java.io.IOException: Cannot run program "aapt": error=2, No such file or directory
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1041)
at java.lang.Runtime.exec(Runtime.java:617)
at java.lang.Runtime.exec(Runtime.java:485)
... 8 more
Caused by: java.io.IOException: error=2, No such file or directory
at java.lang.UNIXProcess.forkAndExec(Native Method)
at java.lang.UNIXProcess.<init>(UNIXProcess.java:135)
at java.lang.ProcessImpl.start(ProcessImpl.java:130)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1022)
... 10 more
It seems it can not use aapt , but i read about apktool.
And it seems that aapt is build inside apktool , why is it not working ?
Well, there
are many reasons why but I will show you most common errors. Note, i’m talking
about general apk modding, not system apk/framework modding
Assets.dex issue «Class xxx has already been
interned» and «Not a valid dex magic value»
By default,
apktool try to decompile dex from assets folder which would decompile to
smali_assets on a root directory of decompiled apk, and compiled to assets.dex
upon compiling
This can
cause compiling issues
Solution:
To fix the
problem, decompile APK again with the flag [code]—only-main-classes[/code] to
only decompile on main classes in root (classes[0-9].dex) then you can compile
without any problem
Note:
Only for apktool 2.4.1 and up
You can try
to delete .dex from assets folder or smali_assets/assets.dex but it may cause
problems
If you are
using APK Easy Tool 1.57 and above, you can enable the option «Only
disassemble the main dex classes» under Options -> Apktool. Again, only
for apktool 2.4.1 and up
Error: No resource identifier found for attribute
‘manageSpace’ in package ‘android’
The attribute
does not exist in the framework or it could be fake attribute to prevent compiling
Solution:
Remove android:manageSpace=»true» from AndroidManifest.xml
Error: String types not allowed
Issue: https://github.com/iBotPeaches/Apktool/issues/2462
Solution:
In this case:
W: Failed to generate resource table for split »
W: E:(PathToDecompiledAPK)resvaluesdrawables.xml:5: error: Error:
String types not allowed (at ‘APKTOOL_DUMMY_1c2’ with value »).
This error
tells you which xml an error occured and which line
Open the XML file: E:(PathToDecompiledAPK)resvaluesdrawables.xml
Remove drawable name=»APKTOOL_DUMMY_1c2″ /> at line 5 and save the file
You will get another
error about public symbol. See below
Error: Public symbol XXX declared here is not defined.
Public symbol
does not exist in public.xml
Solution:
In this case:
W: E:(PathToDecompiledAPK)resvaluespublic.xml:1133: error: Public
symbol drawable/APKTOOL_DUMMY_1c2 declared here is not defined.
Open the XML
file: (PathToDecompiledAPK)resvaluespublic.xml
Remove <public type=»drawable»
name=»APKTOOL_DUMMY_1c2″ id=»0x7f0601c2″ /> at
line 1133 and save the file
Resource error (APKTOOL_DUMMY) (Split APK)
If you get
APKTOOL_DUMMY that’s generally because apktool can’t decode some of the
information in the original APK and creates a ‘dummy’ value instead. Because
there’s no things called APKTOOL_DUMMY in public.xml, the APK can’t be
recompiled. It’s likely because you try to compile splitted APK with some
missing infomation
Solution:
Merge split
APKs manually
https://platinmods.com/threads/how-to-turn-a-split-apk-into-a-normal-non-split-apk.76683
Or use the
SAP (Split APK Packer) tool
https://platinmods.com/threads/sap-split-apks-packer-by-kirlif-windows-linux-merge-split-apks-into-single-apk.101798/
Other issues
— APK is
protected, encrypted or obfuscated. Reversing of such files is beyond the
scope, so find out yourself
— Invalid syntax
in smali and xml. You may have done something wrong
You can
search for useful infomation on the following sites.
Report your
issues to them if you feel like to
Apktool: iBotPeaches/Apktool
Smali/baksmali: JesusFreke/smali
Well, there are many reasons why but I will show you most common errors. Note, i’m talking about general apk modding, not system apk/framework modding
Assets.dex issue «Class xxx has already been interned» and «Not a valid dex magic value»
By default, apktool try to decompile dex from assets folder which would decompile to smali_assets on a root directory of decompiled apk, and compiled to assets.dex upon compiling
This can cause compiling issues
Solution:
To fix the problem, decompile APK again with the flag
to only decompile on main classes in root (classes[0-9].dex) then you can compile without any problem
Note: Only for apktool 2.4.1 and up
You can try to delete .dex from assets folder or smali_assets/assets.dex but it may cause problems
If you are using APK Easy Tool 1.57 and above, you can enable the option «Only disassemble the main dex classes» under Options -> Apktool. Again, only for apktool 2.4.1 and up
Error: No resource identifier found for attribute ‘manageSpace’ in package ‘android’
The attribute does not exist in the framework or it could be fake attribute to prevent compiling
Solution:
Remove android:manageSpace=»true» from AndroidManifest.xml
Error: String types not allowed
Issue: [BUG]Issues repacking res it gives issues with apktool_dummy in integers.xml and dimens.xml · Issue #2462 · iBotPeaches/Apktool
Solution:
In this case:
Code:
W: Failed to generate resource table for split ''
W: E:(PathToDecompiledAPK)resvaluesdrawables.xml:5: error: Error: String types not allowed (at 'APKTOOL_DUMMY_1c2' with value '').
This error tells you which xml an error occured and which line
Open the XML file: E:(PathToDecompiledAPK)resvaluesdrawables.xml
Remove drawable name=»APKTOOL_DUMMY_1c2″ /> at line 5 and save the file
You will get another error about public symbol. See below
Error: Public symbol XXX declared here is not defined.
Public symbol does not exist in public.xml
Solution:
In this case:
Code:
W: E:(PathToDecompiledAPK)resvaluespublic.xml:1133: error: Public symbol drawable/APKTOOL_DUMMY_1c2 declared here is not defined.
Open the XML file: (PathToDecompiledAPK)resvaluespublic.xml
Remove <public type=»drawable» name=»APKTOOL_DUMMY_1c2″ id=»0x7f0601c2″ /> at line 1133 and save the file
Resource error (APKTOOL_DUMMY) (Split APK)
If you get APKTOOL_DUMMY that’s generally because apktool can’t decode some of the information in the original APK and creates a ‘dummy’ value instead. Because there’s no things called APKTOOL_DUMMY in public.xml, the APK can’t be recompiled. It’s likely because you try to compile splitted APK with some missing infomation
Solution:
Merge split APKs manually
Or use the SAP (Split APK Packer) tool
Other issues
— APK is protected, encrypted or obfuscated. Reversing of such files is beyond the scope, so find out yourself
— Invalid syntax in smali and xml. You may have done something wrong
You can search for useful infomation on the following sites.
Report your issues to them if you feel like to
Apktool: iBotPeaches/Apktool
Smali/baksmali: JesusFreke/smali
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
Closed
nderkach opened this issue
Jun 30, 2015
· 6 comments
Comments
I’m trying to decompile and compile the following APK with debug symbols: https://dl.dropboxusercontent.com/u/5017232/Ticketmaster_1.6.4.1_30-orig.apk
./apktool d -d -f Ticketmaster_1.6.4.1_30-orig.apk -o out
./apktool b -d out -o Ticketmaster_1.6.4.1_30-new.apk
I’m using the latest apktool 2.0.0 with JDK 8. I’m running with the following issues when trying to build the apt back:
I: Using Apktool 2.0.0
I: Checking whether sources has changed...
I: Smaling smali folder into classes.dex...
I: Checking whether sources has changed...
I: Smaling smali_classes10 folder into classes10.dex...
I: Checking whether sources has changed...
I: Smaling smali_classes2 folder into classes2.dex...
I: Checking whether sources has changed...
I: Smaling smali_classes5 folder into classes5.dex...
I: Checking whether sources has changed...
I: Smaling smali_classes8 folder into classes8.dex...
I: Checking whether sources has changed...
I: Smaling smali_classes9 folder into classes9.dex...
I: Checking whether resources has changed...
I: Building resources...
/Users/nderkach/Desktop/ticketmaster/out/res/layout/activity_bootscreen.xml:9: error: No resource identifier found for attribute 'insetForeground' in package 'android'
/Users/nderkach/Desktop/ticketmaster/out/res/layout-v21/activity_bootscreen.xml:9: error: No resource identifier found for attribute 'insetForeground' in package 'android'
/Users/nderkach/Desktop/ticketmaster/out/res/layout/adu_walkthrough_activity.xml:6: error: No resource identifier found for attribute 'pageColor' in package 'android'
/Users/nderkach/Desktop/ticketmaster/out/res/layout/edp_combined_activity.xml:7: error: No resource identifier found for attribute 'pstsIndicatorColor' in package 'android'
/Users/nderkach/Desktop/ticketmaster/out/res/layout/horizontal_ticket_recto.xml:6: error: No resource identifier found for attribute 'labelStyle' in package 'android'
/Users/nderkach/Desktop/ticketmaster/out/res/layout/horizontal_ticket_recto.xml:6: error: No resource identifier found for attribute 'valueStyle' in package 'android'
/Users/nderkach/Desktop/ticketmaster/out/res/layout/tm_activity_integrated_listings.xml:34: error: Error: Integer types not allowed (at 'orientation' with value '1').
Exception in thread "main" brut.androlib.AndrolibException: brut.androlib.AndrolibException: brut.common.BrutException: could not exec command: [/var/folders/nc/9y2gpgzs1gz4wg9mp3spyfnm0000gn/T/brut_util_Jar_6348033727496735282.tmp, p, --debug-mode, --forced-package-id, 127, --min-sdk-version, 15, --target-sdk-version, 22, --version-code, 30, --version-name, 1.6.4.1, -F, /var/folders/nc/9y2gpgzs1gz4wg9mp3spyfnm0000gn/T/APKTOOL6979768093236566769.tmp, -0, arsc, -I, /Users/nderkach/Library/apktool/framework/1.apk, -S, /Users/nderkach/Desktop/ticketmaster/out/res, -M, /Users/nderkach/Desktop/ticketmaster/out/AndroidManifest.xml]
at brut.androlib.Androlib.buildResourcesFull(Androlib.java:458)
at brut.androlib.Androlib.buildResources(Androlib.java:396)
at brut.androlib.Androlib.build(Androlib.java:285)
at brut.androlib.Androlib.build(Androlib.java:256)
at brut.apktool.Main.cmdBuild(Main.java:225)
at brut.apktool.Main.main(Main.java:84)
Caused by: brut.androlib.AndrolibException: brut.common.BrutException: could not exec command: [/var/folders/nc/9y2gpgzs1gz4wg9mp3spyfnm0000gn/T/brut_util_Jar_6348033727496735282.tmp, p, --debug-mode, --forced-package-id, 127, --min-sdk-version, 15, --target-sdk-version, 22, --version-code, 30, --version-name, 1.6.4.1, -F, /var/folders/nc/9y2gpgzs1gz4wg9mp3spyfnm0000gn/T/APKTOOL6979768093236566769.tmp, -0, arsc, -I, /Users/nderkach/Library/apktool/framework/1.apk, -S, /Users/nderkach/Desktop/ticketmaster/out/res, -M, /Users/nderkach/Desktop/ticketmaster/out/AndroidManifest.xml]
at brut.androlib.res.AndrolibResources.aaptPackage(AndrolibResources.java:419)
at brut.androlib.Androlib.buildResourcesFull(Androlib.java:444)
... 5 more
Caused by: brut.common.BrutException: could not exec command: [/var/folders/nc/9y2gpgzs1gz4wg9mp3spyfnm0000gn/T/brut_util_Jar_6348033727496735282.tmp, p, --debug-mode, --forced-package-id, 127, --min-sdk-version, 15, --target-sdk-version, 22, --version-code, 30, --version-name, 1.6.4.1, -F, /var/folders/nc/9y2gpgzs1gz4wg9mp3spyfnm0000gn/T/APKTOOL6979768093236566769.tmp, -0, arsc, -I, /Users/nderkach/Library/apktool/framework/1.apk, -S, /Users/nderkach/Desktop/ticketmaster/out/res, -M, /Users/nderkach/Desktop/ticketmaster/out/AndroidManifest.xml]
at brut.util.OS.exec(OS.java:89)
at brut.androlib.res.AndrolibResources.aaptPackage(AndrolibResources.java:413)
... 6 more
I’ve tried to do the same without compiling and decompiling resource files, but then I run into an issue with [Fatal Error] AndroidManifest.xml:1:1: Content is not allowed in prolog
It appears custom attributes (or rather attributes from a library), in this case com.android.support:design:22.2.0
are having troubles being decoded.
[Fatal Error] AndroidManifest.xml:1:1: Content is not allowed in prolog
I’m running into this as well. Why is AndroidManifest.xml even parsed if --no-res
is set?
i have same issue
dex file compile success but …. Building resources… step error
I: Using Apktool 2.0.1
I: Checking whether sources has changed...
I: Smaling smali folder into classes.dex...
W: Unknown file type, ignoring: kat/smali/.DS_Store
W: Unknown file type, ignoring: kat/smali/android/.DS_Store
W: Unknown file type, ignoring: kat/smali/android/opengl/.DS_Store
I: Checking whether resources has changed...
I: Building resources...
warning: string 'body_for_snapshot_friends_email' has no default translation.
warning: string 'cover_date_format' has no default translation.
warning: string 'desc_for_emoticon_download' has no default translation.
.
.
.
/Users/toto/Desktop/mobile/kat_1/res/layout-ldrtl-v17/vox_voice_activity.xml:76: error: No resource identifier found for attribute 'bg_type' in package 'android'
/Users/toto/Desktop/mobile/kat_1/res/layout-ldrtl-v17/vox_voice_activity.xml:84: error: No resource identifier found for attribute 'bg_type' in package 'android'
/Users/toto/Desktop/mobile/kat_1/res/layout-ldrtl-v17/vox_voice_activity.xml:92: error: No resource identifier found for attribute 'bg_type' in package 'android'
/Users/toto/Desktop/mobile/kat_1/res/layout/walkietalkie_layout.xml:5: error: No resource identifier found for attribute 'thm_background' in package 'android'
/Users/toto/Desktop/mobile/kat_1/res/layout/walkietalkie_layout.xml:9: error: No resource identifier found for attribute 'thm_textColor' in package 'android'
/Users/toto/Desktop/mobile/kat_1/res/layout-ldrtl-v17/walkietalkie_layout.xml:5: error: No resource identifier found for attribute 'thm_background' in package 'android'
/Users/toto/Desktop/mobile/kat_1/res/layout-ldrtl-v17/walkietalkie_layout.xml:9: error: No resource identifier found for attribute 'thm_textColor' in package 'android'
Exception in thread "main" brut.androlib.AndrolibException: brut.androlib.AndrolibException: brut.common.BrutException: could not exec command: [/var/folders/pq/1z00kxtn2yv3x6tf5t7_84y40000gn/T/brut_util_Jar_3636030068287513085.tmp, p, --forced-package-id, 127, --min-sdk-version, 14, --target-sdk-version, 22, --version-code, 1400205, --version-name, 5.1.4, -F, /var/folders/pq/1z00kxtn2yv3x6tf5t7_84y40000gn/T/APKTOOL1705594288349679015.tmp, -0, resources.arsc, -0, assets/katEffects-Android.zip, -0, arsc, -I, /Users/toto/Library/apktool/framework/1.apk, -S, /Users/toto/Desktop/mobile/kat_1/res, -M, /Users/toto/Desktop/mobile/kat_1/AndroidManifest.xml]
at brut.androlib.Androlib.buildResourcesFull(Androlib.java:465)
at brut.androlib.Androlib.buildResources(Androlib.java:403)
at brut.androlib.Androlib.build(Androlib.java:291)
at brut.androlib.Androlib.build(Androlib.java:261)
at brut.apktool.Main.cmdBuild(Main.java:225)
at brut.apktool.Main.main(Main.java:84)
Caused by: brut.androlib.AndrolibException: brut.common.BrutException: could Not
i have same issue
dex file compile success but …. Building resources… step error
jiaoyigui-2:Downloads jiaoyigui$ apktool b hello
I: Using Apktool 2.0.3-831765-SNAPSHOT
I: Checking whether sources has changed...
I: Smaling smali folder into classes.dex...
I: Checking whether resources has changed...
I: Building resources...
/Users/jiaoyigui/Downloads/hello/res/values-v23/styles.xml:5: error: Error retrieving parent for item: No resource found that matches the given name '@android:style/AlertDialog'.
/Users/jiaoyigui/Downloads/hello/res/values-v23/styles.xml:6: error: Error retrieving parent for item: No resource found that matches the given name '@android:style/DialogWindowTitle'.
Exception in thread "main" brut.androlib.AndrolibException: brut.androlib.AndrolibException: brut.common.BrutException: could not exec command: [/var/folders/f1/kw9g28fn2dsb2_kwsj4y19nr0000gn/T/brut_util_Jar_686373888929815871.tmp, p, --forced-package-id, 127, --min-sdk-version, 7, --target-sdk-version, 22, --version-code, 450825, --version-name, 2.12.374, -F, /var/folders/f1/kw9g28fn2dsb2_kwsj4y19nr0000gn/T/APKTOOL8887438693574401727.tmp, -0, arsc, -0, arsc, -I, /Users/jiaoyigui/Library/apktool/framework/1.apk, -S, /Users/jiaoyigui/Downloads/hello/res, -M, /Users/jiaoyigui/Downloads/hello/AndroidManifest.xml]
at brut.androlib.Androlib.buildResourcesFull(Androlib.java:472)
at brut.androlib.Androlib.buildResources(Androlib.java:410)
at brut.androlib.Androlib.build(Androlib.java:298)
at brut.androlib.Androlib.build(Androlib.java:268)
at brut.apktool.Main.cmdBuild(Main.java:225)
at brut.apktool.Main.main(Main.java:84)
Caused by: brut.androlib.AndrolibException: brut.common.BrutException: could not exec command: [/var/folders/f1/kw9g28fn2dsb2_kwsj4y19nr0000gn/T/brut_util_Jar_686373888929815871.tmp, p, --forced-package-id, 127, --min-sdk-version, 7, --target-sdk-version, 22, --version-code, 450825, --version-name, 2.12.374, -F, /var/folders/f1/kw9g28fn2dsb2_kwsj4y19nr0000gn/T/APKTOOL8887438693574401727.tmp, -0, arsc, -0, arsc, -I, /Users/jiaoyigui/Library/apktool/framework/1.apk, -S, /Users/jiaoyigui/Downloads/hello/res, -M, /Users/jiaoyigui/Downloads/hello/AndroidManifest.xml]
at brut.androlib.res.AndrolibResources.aaptPackage(AndrolibResources.java:425)
at brut.androlib.Androlib.buildResourcesFull(Androlib.java:458)
... 5 more
Caused by: brut.common.BrutException: could not exec command: [/var/folders/f1/kw9g28fn2dsb2_kwsj4y19nr0000gn/T/brut_util_Jar_686373888929815871.tmp, p, --forced-package-id, 127, --min-sdk-version, 7, --target-sdk-version, 22, --version-code, 450825, --version-name, 2.12.374, -F, /var/folders/f1/kw9g28fn2dsb2_kwsj4y19nr0000gn/T/APKTOOL8887438693574401727.tmp, -0, arsc, -0, arsc, -I, /Users/jiaoyigui/Library/apktool/framework/1.apk, -S, /Users/jiaoyigui/Downloads/hello/res, -M, /Users/jiaoyigui/Downloads/hello/AndroidManifest.xml]
at brut.util.OS.exec(OS.java:89)
at brut.androlib.res.AndrolibResources.aaptPackage(AndrolibResources.java:419)
... 6 more
and my resources is changed. How can I recompile it?
Closing in favour of #1157