Created
May 23, 2015 05:59
-
-
Save OnlyInAmerica/e0e73ae971791c652c61 to your computer and use it in GitHub Desktop.
Pull and decompile Android APK (Jank Edition)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import subprocess | |
DEX2JAR_PATH = ‘/PATH/TO/dex2jar-2.0/d2j-dex2jar.sh' # https://github.com/pxb1988/dex2jar | |
APKTOOL_JAR_PATH = ‘PATH/TO/apktool.jar' # http://ibotpeaches.github.io/Apktool/install/ | |
JDCLI_JAR_PATH = '/PATH/TO/jd-cli.jar' # https://github.com/kwart/jd-cmd | |
# TODO SANITIZE INPUT | |
query = sys.argv[1] | |
# Find and pull apk from device | |
cmd = "adb shell pm list packages | grep %s" % query | |
proc = subprocess.Popen(['adb', 'shell', 'pm', 'list', 'packages', '|', 'grep', query], stdout=subprocess.PIPE) | |
first_package = proc.stdout.read().split(' ')[0].split('package:')[1].strip() | |
proc2 = subprocess.Popen(['adb', 'shell', 'pm', 'path', first_package], stdout=subprocess.PIPE) | |
remote_path = proc2.stdout.read().split(' ')[0].split('package:')[1].strip() | |
print 'Got apk %s at path %s' % (first_package, remote_path) | |
local_path = './' + first_package + '.apk' | |
proc3 = subprocess.Popen(['adb', 'pull', remote_path, local_path]) | |
proc3.wait() | |
print 'apk pulled' | |
# Unzip apk | |
proc4 = subprocess.Popen(['unzip', '-d', './' + first_package, local_path]) | |
proc4.wait() | |
print 'unzipped' | |
# .dex -> .jar | |
proc5 = subprocess.Popen([DEX2JAR_PATH, './' + first_package + '/classes.dex']) | |
proc5.wait() | |
print 'decompiled!' | |
# Extract resources + Manifest | |
proc6 = subprocess.Popen(['java', '-jar', APKTOOL_JAR_PATH, 'd', local_path, '-f']) | |
proc6.wait() | |
print 'got resources and manifest!' | |
# Decompile jar | |
proc6 = subprocess.Popen(['java', '-jar', JDCLI_JAR_PATH, './classes-dex2jar.jar', '-od', './' + first_package + '-source/']) | |
proc6.wait() | |
print 'decompiled jar' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment