bingshi / android-apktool

Automatically exported from code.google.com/p/android-apktool
Other
0 stars 0 forks source link

Arrays.xml decompilation problem #750

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
I'm working on modifying Snapchat. After decompiling and recompiling the APK, 
even without any modifications, the arrays.xml files get messed up.
The affected string-arrays are used for notifications, this is how it looks 
like after recompiling: http://i.imgur.com/vHxa043.png
If I decompile the recompiled APK, the quotes are gone from the arrays.xml 
file: http://i.imgur.com/t5tdAuE.png (initial decompilation on the left, second 
on the right)
To workaround this, I tried escaping the double quotes with a slash (" -> \") 
and replacing them with " but this didn't work.

What is the expected output? What do you see instead?
The arrays.xml in the recompiled APK to be the same as in the original APK. 
However, something gets messed up (maybe something with the quotes).

What version of the product are you using? On what operating system?
apktool v2.0.0 RC3 - Windows 8.1

Please provide any additional information below.
APK is attached

Original issue reported on code.google.com by gamer0...@live.nl on 19 Jan 2015 at 1:09

GoogleCodeExporter commented 9 years ago
Hmm, look like attaching an APK is not working.
Uploaded it here: https://www.androidfilehost.com/?fid=95897840722645900

Original comment by gamer0...@live.nl on 19 Jan 2015 at 1:53

GoogleCodeExporter commented 9 years ago
Duplicated. Decoded, Rebuilt. Decoded Rebuilt application and noticed the 
changes in all arrays.xml files.

Inline double quotes are stripped from <item> values.

Original comment by connor.tumbleson on 19 Jan 2015 at 2:37

GoogleCodeExporter commented 9 years ago
So I took a peek at this yesterday and not sure if this warrants a change. 
Double quotes inside of array <items> must be escaped.

This is not. 

What I mean is this. We can assume the original string is something like this.

 <item><g id="issue_750">%s</g> and <g id="issue_750b">%s</g> foo</item>

Now according to documentation - 
http://developer.android.com/guide/topics/resources/string-resource.html#Formatt
ingAndStyling

<, &, " must be escaped.

This means this strings turns into

 <item><g id=\"issue_750\">%s</g> and <g id=\"issue_750\">%s</g> foo</item>

You put that string into our unit-tests and there is no error. It is properly 
handled. However, the string in this case (post decompiled) is

 <item><g id="issue_750">%s</g> and <g id="issue_750">%s</g> foo</item>

As you can see the double quotes are not escaped. With this string above, I can 
duplicate the problem, however at that point we are writing bad code. So is it 
up to Apktool to fix this?

For example. I built a test apk with this arrays.xml file.

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string-array name="issue_750" formatted="false">
        <item><g id="issue_750">%s</g> and <g id="issue_750b">%s</g> foo</item>
        <item><g id=\"issue_750\">%s</g> and <g id=\"issue_750b\">%s</g> foo</item>
    </string-array>
</resources>

I compiled the apk in release mode and used (aapt d --values resources) to see 
the resources post compiled

        resource 0x7f040000 com.ibotpeaches.issue750:array/issue_750: <bag>
          Parent=0x00000000(Resolved=0x7f000000), Count=2
          #0 (Key=0x02000000): (string8) "<g id=issue_750>%s</g> and <g id=issue_750b>%s</g> foo"
          #1 (Key=0x02000001): (string8) "<g id=\"issue_750\">%s</g> and <g id=\"issue_750b\">%s</g> foo"

That is what I found. As you can see, the non escaped <item> is lacking the 
double quotes because they weren't escaped.

Now on the flipside of the coin. The original apk works, but the decompiled and 
built one doesn't. This exposes a fact that apktool has a chance to fix this 
poor markup. Since it would be a pain in the ass to manually fix these for 
APKs, I will see if its easy to do.

Original comment by connor.tumbleson on 30 Jan 2015 at 1:19

GoogleCodeExporter commented 9 years ago

Original comment by connor.tumbleson on 3 Feb 2015 at 9:56