mirror of
https://github.com/androguard/androguard.git
synced 2024-11-27 06:50:41 +00:00
Merge branch 'nosetests' into coverage
This commit is contained in:
commit
b5ec99b68c
32
.travis.yml
32
.travis.yml
@ -1,4 +1,16 @@
|
||||
language: python
|
||||
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- openjdk-8-jre-headless
|
||||
|
||||
# Download jadx decompiler
|
||||
before-script:
|
||||
- wget https://github.com/skylot/jadx/releases/download/v0.6.1/jadx-0.6.1.zip -O /tmp/jadx-0.6.1.zip
|
||||
- unzip /tmp/jadx-0.6.1.zip
|
||||
- export PATH=$PATH:$PWD/bin
|
||||
|
||||
python:
|
||||
- "2.7"
|
||||
- "3.3"
|
||||
@ -8,29 +20,13 @@ python:
|
||||
- "3.7-dev"
|
||||
# command to install dependencies
|
||||
install:
|
||||
- pip install nose codecov coverage
|
||||
- "pip install ."
|
||||
- "pip install -r requirements.txt"
|
||||
- pip install codecov
|
||||
# command to run tests
|
||||
script:
|
||||
# DEX tests
|
||||
- python tests/test_dex.py
|
||||
# Analysis tests
|
||||
- python tests/test_analysis.py
|
||||
# APK tests
|
||||
- python tests/test_apk.py
|
||||
- python tests/test_axml.py
|
||||
- python tests/test_arsc.py
|
||||
# Session tests
|
||||
- python tests/test_session.py
|
||||
- python tests/test_rename.py
|
||||
# Decompiler Tests
|
||||
- python tests/test_decompiler.py
|
||||
|
||||
# DAD tests
|
||||
- python androguard/decompiler/dad/tests/dataflow_test.py
|
||||
- python androguard/decompiler/dad/tests/dominator_test.py
|
||||
- python androguard/decompiler/dad/tests/rpo_test.py
|
||||
- nosetest -v --with-coverage
|
||||
|
||||
notifications:
|
||||
email:
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
3
tests/test_arsc.py
Executable file → Normal file
3
tests/test_arsc.py
Executable file → Normal 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"
|
||||
|
3
tests/test_axml.py
Executable file → Normal file
3
tests/test_axml.py
Executable file → Normal 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
|
||||
|
||||
|
||||
|
@ -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()
|
||||
|
3
tests/test_dex.py
Executable file → Normal file
3
tests/test_dex.py
Executable file → Normal file
@ -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
|
||||
|
||||
|
||||
|
5
tests/test_types.py
Executable file → Normal file
5
tests/test_types.py
Executable file → Normal 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:
|
||||
|
Loading…
Reference in New Issue
Block a user