How do I recompile .dex source - Java for Android App Development

Hey I was wondering and have been looking for a while how to put the source all back together from the .dex file. I extracted all the .Java files and want to turn it into classes.dex again. So any one can possible help me out?
Thanks in advanced!

cole59z said:
Hey I was wondering and have been looking for a while how to put the source all back together from the .dex file. I extracted all the .Java files and want to turn it into classes.dex again. So any one can possible help me out?
Thanks in advanced!
Click to expand...
Click to collapse
I'm not sure this is a good place to talk reverse-engineering, but well...
Decompiling an apk to Java is usually a very destructive process, even more if the apk was ProGuarded.
This means that unless you manage to fix all the compile issues generated by the decompilation process, you won't be able to pack it back together into a working app (and believe me, you won't).
This is why people bother with smali code, smali/baksmali is the only way to modify an apk and recompile it, afaik.
Either way, this should be done for educational purposes only.
People usually don't use assembly for fun if they could use Java instead^^
I'm not even sure if I don't prefer the BrainF*ck language to smali.

That's the whole point of guarding your source code so no one steals your app. It's very easy to load just about anything into the play store by just changing the package name through all the files. Normally apktool is used to hack smali for system apps or free apps like Facebook to theme them.
Hopefully your asking for educational purposes.
Sent from my HTCONE using XDA Premium 4 mobile app

Related

(Dev) Here goes nothing

This is my attempt to get some more creativity, innovation, and roms here on xda. alot of people here have incredible skills but they cant be harnessed because they dont know what to do. if you are an artist we need you make icon packs. you have made 30 roms but you cant sign them. blah blah.
so no one abuse this but i attached a toolkit to do anything and everything with android on windows. im pushing this to be used for creating themes. hopefully it can help. but i thought it would be nice if everyone had this and the opensource community could start to grow even more.
i like this idea because it can help fellow Devs and even the watchers. everyone can get involved and give something to the community.
And now i present the Avabox
Any questions post them up.
OUTLINE------------------------------------------------------------
unyaffs-you have the ability to take system.img and data.img from you nandroids and get specific items from them.
Autosign- sign anything and everything. name your zip update.zip and follow the readme. roms themes, apps, anything.
Baksmali- put in apk in the folder. read readme. edit any icons wallpapers, anything. close it up and enjoy.
Perlscripts- this opens the boot.img for you.
Read the readme on all of these programs.
So this is going to be a quick tutorial Im gonna put up a video soon on how i got this to work on my computer
First things first download Avabox and unzip it in your C folder (same place you put androidsdk).
then get the java runtime from here not to be confused with the java development kit but since your there might as well grab it as well.
Install the java runtime then reboot
then open up avabox and click on autosign and place the zip you want signed in that folder and name it update.zip (dont add the .zip part it should already be a zip file).
then open up command prompt and type:cd\
cd Avabox/auto-sign
java -jar signapk.jar testkey.x509.pem testkey.pk8 update.zip update_signed.zip
After that last enter give it a second and look in your avabox/update file and you'll notice a new file called update_signed.zip
I know that this is almost word for word from the read me but a few differences can go along way expect a video shortly..... well around wednesday or whenever i can get someone to help with this
porting
im interested in learning how to port and combine different aspects of themes and other mods. will this do it or is there other software i need. I can do the work if shown the way. I read all the post everday with peopl;e asking for this and that and i do it myself. If shown I would help with requests as much as possible. HELP PLEASE
Thank you Avalaunch!!
so with this software, can i take a signed theme mod (like launcher or taskbar) and it will grab the images for me to edit, and then repack and sign to a flashable zip?
Everyone that knows how to use bak/smali, I have a question.
The modifications I made to the extracted pngs aren't getting transferred back to the original apk when I close it back up. Any Ideas? I'm getting really close to a breakthrough for 2.1. Any help would be appreciated
regaw_leinad said:
Everyone that knows how to use bak/smali, I have a question.
The modifications I made to the extracted pngs aren't getting transferred back to the original apk when I close it back up. Any Ideas? I'm getting really close to a breakthrough for 2.1. Any help would be appreciated
Click to expand...
Click to collapse
hm ill have to check into it. it should be making a new classes.dex too. i never really used it on edits.
Avalaunchmods said:
hm ill have to check into it. it should be making a new classes.dex too. i never really used it on edits.
Click to expand...
Click to collapse
It changes the classes.dex and resigns it it looks like, but doesn't copy the mods of the pngs to the apk.
regaw_leinad said:
Everyone that knows how to use bak/smali, I have a question.
The modifications I made to the extracted pngs aren't getting transferred back to the original apk when I close it back up. Any Ideas? I'm getting really close to a breakthrough for 2.1. Any help would be appreciated
Click to expand...
Click to collapse
What do you mean? Baksmali and Smali are for decompiling classes.dex and opening it up for the .smali files that are inside. Smali takes that output and recompiles it back into classes.dex for your .apk or .jar file.
You need to update the baksmali and smali .jar's. You have older versions and that will cause issues with certain .jar and .apk's when decompiling. baksmali-1.2.1.jar and smali-1.2.1.jar are the latest versions and will not require the BOOTCLASS PATH to be included...
Does the autosign work windows 7 (64 bit)? I've heard issues with other autosigns on 7. If it doesn't, no biggie I got xp in a VM... lol
obannvi said:
What do you mean? Baksmali and Smali are for decompiling classes.dex and opening it up for the .smali files that are inside. Smali takes that output and recompiles it back into classes.dex for your .apk or .jar file.
Click to expand...
Click to collapse
Yeah I get it now, after playing with it for a while.
Avalaunch, you should change the first post.
Baksmali- put in apk in the folder. read readme. edit any icons wallpapers, anything. close it up and enjoy.
Click to expand...
Click to collapse
that description is a little confusing to a person that NEVER used smali/baksmali before. It makes it seem like after you edit the unzipped files, you could just run smali and it will put al the changes in the new apk. I figured out that's not how it works lol I feel pretty stupid now looking back at my last question haha
regaw_leinad said:
Yeah I get it now, after playing with it for a while.
Avalaunch, you should change the first post.
that description is a little confusing to a person that NEVER used smali/baksmali before. It makes it seem like after you edit the unzipped files, you could just run smali and it will put al the changes in the new apk. I figured out that's not how it works lol I feel pretty stupid now looking back at my last question haha
Click to expand...
Click to collapse
What im trying to figure out is why would you even need to use baksmali/smali to edit .png's inside an .apk. All that needs to be done is opening of the .apk with 7zip, modify whats in /res/drawable etc then close...No need to sign .apks or anything. If anything, the script needs to contain something to extract /res/ * from the .apk to edit.
obannvi said:
What im trying to figure out is why would you even need to use baksmali/smali to edit .png's inside an .apk. All that needs to be done is opening of the .apk with 7zip, modify whats in /res/drawable etc then close...No need to sign .apks or anything. If anything, the script needs to contain something to extract /res/ * from the .apk to edit.
Click to expand...
Click to collapse
I'm actually doing more than that. I am changing the code to look for instead of <name of file>.jpg to <name of file>.png
While also putting the new png in the apk. Think that's possible? I changed all of the locations where that file comes up in the smali code.
regaw_leinad said:
I'm actually doing more than that. I am changing the code to look for instead of <name of file>.jpg to <name of file>.png
While also putting the new png in the apk. Think that's possible? I changed all of the locations where that file comes up in the smali code.
Click to expand...
Click to collapse
I gotcha. So you're looking in blah.smali for any reference to .jpgs and changing that reference to look for .png instead??
obannvi said:
I gotcha. So you're looking in blah.smali for any reference to .jpgs and changing that reference to look for .png instead??
Click to expand...
Click to collapse
yeah, not working too well atm, but working on it.
I think this is what I've been looking for. Downloading now.
Just noticed that ActivePerl was for 64bit. I am downloading 32bit as I have only have 32bit Vista Pro installed and not the 64bit.
regaw_leinad said:
Yeah I get it now, after playing with it for a while.
Avalaunch, you should change the first post.
that description is a little confusing to a person that NEVER used smali/baksmali before. It makes it seem like after you edit the unzipped files, you could just run smali and it will put al the changes in the new apk. I figured out that's not how it works lol I feel pretty stupid now looking back at my last question haha
Click to expand...
Click to collapse
i guess i need to explain more. i use baksmali to make apks easier to search through. for me at least. instead of changing the type and everything i just put it in the folder and baksmali then do changes and create a new archive. sign and change .apk. if you smali it back to apk then it wont save edits. sorry about that anyways has this helped people so far? i love showing that windows can be a dev platform
&RoidRage said:
I think this is what I've been looking for. Downloading now.
Just noticed that ActivePerl was for 64bit. I am downloading 32bit as I have only have 32bit Vista Pro installed and not the 64bit.
Click to expand...
Click to collapse
yes just google active perl i use win 7 64bit and when this toolbox was made, it was only made for certain people who had 64bit.
Sorry for the n00b question, but I have searched and haven't had much luck. Hopefully, this is the best place for this question. I just started editing .png's and updating some apk's files to customize some things on my phone for looks. However, I am really interested in modifying the taskbar and notification screen, but I have no clue where to start. Is there a guide somewhere I could follow to learn how to change them? What programs, if any additional ones will I need etc..?
Thanks for your help!
Figured it out on my own. framework.apk and resources.apk

[Q] How to edit theme images and not have phone hang on boot?

I've figured out all apk files are really just zip files, but why am I not able to unzip the framework-res.apk file, edit the images within, then save it again without causing my phone to hang on boot?
Is there some step I am missing? I've tried rezipping with normal compression, store only, and only photoshopping and resaving a single image within the apk and still it fails.
How are images edited and updated? What am I missing?
I use apkmanager myself for most theming. You might look into it
Sent from my SCH-I500 using XDA App
An apk is a zip, but it's a *signed* zip
Sent from my SCH-I500 using XDA App
Here is the way I do it. I use 7zip to do this and I think it is the only program that can do it.
The way you can do it is to extract the drawable-hdpi folder within the framework-res.apk then do all your edits and save them with the exact same file names. Then you can go back into your framework-res.apk and drag and drop the drawable-hdpi folder back in and it will over write the original ones. Now just hit the Up (like to move up a directory) button until you see the message "framework-res.apk has been changed. Update it in the archive?" then click yes. Now you can put it on your phone without force closing. If you were just editing framework-res and it was not within another .zip file then you won't get that message and that is fine.
APK Manager.
You can use extract/zip (2/3) for image-only edits, but you need to decompile/compile (9/11) to mess with xml files.
Do *not* sign system apks (like framework-res.apk). Do sign other apks.
Btw, this is in the wrong forum.
(Next step: learn about the update.zip packaging script. Remember to name it something besides update.zip afterwards, because on the Fascinate we're installing everything through Clockwork, which should be the only file actually called update.zip.)
s44 said:
APK Manager.
You can use extract/zip (2/3) for image-only edits, but you need to decompile/compile (9/11) to mess with xml files.
Do *not* sign system apks (like framework-res.apk). Do sign other apks.
Click to expand...
Click to collapse
Oooh! I didn't know this app made xml's editable. That opens up a whole new set of theming fun. I can't wait to release my new theme. It should be well received (I hope)
Btw, this is in the wrong forum.
Click to expand...
Click to collapse
I considered putting this in Themes, but this was a theme development question, so here it ended up. If the Theme and Development forums ever hook up and have a few drinks, then spawn a sub-forum, Theme Development, I assure you it would have been a much easier decision to make
Thanks everyone for helping me out. My last time playing with a phone is an old WinMo 5 device. Anroid seems limiting in it's own ways (no dedicated theme files (can't update without losing the apk theme), but much better for customizing for a 'look' of the OS.

[Q] Help understanding to make Themes

ok so i've read several, several threads on making themes, metamorph files, and what not and just wanted to ask a couple of questions since i'm going to try to start my own theme for my fascinate.
i know i need to be in the framework-res.apk and twframework-res.apk files. Is the twframwork-res.apk only needed if i'm themeing for tw or can i just work in the framework-res.apk? also i've read somewhere not to mess with the .9.png files is this true here or is it ok to change these? also i'm not 100% on how to zip for a clockwork flash. do i just do a normal .zip file or is there something else thats has to be done to be flashable thru clockwork. o and is there anyhting else in the drawable folder i shouldnt touch? thanks for the help in advance
I am a little curious myself, but I haven't taken the time to look into it. You might check out this wonderful pdf:
http://tinyurl.com/2dnt4lv
I hope you get a more proper answer. Bump.
Swyped w/ XDA App. System: http://tinyurl.com/26tmcr9
Best way to learn how to build something is to take it apart. There are many valuable resources on line about android themeing. Knowledge of performing xml edits for font color and graphic placement. And using 7zip to be able to open an apk using the open archive feature and being able to extract and add image files from the drawable-hdpi folder. Make a back up of you phone and utilize some reverse engineering and experiment with some image replacement and give it a flash. Coming from windows mobile and no android knowledge I had things figured with about 3 hours of reading and experimenting.
good day.
You will need both framework files if you intend on getting it fully themed. It all depends on what you want to change. You can mess with the .9's, assuming you know how to do it properly. IE: modify your .9, edit your .9 in draw9patch, then compile in eclipse.
To sign a zip ---> java -jar signapk.jar testkey.x509.pem testkey.pk8 zip-name.zip new-zip-name.zip.zip
ty for the pdf that explains a lot in simple terms, and maybe I'll dive in on my eris first just in case lol, and thanks for the zip signing
Sent from my SCH-I500 using XDA App
Also look up apk manager in search (don't have the link handy)
on the .9.png files do I just open them in gimp/photoshop and then open it again in draw9patch to resave it? lol lil confused on these particular files
Sent from my SCH-I500 using XDA App

Need a means to compile apks

OK seeing as my computer currently doesn't work, I need to know if there is an app for my phone that will at least edit the contents of an apk, if not compile one. Anyone?
Also, if this is in the wrong section, feel free to move it, mods.
From my X10a running WB CM 6.1.3 V053
Realorasz said:
OK seeing as my computer currently doesn't work, I need to know if there is an app for my phone that will at least edit the contents of an apk, if not compile one. Anyone?
Also, if this is in the wrong section, feel free to move it, mods.
From my X10a running WB CM 6.1.3 V053
Click to expand...
Click to collapse
apk's are just renamed zip files.
If so, then is there an app that will directly edit zip files? And do they need to be set to store compression level? If so, is there an app that does so?
From my X10a running WB CM 6.1.3 V053
Realorasz said:
If so, then is there an app that will directly edit zip files? And do they need to be set to store compression level? If so, is there an app that does so?
From my X10a running WB CM 6.1.3 V053
Click to expand...
Click to collapse
yes, set to store...all you have to do is long-press the file and select rename...same to change it back afterward. I don't know about what app will allow you to set to store, but there are a TON of free zip apps. Check the market
I need to edit them though, and if I extract it edit it then zip it with an app, it's not set to store.
From my X10a running WB CM 6.1.3 V053
Root explorer can open xml files in apps but I don't think it can edit them.
After modding the contents of a non-system apk file i believe you'll have to re-sign the apk. I dont know of any way to do that on your phone, i am admittedly not an expert though. Ive modded icons and such for apps and the only way I could find out how to get them installed was to re-sign them on my PC and push back to the phone.
Sent from my X10i using XDA App
CMoney87 said:
After modding the contents of a non-system apk file i believe you'll have to re-sign the apk. I dont know of any way to do that on your phone, i am admittedly not an expert though. Ive modded icons and such for apps and the only way I could find out how to get them installed was to re-sign them on my PC and push back to the phone.
Sent from my X10i using XDA App
Click to expand...
Click to collapse
Yeah signapktic can sign on the phone, all I need is an app that either will, zip things set to store like in sundae or one that will directly modify the contents of the zip.
From my X10a running WB CM 6.1.3 V053
The files inside apk is I think encrypted. normal text viewers (ex. notepad) cant see it. and the resource files (styles strings colours ) are archived again. Btw it would be great if we have an app to disassemble them within 4n. Coz copying apk from and to to computer is a pain
akila87 said:
The files inside apk is I think encrypted. normal text viewers (ex. notepad) cant see it. and the resource files (styles strings colours ) are archived again. Btw it would be great if we have an app to disassemble them within 4n. Coz copying apk from and to to computer is a pain
Click to expand...
Click to collapse
Well making it a zip on my phone didn't screw anything up. I can still browse normally. What I need is a means to edit a zip without compressing it, like you have to for bootanimatjons and everything else.
From my X10a running WB CM 6.1.3 V053
I would suggest having a look through the market....download every free app you can find and see if any help. There are so many out there that I have no idea which would work for exactly what you will want it to do. Really, trial and error is the best way, sometimes lol
eclipse
I'm not sure I understand correctly, some previously mentioned are right on track.
Contents of an APK file are as normal zip files, extract the APK with winrar, 7zip or similar program.. make modifications and re-zip it and change the file name.
Important process called "Zip Align" optimizes the file for the APK format and helps to optimize and align the archive for memory mapping I/O ensuring the payload is delivered correctly, for more info - mmap
If you would like to reverse an APK file, I choose to use APKTOOL a Google hosted project and complete with it's own reverse engineering syntax called "baksmali" - This wraps AAPT - Android Asset Packaging Tool part of the android SDK - need this installed.
An issue exists with obfuscated Java classes. Meaning source code has been scrambled (obfuscation algorithm) enabling it be understood by a compiler but no longer is human readable. Another issue is Signing the APK file as most installers are to authenticate the issuing publisher.
To build an APK anyone only need's have the Eclipse IDE and Android SDK installed and you can do this without even having an Android device by using the emulator to build and test your application.
Happy play!
EDIT: Apk edit and Apk tool are both able to help in this situation also.

[Q] [Help] Need help about decompiling apk's

Well, I was developing a little game, some days ago I formatted my pc and forgot to make a backup of my projects, fortunately I have .apk file in my dropbox account, so I tried to decompile using APKtoJava and browser decompiler.
I got res files, every XML file it's ok but, the src part is not fine at all.
Most of .java files can't compile, those files have errors, and reading the code I found variable names changed, strange code lines added, etc.
I could fix lines but last time modified files was on august (stopped development due to exams, etc), so I don't remember too much what I have done, in fact, expected to remember what I did reading code, but with those modified lines can't expect to remember fine.
I ask you for help, is there another way to get the code exactly I have made? or at least with no errors?
Thanks.
Well this happened to me too once, fortunately it was just a learning project for me, nothing important. But still I can understand how you feel. Try this -
Try decompiling from apk to java without selecting the smali code option. If you select smali code the whole code generally messes up. Also do not select the Convert to Eclipse Project option (although it could work in your case, never worked well for me). This way you will at least get your source files. Then use Virtuous Ten Studio, it will decompile everything perfectly except for source files. And then try to put them back together piece by piece, although it's easier said than done.
Good Luck with it :thumbup:
Sent from my Galaxy Nexus using Tapatalk

Categories

Resources