From 6b1c69cb28251e540b2b46185d96a264d953945e Mon Sep 17 00:00:00 2001 From: feliam Date: Fri, 24 Mar 2017 19:10:33 -0300 Subject: [PATCH] Dev fix decree (#98) * Re enable skipped test * Re enable skipped test * Hack so we can use upstream Elftool * pr comments * pr comments - staticmethod * pr comments - implicit > explicit --- manticore/binary/__init__.py | 14 +++++++++++++- tests/test_binaries.py | 4 ++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/manticore/binary/__init__.py b/manticore/binary/__init__.py index 11b6156..84eaab5 100644 --- a/manticore/binary/__init__.py +++ b/manticore/binary/__init__.py @@ -40,10 +40,22 @@ class Binary(object): from elftools.elf.elffile import ELFFile +import StringIO class CGCElf(Binary): + + @staticmethod + def _cgc2elf(filename): + #hack begin so we can use upstream Elftool + with open(filename, 'rb') as fd: + stream = StringIO.StringIO(fd.read()) + stream.write('\x7fELF') + stream.name = fd.name + return stream + def __init__(self, filename): super(CGCElf, self).__init__(filename) - self.elf = ELFFile(file(filename)) + stream = self._cgc2elf(filename) + self.elf = ELFFile(stream) self.arch = {'x86':'i386','x64':'amd64'}[self.elf.get_machine_arch()] assert 'i386' == self.arch diff --git a/tests/test_binaries.py b/tests/test_binaries.py index ed45d3f..6586b3b 100644 --- a/tests/test_binaries.py +++ b/tests/test_binaries.py @@ -80,7 +80,6 @@ class IntegrationTest(unittest.TestCase): self.assertEqual(hashlib.md5(data).hexdigest() , 'c52d7d471ba5c94fcf59936086821a6b') - @unittest.skip('TODO(mark); skipping so we can move on with our lives and merge x86_new. ask felipe to fix later.') def testDecree(self): dirname = os.path.dirname(__file__) filename = os.path.abspath(os.path.join(dirname, 'binaries/cadet_decree_x86')) @@ -91,13 +90,14 @@ class IntegrationTest(unittest.TestCase): self.assertEqual(len(data), 1828) self.assertEqual(hashlib.md5(data).hexdigest() , '8955a29d51c1edd39b0e53794ebcf464') workspace = '%s/workspace'%self.test_dir - self._runWithTimeout(['python', SE, + self._runWithTimeout(['python', '-m', 'manticore', '--log', '%s/output.log'%self.test_dir, '--workspace', workspace, '--timeout', '20', '--proc', '4', '--policy', 'uncovered', filename]) + data = file('%s/visited.txt'%workspace,'r').read() visited = len(set(data.split('\n'))) self.assertTrue(visited > 100 )