diff options
-rw-r--r-- | tests/analysis/contents/endian.py | 25 | ||||
-rw-r--r-- | tests/analysis/contents/memory.py | 7 | ||||
-rw-r--r-- | tests/analysis/contents/restricted.py | 21 | ||||
-rw-r--r-- | tests/analysis/disass/block.py | 6 | ||||
-rw-r--r-- | tests/arch/errors.py | 7 | ||||
-rw-r--r-- | tests/arch/immediate.py | 8 | ||||
-rw-r--r-- | tests/arch/processor.py | 5 | ||||
-rw-r--r-- | tests/core/logs.py | 10 | ||||
-rw-r--r-- | tests/format/elf/non_existing_binary.py | 4 | ||||
-rw-r--r-- | tests/format/elf/oob_section_name.py | 17 | ||||
-rw-r--r-- | tests/format/elf/overlapping_areas.py | 30 | ||||
-rw-r--r-- | tests/format/elf/strings.py | 32 | ||||
-rw-r--r-- | tests/format/errors.py | 17 |
13 files changed, 119 insertions, 70 deletions
diff --git a/tests/analysis/contents/endian.py b/tests/analysis/contents/endian.py index 209600a..77ed77a 100644 --- a/tests/analysis/contents/endian.py +++ b/tests/analysis/contents/endian.py @@ -6,6 +6,7 @@ from chrysacase import ChrysalideTestCase +from pychrysalide import arch from pychrysalide.analysis.contents import FileContent, RestrictedContent from pychrysalide.arch import vmpa import tempfile @@ -54,36 +55,36 @@ class TestEndianness(ChrysalideTestCase): start = vmpa(12, vmpa.VMPA_NO_VIRTUAL) - val = fcnt.read_u16(start, vmpa.SRE_LITTLE_WORD) + val = fcnt.read_u16(start, arch.SRE_LITTLE_WORD) self.assertEqual(val, 0x1516) start = vmpa(12, vmpa.VMPA_NO_VIRTUAL) - val = fcnt.read_u16(start, vmpa.SRE_BIG_WORD) + val = fcnt.read_u16(start, arch.SRE_BIG_WORD) self.assertEqual(val, 0x1615) # 32 bits start = vmpa(12, vmpa.VMPA_NO_VIRTUAL) - val = fcnt.read_u32(start, vmpa.SRE_LITTLE_WORD) + val = fcnt.read_u32(start, arch.SRE_LITTLE_WORD) self.assertEqual(val, 0x17181516) start = vmpa(12, vmpa.VMPA_NO_VIRTUAL) - val = fcnt.read_u32(start, vmpa.SRE_BIG_WORD) + val = fcnt.read_u32(start, arch.SRE_BIG_WORD) self.assertEqual(val, 0x16151817) # 64 bits start = vmpa(0, vmpa.VMPA_NO_VIRTUAL) - val = fcnt.read_u64(start, vmpa.SRE_LITTLE_WORD) + val = fcnt.read_u64(start, arch.SRE_LITTLE_WORD) self.assertEqual(val, 0x0708050603040102) start = vmpa(0, vmpa.VMPA_NO_VIRTUAL) - val = fcnt.read_u64(start, vmpa.SRE_BIG_WORD) + val = fcnt.read_u64(start, arch.SRE_BIG_WORD) self.assertEqual(val, 0x0201040306050807) @@ -96,34 +97,34 @@ class TestEndianness(ChrysalideTestCase): start = vmpa(12, vmpa.VMPA_NO_VIRTUAL) - val = fcnt.read_u16(start, vmpa.SRE_LITTLE) + val = fcnt.read_u16(start, arch.SRE_LITTLE) self.assertEqual(val, 0x1615) start = vmpa(12, vmpa.VMPA_NO_VIRTUAL) - val = fcnt.read_u16(start, vmpa.SRE_BIG) + val = fcnt.read_u16(start, arch.SRE_BIG) self.assertEqual(val, 0x1516) # 32 bits start = vmpa(12, vmpa.VMPA_NO_VIRTUAL) - val = fcnt.read_u32(start, vmpa.SRE_LITTLE) + val = fcnt.read_u32(start, arch.SRE_LITTLE) self.assertEqual(val, 0x18171615) start = vmpa(12, vmpa.VMPA_NO_VIRTUAL) - val = fcnt.read_u32(start, vmpa.SRE_BIG) + val = fcnt.read_u32(start, arch.SRE_BIG) self.assertEqual(val, 0x15161718) # 64 bits start = vmpa(0, vmpa.VMPA_NO_VIRTUAL) - val = fcnt.read_u64(start, vmpa.SRE_LITTLE) + val = fcnt.read_u64(start, arch.SRE_LITTLE) self.assertEqual(val, 0x0807060504030201) start = vmpa(0, vmpa.VMPA_NO_VIRTUAL) - val = fcnt.read_u64(start, vmpa.SRE_BIG) + val = fcnt.read_u64(start, arch.SRE_BIG) self.assertEqual(val, 0x0102030405060708) diff --git a/tests/analysis/contents/memory.py b/tests/analysis/contents/memory.py index e8ba6b5..55ce035 100644 --- a/tests/analysis/contents/memory.py +++ b/tests/analysis/contents/memory.py @@ -7,6 +7,7 @@ from chrysacase import ChrysalideTestCase +from pychrysalide import arch from pychrysalide.analysis.contents import MemoryContent from pychrysalide.arch import vmpa, mrange @@ -38,12 +39,12 @@ class TestMemoryContent(ChrysalideTestCase): start = vmpa(14, vmpa.VMPA_NO_VIRTUAL) - val = cnt.read_u16(start, vmpa.SRE_LITTLE) + val = cnt.read_u16(start, arch.SRE_LITTLE) self.assertEqual(val, 0x1817) start = vmpa(10, vmpa.VMPA_NO_VIRTUAL) - val = cnt.read_u32(start, vmpa.SRE_LITTLE) + val = cnt.read_u32(start, arch.SRE_LITTLE) self.assertEqual(val, 0x16150013) @@ -62,4 +63,4 @@ class TestMemoryContent(ChrysalideTestCase): with self.assertRaisesRegex(Exception, 'Invalid read access.'): start = vmpa(0, vmpa.VMPA_NO_VIRTUAL) - val = cnt.read_u16(start, vmpa.SRE_LITTLE) + val = cnt.read_u16(start, arch.SRE_LITTLE) diff --git a/tests/analysis/contents/restricted.py b/tests/analysis/contents/restricted.py index 6484299..08aa968 100644 --- a/tests/analysis/contents/restricted.py +++ b/tests/analysis/contents/restricted.py @@ -7,6 +7,7 @@ from chrysacase import ChrysalideTestCase +from pychrysalide import arch from pychrysalide.analysis.contents import FileContent, RestrictedContent from pychrysalide.arch import vmpa, mrange import tempfile @@ -63,10 +64,10 @@ class TestRestrictedContent(ChrysalideTestCase): val = rcnt.read_u8(start) self.assertEqual(val, 0x16) - val = rcnt.read_u16(start, vmpa.SRE_LITTLE) + val = rcnt.read_u16(start, arch.SRE_LITTLE) self.assertEqual(val, 0x1817) - val = rcnt.read_u32(start, vmpa.SRE_LITTLE) + val = rcnt.read_u32(start, arch.SRE_LITTLE) self.assertEqual(val, 0x24232221) @@ -110,15 +111,15 @@ class TestRestrictedContent(ChrysalideTestCase): self.assertEqual(val, 0x15) start = vmpa(12, vmpa.VMPA_NO_VIRTUAL) - val = rcnt.read_u16(start, vmpa.SRE_LITTLE) + val = rcnt.read_u16(start, arch.SRE_LITTLE) self.assertEqual(val, 0x1615) start = vmpa(12, vmpa.VMPA_NO_VIRTUAL) - val = rcnt.read_u32(start, vmpa.SRE_LITTLE) + val = rcnt.read_u32(start, arch.SRE_LITTLE) self.assertEqual(val, 0x18171615) start = vmpa(12, vmpa.VMPA_NO_VIRTUAL) - val = rcnt.read_u64(start, vmpa.SRE_LITTLE) + val = rcnt.read_u64(start, arch.SRE_LITTLE) self.assertEqual(val, 0x2423222118171615) start = vmpa(23, vmpa.VMPA_NO_VIRTUAL) @@ -126,15 +127,15 @@ class TestRestrictedContent(ChrysalideTestCase): self.assertEqual(val, 0x28) start = vmpa(22, vmpa.VMPA_NO_VIRTUAL) - val = rcnt.read_u16(start, vmpa.SRE_LITTLE) + val = rcnt.read_u16(start, arch.SRE_LITTLE) self.assertEqual(val, 0x2827) start = vmpa(20, vmpa.VMPA_NO_VIRTUAL) - val = rcnt.read_u32(start, vmpa.SRE_LITTLE) + val = rcnt.read_u32(start, arch.SRE_LITTLE) self.assertEqual(val, 0x28272625) start = vmpa(16, vmpa.VMPA_NO_VIRTUAL) - val = rcnt.read_u64(start, vmpa.SRE_LITTLE) + val = rcnt.read_u64(start, arch.SRE_LITTLE) self.assertEqual(val, 0x2827262524232221) @@ -201,9 +202,9 @@ class TestRestrictedContent(ChrysalideTestCase): with self.assertRaisesRegex(Exception, 'Invalid read access.'): start = vmpa(11, vmpa.VMPA_NO_VIRTUAL) - val = rcnt.read_u16(start, vmpa.SRE_LITTLE) + val = rcnt.read_u16(start, arch.SRE_LITTLE) with self.assertRaisesRegex(Exception, 'Invalid read access.'): start = vmpa(23, vmpa.VMPA_NO_VIRTUAL) - val = rcnt.read_u16(start, vmpa.SRE_LITTLE) + val = rcnt.read_u16(start, arch.SRE_LITTLE) diff --git a/tests/analysis/disass/block.py b/tests/analysis/disass/block.py index 8de44e1..1663150 100644 --- a/tests/analysis/disass/block.py +++ b/tests/analysis/disass/block.py @@ -26,7 +26,7 @@ class TestBasicBlocks(ChrysalideTestCase): fullname = sys.modules[cls.__module__].__file__ dirpath = os.path.dirname(fullname) - os.system('make -C %s hello 2>&1 > /dev/null' % dirpath) + os.system('make -C %s hello > /dev/null 2>&1' % dirpath) @classmethod @@ -39,7 +39,7 @@ class TestBasicBlocks(ChrysalideTestCase): fullname = sys.modules[cls.__module__].__file__ dirpath = os.path.dirname(fullname) - os.system('make -C %s clean 2>&1 > /dev/null' % dirpath) + os.system('make -C %s clean > /dev/null 2>&1' % dirpath) def testBlockList(self): @@ -67,7 +67,7 @@ class TestBasicBlocks(ChrysalideTestCase): found = sym.basic_blocks.find_by_starting_addr(sym.range.addr) self.assertIsNotNone(found) - self.assertEqual(found, sym.basic_blocks.items[0]) + self.assertEqual(found, list(sym.basic_blocks)[0]) self.assertEqual(found.index, 0) diff --git a/tests/arch/errors.py b/tests/arch/errors.py index 9d5e273..8affb77 100644 --- a/tests/arch/errors.py +++ b/tests/arch/errors.py @@ -26,7 +26,12 @@ class TestArchErrors(ChrysalideTestCase): pattern.append([ArchProcessor.APE_LABEL, addr, 'random desc #%d' % i]) - proc = ArchProcessor() + + class NewProc(ArchProcessor): + pass + + + proc = NewProc() for i in range(errlen): diff --git a/tests/arch/immediate.py b/tests/arch/immediate.py index b3ddc6d..74b8069 100644 --- a/tests/arch/immediate.py +++ b/tests/arch/immediate.py @@ -13,7 +13,7 @@ class TestImmediate(ChrysalideTestCase): """TestCase for arch.ImmOperand.""" - def validateValue(self, value, size, padding, syntax, strings): + def validateValue(self, value, size, padding, strings): """Check all kinds of things with a given immediate operand.""" display = [ @@ -32,7 +32,7 @@ class TestImmediate(ChrysalideTestCase): op.padding = padding op.display = d - string = op.to_string(syntax) + string = op.to_string() self.assertEqual(string, strings[d]) @@ -46,7 +46,7 @@ class TestImmediate(ChrysalideTestCase): ImmOperand.IOD_HEX: '0x1' } - self.validateValue(1, arch.MDS_8_BITS_UNSIGNED, False, arch.ASX_INTEL, strings) + self.validateValue(1, arch.MDS_8_BITS_UNSIGNED, False, strings) def testByteOnePadded(self): @@ -59,4 +59,4 @@ class TestImmediate(ChrysalideTestCase): ImmOperand.IOD_HEX: '0x01' } - self.validateValue(1, arch.MDS_8_BITS_UNSIGNED, True, arch.ASX_INTEL, strings) + self.validateValue(1, arch.MDS_8_BITS_UNSIGNED, True, strings) diff --git a/tests/arch/processor.py b/tests/arch/processor.py index 5ad6490..97a713d 100644 --- a/tests/arch/processor.py +++ b/tests/arch/processor.py @@ -16,7 +16,6 @@ class TestProcessor(ChrysalideTestCase): """TestCase for arch.ArchProcessor.""" - def testGI(self): """Validate the GObject introspection.""" @@ -27,7 +26,7 @@ class TestProcessor(ChrysalideTestCase): class NewContext(ProcContext): pass - class NewProc(ArchProcessor): + class NewProcWithCtx(ArchProcessor): def _get_context(self): return NewContext() @@ -36,7 +35,7 @@ class TestProcessor(ChrysalideTestCase): return None - np = NewProc() + np = NewProcWithCtx() data = b'\x01\x02\x03\x04' cnt = MemoryContent(data) diff --git a/tests/core/logs.py b/tests/core/logs.py index 96be519..69a4775 100644 --- a/tests/core/logs.py +++ b/tests/core/logs.py @@ -6,16 +6,16 @@ from chrysacase import ChrysalideTestCase -from pychrysalide.core import logs +from pychrysalide import core class TestCoreLogs(ChrysalideTestCase): - """TestCase for analysis.core.logs.""" + """TestCase for analysis.core.core.""" def testDefaultLevel(self): """Ensure all messages are hidden by default.""" - self.assertEqual(logs.get_verbosity(), logs.LMT_COUNT) + self.assertEqual(core.get_verbosity(), core.LMT_COUNT) def testWrongLevel(self): @@ -23,7 +23,7 @@ class TestCoreLogs(ChrysalideTestCase): with self.assertRaisesRegex(Exception, 'argument 1 must be int, not str'): - logs.set_verbosity('XXX') + core.set_verbosity('XXX') def testWrongMessage(self): @@ -31,4 +31,4 @@ class TestCoreLogs(ChrysalideTestCase): with self.assertRaisesRegex(Exception, 'Invalid type of message'): - logs.log_message(logs.LMT_COUNT, 'Message') + core.log_message(core.LMT_COUNT, 'Message') diff --git a/tests/format/elf/non_existing_binary.py b/tests/format/elf/non_existing_binary.py index a6eddd3..c984344 100644 --- a/tests/format/elf/non_existing_binary.py +++ b/tests/format/elf/non_existing_binary.py @@ -19,6 +19,6 @@ class TestNonExistingBinary(ChrysalideTestCase): cnt = FileContent('non_existing_binary') self.assertIsNone(cnt) - with self.assertRaisesRegex(TypeError, 'The argument must be an instance of BinContent.'): + with self.assertRaisesRegex(TypeError, 'argument 1 must be pychrysalide.analysis.BinContent, not None'): - fmt = ElfFormat(cnt, None, None) + fmt = ElfFormat(cnt) diff --git a/tests/format/elf/oob_section_name.py b/tests/format/elf/oob_section_name.py index a478ec7..64d7dc3 100644 --- a/tests/format/elf/oob_section_name.py +++ b/tests/format/elf/oob_section_name.py @@ -30,7 +30,20 @@ class TestNonExistingBinary(ChrysalideTestCase): fullname = sys.modules[cls.__module__].__file__ dirpath = os.path.dirname(fullname) - os.system('make -C %s oob_section_name 2>&1 > /dev/null' % dirpath) + os.system('make -C %s oob_section_name > /dev/null 2>&1' % dirpath) + + + @classmethod + def tearDownClass(cls): + + super(TestNonExistingBinary, cls).tearDownClass() + + cls.log('Delete built binaries...') + + fullname = sys.modules[cls.__module__].__file__ + dirpath = os.path.dirname(fullname) + + os.system('make -C %s clean > /dev/null 2>&1' % dirpath) def testOOBSectionName(self): @@ -44,5 +57,5 @@ class TestNonExistingBinary(ChrysalideTestCase): cnt = FileContent(fullname[:baselen] + 'oob_section_name') self.assertIsNotNone(cnt) - fmt = ElfFormat(cnt, None, None) + fmt = ElfFormat(cnt) self.assertIsInstance(fmt, ElfFormat) diff --git a/tests/format/elf/overlapping_areas.py b/tests/format/elf/overlapping_areas.py index 4c78625..5e3ba07 100644 --- a/tests/format/elf/overlapping_areas.py +++ b/tests/format/elf/overlapping_areas.py @@ -16,6 +16,7 @@ from chrysacase import ChrysalideTestCase from pychrysalide.analysis import LoadedBinary from pychrysalide.analysis.contents import FileContent +from pychrysalide.format.elf import ElfFormat from threading import Event import os import sys @@ -34,7 +35,20 @@ class TestOverlappingAreas(ChrysalideTestCase): fullname = sys.modules[cls.__module__].__file__ dirpath = os.path.dirname(fullname) - os.system('make -C %s overlapping_areas 2>&1 > /dev/null' % dirpath) + os.system('make -C %s overlapping_areas > /dev/null 2>&1' % dirpath) + + + @classmethod + def tearDownClass(cls): + + super(TestOverlappingAreas, cls).tearDownClass() + + cls.log('Delete built binaries...') + + fullname = sys.modules[cls.__module__].__file__ + dirpath = os.path.dirname(fullname) + + os.system('make -C %s clean > /dev/null 2>&1' % dirpath) def testOOBSectionName(self): @@ -48,15 +62,9 @@ class TestOverlappingAreas(ChrysalideTestCase): cnt = FileContent(fullname[:baselen] + 'overlapping_areas') self.assertIsNotNone(cnt) - binary = LoadedBinary(cnt) - - def disass_done(binary): - worker.set() - - binary.connect('disassembly-done', disass_done) - - worker = Event() + fmt = ElfFormat(cnt) + self.assertIsInstance(fmt, ElfFormat) - binary.analyse() + binary = LoadedBinary(fmt) - worker.wait() + binary.analyze_and_wait() diff --git a/tests/format/elf/strings.py b/tests/format/elf/strings.py index 0e09d75..71d365e 100644 --- a/tests/format/elf/strings.py +++ b/tests/format/elf/strings.py @@ -9,6 +9,7 @@ from chrysacase import ChrysalideTestCase from pychrysalide.analysis.contents import FileContent from pychrysalide.analysis import LoadedBinary from pychrysalide.arch import RawInstruction +from pychrysalide.format.elf import ElfFormat from threading import Event import os import sys @@ -27,7 +28,20 @@ class TestElfString(ChrysalideTestCase): fullname = sys.modules[cls.__module__].__file__ dirpath = os.path.dirname(fullname) - os.system('make -C %s strings 2>&1 > /dev/null' % dirpath) + os.system('make -C %s strings > /dev/null 2>&1' % dirpath) + + + @classmethod + def tearDownClass(cls): + + super(TestElfString, cls).tearDownClass() + + cls.log('Delete built binaries...') + + fullname = sys.modules[cls.__module__].__file__ + dirpath = os.path.dirname(fullname) + + os.system('make -C %s clean > /dev/null 2>&1' % dirpath) def testElfStrings(self): @@ -41,19 +55,13 @@ class TestElfString(ChrysalideTestCase): cnt = FileContent(fullname[:baselen] + 'strings') self.assertIsNotNone(cnt) - binary = LoadedBinary(cnt) - self.assertIsNotNone(binary) - - def disass_done(binary): - worker.set() + fmt = ElfFormat(cnt) + self.assertIsInstance(fmt, ElfFormat) - binary.connect('disassembly-done', disass_done) - - worker = Event() - - binary.analyse() + binary = LoadedBinary(fmt) + self.assertIsNotNone(binary) - worker.wait() + binary.analyze_and_wait() expected = { 'hello_arm_str' : False, diff --git a/tests/format/errors.py b/tests/format/errors.py index 36b7129..4ee38f1 100644 --- a/tests/format/errors.py +++ b/tests/format/errors.py @@ -27,7 +27,20 @@ class TestFormatErrors(ChrysalideTestCase): fullname = sys.modules[cls.__module__].__file__ dirpath = os.path.dirname(fullname) - os.system('make -C %s%self strings 2>&1 > /dev/null' % (dirpath, os.sep)) + os.system('make -C %s%self strings > /dev/null 2>&1' % (dirpath, os.sep)) + + + @classmethod + def tearDownClass(cls): + + super(TestFormatErrors, cls).tearDownClass() + + cls.log('Delete built binaries...') + + fullname = sys.modules[cls.__module__].__file__ + dirpath = os.path.dirname(fullname) + + os.system('make -C %s%self clean > /dev/null 2>&1' % (dirpath, os.sep)) def testBasic(self): @@ -49,7 +62,7 @@ class TestFormatErrors(ChrysalideTestCase): baselen = len(fullname) - len(filename) cnt = FileContent(fullname[:baselen] + 'elf' + os.sep + 'strings') - fmt = ElfFormat(cnt, None, None) + fmt = ElfFormat(cnt) for i in range(errlen): |