__init__.py 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. from .. import *
  2. from ..types import *
  3. from ..constants import *
  4. from ctypes import *
  5. import os
  6. def _class(elf): return ord(elf_getident(elf, None).contents[EI_CLASS])
  7. def is32(elf): return _class(elf) == ELFCLASS32
  8. def is64(elf): return _class(elf) == ELFCLASS64
  9. def select(elf, fname):
  10. if is32(elf):
  11. return globals()['elf32_' + fname]
  12. else:
  13. return globals()['elf64_' + fname]
  14. def section_name(elfP, secP):
  15. shstrndx = c_size_t()
  16. r = elf_getshstrndx(elfP, byref(shstrndx))
  17. shdr = select(elfP, 'getshdr')(secP)
  18. return elf_strptr(elfP, shstrndx, shdr.contents.sh_name)
  19. def section_type(elfP, secP):
  20. return select(elfP, 'getshdr')(secP).contents.sh_type
  21. def section_link(elfP, secP):
  22. return select(elfP, 'getshdr')(secP).contents.sh_link
  23. def section_hdr(elfP, secP):
  24. return select(elfP, 'getshdr')(secP).contents
  25. def open_elf(fname):
  26. fd = os.open(fname, os.O_RDONLY)
  27. return elf_begin(fd, ELF_C_READ, None)
  28. def sym_name(elf, scn, sym):
  29. return elf_strptr(elf, section_link(elf, scn), sym.st_name)