Welcome to XDA

Search to go directly to your device's forum

Register an account

Unlock full posting privileges

Ask a question

No registration required
Post Reply

[Shell Script]GetJava (get java code from apks instantly)

OP broodplank1337

11th December 2013, 02:17 AM   |  #1  
broodplank1337's Avatar
OP Recognized Contributor / Recognized Developer
Flag Nijmegen
Thanks Meter: 10,090
 
4,943 posts
Join Date:Joined: Nov 2011
Donate to Me
More
I wrote this small shell script that basically extracts classes.dex from an apk/jar, then decompiles the classes.dex to jar classes, extracts the classes and converts them to java code.

Script got posted on the portal (http://www.xda-developers.com/androi...java-projects/)

Installation: (dont skip this step)
place it in ~/bin, give execute rights and then run
Code:
getjava --getdeps
Usage:
Code:
getjava file.apk [--debug]
--debug param is optional and gives extra output

when entering "getjava apkname.apk" you will get as output a folder called:

apkname.apk_java

which contains the decompiled classes.
obfuscation may scramble the code


Script:
Code:
#!/bin/bash
# getjava v1.0
# to get java code from apks instantly
# by broodplank
# 
# Credits: 
# Dex2Jar - Google
# JAD - Pavel Kouznetsov

if [[ ( $1 = "--getdeps" ) || ( $2 = "--getdeps" ) ]]; then
	echo "Installing required dependencies..."
        echo
        sudo apt-get install p7zip unzip wget -y
        wget -P ~ http://www.broodplank.net/files/getjava_dep.zip
        unzip -o ~/getjava_dep.zip -d ~/bin
	rm -f ~/getjava_dep.zip
        echo "Done, please restart the script"
	exit
fi;  


if [[ $2 = "--debug" ]]; then
	export DEBUGPARAM1="-d -v"
	export DEBUGPARAM2="-v"
else
	export DEBUGPARAM1=""
	export DEBUGPARAM2=""
fi;  


if [[ ( $1 = "" ) || ( $1 = "--help" ) || ( $1 = "-help" ) ]]; then
        echo "getjava -- get java from apk or jar instantly"
	echo "usage: getjava [apk/jar path] [options]"
        echo 
        echo "options:"
        echo " --getdeps		Installs all required dependencies automatically"
        echo " --debug		Show additional debugging information"
	echo
	echo "by broodplank"
	exit
else
	DIR=${1%/*}
	FILE=${1##*/}
        EXTENSION=${1##*.}
        OUTDIR="${PWD}/${FILE}_out"
fi;

rm -Rf ${OUTDIR}
rm -Rf ${PWD}/${FILE}_java
mkdir -p ${OUTDIR} 
7za x -yr -o${OUTDIR} ${1} classes.dex
d2j-dex2jar.sh ${DEBUGPARAM1} -os -ts ${OUTDIR}/classes.dex -o ${OUTDIR}/classes_dex2jar.jar
7za x -yr -o${OUTDIR}/out ${OUTDIR}/classes_dex2jar.jar
find -iname '*.class' -execdir jad ${DEBUGPARAM2} -o -r -s .java -d ${OUTDIR}/java -o {} \;
rm ${OUTDIR}/classes.dex ${OUTDIR}/classes_dex2jar.jar 
mv -f ${OUTDIR}/java ${PWD}/${FILE}_java
rm -Rf ${OUTDIR}
Last edited by broodplank1337; 19th December 2013 at 10:10 PM.
The Following 16 Users Say Thank You to broodplank1337 For This Useful Post: [ View ]
19th December 2013, 03:31 AM   |  #2  
Member
Thanks Meter: 4
 
85 posts
Join Date:Joined: Jan 2009
After converted apk to java, the most important question is "did it run on java enabled phone" ?
19th December 2013, 06:32 AM   |  #3  
defcomg's Avatar
Senior Member
Flag Port Elizabeth
Thanks Meter: 1,859
 
2,453 posts
Join Date:Joined: Dec 2006
Donate to Me
More
Quote:
Originally Posted by z720

After converted apk to java, the most important question is "did it run on java enabled phone" ?

The Following 4 Users Say Thank You to defcomg For This Useful Post: [ View ]
19th December 2013, 07:04 AM   |  #4  
broodplank1337's Avatar
OP Recognized Contributor / Recognized Developer
Flag Nijmegen
Thanks Meter: 10,090
 
4,943 posts
Join Date:Joined: Nov 2011
Donate to Me
More
Quote:
Originally Posted by z720

After converted apk to java, the most important question is "did it run on java enabled phone" ?

Wat

So you're actually saying if the java code itself did run on a java enabled phone? which are all android devices. no it does not of course.
or if you mean if you're able to recompile the apk with the decompiled sources? if so, then in some cases you can but mostly on small apps.
the script is made for getting an insight on how the code is built.

Quote:
Originally Posted by defcomg

+1
The Following User Says Thank You to broodplank1337 For This Useful Post: [ View ]
19th December 2013, 07:42 AM   |  #5  
Jarmezrocks's Avatar
Senior Member
Flag Gold Coast
Thanks Meter: 465
 
949 posts
Join Date:Joined: Mar 2011
Donate to Me
More
Quote:
Originally Posted by broodplank1337

Wat

So you're actually saying if the java code itself did run on a java enabled phone? which are all android devices. no it does not of course.
or if you mean if you're able to recompile the apk with the decompiled sources? if so, then in some cases you can but mostly on small apps.
the script is made for getting an insight on how the code is built.



+1

Hey dude,

Congrats! nice work. Have you done a side by side comparison of your script against DED or Android DARE? When I get home tonight I will give it a run and feed you back my results. Have you got a common APK that I could use as a control?

I will send you the resulting decompiled Java classes from DARE for you to look at
The Following User Says Thank You to Jarmezrocks For This Useful Post: [ View ]
19th December 2013, 07:49 AM   |  #6  
ayysir's Avatar
Recognized Developer
Flag Bronx, NY
Thanks Meter: 6,163
 
4,455 posts
Join Date:Joined: Aug 2011
Donate to Me
More
noice great work

any work making a repacker version?
Last edited by ayysir; 19th December 2013 at 07:51 AM.
The Following User Says Thank You to ayysir For This Useful Post: [ View ]
19th December 2013, 11:33 AM   |  #7  
broodplank1337's Avatar
OP Recognized Contributor / Recognized Developer
Flag Nijmegen
Thanks Meter: 10,090
 
4,943 posts
Join Date:Joined: Nov 2011
Donate to Me
More
Quote:
Originally Posted by Jarmezrocks

Hey dude,

Congrats! nice work. Have you done a side by side comparison of your script against DED or Android DARE? When I get home tonight I will give it a run and feed you back my results. Have you got a common APK that I could use as a control?

I will send you the resulting decompiled Java classes from DARE for you to look at

Thanks! No I haven't done any comparison actually, I just wrote it and shared it on Dev forums, I never expected it to hit the portal so it's still a really simple script, will extend it and make it better. If anyone would like to contribute to the script, take look at github (just made it) https://github.com/broodplank/GetJava

Attached an apk that is not obfuscated and has very decent java output

Quote:
Originally Posted by ayysir

noice great work

any work making a repacker version?

Thanks, well implementing a repacker is not really the idea. it's because almost all apks will not repack successfully. What I can create tho is an option to export it to an eclipse project such as in ApktoJava (my windows version of this tool)
Attached Files
File Type: apk GalaxyS4Settings.apk - [Click for QR Code] (138.3 KB, 24 views)
The Following User Says Thank You to broodplank1337 For This Useful Post: [ View ]
19th December 2013, 08:14 PM   |  #8  
10tacleBoy's Avatar
Member
Thanks Meter: 39
 
49 posts
Join Date:Joined: Oct 2012
More
@broodplank1337

Thx for this great script. This is what I were looking for some years ago. Good work .
The Following User Says Thank You to 10tacleBoy For This Useful Post: [ View ]
19th December 2013, 08:38 PM   |  #9  
elesbb's Avatar
Senior Member
Thanks Meter: 4,441
 
6,900 posts
Join Date:Joined: Jun 2010
Donate to Me
More
Quick question, how's this different from dex2jar?
19th December 2013, 10:08 PM   |  #10  
broodplank1337's Avatar
OP Recognized Contributor / Recognized Developer
Flag Nijmegen
Thanks Meter: 10,090
 
4,943 posts
Join Date:Joined: Nov 2011
Donate to Me
More
Quote:
Originally Posted by 10tacleBoy

@broodplank1337

Thx for this great script. This is what I were looking for some years ago. Good work .

You're welcome :P it's always handy to have ;p

Quote:
Originally Posted by elesbb

Quick question, how's this different from dex2jar?

Well if you read the OP you will see that it does more then just convert the dex to a jar file. sine thats the only thing dex2jar can do

I wrote this small shell script that basically extracts classes.dex from an apk/jar, then decompiles the classes.dex to jar classes, extracts the classes and converts them to java code.

Post Reply Subscribe to Thread
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes