1# -------------------------------------------------------------------------------
2# elftools: ehabi/structs.py
3#
4# Encapsulation of Construct structs for parsing an EHABI, adjusted for
5# correct endianness and word-size.
6#
7# LeadroyaL (leadroyal@qq.com)
8# This code is in the public domain
9# -------------------------------------------------------------------------------
10
11from ..construct import UBInt32, ULInt32, Struct
12
13
14class EHABIStructs(object):
15    """ Accessible attributes:
16
17            EH_index_struct:
18                Struct of item in section .ARM.exidx.
19
20            EH_table_struct:
21                Struct of item in section .ARM.extab.
22    """
23
24    def __init__(self, little_endian):
25        self._little_endian = little_endian
26        self._create_structs()
27
28    def _create_structs(self):
29        if self._little_endian:
30            self.EHABI_uint32 = ULInt32
31        else:
32            self.EHABI_uint32 = UBInt32
33        self._create_exception_handler_index()
34        self._create_exception_handler_table()
35
36    def _create_exception_handler_index(self):
37        self.EH_index_struct = Struct(
38            'EH_index',
39            self.EHABI_uint32('word0'),
40            self.EHABI_uint32('word1')
41        )
42
43    def _create_exception_handler_table(self):
44        self.EH_table_struct = Struct(
45            'EH_table',
46            self.EHABI_uint32('word0'),
47        )
48