I am a student interested in Android Security. I was trying to modify a APK file using baksmali and smali. However, I am not able to run the repackaged app in my mobile. When I click on the icon it say "Unfortunately, test has stopped" and exists. (Even the icon of the app got changed, now I see default android icon instead of old real colorful icon of the app)
What could be the reason for this ? Actually I haven't even modified code of the apk file. I just unzipped apk to get dex file, then I converted it to smali using baksmali.jar
, and then back to dex using smali.jar
. Finally zipped and signed.
What I have done in detail:
Decompress the apk file
$ Unzip test.apk
Convert 1classes.dex1 to smali
$ baksmali -x classes.dex -o smaliClasses
Converted the classes back to
classes.dex
(replaced oldclasses.dex
, in fact I did not add any new code to smali file. I wanted to know whether this works first).$ smali smaliClasses -o classes.dex
Zip all the files to
test.zip
$ zip test.zip AndroidManifest.xml classes.dex res META-INF resourses.arsc
Rename
test.zip
totest.apk
$ mv test.zip test.apk
Now I believe I have to sign the APK again, please correct me if am wrong here.
Edited:
java -jar signapk.jar testkey.x509.pem testkey.pk8 test.apk test-patched.apk
I tried to install the new repackaged APK. Using adb shell. Adb shell showed it successfully installed. However, I am not able to run the repackaged app in mobile. The App crashes when I click on it. It says "Unfortunately, test has stopped".
Why doesn't the repackaged app running ? I don't understand what I am missing here ?
Edited:
I tried to repackage the same app using apktool. I extracted the smali files using it and repackaged. But why repackaging is not working with baksmali, smali, zip and signapk. Is zipping the real problem in this procedure? I see the size of the app is reduced drastically when I zip it and rename it to .apk compared to the original apk file :|
baksmali -x option
) on purpose? You are it would appear that since you are performing this option, without providing a "bootclasspath" you're going to get some odd smali code that might not be able to converted back into a dex file. Also, just remove the META-INF folder prior to zipping and trying doingzip -r unsigned.apk *
inside the directory with all the contents. If this still crashes, try posting the logcat output