
How to patch an Android application:
First off, some basics. Android applications are delivered in a single .apk file. This is simply a differently-named .zip file, so any common zip tool should be able to unpack it. Inside you will usually find all the resources (images, sounds) and (among other things) a file called classes.dex which contains the code for that application. This is bytecode for the dalvik VM. You can disassemble this bytecode into something you could call android assembler
. Compared to real
assembler code, this is pretty high-level, but still nothing like a high-level language like java. As method and member names are preserved, it is usually fairly easy to understand unless the author used an obfuscator before release (In that case, all your methods will be named a, b, c...).
To follow this example along, you need a few tools:
As a simple example, we'll be removing the focus sound from the android camera. – As we'll be replacing a builtin
app, you will need root access to your phone.
adb pull /system/app/Camera.apk
classes.dex file from it
unzip Camera.apk classes.dex
out/ subdirectory.
java -jar baksmali-1.2.6.jar classes.dex
You can peek around the out/ subdir where all the code is. Change whatever you want.
com/android/camera/Camera$AutoFocusCallback.smali
To remove the focus sound, look for a line containing
and invoke-virtual
. In my version it looks like this:->startTone
invoke-virtual {v0, v1}, Landroid/media/ToneGenerator;->startTone(I)Z"
Just delete that line.
.apk. First we re-assemble the code into a classes.dex:
java -jar smali-1.2.6.jar out -o classes.dex
.apk with
zip Camera.apk classes.dex
java -jar signapk.jar testkey.x509.pem testkey.pk8 Camera.apk Camera_signed.apk
.apk. Because it's a system app, we need to actually replace the file like this:
adb remount
adb push Camera_signed.apk /system/app/Camera.apk
If it were a normal app, you would simply uninstall the original, and then install the .apk like any other app. (e.g. with adb install foo.apk)
After you reboot your phone, your Camera should now be less noisy. Yay!
– Sec
P.S.: If you want to remove the shutter
sound instead, check this thread on xda-developers.com. Basically it boils down to:
adb remount
adb shell rm /system/media/audio/ui/camera_click.ogg
apktool sieht nett aus, muss ich beizeiten mal ausprobieren. Dennoch finde ich es wichtig es einmal selbst gemacht zu haben, damit man die Grundlagen versteht.
Das stimmt wohl. Habe ich anfangs auch so gemacht, aber gerade wenn man viel damit rumprobiert und die apks oft wieder auf ein Geraet zurueck spielen muss, wirds von Hand etwas nervig ;) Wenn man das allerdings selten tut reichen natuerlich auch die Scripte.
Gerade wenn man auch die .xml's editieren will sehe ich den Komfortgewinn durchaus :-) Eine Sache noch: Wenn ich das richtig sehe, übernimmt apktool aber nicht das signen, oder? Gibts eigentlich eine Möglichkeit ungesignte apps laufen zu lassen, oder muss man das nach wie vor per Hand tun?
Felix wrote on Tue, 15 Mar 2011 09:31
You can also automate most of this with apktool if you do this kinda stuff regularly. Especially the XML decoding is helpful (even though there are of course small scrips to do that as well) See https://code.google.com/p/android-apktool/