This commit is contained in:
adesnos 2015-09-11 12:02:37 +02:00
parent cf8a99337e
commit 33923d032e
7 changed files with 107 additions and 182 deletions

View File

@ -9,7 +9,15 @@ install:
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
# DAD tests
- python androguard/decompiler/dad/tests/dataflow_test.py
- python androguard/decompiler/dad/tests/dominator_test.py

19
tests/test_analysis.py Normal file
View File

@ -0,0 +1,19 @@
import unittest
import sys
PATH_INSTALL = "./"
sys.path.append(PATH_INSTALL)
from androguard.core.bytecodes import dvm
from androguard.core.analysis import analysis
class AnalysisTest(unittest.TestCase):
def testDex(self):
with open("examples/android/TestsAndroguard/bin/classes.dex", "r") as fd:
d = dvm.DalvikVMFormat(fd.read())
dx = analysis.newVMAnalysis(d)
self.assertTrue(dx)
if __name__ == '__main__':
unittest.main()

19
tests/test_apk.py Normal file
View File

@ -0,0 +1,19 @@
import unittest
import sys
PATH_INSTALL = "./"
sys.path.append(PATH_INSTALL)
from androguard.core.bytecodes import dvm
from androguard.core.analysis import analysis
class AXMLTest(unittest.TestCase):
def testDex(self):
with open("examples/android/TestsAndroguard/bin/classes.dex", "r") as fd:
d = dvm.DalvikVMFormat(fd.read())
dx = analysis.newVMAnalysis(d)
self.assertTrue(dx)
if __name__ == '__main__':
unittest.main()

View File

@ -1,98 +1,19 @@
#!/usr/bin/env python
import logging
import datetime
import unittest
import sys
PATH_INSTALL = "./"
sys.path.append(PATH_INSTALL)
from optparse import OptionParser
from androguard.core.analysis import auto
from androguard.core.androconf import set_debug
from androguard.core.bytecodes import dvm
from androguard.core.analysis import analysis
option_0 = {'name': ('-d', '--directory'), 'help': 'directory input', 'nargs': 1}
option_1 = {'name': ('-v', '--verbose'), 'help': 'add debug', 'action': 'count'}
options = [option_0, option_1]
logger = logging.getLogger("main")
console_handler = logging.StreamHandler()
console_handler.setFormatter(logging.Formatter("%(message)s"))
logger.addHandler(console_handler)
logger.setLevel(logging.INFO)
def test(got, expected):
if got == expected:
prefix = ' OK '
else:
prefix = ' X '
print '%s got: %s expected: %s' % (prefix, repr(got), repr(expected)),
return (got == expected)
class AXMLTest(unittest.TestCase):
def testDex(self):
with open("examples/android/TestsAndroguard/bin/classes.dex", "r") as fd:
d = dvm.DalvikVMFormat(fd.read())
dx = analysis.newVMAnalysis(d)
self.assertTrue(dx)
class AndroLog(object):
def __init__(self, id_file, filename):
self.id_file = id_file
self.filename = filename
def dump(self, msg):
now = datetime.datetime.now()
str_date = now.strftime("%Y-%m-%d %H:%M:%S ")
logger.info(str_date + "%s[%d]: %s" % (self.filename, self.id_file, msg))
def error(self, msg):
now = datetime.datetime.now()
str_date = now.strftime("%Y-%m-%d %H:%M:%S ")
logger.info(str_date + "ERROR %s[%d]: %s" % (self.filename, self.id_file, msg))
import traceback
traceback.print_exc()
class MyARSCAnalysis(auto.DirectoryAndroAnalysis):
def __init__(self, directory):
super(MyARSCAnalysis, self).__init__(directory)
def filter_file(self, log, fileraw):
ret, file_type = super(MyARSCAnalysis, self).filter_file(log, fileraw)
if file_type != "APK" and file_type != "ARSC":
return (False, None)
return (ret, file_type)
def analysis_arsc(self, log, arsc):
log.dump("%s" % str(arsc))
return False
def analysis_apk(self, log, apk):
if apk.is_valid_APK():
log.dump("%s" % str(apk.get_android_resources()))
return False
def crash(self, log, why):
log.error(why)
def main(options, arguments):
if options.verbose:
set_debug()
if options.directory:
settings = {
"my": MyARSCAnalysis(options.directory),
"log": AndroLog,
"max_fetcher": 3,
}
aa = auto.AndroAuto(settings)
aa.go()
if __name__ == "__main__":
parser = OptionParser()
for option in options:
param = option['name']
del option['name']
parser.add_option(*param, **option)
options, arguments = parser.parse_args()
sys.argv[:] = arguments
main(options, arguments)
if __name__ == '__main__':
unittest.main()

View File

@ -1,97 +1,19 @@
#!/usr/bin/env python
import logging
import datetime
import unittest
import sys
PATH_INSTALL = "./"
sys.path.append(PATH_INSTALL)
from optparse import OptionParser
from androguard.core.analysis import auto
from androguard.core.androconf import set_debug
from androguard.core.bytecodes import dvm
from androguard.core.analysis import analysis
option_0 = {'name': ('-d', '--directory'), 'help': 'directory input', 'nargs': 1}
option_1 = {'name': ('-v', '--verbose'), 'help': 'add debug', 'action': 'count'}
options = [option_0, option_1]
logger = logging.getLogger("main")
console_handler = logging.StreamHandler()
console_handler.setFormatter(logging.Formatter("%(message)s"))
logger.addHandler(console_handler)
logger.setLevel(logging.INFO)
def test(got, expected):
if got == expected:
prefix = ' OK '
else:
prefix = ' X '
print '%s got: %s expected: %s' % (prefix, repr(got), repr(expected)),
return (got == expected)
class AXMLTest(unittest.TestCase):
def testDex(self):
with open("examples/android/TestsAndroguard/bin/classes.dex", "r") as fd:
d = dvm.DalvikVMFormat(fd.read())
dx = analysis.newVMAnalysis(d)
self.assertTrue(dx)
class AndroLog(object):
def __init__(self, id_file, filename):
self.id_file = id_file
self.filename = filename
def dump(self, msg):
now = datetime.datetime.now()
str_date = now.strftime("%Y-%m-%d %H:%M:%S ")
logger.info(str_date + "%s[%d]: %s" % (self.filename, self.id_file, msg))
def error(self, msg):
now = datetime.datetime.now()
str_date = now.strftime("%Y-%m-%d %H:%M:%S ")
logger.info(str_date + "ERROR %s[%d]: %s" % (self.filename, self.id_file, msg))
import traceback
traceback.print_exc()
class MyAXMLAnalysis(auto.DirectoryAndroAnalysis):
def __init__(self, directory):
super(MyAXMLAnalysis, self).__init__(directory)
def filter_file(self, log, fileraw):
ret, file_type = super(MyAXMLAnalysis, self).filter_file(log, fileraw)
if file_type != "APK" and file_type != "AXML":
return (False, None)
return (ret, file_type)
def analysis_axml(self, log, axml):
log.dump("%s" % str(axml.get_xml_obj()))
return False
def analysis_apk(self, log, apk):
log.dump("%s" % str(apk.get_android_manifest_xml()))
return False
def crash(self, log, why):
log.error(why)
def main(options, arguments):
if options.verbose:
set_debug()
if options.directory:
settings = {
"my": MyAXMLAnalysis(options.directory),
"log": AndroLog,
"max_fetcher": 3,
}
aa = auto.AndroAuto(settings)
aa.go()
if __name__ == "__main__":
parser = OptionParser()
for option in options:
param = option['name']
del option['name']
parser.add_option(*param, **option)
options, arguments = parser.parse_args()
sys.argv[:] = arguments
main(options, arguments)
if __name__ == '__main__':
unittest.main()

View File

@ -4,15 +4,32 @@ import sys
PATH_INSTALL = "./"
sys.path.append(PATH_INSTALL)
from androguard.core.analysis import auto
from androguard.core.androconf import set_debug
from androguard.core.bytecodes import dvm
class DexTest(unittest.TestCase):
def testDex(self):
pass
with open("examples/android/TestsAndroguard/bin/classes.dex", "r") as fd:
d = dvm.DalvikVMFormat(fd.read())
self.assertTrue(d)
classes = d.get_classes()
self.assertTrue(classes)
self.assertEqual(len(classes), 340)
methods = d.get_methods()
self.assertTrue(methods)
self.assertEqual(len(methods), 2600)
fields = d.get_fields()
self.assertTrue(fields)
self.assertEqual(len(fields), 803)
def testMultiDex(self):
pass
class InstructionTest(unittest.TestCase):
def testNOP(self):
pass
if __name__ == '__main__':
unittest.main()

19
tests/test_session.py Normal file
View File

@ -0,0 +1,19 @@
import unittest
import sys
PATH_INSTALL = "./"
sys.path.append(PATH_INSTALL)
from androguard.core.bytecodes import dvm
from androguard.core.analysis import analysis
class AnalysisTest(unittest.TestCase):
def testDex(self):
with open("examples/android/TestsAndroguard/bin/classes.dex", "r") as fd:
d = dvm.DalvikVMFormat(fd.read())
dx = analysis.newVMAnalysis(d)
self.assertTrue(dx)
if __name__ == '__main__':
unittest.main()