iBotPeaches / Apktool

A tool for reverse engineering Android apk files
https://apktool.org/
Apache License 2.0
20.09k stars 3.57k forks source link

apktool b fails on XML parsing errors #1685

Open gilhartman opened 6 years ago

gilhartman commented 6 years ago

Information

  1. Apktool Version (apktool -version) - 2.3.0
  2. Operating System (Mac, Linux, Windows) - Mac
  3. APK From? (Playstore, ROM, Other) - apkpure

Stacktrace/Logcat

/temp>apktool d /temp/Secure\ Mail_v10.6.20-18_apkpure.com.apk -o openapk
I: Using Apktool 2.3.0 on Secure Mail_v10.6.20-18_apkpure.com.apk
I: Loading resource table...
I: Decoding AndroidManifest.xml with resources...
I: Loading resource table from file: /Users/gil/Library/apktool/framework/1.apk
I: Regular manifest package...
I: Decoding file-resources...
I: Decoding values */* XMLs...
I: Baksmaling classes.dex...
I: Baksmaling classes2.dex...
I: Baksmaling classes4.dex...
I: Baksmaling classes3.dex...
I: Copying assets and libs...
I: Copying unknown files...
I: Copying original files...
/temp>apktool b openapk -o closedapk.apk
I: Using Apktool 2.3.0
I: Checking whether sources has changed...
I: Smaling smali folder into classes.dex...
I: Checking whether sources has changed...
I: Smaling smali_classes2 folder into classes2.dex...
I: Checking whether sources has changed...
I: Smaling smali_classes3 folder into classes3.dex...
I: Checking whether sources has changed...
I: Smaling smali_classes4 folder into classes4.dex...
I: Checking whether resources has changed...
I: Building resources...
W: /temp/openapk/res/values-ja/strings.xml:29: error: Error parsing XML: mismatched tag
W:
W: /temp/openapk/res/values-ja-sw600dp-v13/strings.xml:12: error: Error parsing XML: mismatched tag
W:
W: /temp/openapk/res/values-zh-rCN/strings.xml:61: error: Error parsing XML: mismatched tag
W:
Exception in thread "main" brut.androlib.AndrolibException: brut.androlib.AndrolibException: brut.common.BrutException: could not exec (exit code = 1): [/var/folders/r_/lfrzsqgn4cxb416ysxq75sqh0000gn/T/brut_util_Jar_3292698851755085870.tmp, p, --forced-package-id, 127, --min-sdk-version, 21, --target-sdk-version, 25, --version-code, 25049130, --version-name, 10.6.20-18, --no-version-vectors, -F, /var/folders/r_/lfrzsqgn4cxb416ysxq75sqh0000gn/T/APKTOOL5998761831848268597.tmp, -0, arsc, -0, txt, -0, arsc, -I, /Users/gil/Library/apktool/framework/1.apk, -S, /temp/openapk/res, -M, /temp/openapk/AndroidManifest.xml]
    at brut.androlib.Androlib.buildResourcesFull(Androlib.java:485)
    at brut.androlib.Androlib.buildResources(Androlib.java:419)
    at brut.androlib.Androlib.build(Androlib.java:318)
    at brut.androlib.Androlib.build(Androlib.java:270)
    at brut.apktool.Main.cmdBuild(Main.java:224)
    at brut.apktool.Main.main(Main.java:75)
Caused by: brut.androlib.AndrolibException: brut.common.BrutException: could not exec (exit code = 1): [/var/folders/r_/lfrzsqgn4cxb416ysxq75sqh0000gn/T/brut_util_Jar_3292698851755085870.tmp, p, --forced-package-id, 127, --min-sdk-version, 21, --target-sdk-version, 25, --version-code, 25049130, --version-name, 10.6.20-18, --no-version-vectors, -F, /var/folders/r_/lfrzsqgn4cxb416ysxq75sqh0000gn/T/APKTOOL5998761831848268597.tmp, -0, arsc, -0, txt, -0, arsc, -I, /Users/gil/Library/apktool/framework/1.apk, -S, /temp/openapk/res, -M, /temp/openapk/AndroidManifest.xml]
    at brut.androlib.res.AndrolibResources.aaptPackage(AndrolibResources.java:454)
    at brut.androlib.Androlib.buildResourcesFull(Androlib.java:471)
    ... 5 more
Caused by: brut.common.BrutException: could not exec (exit code = 1): [/var/folders/r_/lfrzsqgn4cxb416ysxq75sqh0000gn/T/brut_util_Jar_3292698851755085870.tmp, p, --forced-package-id, 127, --min-sdk-version, 21, --target-sdk-version, 25, --version-code, 25049130, --version-name, 10.6.20-18, --no-version-vectors, -F, /var/folders/r_/lfrzsqgn4cxb416ysxq75sqh0000gn/T/APKTOOL5998761831848268597.tmp, -0, arsc, -0, txt, -0, arsc, -I, /Users/gil/Library/apktool/framework/1.apk, -S, /temp/openapk/res, -M, /temp/openapk/AndroidManifest.xml]
    at brut.util.OS.exec(OS.java:95)
    at brut.androlib.res.AndrolibResources.aaptPackage(AndrolibResources.java:448)
    ... 6 more

Steps to Reproduce

  1. apktool d
  2. apktool b

Frameworks

If this APK is from an OEM ROM (Samsung, HTC, LG). Please attach framework files (.apks that live in /system/framework or /system/priv-app)

APK

If this APK can be freely shared, please upload/attach a link to it. https://apkpure.com/secure-mail/com.citrix.mail.droid/download/25049130-APK?from=details%2Fversion or https://download.apkpure.com/b/apk/Y29tLmNpdHJpeC5tYWlsLmRyb2lkXzI1MDQ5MTMwX2E5MWZmMTUx?_fn=U2VjdXJlIE1haWxfdjEwLjYuMjAtMThfYXBrcHVyZS5jb20uYXBr&k=fd7f4be01254c1b2f59d2c3f918ad0305a312f4d&as=9bd6f0c2238e685f86651a007e2583e75a2e8cc5&_p=Y29tLmNpdHJpeC5tYWlsLmRyb2lk&c=1%7CBUSINESS

Questions to ask before submission

  1. Have you tried apktool d, apktool b without changing anything? yes
  2. If you are trying to install a modified apk, did you resign it? not relevant
  3. Are you using the latest apktool version? yes
Ibuprophen commented 6 years ago

It's a weird/funny thing too.

I get this error for about 50% of the apps that I compiled...

But, the funny thing is that when I take those apps and use something like an app called APK Editor (and few others on the PC/Android) and then decompile and recompile, without making any changes, the app in question, that reflected the parsing error, then installs fine without any errors.

I'm not sure what and why but, I just thought that this information would be helpful for figuring this out.

Any ideas @iBotPeaches?

Zane96 commented 6 years ago

I have meet the same error, I failed all the app...

iBotPeaches commented 6 years ago

These errors are probably due to our string decoding when we inject styles back into the human readable string.

So lets look at what Apktool decoded.

<string name="noContactsHelpText">"\"表示できる連絡先がありません。

連絡先を追加するには、"<font fgcolor="#ffffffff"><b>[メニュー]</b></font>"キーをタップして次の操作を行います。

"<li>スマートフォンと同期可能な連絡先を使ってアカウントを追加またはセットアップするには、<font fgcolor="#ffffffff"><b>[アカウント]</b></font>"をタップします
"</li>"
"<li>新しい連絡先を最初から作成するには、</li><font fgcolor="#ffffffff"><b>[連絡先を新規登録]</b></font>"をタップします
"</li>"
"<li>SIMまたはSDカードから連絡先をインポートするには、</li><font fgcolor="#ffffffff"><b>[インポート/エクスポート]</b></font>"をタップします
"</li>"” "</string>

So yeah thats a mess. I can't even read that right now to figure out where the mess is.

MarcMil commented 6 years ago

Here is another app with the same issue. Maybe it is easier to figure out with it: https://drive.google.com/open?id=1pfV2bjHQepke51LqV4WxJaQC7wgMmlZI

This whole content seems to belong to one string:

<string name="str_timing_kumbhmela_info">" The Nasik Kumbhmela celebration is held once in every 12 years in Nashik - it is scheduled for 2015. It draws millions of devotees and tourists from all over the country and the world. Trimbakeshwar is a holy town that houses one of the twelve Jyotirlingas in India. It also is the origin of the river Godavari and is situated 38 kms away from Nasik. The Sinhasta Kumbh Mela is held once in 12 years in Nashik and Trimbakeshwar. According to historical records, Nasik is one of four places where the elixir of immortality, the 'amrit', fell to earth from a pitcher as gods and demons were engaged in the tussle to gain the ownership of the jar full of 'amrit'. The Kumbh Mela rotates among the four holy sites every three years. The Kumbh Mela is marked by millions of devotees' plunge into the river Godavari that is believed would cleanse their souls leading to salvation. A ritual bath at a predetermined time and place is the major event of the festival. 

"<b>* In 2015 - 2016, Jupiter enters the zodiac sign of Leo, hence Trimbakeshwar will witness the Kumbha Parva.</b>"

"<b>Timings of Trimbakeshwar Sinhastha</b>"

"<b><li>Starting:- 12/07/2015 at 18 that is on Ashadh vadya Tritiya, Monday, shaka 1937.</li></b>"
"<b><li>Ending:- 11/08/2016 at 8.40 i.e. on Sharvan shudha Ashtami(8thday),Thursday. shaka 1938.</li></b>"

"<b>Shahi Snan (Princely Bathing) time of Simhasta for sadhus and mahantas are as follows.</b>"
"<b><li>First Shahi Snan - Saturday shaka 1937, month shravana shudha poonam, <b>date 29/08/2015.</b></li></b>"
"<b><li>Second shahi snan - Sunday shake 1937 miti Shravan Krishna amavasya <b>date 13/09/2015.</b> This day will carry importance as sun, moon and Jupiter will be in same zodiac signs, this is why snans hava very special importance. Therefore the devotee should remember this day.</li></b>"
"<b><li>Third shahi snan - will be on Friday shaka 1937 miti bhadarapada shudha dwadashi (vamandwadashi) <b>date 25/09/2015.</b></li></b>"

So, I guess that there is HTML content within XML, so this needs probably to be escaped. I do not know why there are quotes within each line.

ghost commented 5 years ago

C:\SpyMAX-1v\apktool\temp\AndroidManifest.xml:1: error: No resource identifier found for attribute 'compileSdkVersion' in package 'android' W: