[Q] Decompile/Recompile APKs using APKTool - Other Tools & General Discussion

I'm trying to get into modding apps. I first wanted to decompile/recompile an unmodded app just to make sure it would work in the end.
I downloaded apktool (2.0RC4) with the JAR and BAT wrapper (on Windows 7) and got it working properly.
I pulled the /system/framework framework-res.apk from my device
I ran the following commands without any sign of error
Code:
//install framework
apktool if framework-res.apk
//decompile to \app folder
apktool d app.apk
//recompile \app folder
apktool b app
Now I went in and took the app.apk in dist folder and ran on my phone. It errored that the APK wasn't structured correctly, or something.
So I opened up both my original APK and my new APK in WinRar and copies over resources.arsc, the META-INF folder and AndroidManifest.xml.
Side question: This is supposedly supposed to re-sign the apk. I understand how this MIGHT work here since it's unmodified, but generally speaking it makes no sense if you could copy the signature to something else and say it's signed. I imagine the internal validation would fail? Should I be re-signing it myself? As long as it runs on the phone I don't care who people think it came from.
Anyway, after I copy the new APK to my phone and run it, it installs for a while then throws up "App Not Installed" with the DONE button.
I tried using APKSigner to put a bogus signature on there to see if that helped, and it did. I managed to install the APK but when it boots up it becomes unresponsive almost immediately.
How can I decompile/recompile an apk and then run it without any modifications?
Thanks in advance!

Debug Mode
After checking catlog I noticed the app tried to re-orient and broke shortly after, so after rebooting my APK it ran. I just had some bad luck.
However now that I can re-compile the application, I am trying to re-compile it in debug mode so I can step through it and find where I want to be. I have done this tutorial:
<Was unable to post link, it is entitled HowTo: Debug Android APKs with Eclipse and DDMS on blog.dornes.nu>
The steps are:
//this decompiles in debug mode
apktool d -d app.apk -o source
I then manually edited the AndroidManifest.xml and added android:debuggable='true' to the 'application' tag
//rebuild in debug
apktool b -d source app.debug.apk
Then I signed the APK using ZipSigner
Installed APK successfully
Went to developer options and used select debug app
(The Wait for Debug to Start option does keep the app from running, but when I turn it off the app boots and crashes)
So now that it is recompiled in debug, it crashes, and I've tried it many times.
I will see if I can complete the rest of the tutorial next time I'm in front of a PC, maybe with it connected to the debugger I can step through. Any reason why an app decompiled and recompiled into debug would crash?
Thanks!

Related

[Q] How to edit .xml files within and .apk

Im not trying to re-engineer an app, but I simply want to check out an apk to look at the placement of a certain line of code. When i open up the files within the apk though, i get a bunch of nonsense. How do I edit the files within the apk...i know theres a way, or else we wouldnt have custom roms.
Apktool (or some wrapper like Apk Manager). It's quite outdated, so you won't be able to decode some newer apks though.
Brut.all said:
Apktool (or some wrapper like Apk Manager). It's quite outdated, so you won't be able to decode some newer apks though.
Click to expand...
Click to collapse
gahh, i was hoping there would be an easier way than that xP...I experimented with apktool, but it wasnt recognizing the .apk i was typing in...i just suck with command prompt stuff
....thanks anyway though
schwartzman93 said:
gahh, i was hoping there would be an easier way than that xP...I experimented with apktool, but it wasnt recognizing the .apk i was typing in...i just suck with command prompt stuff
Click to expand...
Click to collapse
Brut.all also mentioned APK Manager in his post which is a script wrapper for his apktool that automates much of the process. It's available at the link I gave for both Windows and Linux. All you should need to do is run the script, place your apk in the appropriate folder created by the script, have the script decompile your apk, then you can find the decoded xml file(s) of interest.
thanks guys
i was having a bit of trouble with apk mananger, i couldnt get it to do anything with this one app, i would tell it an action and it just closed the script
EDIT: I figured it out
Hi guys, i'm using APK Manager and i was able to change the xml without having any trouble by decompressing the apk. I'm wondering what i need to do in order to resign the APK. I have already tried to compress the apk and then sign it, but streight away after I installed the apk i got in boot looping.
The file i'm talking about is the framework-res.apk
Any suggestion?
Thanks in advance.
Edit/
Solved.
Basically i was trying to sign framework-res.apk, instead i have found the solution in this forum that actually worked fine for me:
Code:
1. Place your original "framework-res.apk" into "\place-apk-here-for-modding\" folder
2. Run "script.bat"
3. Set Project (22) and choose the "framework-res.apk" (1)
4. Decompile (9)
5. Place or overwrite new Xmls and PNGs in "\projects\framework-res.apk\res\drawable or drawable-hdpi"
5. Recompile (11)
6. Answer "Yes" when it asks wheter it is system file
7. Answer "Yes" when it asks "would you like to copy over any additional files...?"
8. Script is paused => (don't press a key)
9. Go to the "keep" folder (it's in the same folder than "script.bat")
10. In this "Keep" Folder,
- delete "resources.arsc" file
- delete originals "stat_sys_battery.xml" and "stat_sys_battery_charge.xml" from the "keep\res\drawable" folder
- delete all originals PNGs that were meant to be edited
11. Go back to "script.bat" and press a key to let him finish the job
12. Your new "framework-res.apk" has been created in the "\place-apk-here-for-modding\" folder. It's called "unsignedframework-res.apk".. but he's not working yet.
13. Unzip all the content of the "unsignedframework-res.apk". You should have 5 objects (3 folders, 2 files).
14. Zip these files with Winrar/Winzip (whatever) but you must choose "No compression" method to zip it.
15. Rename this zip into "framework-res.apk".
15. Put it into an update.zip and it should be OK to flash trough the recovery mode.
Thanks anyway!

Need someone to compile an APK for me

Alright, so I decompiled the apk, edited the XML files I needed to. And now it won't compile. Keeps throwing java errors. Would someone be so kind to compile this for me?
This is a System APK so it needs to be compiled and signed. If you're curious or it needs extra files pulled from somewhere, it's the SystemUI.apk in the CM7 Droid nightly build 88.
Thanks!!
Here's what I need compiled:
http://mikelierman.com/SystemUI.apk.zip
0vermind said:
Alright, so I decompiled the apk, edited the XML files I needed to. And now it won't compile. Keeps throwing java errors. Would someone be so kind to compile this for me?
This is a System APK so it needs to be compiled and signed. If you're curious or it needs extra files pulled from somewhere, it's the SystemUI.apk in the CM7 Droid nightly build 88.
Thanks!!
Here's what I need compiled:
http://mikelierman.com/SystemUI.apk.zip
Click to expand...
Click to collapse
What did you use to decompile it? APK Manager from this thread?
http://forum.xda-developers.com/showthread.php?t=695701
Oh and once you compile it, you don't have to sign it because is a system app and not a regular app.
0vermind said:
Alright, so I decompiled the apk, edited the XML files I needed to. And now it won't compile. Keeps throwing java errors. Would someone be so kind to compile this for me?
This is a System APK so it needs to be compiled and signed. If you're curious or it needs extra files pulled from somewhere, it's the SystemUI.apk in the CM7 Droid nightly build 88.
Click to expand...
Click to collapse
What errors are you getting from apktool? It's going to be hard for someone else to compile an apk that has not been decoded by them and not knowing what files have been changed. Letting us know at least what .png or .xml files were modified would be a start but will work best if we could just figure out why you aren't able to build with your modifications.
The first thing I noticed from the zip you attached is that it's missing the apktool.yml file that should get created a package is decoded. Second, make sure to pull /system/framework/framework-res.apk so resources can be decoded/built properly. If you are using APK Manager, use option 10 to decode with framework-res.apk. If you are just using apktool run the command "apktool if framework-res.apk" before decoding.
mazdarider23 said:
Oh and once you compile it, you don't have to sign it because is a system app and not a regular app.
Click to expand...
Click to collapse
SystemUI.apk actually does get signed using the platform key. The easiest way to do so in my opinion is to use ZipSigner 2 on your phone. Also, once you've placed the modified SystemUI.apk into /system/app make sure it's permissions are rw-r--r--(chmod 644 /system/app/SystemUI.apk) and it's owner:group is root:root(chown 0:0 /system/app/SystemUI.apk). Next reboot to recovery, wipe dalvik-cache and cache, then reboot.
MongooseHelix said:
What errors are you getting from apktool? It's going to be hard for someone else to compile an apk that has not been decoded by them and not knowing what files have been changed. Letting us know at least what .png or .xml files were modified would be a start but will work best if we could just figure out why you aren't able to build with your modifications.
The first thing I noticed from the zip you attached is that it's missing the apktool.yml file that should get created a package is decoded. Second, make sure to pull /system/framework/framework-res.apk so resources can be decoded/built properly. If you are using APK Manager, use option 10 to decode with framework-res.apk. If you are just using apktool run the command "apktool if framework-res.apk" before decoding.
SystemUI.apk actually does get signed using the platform key. The easiest way to do so in my opinion is to use ZipSigner 2 on your phone. Also, once you've placed the modified SystemUI.apk into /system/app make sure it's permissions are rw-r--r--(chmod 644 /system/app/SystemUI.apk) and it's owner:group is root:root(chown 0:0 /system/app/SystemUI.apk). Next reboot to recovery, wipe dalvik-cache and cache, then reboot.
Click to expand...
Click to collapse
Well I'm glad you told me because little old me has been modifying system apps since the days of the nexus one and I've yet to sign one....I think is all depends on who's doing the modification...hahahaha....Good luck 0vermind on finding someone to compiling your systemui.apk!
mazdarider23 said:
Well I'm glad you told me because little old me has been modifying system apps since the days of the nexus one and I've yet to sign one....I think is all depends on who's doing the modification...hahahaha....Good luck 0vermind on finding someone to compiling your systemui.apk!
Click to expand...
Click to collapse
I'm not quite sure what to make of that comment...I certainly wasn't trying to step on your toes so I apologize if it came across that way. Just wanted to help avoid and rule out any issues that might come up. With APK Manager or by using 7zip, you can move the manifest and/or META-INF folder containing the signature from the original but to imply that system apps are not signed is incorrect.
I also think it is important that those messing with system apps understand that there are different keys used to sign apps. For anybody reading this that wants to figure out how certain packages are signed, here's a bit of an explanation. If we extract SystemUI.apk, we see a directory called META-INF. This holds the key/signature info. The key's serial number can be determined with the following command:
Code:
keytool -printcert -v -file SystemUI/META-INF/CERT.RSA | grep SerialNumber
You can check other apks/jars and noticing which have matching serial numbers, meaning they are signed with the same key...
platform key - SystemUI.apk, Settings.apk, Phone.apk, etc
shared key - Contacts.apk, UserDictionaryProvider.apk, etc
test key - Calendar.apk, DeskClock.apk, etc
google proprietary key - Vending.apk, Talk.apk, etc (including some market user apps like Maps, VoiceSearch, Docs)
MongooseHelix said:
I'm not quite sure what to make of that comment...I certainly wasn't trying to step on your toes so I apologize if it came across that way. Just wanted to help avoid and rule out any issues that might come up. With APK Manager or by using 7zip, you can move the manifest and/or META-INF folder containing the signature from the original but to imply that system apps are not signed is incorrect.
I also think it is important that those messing with system apps understand that there are different keys used to sign apps. For anybody reading this that wants to figure out how certain packages are signed, here's a bit of an explanation. If we extract SystemUI.apk, we see a directory called META-INF. This holds the key/signature info. The key's serial number can be determined with the following command:
Code:
keytool -printcert -v -file SystemUI/META-INF/CERT.RSA | grep SerialNumber
You can check other apks/jars and noticing which have matching serial numbers, meaning they are signed with the same key...
platform key - SystemUI.apk, Settings.apk, Phone.apk, etc
shared key - Contacts.apk, UserDictionaryProvider.apk, etc
test key - Calendar.apk, DeskClock.apk, etc
google proprietary key - Vending.apk, Talk.apk, etc (including some market user apps like Maps, VoiceSearch, Docs)
Click to expand...
Click to collapse
Thanks, I didn't know this! I'm glad there's people like you and mazdarider23 on this forum that know **** like this!!!

[Q] question about (de)compile...

I'm getting this issue:
I got Settings.apk and framework.apk from a rom, then i opened apktool and
1) imported fw: apktool if framework.apk
2) decompiled apk: apktool d Settings.apk
3)edited a string in a xml
4) rebuilt all: apktool b Settings Settings.apk
5)pushed it into system/app
6) fix permissions and reboot.
Settings now should work, but it doesnt. Can somebody tell me where i do a mistake?
Thank you
(I used win8, but i could use macos or ubuntu as well)
sign it first
ej8989 said:
sign it first
Click to expand...
Click to collapse
I did it. same result. maybe the application I used is not good (Auto-Sign v0.65). what application i've to use?
I didnt write it before, however the rom is on 4.2.1 (cyanogen 10.1)
put your re-complied apk to your phone's sd card and use zipsigner2 from playstore to sign it.
ej8989 said:
put your re-complied apk to your phone's sd card and use zipsigner2 from playstore to sign it.
Click to expand...
Click to collapse
Nothing. Maybe this is not good for 4.2.1? (I've used it lots of times with 4.1)
Well, apktool is using smali/baksmali to compile/decompile classes.dex/apk_name.odex file.
The problem can occur when you use different baksmali version when you decompile and also not the right version to compile (as the system expects it to be). You can also experience issues if the apk is not zipaligned properly (check down who to do that)
apktool has the smali/baksmali code inside it so you will need to get the newest version for it for JB for example.
You can check why the status bar is not there when you monitor the logcat and look for DEX related logs in the beginning.
You can also use smali/baksmali on your own: http://code.google.com/p/smali/wiki/DeodexInstructions
and just place the generated classes.dex in the apk
then zipalign -f 4 filein.apk fileout.apk (http://developer.android.com/tools/help/zipalign.html)
then push back fileout.apk (sytemui.apk in your case)
Sent from my Galaxy Nexus using xda premium

How to guide decompiling/compiling systemUI.apk

If you are not having problems compiling SystemUI.apk with no problems then this is not for you
WARNING:
You should not attempt to do this on a device that does not have a recovery, because if something goes wrong you may have to reinstall your rom (not very likely though). You should probably back up SystemUI.apk You should also have some experience modding and some experience using Apktool and Linux.
INTRO:
If your having problems modding SystemUI.apk on JB then this thread is just for you. I recently found out how to mod the Jelly Bean SystemUI. Jelly Bean has made it very difficult to mod. Yes it is still easy to replace images, but if you want to do some major changes to the UI such as a 100 percent battery mod or changing the status bar color then you will need to know exactly how to do it. For example, if you get the UI decompiled without errors and you recompile it without errors YOUR RECOMPILED SystemUI.apk WILL NOT WORK and your status bar will disappear etc... There is a special way to get everything working and I will show you how.
STEP 1:
LINUX>>
Before we start I recommend that you have File Roller: one of the most popular archive managers for Linux (Ubuntu comes with it). If your distribution uses a Debian package manager (most popular ones do) then all you have to do is go into the terminal and type:
Code:
sudo apt-get install file-roller
Now you will have File Roller. You also will need java installed. Check if you have java by typing:
Code:
java
in the terminal. If you dont have java and your using a Debian package manager then type:
Code:
sudo apt-get install openjdk-6-jre
or download from the java website and install it.
WINDOWS>>
Before we start, you will need 7zip and java. Just search and you will find the programs to install
STEP 2:
Now we will install APKTOOL. You may already have it installed BUT your version will probably not work. I have ran around the internet for a modified apktool that wont give you errors (If you follow my directions). I came across a great thread. check it out and download all the tools their (dont forget aapt) http://forum.xda-developers.com/show....php?t=1755243. If you are in Linux rename the jar file to apktool.jar and move the the jar plus aapt to /usr/local/bin. You will need root. If you are in Windows rename the jar to apktool.jar and move it and aapt to your WINDOWS directory. You also need zipalign http://powerpoint45.webs.com/android/zipalign(I think this one is only for linux so if ur on windows either test this one or get zipalign from android sdk)move it to your WINDOWS dir/bin dir. You need one more thing. It is from the apktool websitehttp://code.google.com/p/android-apktool/. According to your os download either apktool-install-linux-r04-brut1.tar.bz2 or apktool-install-windows-r04-brut1.tar.bz2. Extract the contents. You only need one file from the archive. In linux move apktool (not apktool.jar) to /usr/local/bin. In Windows move apktool.bat to your WINDOWS directory. Dont jump ahead and say "Now that I got apktool set up, I know what to do", because it gets a lot more difficult than you are used to using apktool.
STEP 3:
Now that you have apktool set up, you need to know how to mod SystemUI.apk. Get SystemUI.apk from /system/app within your device onto the computer. Now make a backup of SystemUI.apk on your computer because we will NEED it later. So you need two SystemUI.apk files on your computer. You could name one “backup” if you'd like. So now now we need to decompile the apk. Go into the terminal/cmd and cd/chdir into the directory you have SystemUI.apk. Now type
Code:
apktool if SystemUI.apk
It will then install frameworkneeded.Then type:
Code:
apktool d SystemUI.apk
It will decompile the apk. It will take a bit of time for it to fully decompile. The decompiled code will be in a folder in your current directory called SystemUI. If It had errors decompiling, (IT WILL FOR MOST NEXTUS 7 ROMS) you will need to install framework manually. Download framework here:http://db.tt/Rpc6zskQ and place the two APK files into apktool framework folder (replace the old framework files). In Linux it is located at /home/yourusername/apktool/framework and in windows it is something like C:\\Documents And Settings\yourusername\apktool\framework. After that delete the SystemUI folder that was made by the bad decompiling proccess and repeat the decompile command.
STEP 4:
This is the part where you start modding. You can make many customizations to the UI this way as you probably know. I will just show you how to make a 100 percent battery mod. You need to go into the decompile folder (SystemUI) using a file manager, Then from SystemUI, go delete res/drawable/stat_sys_battery.xml and replace it with http://powerpoint45.webs.com/android...ys_battery.xml (to download that file right click on link and click something like "save link as"). Now you need to move to a new directory: /res. In that folder you need to look through all the directories that start with the word drawable. For example drawable-mdpi. There is one directory that your device uses for images but you may not know which one. Your device might be MDPI but use drawable-sw600dp from the UI instead of drawable-mdpi. So if you dont know or you want to be safe then search through the drawable folders and if their are any battery icons then remember you will need to add 100 battery icons to each one of the folders with battery icons. The battery icons are the ones named something like stat_sys_battery_0.png. So if you need to add 100 icons they need to be named in numerical order from stat_sys_battery_0.png to stat_sys_battery_100.png. Dont worry though, you wont need to rename 100 icons. Their ar many battery mods online that you can get them from, but I have some images you can download: http://powerpoint45.webs.com/android...RY_BLUE.tar.gz. Download it, extract it and copy all the images into all the drawable folders that contain battery icons. Now your ready for compiling; The step that is different than how we have always done it before Jelly Bean existed. keep in mind that some images can not be changed or edited at all durring this step because it will result with many errors durring compiling. You would have to add images to the archive after its compiled
STEP 5:
Like I said at the end of step 4, this step will be different than you have seen before. This is also the step where you will be using File Roller/7zip. To build the apk make sure you are in the terminal in the directory where SystemUI exists and type:
Code:
apktool b SystemUI almostdone.apk
almostdone.apk is the output file. Once it is done building you need to open the backup apk you made at the beginning with File Roller /7zip. Also open almostdone.apk with File Roller/7zip. From inside the backup.apk drag meta-inf folder & androidmanifest.xml to allmostdone.apk. Now all you need to do is zipalign the apk. Lets say your backup apk is named backup.apk. Go into the terminal at the directory you are working
in and type
Code:
zipalign -v 4 allmostdone.apk done.apk
This will optimize the apk. The output is done.apk.
STEP6:
Now you install the apk. Their are many meathods of installing the apk, here are a couple. Transfer done.apk to your device and rename it to SystemUI.apk. Now use a root browser or terminal app to replace the other SystemUI.apk on your system at /system/app. And make sure you give it the same permissions as all the other apk's in the system/app directory. Then reboot. Or you could make a flashable zip to install it.

[HELP][DECOMPILING] I can't install/use the modded apk

Hi, okay guys, i wanna ask something. I was able to decompile, recompile, sign apk (using 7-zip) last year. Then, somethings happened to my laptop. I have to install a new windows 8.
All i have done is :
1) Installing JRE 7u45 64 bit and JDK 7u40 64 bit
2) Pulling SemcGenericUxpRes.apk, installing it by typing on the command "apktool if SemcGenericUxpRes.apk"
3) Pulling framework-res.apk, installing it by typing on the command "apktool if framework-res.apk"
4) Decompiling some app. After that, i typed on the command "apktool b XXX" where XXX refers to the decompiled folder
5) Drag and Drop the META-INF folder from the original to the new one
6) Pushing to my Xperia Miro. But the app doesnt show up on the launcher
7) When i recompile SystemUI.apk, signing it, then pushing it to system/app, setting the permissions, then using Restart SystemUI app, its worked. But after i restarted my phone, my SystemUI is gone
Does anybody here have the same problem with me?
Here is my Specification of my laptop :
Acer Aspire E1 -471G
Windows 8 64 bit version
JRE and JDK installed as ive told you above
Apktool, tried from version 1.5.1PR2 until 1.5.2 version
7-zip version 9.20 64 bit version
Winrar version 5.00 64 bit version
The last time i was able to recompile and use the modified apk was one year ago. The specification is same like above. Help me, please! :crying:
Did you sign your new apk?
PulseDroid said:
Did you sign your new apk?
Click to expand...
Click to collapse
Hi, thanks for your reply. Okay, in this post : http://forum.xda-developers.com/showthread.php?t=2011325 its showed me to copy the META-INF folder. And ive already copy that folder. Its failed to install in my phone. I tried using Adb Install xx.apk but shows me this :
"Failure [INSTALL_PARSE_FAILED_NO_CERTIFICATES]"
And when i push it manually to /data/app/ or /system/app/ it doesnt showed up to my launcher.
Ive tried to zipalign it, but still error. So, what is wrong with my phone?
What certificate did you use in Zipalign?
Certificate from the original apk. Drag and Drop the META-INF folder using 7-zip
Skip the META-INF copy step.
Rather use this
Okay, ive downloaded the application.
So, ive just decompiled the SystemUI.apk. Which one should i select? Thanks for your help

Categories

Resources