Mobile Tech Support

  • Subscribe to our RSS feed.
  • Twitter
  • StumbleUpon
  • Reddit
  • Facebook
  • Digg

Friday, 11 May 2012

Reverse Engineering - Android APK

Posted on 03:27 by Unknown
There's nothing really complex about this post. In the past I've always maintained that reversing is kind of tough; and that's true if its an EXE,DLL etc. But in the case of an Android application; it really is very easy.

While all this information is already there, here is a very short blog post summarizing how you get from APK to Source. I used a Vuln app available here; but you can use anything really. Here goes:

1. Extract the APK to a folder. Its just a Zip file so any archiving program should do; I use the inbuilt Ubuntu GUI archiving tool.

2. Rename the folder to something like original_helloworld. That's because we will play around with all the files inside  and it might be nice to have an original copy somewhere to look at when needed.

3. Look at the file AndroidManifest.xml. It'll open in a Text editor but its largely binary; hence unreadable. Use Apktool to decode this XML file as well as every other XML file in the APK. You can get it from http://code.google.com/p/android-apktool/. Download the main apktool package (contains a JAR) and the platform specific one as well (contains the apktool binary). Run apktool . It'll run and give you all the XML files totally decoded; so you can now read them.

4. You now want to recover code. All code is in classes.dex. Think of Dex as Android Byte code which is reversible to Java Byte Code....which eventually is reversible
to Java code. So we first 'dedex'. You can either use the output of apktool above; which after running gives you its output in a folder called 'smali'. A slightly more
 'easy to read' format is given by dedexer though (less spaces; cleaner output) available at http://dedexer.sourceforge.net. You use it as follows to 'dedex' classes.d
ex - java -jar ddx1.22.jar -d /opt/Android/vulnapps/Tmp_test_apps/InsecureBankDeDexed /opt/Android/vulnapps/Tmp_test_apps/InsecureBank.apk_FILES/classes.dex. Look inside InsecureBankDeDexed for the output. So in a nutshell, after we DeDex we get Android Byte code.

5. Once you have Android byte code; since Android code 'looks' very much like Java, you can convert Android byte code to Java byte code. Use dex2jar downloaded from
http://code.google.com/p/dex2jar/ and run it as follows ./dex2jar.sh ../../vulnapps/Tmp_test_apps/InsecureBank.apk. This results in a JAR file getting created in the d
irectory where the APK is already present. The JAR file contains all the JAVA class files; namely the Java byte code - something that you get once you compile your Jav
a code.

6. The last step is to convert your Java byte code into actual Java code. You need something called a Java decompiler for this. You can download one called the Jd-Gui from here - http://java.decompiler.free.fr/?q=jdgui. Once its downloaded, unzip the JAR and store all its class files in a single folder like JavaClassFiles. Launch JD-GUI and select 1 class file. Save the source. Repeat for each class file [Painful I know :(]. You now have all the source code and can do some static analysis on the code :). There's probably some cooler way to decompile all the class files in a folder; but I won't dig too deep into that just now.

Largely this presentation was where I got almost everything from. Will write more when I do some static analysis.
Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest
Posted in android, apk, engineering, reverse, source | No comments
Newer Post Older Post Home

0 comments:

Post a Comment

Subscribe to: Post Comments (Atom)

Popular Posts

  • EMC Defenders CTF - Week 3 - Contest 14 - Reversing
    I played the EMC defenders CTF with a few of my friends a while back. We sadly couldn't complete all the challenges. All the same it was...
  • AuthenTec co-founder discusses how Touch ID fingerprint reader evolved from early prototypes!!!
    AuthenTec co-founder F. Scott Moody recently stopped by his alma mater to deliver a  speech  about the company he helped launch. His company...
  • Hackers breach vBulletin support forum using zero-day vulnerability!!!
    A group of European hackers by the name of Inj3ct0r Team have taken  responsibility  for hacking the support forums of vBulletin.com and the...
  • ASRock unveils a pair of motherboards designed specifically for Bitcoin mining!!!
    Those looking to generate some extra cash by mining for Bitcoin now have a couple of new hardware options courtesy of ASRock. The motherboar...
  • Amazon's trio of biospheres gets two thumbs up from Seattle Design Review Board!!!
    Earlier this year Amazon  submitted a building proposal  to construct a series of massive biospheres in downtown Seattle adjacent to three o...
  • 20 Life Hacks and Tools to Boost Productivity on Your Computer!!!
    With the flood of  new technologies , websites, apps, news, work files, pictures, articles and the like, staying organized and focused is be...
  • Why and how to set up your own wiki with Dokuwiki!!!
    DokuWiki is a simple but versatile wiki. Find out how to install, configure, and begin using DokuWiki.  A couple of weeks ago, I had to set ...
  • Chrome used more than Firefox, Opera and Internet Explorer combined!!!
    Google Chrome is absolutely dominating the web browser market, at least according to social analytics firm  Shareaholic , which yesterday re...
  • A peek at the inside of Sony's PlayStation 4!!!
    See  what's inside the PlayStation 4 with these exclusive photos  Inside Sony headquarters, at the heart of Tokyo’s Shinagawa district, ...
  • Crysis developer releases free-to-play FPS browser game Warface!!!
    Crytek is well known for its graphically impressive and visually stunning games on PC and console, but now the developer is taking its exper...

Categories

  • 100
  • 12.04
  • 2.2
  • 2013
  • 21
  • 4848
  • 8080
  • add
  • alternative
  • analysis
  • android
  • apk
  • app
  • applet
  • applets
  • appletviewer
  • application
  • appsec
  • asmx
  • assembly
  • attack
  • attacks
  • basic
  • basics
  • beginner
  • blazeds
  • blog
  • book
  • books
  • breakpoint
  • breakpoints
  • browser
  • burp
  • CALL
  • capture
  • certificate
  • chain
  • cheops
  • client side
  • code
  • conference
  • console
  • content-type
  • coverage
  • CRLF
  • cross
  • crossdomain
  • csrf
  • ctf
  • customer service
  • database
  • deblaze
  • debug
  • debugger
  • decision
  • defcon
  • delete
  • deleting
  • dll
  • dogbert
  • dom
  • dynamic
  • element
  • emulator
  • encryption
  • engineering
  • entity
  • environment
  • example
  • executable
  • external
  • firebug
  • flash
  • flex
  • FlourineFX
  • flow
  • flowchart
  • forensics
  • fs
  • fuzz
  • glassfish
  • graph
  • handbook
  • harden
  • hash
  • hints
  • hit
  • hittrace
  • howto
  • IDA
  • idapro
  • IDB
  • immunity
  • in use
  • incremental
  • inetsim
  • injection
  • install
  • introduction
  • java
  • java.policy
  • javaee
  • javascript
  • jks
  • jump
  • keyboard
  • lab
  • loaderdata
  • malware
  • management
  • mapper
  • market
  • MD Description
  • MD FAQ
  • MD Technical Support
  • MD Updates
  • MD User Guide
  • md5deep
  • mount
  • msdn
  • network
  • newbie
  • olly
  • ollydbg
  • options
  • packet
  • password
  • pbkdf
  • pcap
  • peb
  • peb_ldr_data
  • penetration
  • pentest
  • permissions
  • phone
  • pkcs12
  • policytool
  • port
  • practical
  • procedure
  • proxy
  • resign
  • resignation
  • response
  • restrict
  • reverse
  • reversing
  • review
  • salt
  • same origin
  • sample
  • scripting
  • sdk
  • secure
  • security
  • set
  • setup
  • sharif
  • shortcuts
  • SI
  • signed
  • site
  • snapshot
  • soapui
  • source
  • splitting
  • ssl
  • start
  • static
  • steps
  • stunnel
  • superblock
  • support
  • test
  • thoughts
  • thread
  • tips
  • tool
  • tools
  • tor
  • trace
  • truecrypt
  • tutorial
  • ubuntu
  • umask
  • understand
  • university
  • unsigned
  • video
  • view
  • virgin
  • virtual
  • virtual box
  • virtual machine
  • virtualbox
  • vm
  • watch
  • web
  • web application
  • web service
  • work
  • wsdl
  • xhr
  • xml
  • xss
  • xxe

Blog Archive

  • ►  2013 (496)
    • ►  November (143)
    • ►  October (297)
    • ►  September (51)
    • ►  August (2)
    • ►  March (1)
    • ►  January (2)
  • ▼  2012 (16)
    • ►  October (3)
    • ►  September (1)
    • ►  August (4)
    • ►  June (1)
    • ▼  May (4)
      • New Mobile Doctor for Free
      • Reverse Engineering - Android APK
      • Market app - Android 2.2
      • Blogging elsewhere for a bit
    • ►  April (2)
    • ►  February (1)
  • ►  2011 (22)
    • ►  October (1)
    • ►  September (2)
    • ►  August (1)
    • ►  July (9)
    • ►  June (1)
    • ►  May (2)
    • ►  April (6)
  • ►  2010 (8)
    • ►  August (3)
    • ►  April (2)
    • ►  January (3)
  • ►  2009 (6)
    • ►  December (6)
Powered by Blogger.

About Me

Unknown
View my complete profile