1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
#------------------------------------------------------------------------------
# elftools tests
#
# Yann Rouillard (yann@pleiades.fr.eu.org)
# This code is in the public domain
#------------------------------------------------------------------------------
import unittest
import os
from elftools.elf.elffile import ELFFile
from elftools.elf.dynamic import DynamicSection, DynamicTag
class TestDoubleDynstrSections(unittest.TestCase):
""" This test make sure than dynamic tags
are properly analyzed when two .dynstr
sections are present in an elf file
"""
reference_data = [
'libz.so.1',
'libc.so.6',
'lib_versioned.so.1',
]
def _test_double_dynstr_section_generic(self, testfile):
with open(os.path.join('test', 'testfiles_for_unittests', testfile),
'rb') as f:
elf = ELFFile(f)
for section in elf.iter_sections():
if isinstance(section, DynamicSection):
d_tags = [getattr(x, x.entry.d_tag[3:].lower())
for x in section.iter_tags()
if x.entry.d_tag in DynamicTag._HANDLED_TAGS]
self.assertListEqual(
TestDoubleDynstrSections.reference_data,
d_tags)
return
self.fail('No dynamic section found !!')
def test_double_dynstr_section(self):
""" First test with the good dynstr section first
"""
self._test_double_dynstr_section_generic(
'lib_with_two_dynstr_sections.so.1.elf')
def test_double_dynstr_section_reverse(self):
""" Second test with the good dynstr section last
"""
self._test_double_dynstr_section_generic(
'lib_with_two_dynstr_sections_reversed.so.1.elf')
if __name__ == '__main__':
unittest.main()
|