mirror of
https://github.com/androguard/androguard.git
synced 2024-11-23 13:09:55 +00:00
use nosetests
This commit is contained in:
parent
1f7f107d39
commit
2583e9c29a
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -2,9 +2,6 @@ import unittest
|
||||
|
||||
import sys
|
||||
|
||||
PATH_INSTALL = "./"
|
||||
sys.path.append(PATH_INSTALL)
|
||||
|
||||
from androguard.core.bytecodes import apk
|
||||
|
||||
|
||||
|
@ -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"
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
@ -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()
|
||||
|
46
tests/test_decompilerjadx.py
Normal file
46
tests/test_decompilerjadx.py
Normal 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()
|
||||
|
@ -2,9 +2,6 @@ import unittest
|
||||
|
||||
import sys
|
||||
|
||||
PATH_INSTALL = "./"
|
||||
sys.path.append(PATH_INSTALL)
|
||||
|
||||
from androguard.core.bytecodes import dvm
|
||||
|
||||
|
||||
|
@ -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):
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user