-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathobject_extractor.py
98 lines (64 loc) · 2.33 KB
/
object_extractor.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
import time
import sys
import re
import Stigma
import StigmaStringParsingLib
class SmaliObjectTypeOccurrence:
# Example Instance (result of calling print(repr(some_instance_of_this_class))
# Landroid/support/v4/text/util/LinkifyCompat$LinkifyMask; occuring at /tmp/apkOutput_f1n9d2zp/smali/android/support/v4/text/util/LinkifyCompat$LinkifyMask.smali : line 1
# this needs unit tests! (especially the __eq__ method)
def __init__(self, file_path, line_num, obj_ref):
self.file_path = file_path
self.line_num = line_num
self.obj_ref = obj_ref
def __eq__(self, other):
if(isinstance(other, SmaliObjectTypeOccurrence)):
return self.obj_ref == other.obj_ref
if(isinstance(other, str)):
return self.obj_ref == other
return False
def __hash__(self):
return hash(self.obj_ref)
def __str__(self):
return self.obj_ref
def __repr__(self):
return str(self) + " occuring at " + str(self.file_path) + " : line " + str(self.line_num)
def getAllClassReferences():
paths = Stigma.getFiles()
refs_list = []
for path in paths:
fh = open(path, "r")
line_num = 0
for line in fh.readlines():
line_num += 1
match_list = re.findall(StigmaStringParsingLib.IS_OBJECT_TYPE, line)
#print(path + " : line " + str(line_num))
for string in match_list:
#print("\t" + string)
soto = SmaliObjectTypeOccurrence(path, line_num, string)
refs_list.append(soto)
return refs_list
def get_target_classes(class_options):
# this should (in the future) be setup to read from a file
# or present the user with a tkinter GUI or something
# probably use a set or dictionary to display to user without
# displaying duplicates
for item in class_options:
if item == "Landroid/location/Location;":
return [item]
print("WARNING! No Target Class(es) Selected!")
return []
def main():
Stigma.deleteFiles()
print("Temp files at: " + str(Stigma.temp_file.name))
Stigma.dumpApk()
classes_list = getAllClassReferences()
target_classes = get_target_classes(classes_list)
print(target_classes)
# this input is here because it is helpful to keep the temporary files
# around for debugging purposes. In final release maybe remove it.
print("Temp files at: " + str(Stigma.temp_file.name))
input("Press Enter to Delete Temporary Files: ")
Stigma.deleteFiles()
if __name__ == "__main__":
main()