mirror of
https://github.com/androguard/androguard.git
synced 2024-11-26 22:40:33 +00:00
update
This commit is contained in:
parent
cf8a99337e
commit
33923d032e
@ -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
19
tests/test_analysis.py
Normal 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
19
tests/test_apk.py
Normal 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()
|
@ -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()
|
||||
|
@ -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()
|
||||
|
@ -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
19
tests/test_session.py
Normal 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()
|
Loading…
Reference in New Issue
Block a user