forked from androguard/androguard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_axml.py
executable file
·135 lines (103 loc) · 4.01 KB
/
test_axml.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import unittest
import sys
from xml.dom import minidom
PATH_INSTALL = "./"
sys.path.append(PATH_INSTALL)
from androguard.core.bytecodes import axml
class AXMLTest(unittest.TestCase):
def testAXML(self):
filenames = [
"examples/axml/AndroidManifest-Chinese.xml",
"examples/axml/AndroidManifest-xmlns.xml",
"examples/axml/AndroidManifest.xml", "examples/axml/test.xml",
"examples/axml/test1.xml", "examples/axml/test2.xml",
"examples/axml/test3.xml"
]
for filename in filenames:
with open(filename, "rb") as fd:
ap = axml.AXMLPrinter(fd.read())
self.assertIsNotNone(ap)
e = minidom.parseString(ap.get_buff())
self.assertIsNotNone(e)
def testNonZeroStyleOffset(self):
"""
Test if a nonzero style offset in the string section causes problems
if the counter is 0
"""
filename = "examples/axml/AndroidManifestNonZeroStyle.xml"
with open(filename, "rb") as f:
ap = axml.AXMLPrinter(f.read())
self.assertIsInstance(ap, axml.AXMLPrinter)
e = minidom.parseString(ap.get_buff())
self.assertIsNotNone(e)
def testExtraNamespace(self):
"""
Test if extra namespaces cause problems
"""
filename = "examples/axml/AndroidManifestExtraNamespace.xml"
with open(filename, "rb") as f:
ap = axml.AXMLPrinter(f.read())
self.assertIsInstance(ap, axml.AXMLPrinter)
e = minidom.parseString(ap.get_buff())
self.assertIsNotNone(e)
def testTextChunksWithXML(self):
"""
Test for Text chunks containing XML
"""
filename = "examples/axml/AndroidManifestTextChunksXML.xml"
with open(filename, "rb") as f:
ap = axml.AXMLPrinter(f.read())
self.assertIsInstance(ap, axml.AXMLPrinter)
e = minidom.parseString(ap.get_buff())
self.assertIsNotNone(e)
def testWrongFilesize(self):
"""
Assert that files with a broken filesize are not parsed
"""
filename = "examples/axml/AndroidManifestWrongFilesize.xml"
with self.assertRaises(AssertionError) as cnx:
with open(filename, "rb") as f:
axml.AXMLPrinter(f.read())
self.assertTrue("Declared filesize does not match" in str(cnx.exception))
def testNullbytes(self):
"""
Assert that Strings with nullbytes are handled correctly
"""
filename = "examples/axml/AndroidManifestNullbytes.xml"
with open(filename, "rb") as f:
ap = axml.AXMLPrinter(f.read())
self.assertIsInstance(ap, axml.AXMLPrinter)
e = minidom.parseString(ap.get_buff())
self.assertIsNotNone(e)
def testMaskingNamespace(self):
"""
Assert that Namespaces which are used in a tag and the tag is closed
are actually correctly parsed.
"""
filename = "examples/axml/AndroidManifestMaskingNamespace.xml"
with open(filename, "rb") as f:
ap = axml.AXMLPrinter(f.read())
self.assertIsInstance(ap, axml.AXMLPrinter)
e = minidom.parseString(ap.get_buff())
self.assertIsNotNone(e)
def testDoubleNamespace(self):
"""
Test if weird namespace constelations cause problems
"""
filename = "examples/axml/AndroidManifestDoubleNamespace.xml"
with open(filename, "rb") as f:
ap = axml.AXMLPrinter(f.read())
self.assertIsInstance(ap, axml.AXMLPrinter)
e = minidom.parseString(ap.get_buff())
self.assertIsNotNone(e)
def testPackers(self):
"""
Assert that Packed files are read
"""
filename = "examples/axml/AndroidManifestLiapp.xml"
with open(filename, "rb") as f:
ap = axml.AXMLPrinter(f.read())
self.assertIsInstance(ap, axml.AXMLPrinter)
self.assertTrue(ap.is_packed())
if __name__ == '__main__':
unittest.main()