# Eli Bendersky (eliben@gmail.com)\r
# This code is in the public domain\r
#-------------------------------------------------------------------------------\r
-from .exceptions import ELFParseError\r
+from .exceptions import ELFParseError, ELFError\r
\r
\r
def struct_parse(struct, stream, stream_pos=None):\r
except ConstructError as e:\r
raise ELFParseError(e.message)\r
\r
+\r
+def elf_assert(cond, msg=''):
+ """ Assert that cond is True, otherwise raise ELFError(msg)\r
+ """\r
+ if not cond:\r
+ raise ELFError(msg)\r
+\r
# This code is in the public domain\r
#-------------------------------------------------------------------------------\r
from ..common.exceptions import ELFError\r
-from ..common.utils import struct_parse\r
+from ..common.utils import struct_parse, elf_assert\r
from ..construct import ConstructError\r
from .structs import ELFStructs\r
from .sections import Section, StringTableSection, SymbolTableSection\r
#\r
self.stream.seek(0)\r
magic = self.stream.read(4)\r
- self._assert(magic == '\x7fELF', 'Magic number does not match')\r
+ elf_assert(magic == '\x7fELF', 'Magic number does not match')\r
\r
ei_class = self.stream.read(1)\r
if ei_class == '\x01':\r
of this object.
"""\r
return struct_parse(self.structs.Elf_Ehdr, self.stream, stream_pos=0)\r
- \r
- def _assert(self, cond, msg=''):
- """ Assert that cond is True, otherwise raise ELFError(msg)
- """\r
- if not cond:\r
- raise ELFError(msg)\r
\r
# This code is in the public domain\r
#-------------------------------------------------------------------------------\r
from ..construct import CString\r
-from ..common.utils import struct_parse\r
+from ..common.utils import struct_parse, elf_assert\r
\r
\r
class Section(object):\r
def __init__(self, header, name, stream, stringtable):\r
super(SymbolTableSection, self).__init__(header, name, stream)
self.stringtable = stringtable\r
- \r
-\r