iBotPeaches / Apktool

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

Decompilation introduces quotes into string resources in res/values/strings.xml #315

Closed iBotPeaches closed 11 months ago

iBotPeaches commented 9 years ago

Original issue 204 created by ericchubb on 2011-08-11T11:20:18.000Z:

What steps will reproduce the problem?

Download http://www.freewarelovers.com/android/download/temp/1298727501_Guns-n-Glory_FREE_1.5.1.apk (too big to attach to the bug)

  1. Decompile the APK file using apktool v1.4.1
  2. browser to the "res/values/strings.xml"
  3. There is a string with the text "Did you hear that terrible crash in the mountains."
  4. In version 1.4.1 of apktool, the string has quotes at the beginning and end of the text. In version 1.3.1, it did not. These quotes are visible in the text in the running application post-recompilation, and look like they shouldn't be there.
iBotPeaches commented 9 years ago

Comment #1 originally posted by Brut.alll on 2011-08-12T08:45:17.000Z:

As far as I know it's perfectly ok. Also above string is identical in original and rebuilt file. You can check this about by yourself using: "aapt d --values resources Guns-n-Glory_FREE_1.5.1.apk" command.

iBotPeaches commented 9 years ago

Comment #2 originally posted by ericchubb on 2011-08-16T15:53:32.000Z:

Hi there,

Our method for diagnosing this problem was to install Guns N'Glory, examine resources in the running app, then decompile it using APKTOOL, recompile it without changing anything and reinstall it and run it. This process introduces quotes in v 1.4.1 where it didn't in 1.3.1. You can in the image attached.

iBotPeaches commented 9 years ago

Comment #3 originally posted by ericchubb on 2011-08-16T15:54:44.000Z:

Hi there,

Our method for diagnosing this problem was to install Guns N'Glory, examine resources in the running app, then decompile it using APKTOOL, recompile it without changing anything and reinstall it and run it. This process introduces quotes in v 1.4.1 where it didn't in 1.3.1. You can in the image attached - on the left is the output from Apktool 1.3.1 and on the right is 1.4.1

iBotPeaches commented 9 years ago

Comment #4 originally posted by Brut.alll on 2011-08-16T19:25:14.000Z:

Hmm, I've checked this and I don't see these quotes in the game. What's your version of aapt tool? I mean: which sdk level, not "aapt version" command. Also could you run "aapt d --values resources Guns-n-Glory_FREE_1.5.1.apk" on a recompiled file and search for T_APPNAME?

iBotPeaches commented 9 years ago

Comment #5 originally posted by tzafrir11 on 2011-08-21T19:36:52.000Z:

happens to me as well when decompiling ClockPackage.apk ver 1.3.1 works fine ver 1.4.1 add quotes to two values in /res/values/strings.xml difference can be seen if decompiling with both versions and using a file diff program.

this cause apk to crash whenever I set an alarm.

iBotPeaches commented 9 years ago

Comment #6 originally posted by Brut.alll on 2011-11-05T21:19:18.000Z:

@tzafrir11 Are you sure crash was caused by these quotes? As I said I have changed the way apktool decodes strings, so its pretty normal that output of v1.3.1 and v1.4.1 differs.

AFAIK new strings encoding works well.

iBotPeaches commented 9 years ago

Comment #7 originally posted by tzafrir11 on 2011-11-06T18:53:25.000Z:

I'm attaching a different file. think the previous one was not the correct.

I decompile using 1.4.1 compile push resources.arsc from compiled to the original push to device -> it's broken.

I think this is the strings because if I decompile and copy the strings.xml and arrays.xml to a different rom (trying to copy language translations) it breaks the app but if I use strings.xml and arrays.xml from different source trying to patch translations to the same apk - it works well.

comparing now the two files i see this difference in strings.xml

עד %d תווים זמינים עד %1$d תווים זמינים

mainly %s instead of %s$1 and in arrays.xml many places that have ' as part of the value string are quoted on the file that breaks ("te'xt") and unquoted on the working file ( tex't)

thank you for looking into it

iBotPeaches commented 9 years ago

Comment #8 originally posted by Brut.alll on 2011-11-06T23:01:13.000Z:

@tzafrir11 Works for me - it's "עד %d תווים זמינים" after rebuilding. Are you sure you're using apktool 1.4.1? Run "apktool" and look at the top of usage help.

iBotPeaches commented 9 years ago

Comment #9 originally posted by tzafrir11 on 2011-11-07T05:40:16.000Z:

yes. its ver 1.4.1 after recompiling and switiching the resources.arsc from the compiled file to the original file push file to device, enter clock, and set an alaram for 7 am (time which is before current time) when you press ok - app force close.

iBotPeaches commented 9 years ago

Comment #10 originally posted by firefds on 2011-11-29T22:54:08.000Z:

I have a similar problem with ClockPackage.apk (you can check it with one supplied above).

When you decompile with 1.3.1 check the arrays.xml. you will see (for example) the line This alarm is set for %1$s, %2$s, and %3$s from now. When I decompile with 1.4.1 and test release 1.4.2 I get: This alarm is set for %1$1$s, %2$$2s, and %3$$3s from now This difference causes FC when trying to set an alarm for example.

I found this bug with several system apks such as mms.apk clockpackage.apk It is found mainly in arrays.xml and plurals.apk

iBotPeaches commented 9 years ago

Comment #11 originally posted by connor.tumbleson on 2012-11-19T23:01:32.000Z:

<empty>

AnnMarieE commented 9 years ago

I understand was this was closed as the issue is still present in the current version. The addition of the quotes in the strings.xml file can been seen in the running APK file, however I believe that it is only strings which have character escaping in the text which is the problem. For example these are the original strings in the version 1.3.1: Guns\'n\'Glory Hey Boss! It\'s Pedro! We\'ve spotted a few of these settlers coming through the canyon! You should send a Desperado out there! Remember, you can also deselect him again and leave him standing out in the sun if you press the Action key!

Which are now the following after an initial unpacking: "Guns'n'Glory" "Hey Boss! It's Pedro! We've spotted a few of these settlers coming through the canyon! You should send a Desperado out there! Remember, you can also deselect him again and leave him standing out in the sun if you press the Action key!"

Why have these quotes now become part of the segment as they are left there and are visible in the running version of the software?

apk quotes - v1 3 1 vs v2 0 apk v2 0 - no quotes

iBotPeaches commented 9 years ago

I was under the impression these two strings were the same.

Guns\'n\'Glory
"Guns'n'Glory"

One forces you to escape characters while the other doesn't. The double quotes shouldn't be there though in the final apk. Since you provided some example strings, I will add them to our unit-tests and see what we are dealing with.

AnnMarieE commented 9 years ago

Great thanks. The last screenshot shows an example of a really long string, but as it appears there is no escaping necessary within the segment, then no quotes are added to this one.

AnnMarieE commented 9 years ago

Can you please tell me if you have evaluated this issue? Currently it is a blocker for us in upgrading to the latest version of the APKTool.exe.

iBotPeaches commented 9 years ago

I have not, its pretty low priority compared to some other bugs. Sorry!

Pat-15 commented 9 years ago

We see this problem too, see attached screenshot which shows installation of original Whatsapp app vs. installation of Whatsapp decompiled and recompiled with current Apktool. This issue has been present since 1.4.1 and unfortunately we have to stay on 1.3.1 until it is fixed. orig vs new

iBotPeaches commented 11 months ago

Screenshot_20230730-114038

I know this is honestly 7 years old and useless to even respond, but I took the effort to download the original application and tested it with a basic launch. That photo is above.

I then decoded and re-assembled with no changes.

➜  315 apktool d 315.apk 
I: Using Apktool 2.8.2-22eb80-SNAPSHOT on 315.apk
I: Loading resource table...
I: Decoding file-resources...
I: Loading resource table from file: /home/ibotpeaches/.local/share/apktool/framework/1.apk
I: Decoding values */* XMLs...
I: Decoding AndroidManifest.xml with resources...
I: Regular manifest package...
I: Baksmaling classes.dex...
I: Copying assets and libs...
I: Copying unknown files...
I: Copying original files...
➜  315 apktool b 315 --use-aapt2
I: Using Apktool 2.8.2-22eb80-SNAPSHOT
I: Checking whether sources has changed...
I: Smaling smali folder into classes.dex...
I: Checking whether resources has changed...
I: Building resources...
I: Building apk file...
I: Copying unknown files/dir...
I: Built apk into: 315/dist/315.apk
➜  315 

Re-launched and went back to same place.

Screenshot_20230730-121139

This seems all right now. I'm guessing either our styled rewrite or something resolved this. Sorry for ignoring for almost a decade.

Closing.