1 #------------------------------------------------------------------------------
4 # Yann Rouillard (yann@pleiades.fr.eu.org)
5 # This code is in the public domain
6 #------------------------------------------------------------------------------
10 from elftools
.elf
.elffile
import ELFFile
11 from elftools
.elf
.dynamic
import DynamicSection
, DynamicTag
14 class TestDoubleDynstrSections(unittest
.TestCase
):
15 """ This test make sure than dynamic tags
16 are properly analyzed when two .dynstr
17 sections are present in an elf file
26 def _test_double_dynstr_section_generic(self
, testfile
):
28 with
open(os
.path
.join('test', 'testfiles_for_unittests', testfile
),
31 for section
in elf
.iter_sections():
32 if isinstance(section
, DynamicSection
):
33 d_tags
= [getattr(x
, x
.entry
.d_tag
[3:].lower())
34 for x
in section
.iter_tags()
35 if x
.entry
.d_tag
in DynamicTag
._HANDLED
_TAGS
]
37 TestDoubleDynstrSections
.reference_data
,
40 self
.fail('No dynamic section found !!')
43 def test_double_dynstr_section(self
):
44 """ First test with the good dynstr section first
46 self
._test
_double
_dynstr
_section
_generic
(
47 'lib_with_two_dynstr_sections.so.1.elf')
49 def test_double_dynstr_section_reverse(self
):
50 """ Second test with the good dynstr section last
52 self
._test
_double
_dynstr
_section
_generic
(
53 'lib_with_two_dynstr_sections_reversed.so.1.elf')
56 if __name__
== '__main__':