forked from vitome/SafeDroid-v2.0
-
Notifications
You must be signed in to change notification settings - Fork 0
/
androwarn_reverse.py
106 lines (82 loc) · 3.09 KB
/
androwarn_reverse.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# Global imports
import sys, re, logging
# OptionParser imports
from optparse import OptionParser
# Androguard imports
PATH_INSTALL = "./androguard/"
sys.path.append(PATH_INSTALL)
# Androwarn modules import
PATH_INSTALL = "./"
sys.path.append(PATH_INSTALL)
from androwarn.core.core import *
from androwarn.search.search import *
from androwarn.util.util import *
#from androwarn.report.report import *
from androwarn.analysis.analysis import *
# Logger definition
log = logging.getLogger('log')
log.setLevel(logging.ERROR)
formatter = logging.Formatter('[%(levelname)s] %(message)s')
handler = logging.StreamHandler()
handler.setFormatter(formatter)
log.addHandler(handler)
# Options definition
option_0 = { 'name' : ('-i', '--input'), 'help' : 'APK file to analyze', 'nargs' : 1 }
option_1 = { 'name' : ('-v', '--verbose'), 'help' : 'Verbosity level { 1-3 } (ESSENTIAL, ADVANCED, EXPERT)', 'nargs' : 1 }
option_2 = { 'name' : ('-r', '--report'), 'help' : 'Report type { txt, html }', 'nargs' : 1 }
option_3 = { 'name' : ('-d', '--display-report'), 'help' : 'Display analysis results to stdout', 'action' : 'count' }
option_4 = { 'name' : ('-L', '--log-level'), 'help' : 'Log level { DEBUG, INFO, WARN, ERROR, CRITICAL }', 'nargs' : 1 }
option_5 = { 'name' : ('-n', '--no-connection'), 'help' : 'Disable online lookups on Google Play', 'action' : 'count'}
options = [option_0, option_1, option_2, option_3, option_4, option_5]
def main(options, arguments) :
if (options.input != None) :
# Log_Level
if options.log_level != None :
try :
log.setLevel(options.log_level)
except :
parser.error("Please specify a valid log level")
# Verbose
if (options.verbose != None) and (options.verbose in VERBOSE_LEVEL) :
verbosity = options.verbose
else :
parser.error("Please specify a valid verbose level")
# Report Type
if (options.report != None) and (options.report in REPORT_TYPE) :
report_wanted = True
report = options.report
elif (options.report == None) and (options.display_report != None) :
report_wanted = False
else :
parser.error("Please specify a valid report type")
# Online Lookups enabled
no_connection = {True : CONNECTION_DISABLED, False : CONNECTION_ENABLED}[options.no_connection != None]
# Input
APK_FILE = options.input
a, d, x = AnalyzeAPK(APK_FILE)
package_name = grab_application_package_name(a)
#api_result = generate_API_List(x)
data = perform_analysis(APK_FILE, a, d, x, no_connection)
def getAPIfromDEX(DEXfile, pkg):
try:
d, x = AnalyzeDex(DEXFile)
except:
raise
api_result = generate_API_List(x, pkg)
return api_result
def getAPIfromPkg(apk):
try:
a, d, x = AnalyzeAPK(apk)
except:
raise
print 'Error'
data = perform_analysis(apk, a, d, x, False)
return data
if __name__ == "__main__" :
parser = OptionParser()
for option in options :
param = option['name']
del option['name']
parser.add_option(*param, **option)
options, arguments = parser.parse_args()
main(options, arguments)