[Sony Xperia S, Acro S, Ion] brunojcm:
Hi again!

Some people asked how I did the mod I posted on the thread http://xdaforums.com/showthread.php?t=1738094 and I promised I would say it.

First off, this method will require you to go deep inside binary files, so please don't try to do it if you didn't completely understand every step and know the basics about the hexadecimal, binary diffs, etc.

Before start

I will start saying what was supposed to work. You should use apktool to decode the apk, modify what you want, and then use apktool build it again. But, as of the latest version of apktool I tried (1.4.3), decode and build doesn't work for for Xperia S' framework-res.apk. (Maybe bug http://code.google.com/p/android-apktool/issues/detail?id=313 and http://code.google.com/p/android-apktool/issues/detail?id=256 are related?)

The closest I could get is using apktool 1.4.1, but the generated file was so smaller than the original and I wasn't brave enough to test on my phone.

Anyway, you will need to do this "normal" process (decode and build) for this method too. You can use any version of apktool that decode and build without errors. I used 1.4.1, but I believe a newer version could get a closer output, thus a easy file to do a binary diff. Don't worry, we won't flash these malformed apk's! :P

So, lets start.

PLEASE, read all the steps before start to understand the whole thing. The main idea is to find some bytes that precedes the value we want to change, then find these bytes on the original resources file and change the value we want.

1. Make sure you have adb, apktool, and everything needed on your path. I will give you the commands assuming all of them are in your path.

2. Get the necessary apk's from your phone:

brunojcm@brunojcm-desktop:~/Android/LT26i$ adb pull /system/framework/framework-res.apk
3972 KB/s (22227101 bytes in 5.463s)
brunojcm@brunojcm-desktop:~/Android/LT26i$ adb pull /system/framework/SemcGenericUxpRes.apk
4970 KB/s (2095961 bytes in 0.411s)

3. Install the apk's on apktool

brunojcm@brunojcm-desktop:~/Android/LT26i$ apktool if framework-res.apk nozomi
I: Framework installed to: /home/brunojcm/apktool/framework/1-nozomi.apk
brunojcm@brunojcm-desktop:~/Android/LT26i$ apktool if SemcGenericUxpRes.apk nozomi
I: Framework installed to: /home/brunojcm/apktool/framework/2-nozomi.apk

4. decode and build the framework-res.apk WITHOUT changing anything:

brunojcm@brunojcm-desktop:~/Android/LT26i$ apktool d -f -t nozomi framework-res.apk framework-res
(some lines, with warnings)
I: Done.
I: Copying assets and libs...

brunojcm@brunojcm-desktop:~/Android/LT26i$ apktool b framework-res unchanged/framework-res.apk
(few lines)
I: Building apk file...

5. Do the same of the step above, but CHANGING what you want before build. Pay attention to the output folder of the build, it's different from the previous step.

brunojcm@brunojcm-desktop:~/Android/LT26i$ apktool d -f -t nozomi framework-res.apk framework-res
(some lines, with warnings)
I: Done.
I: Copying assets and libs...

(CHANGE WHAT YOU WANT)

brunojcm@brunojcm-desktop:~/Android/LT26i$ apktool b framework-res changed/framework-res.apk
(few lines)
I: Building apk file...

I changed the config_showNavigationBar, inside framework-res/res/values/bools.xml, but you can try changing what you want. I recommend you to start changing one single boolean value, then you can try to do more advanced things.

6. Here starts the fun! Since we have almost the same apk file, because we built both using the same apktool version, the only different bytes must be the boolean we changed. So we can unpack both apk's and run a binary diff of the resources.arsc. I'm using the vbindiff (apt-get install vbindiff) on ubuntu, but there should be other binary diffs or hexadecimal editors. So unpack and run the following:

vbindiff unchanged/framework-res.apk_FILES/resources.arsc changed/framework-res.apk_FILES/resources.arsc

It will show you the binary representation of the two files, the changed and the unchanged. Press enter once and you will see some chars in red (if you don't see, you did something worng). These represent the changed value. It was 00 00 00 00 (false) and is FF FF FF FF (true) on the modified file. Now we can observe what we have around the value we want to changed. We need to observe because we're going to edit the original file. Note that there is a column containing a hexa sequence (27, 28, 29, 2A, 2B). Our changed value is in the same line of the 29. This is the line that starts with '0077 F500'.

Copy the text of the vbindiff, containing the changed value and everything around it, to a draft file for further reference. I've attached a print of this screen, se below.

7. Now we need to do the final ninja hit: Change the original apk. Actually, the original resources.arsc. But things are no so easy, because the value we need to change is not on the same position it was is the file we changed. If we go to the position 0077 F500, something completely diferent will be there. So we need to search for something near the value we want to change. I will search for the sequence '29 1D', which is 8 bytes before the value we want to change. Yes, it's a short sequence and will occours a lot of times, but it is the best we can use. Maybe '00 29 1D', but no more than that. Let's go, unpack the original framework-res.apk and run:

vbindiff framework-res.apk_FILES/resources.arsc

Now hit F to find the sequence, and H to Hexa sequence, and type the sequence you choose (here, '00 29 1D'). To find the next occourrence, press F, then N. Do it until you find this sequence in a similiar way of the original file, having one line below with 2A, and below 2B etc. It should be near '007D C5CF'. Now you need to press E, go to the column where you have '00 00 00 00' and change to 'FF FF FF FF'. Pay attention to the other lines to change the right columns. The edited values will be in yellow. You can see the second attached print screen.

8. This is the easiest step, just copy the modified resources.arsc to the original apk. It should not be the apktool-built one, it should be the file you modified on the vbindiff editor.

I did it using the Gnome archive manager, just drag and drop the resources.arsc inside the archiver window after open the framework-res.apk.

And voilà! Your modded apk is ready!

------

Hope someone can understand this and make some mods. I did my best to explain what I did, but it's a really hard procedure thus not easy to explain.

If you have any doubts, just post and I will try to answer!

And if you like, click thanks to me! ;)