forked from honeynet/apkinspector
-
Notifications
You must be signed in to change notification settings - Fork 0
/
APKtool.py
71 lines (60 loc) · 2.04 KB
/
APKtool.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
import os
import sys
import Global
from startQT import SYSPATH
# use the apktool to get the smali codes and AndroidManifest.xml
# return 1: success ; return 0: fail
def callAPKtool(filename):
outputPath = SYSPATH + "/temp/ApktoolOutput"
cmd = "apktool d -d -f " + filename + " " + outputPath
if os.system(cmd) !=0:
return 0
else:
return 1
class APKtool:
firstFlag = None
lastClassName = None
def __init__(self):
print "apktool 2"
# self.successFlag = Global.FLAG_APKTOOL
self.successFlag = 1
self.firstFlag = 0
self.lastClassName = ""
def getManifest(self):
if self.successFlag == 0:
print "apktool fail3"
return [0, ""]
print "apktool success 4"
path = SYSPATH + "/temp/ApktoolOutput/AndroidManifest.xml"
try:
data = open(path, "r").read()
except IOError:
print "IOError"
data = ""
return [1, data]
# get the smali codes
def getSmaliCode(self, className):
if self.successFlag == 0:
return [0, ""]
print className
className = className[1:-1] + ".smali"
# this is the first time to call method "getSmaliCode"
if self.firstFlag == 0:
self.firstFlag ==1
self.lastClassName = className
classPath = SYSPATH + "/temp/ApktoolOutput/smali/" + className
try:
data = open(classPath, "r").read()
except IOError:
print "IOError"
data = ""
return [1, data]
# if the lastClassName is equal to className, the smali codes need not to be updated
if self.firstFlag == 1:
if self.lastClassName == className:
return [0, ""]
else:
self.lastClassName = className
classPath = SYSPATH + "/temp/ApktoolOutput/" + className
data = open(classPath, "r").read()
return [1, data]