5,599,135 Members 34,074 Now Online
XDA Developers Android and Mobile Development Forum

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

Tip us?
 
broodplank1337
Old
(Last edited by broodplank1337; 19th December 2013 at 09:10 PM.)
#1  
broodplank1337's Avatar
Recognized Contributor / Recognized Developer - OP
Thanks Meter 9401
Posts: 4,735
Join Date: Nov 2011
Location: Nijmegen

 
DONATE TO ME
Prompt [Shell Script]GetJava (get java code from apks instantly)

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}
Device: Samsung Galaxy S4 (i9505)

Latest Development:

Roms:
AOSP v4.4.2 (KVT49L) from source for I9505 (Github)
- Cleanest ROM available for i9505. along with up-to-date stock kernel, also forms a perfect base for ROM developers.

Apps:
Galaxy S4 Glove Mode App (Playstore link)
- Do you want the Glove Mode of the S4 but your ROM doesn't support it? Use this app to enable/disable it easily.

Latest Scraps:
Proprietary Lib Cleaner / Silent proprietary libs / Live Thermal Monitor / GIT Conflict Fixer


Upcoming projects:

broodROM KitKat "Aiming for perfection"
- Custom ROM with really high standards, more info soon, Target devices: All popular new-generation smartphones (mainly Samsung)


For sources you can visit my Github. Or take a look at all my projects

The Following 16 Users Say Thank You to broodplank1337 For This Useful Post: [ Click to Expand ]
 
z720
Old
#2  
Member
Thanks Meter 0
Posts: 34
Join Date: Jan 2009
After converted apk to java, the most important question is "did it run on java enabled phone" ?
 
defcomg
Old
#3  
defcomg's Avatar
Senior Member
Thanks Meter 1716
Posts: 2,224
Join Date: Dec 2006
Location: Port Elizabeth

 
DONATE TO ME
Quote:
Originally Posted by z720 View Post
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: [ Click to Expand ]
 
broodplank1337
Old
#4  
broodplank1337's Avatar
Recognized Contributor / Recognized Developer - OP
Thanks Meter 9401
Posts: 4,735
Join Date: Nov 2011
Location: Nijmegen

 
DONATE TO ME
Quote:
Originally Posted by z720 View Post
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 View Post
+1
Device: Samsung Galaxy S4 (i9505)

Latest Development:

Roms:
AOSP v4.4.2 (KVT49L) from source for I9505 (Github)
- Cleanest ROM available for i9505. along with up-to-date stock kernel, also forms a perfect base for ROM developers.

Apps:
Galaxy S4 Glove Mode App (Playstore link)
- Do you want the Glove Mode of the S4 but your ROM doesn't support it? Use this app to enable/disable it easily.

Latest Scraps:
Proprietary Lib Cleaner / Silent proprietary libs / Live Thermal Monitor / GIT Conflict Fixer


Upcoming projects:

broodROM KitKat "Aiming for perfection"
- Custom ROM with really high standards, more info soon, Target devices: All popular new-generation smartphones (mainly Samsung)


For sources you can visit my Github. Or take a look at all my projects

The Following User Says Thank You to broodplank1337 For This Useful Post: [ Click to Expand ]
 
Jarmezrocks
Old
#5  
Jarmezrocks's Avatar
Senior Member
Thanks Meter 379
Posts: 833
Join Date: Mar 2011
Location: Gold Coast

 
DONATE TO ME
Quote:
Originally Posted by broodplank1337 View Post
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

help find a cure for Narcolepsy
donations to this cause do not come directly to me, they are
anonymous but please tell me so I can give you thanks
The Following User Says Thank You to Jarmezrocks For This Useful Post: [ Click to Expand ]
 
ayysir
Old
(Last edited by ayysir; 19th December 2013 at 06:51 AM.)
#6  
ayysir's Avatar
Recognized Developer
Thanks Meter 5486
Posts: 4,155
Join Date: Aug 2011
Location: Bronx, NY

 
DONATE TO ME
noice great work

any work making a repacker version?
Github
https://github.com/ayysir/


Projects:
All-Star Devs Kernel for SGS3 - http://goo.gl/fsyvs

AEI - Android Environment Installer - http://goo.gl/4TKdi

Kernel Build Script How To - http://goo.gl/admz2

AOSPA ROMS BELOW



The Following User Says Thank You to ayysir For This Useful Post: [ Click to Expand ]
 
broodplank1337
Old
#7  
broodplank1337's Avatar
Recognized Contributor / Recognized Developer - OP
Thanks Meter 9401
Posts: 4,735
Join Date: Nov 2011
Location: Nijmegen

 
DONATE TO ME
Quote:
Originally Posted by Jarmezrocks View Post
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 View Post
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, 19 views)
Device: Samsung Galaxy S4 (i9505)

Latest Development:

Roms:
AOSP v4.4.2 (KVT49L) from source for I9505 (Github)
- Cleanest ROM available for i9505. along with up-to-date stock kernel, also forms a perfect base for ROM developers.

Apps:
Galaxy S4 Glove Mode App (Playstore link)
- Do you want the Glove Mode of the S4 but your ROM doesn't support it? Use this app to enable/disable it easily.

Latest Scraps:
Proprietary Lib Cleaner / Silent proprietary libs / Live Thermal Monitor / GIT Conflict Fixer


Upcoming projects:

broodROM KitKat "Aiming for perfection"
- Custom ROM with really high standards, more info soon, Target devices: All popular new-generation smartphones (mainly Samsung)


For sources you can visit my Github. Or take a look at all my projects

The Following User Says Thank You to broodplank1337 For This Useful Post: [ Click to Expand ]
 
10tacleBoy
Old
#8  
10tacleBoy's Avatar
Member
Thanks Meter 37
Posts: 46
Join Date: Oct 2012
@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: [ Click to Expand ]
 
elesbb
Old
#9  
elesbb's Avatar
Senior Member
Thanks Meter 3873
Posts: 6,251
Join Date: Jun 2010

 
DONATE TO ME
Quick question, how's this different from dex2jar?
 
broodplank1337
Old
#10  
broodplank1337's Avatar
Recognized Contributor / Recognized Developer - OP
Thanks Meter 9401
Posts: 4,735
Join Date: Nov 2011
Location: Nijmegen

 
DONATE TO ME
Quote:
Originally Posted by 10tacleBoy View Post
@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 View Post
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.
Device: Samsung Galaxy S4 (i9505)

Latest Development:

Roms:
AOSP v4.4.2 (KVT49L) from source for I9505 (Github)
- Cleanest ROM available for i9505. along with up-to-date stock kernel, also forms a perfect base for ROM developers.

Apps:
Galaxy S4 Glove Mode App (Playstore link)
- Do you want the Glove Mode of the S4 but your ROM doesn't support it? Use this app to enable/disable it easily.

Latest Scraps:
Proprietary Lib Cleaner / Silent proprietary libs / Live Thermal Monitor / GIT Conflict Fixer


Upcoming projects:

broodROM KitKat "Aiming for perfection"
- Custom ROM with really high standards, more info soon, Target devices: All popular new-generation smartphones (mainly Samsung)


For sources you can visit my Github. Or take a look at all my projects


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes