use nosetests

This commit is contained in:
Sebastian Bachmann 2017-11-24 22:45:05 +01:00
parent 1f7f107d39
commit 2583e9c29a
11 changed files with 66 additions and 52 deletions

View File

@ -3490,6 +3490,9 @@ class ClassDefItem(object):
def __str__(self):
return "%s->%s" % (self.get_superclassname(), self.get_name())
def __repr__(self):
return "<dvm.ClassDefItem {}>".format(self.__str__())
def get_methods(self):
"""
Return all methods of this class

View File

@ -2,9 +2,6 @@ import unittest
import sys
PATH_INSTALL = "./"
sys.path.append(PATH_INSTALL)
from androguard.core.bytecodes import dvm
from androguard.core.analysis import analysis

View File

@ -2,9 +2,6 @@ import unittest
import sys
PATH_INSTALL = "./"
sys.path.append(PATH_INSTALL)
from androguard.core.bytecodes import apk

View File

@ -1,9 +1,6 @@
import sys
import unittest
PATH_INSTALL = "./"
sys.path.append(PATH_INSTALL)
from androguard.core.bytecodes import apk, axml
TEST_APP_NAME = "TestsAndroguardApplication"

View File

@ -3,9 +3,6 @@ import unittest
import sys
from xml.dom import minidom
PATH_INSTALL = "./"
sys.path.append(PATH_INSTALL)
from androguard.core.bytecodes import axml

View File

@ -6,9 +6,6 @@ import re
from androguard.misc import AnalyzeAPK
from androguard.decompiler.dad.decompile import DvMethod, DvClass
PATH_INSTALL = "./"
sys.path.append(PATH_INSTALL)
class DecompilerTest(unittest.TestCase):
def testSimplification(self):
@ -33,46 +30,35 @@ class DecompilerTest(unittest.TestCase):
self.assertNotIn("{5, 0, 10, 0};", z.get_source())
def gen(c, dx, doAST=False):
"""
Generate test cases to process methods
"""
def test(self):
for m in c.get_methods():
mx = dx.get_method(m)
ms = DvMethod(mx)
ms.process(doAST=doAST)
self.assertIsNotNone(ms.get_source())
return test
def gen_cl(c, dx):
def test(self):
dc = DvClass(c, dx)
dc.process()
def dvmethod(c, dx, doAST=False):
for m in c.get_methods():
mx = dx.get_method(m)
ms = DvMethod(mx)
ms.process(doAST=doAST)
assert ms.get_source() is not None
self.assertIsNotNone(dc.get_source())
return test
def dvclass(c, dx):
dc = DvClass(c, dx)
dc.process()
assert dc.get_source() is not None
if __name__ == '__main__':
def test_all_decompiler():
# Generate test cases for this APK:
a, d, dx = AnalyzeAPK("examples/tests/hello-world.apk")
for c in d.get_classes():
test_name = re.sub("[^a-zA-Z0-9_]", "_", c.get_name()[1:-1])
# Test the decompilation of a single class
testcase = gen_cl(c, dx)
setattr(DecompilerTest, "test_class_{}".format(test_name), testcase)
yield dvclass, c, dx
# Test the decompilation of all single methods in the class
# if methods are in the class
if len(c.get_methods()) == 0:
continue
testcase = gen(c, dx)
setattr(DecompilerTest, "test_process_{}".format(test_name), testcase)
testcase_ast = gen(c, dx, doAST=True)
setattr(DecompilerTest, "tes_astprocess_{}".format(test_name), testcase_ast)
yield dvmethod, c, dx, False
yield dvmethod, c, dx, True
if __name__ == '__main__':
unittest.main()

View File

@ -0,0 +1,46 @@
import unittest
import sys
import re
import os
from androguard.misc import AnalyzeAPK
from androguard.decompiler.decompiler import DecompilerJADX
def which(program):
"""
Thankfully copied from https://stackoverflow.com/a/377028/446140
"""
def is_exe(fpath):
return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
fpath, fname = os.path.split(program)
if fpath:
if is_exe(program):
return program
else:
for path in os.environ["PATH"].split(os.pathsep):
exe_file = os.path.join(path, program)
if is_exe(exe_file):
return exe_file
return None
class DecompilerTest(unittest.TestCase):
@unittest.skipIf(which("jadx") is None, "Skipping JADX test as jadx "
"executable is not in path")
def testJadx(self):
a, d, dx = AnalyzeAPK("examples/tests/hello-world.apk")
decomp = DecompilerJADX(d, dx)
self.assertIsNotNone(decomp)
d.set_decompiler(decomp)
for c in d.get_classes():
self.assertIsNotNone(c.get_source())
if __name__ == '__main__':
unittest.main()

View File

@ -2,9 +2,6 @@ import unittest
import sys
PATH_INSTALL = "./"
sys.path.append(PATH_INSTALL)
from androguard.core.bytecodes import dvm

View File

@ -2,8 +2,6 @@ import unittest
from androguard.core.bytecodes import dvm
from androguard.core.analysis import analysis
import sys
PATH_INSTALL = "./"
sys.path.append(PATH_INSTALL)
class RenameTest(unittest.TestCase):

View File

@ -3,9 +3,6 @@ import unittest
import sys
from androguard.core.bytecodes.apk import APK
PATH_INSTALL = "./"
sys.path.append(PATH_INSTALL)
from androguard import session

View File

@ -22,9 +22,6 @@ from __future__ import print_function
import sys
import unittest
PATH_INSTALL = "./"
sys.path.append(PATH_INSTALL)
from androguard.session import Session
TEST_CASE = 'examples/android/TestsAndroguard/bin/classes.dex'
@ -70,6 +67,8 @@ VALUES = {
}
class TypesTest(unittest.TestCase):
@unittest.skip("Not working test!")
def testTypes(self):
s = Session()
with open(TEST_CASE, "rb") as fd: