forked from DrizzleRisk/BUnpacker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bunpacker.py
84 lines (80 loc) · 2.83 KB
/
bunpacker.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#coding=utf-8
import sys,shutil
reload(sys)
sys.setdefaultencoding('utf-8')
import os,time,zipfile
from xml.dom import minidom
PACKAGE_NAME = ''
START_ACTIVITY = ''
APK_PATH = ''
def Title():
print '[>>>] BUnpacker [<<<]'
print '[>>>] code by Drizzle [<<<]'
print '[>>>] 2016.10 [<<<]'
def CheckEnv():
Title()
print '[*] Init env'
global APK_PATH
global PACKAGE_NAME
global START_ACTIVITY
#初始化环境
if not os.path.exists('result'):
os.mkdir('result')
if not os.path.exists('tmp'):
os.mkdir('tmp')
CPU = 'x86'
os.popen('adb root')
result = os.popen('adb shell cat /proc/cpuinfo').read()
if result.find('ARM') != -1:
CPU = 'armeabi'
print '[*] Target: '+CPU
print '[---------------------------------------]'
os.popen('adb push ext-tools/' + CPU + '/bulib /data/local/tmp')
os.popen('adb install ' + APK_PATH)
print '[---------------------------------------]'
#获取包信息备用
print '[*] Get package info'
nxml = open('tmp/nxml.xml','w')
zf = zipfile.ZipFile(APK_PATH, 'r')
content = zf.read('AndroidManifest.xml')
nxml.write(content)
nxml.close()
content = os.popen('java -jar ext-tools/AXMLPrinter2.jar tmp/nxml.xml').read()
mfest = minidom.parseString(content)
manifest = mfest.getElementsByTagName('manifest')
activities = mfest.getElementsByTagName("activity")
for node in manifest:
PACKAGE_NAME = node.getAttribute("package")
for activity in activities:
for sitem in activity.getElementsByTagName("action"):
val = sitem.getAttribute("android:name")
if val == "android.intent.action.MAIN" :
START_ACTIVITY = activity.getAttribute("android:name")
def Dump():
print '[*] Dump dex'
global PACKAGE_NAME
global START_ACTIVITY
os.popen('adb shell am force-stop ' + PACKAGE_NAME)
time.sleep(1)
os.popen('adb shell am start -n ' + PACKAGE_NAME + '/' + START_ACTIVITY)
content = os.popen('adb shell ./data/local/tmp/bulib ' + PACKAGE_NAME).read()
print '[---------------------------------------]'
os.popen('adb pull ' + content + ' result/' + PACKAGE_NAME + '.dex')
print '[---------------------------------------]'
if os.path.exists('result/' + PACKAGE_NAME + '.dex'):
print '[*] Success >> ' + 'result/' + PACKAGE_NAME + '.dex'
#清理环境
if os.path.exists('tmp'):
shutil.rmtree('tmp')
def Useage():
Title()
print '[*] Useage: bunpacker.py jiagu.apk'
print '[*] 1.Before Running ,make sure a rooted Android system has been connected to your PC'
print '[*] 2.Only for testing,Do not be evil !'
if __name__ == '__main__':
if len(sys.argv) < 2:
Useage()
else:
APK_PATH = sys.argv[1]
CheckEnv()
Dump()