Extracting Android .apk and reading contents of XML file in res/layout - java

I am trying to reverse engineer an existing android app and understand how a particular UI is constructed. I've found that I can rename the apk to zip and view some of the compiled source. The res/layout directory is populated with all the xml files that define the UI, but while they do have the xml extension, they are not in XML format. Is there anyway to convert these files back to text based markup?

I think you can use android-apktool. The XML files look very well.

Create a new folder and put the .apk file which you want to decode into that.
Download the latest version of from here.
Open cmd then navigate to the root directory of APKtool and type the following command:
apktool d myApp.apk
(where myApp.apk is the filename that you want to decode)
now you get a file folder in that folder and can easily read the apk's xml files.
Here is the link for more detail install instructions

For those Who are shortcut lovers:
and using ubunto,
go to cmd : ctl+alt+t
type:
sudo apt install apktool
press enter
then go to your apk(to decompile) folder. by using
cd ~/folder_name
then type:
apktool d yourAppName.apk
and boom , you are done.

First covert your .apk to .zip. Inside that you will get a compiled-bundled version of java class files called .dex. apply the below trick to convert that dex to class files
There's a way to do this. A slight atypical way is to download this opensource tool dextojar http://code.google.com/p/dex2jar/
This will convert your dex files to Jar file. Unjar these files to get java class files.
Then reverse engineer the java class files to get the java code. Don't use it to break some commercial projects.
Thanks

if you just want to know the UI construction ,you can use Hierarchy Viewer

Related

Editing java file within jar library

I need to replace one word (REPLACE with MODULATE) within the StdDraw3D.java file. I have opened the jar jd-gui and am pretty stuck now. I have been looking for videos or websites and cant quite find a way to do it. Any help would be greatly appreciated. I have not copy paste the code as i don't need help with code just how to edit or replace the original java file.
You have to download the complete source code for StdDraw.jar, update the required java file and rebuild the code again to get the updated jar file. Then use the updated jar in your project.
Steps:-
1. Download the StdDraw.jar
Extract the jar file in folder by right click on it and click on extract.
Copy the StdDraw3D.java file and edit and make required changes then compile it again. Then copy the changed class and java files in the above folder.
Now again create jar file out of that folder.

How to add resource file to Android apk after compilation and build of apk?

Is it possible to add a .class java-class file or if that's not possible a .txt text-file to an APK after it has been built and without source code?
We compile and build an Android application as apk file. And now the customer without needing the development tools has to be able to add at least a custom txt text-file to the APK before installing it on his devices.
The goal is that we write a program that will use the original apk and will add the text file to the apk, so the customer does not need any development tools.
It is not a restriction that the customer does not get the source code but that no additional software shall be installed. Our tool also has to run without installation.
The good news is that an APK file is just a zip file, so it's pretty easy to manipulate files that inside it.
The bad news is that you can add a .class file but Android will not be able to use it... that's because Android uses a different format (Dex) and expects code to be in Dex files instead of plain Java bytecode...
If you wanted to include a custom .txt file then all you'd have to do is copy it to the assets/ directory inside of the APK. Files in this folder are can be extracted to your applications internal folders, so it should be pretty easy to load it directly from there. But don't forget that tinkering with an APK file will invalidate its signature, meaning that you'll have to re-sign that APK in order to install it via an app store.

How to save a .dat file to a certain directory on my desktop

I am writing Java code to generate .dat and .idx files, which I can do.
The files are saved to my workspace folder which I set up as a default when I started Eclipse.
Now I want to save these files and only these files I create to another directory on my server.
Is there code that can do this or do I have to change the settings in Eclipse to do this?
Its a easy thing. Check below if this is what you want. Use
File file = new File("C:\\results\\results.txt");
C:\results\ is your outside directory.
No you can definitely do it programmatically. When specifying the path use something like:
"/c/users/someperson/desktop/blah.dat"

Edit the .properties file inside a jar without extracting it or changed to .zip format

I currently involved in a project which requires to load a properties file which is located inside a jar file and i need to edit tat. I have Googled a bit and saw quite a few different ways of achieving this ALL idea says i need to rename it to .zip file and after editing again converted to .jar , but i am not satisfied with that answer because i would like to perform the editing without extracting the jar ...is there any possibility by using command prompt or using some interface.... ANY IDEA FRIENDS
JAR files are built on the ZIP file format and have the .jar file extension. you can create or extract JAR files using the jar command that comes with a JDK. You can also use zip tools to do so;
You have to know that JAR files - like any other ZIP files is in compressed format. You cannot update a file inside a zip archive without extracting it and putting it back to the archive,no matter what tool may you use (Zip,WinRar,7-Zip or jar) you are just extracting the file and editing and then putting it back to the archive.The below given answers are also doing that,but the file are being extracted to a temporary directory and you are not seeing it.
If you install 7-zip you should be able to open the jar file directly and drag the properties file out of the archive to the desktop or something. Once there you can open/edit then drag it back to the 7-zip window. That's how I do it.
Use 7zip, right click on jar and with 7z say open archive, then go to property file, double click and open file with notepad, edit it and save. Now when you will close 7z console, it will ask "update archive?" Say yes... That's it.
Yes you can, In Centos 7 and the vim version 7.4 you can edit zip or jar files zip whit out unzip. So you execute the next commands and you can edit your properties file.
vim Programm.jar 2
[Then you see a lot of directories, so you go to the specific file you wan edit and push enter then you can edit the file use vim with the vim commands.]

is it possible to combine unknown format file to jar file

i have developed a project in java using swings and mysql. now in order to assign security to the project i want to store the Registration key in an unknown file format like .xyz using serialization. the key entered by the user is compared with the key stored in .xyz file. now, is it possible to add my .xyz file with jar file? if yes how is it possible? please help me to complete the project. thank you.
Jar file is just a zip file. You can add there as many files of any type as you want.
I do not know how your project is organized. If you do not use maven or gradle you probably have to add your file to src folder. If you do use maven add it to resources folder.

Categories

Resources