Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't append section if there is no .shstrtab section #21

Open
ryanhz opened this issue Apr 20, 2022 · 0 comments
Open

Can't append section if there is no .shstrtab section #21

ryanhz opened this issue Apr 20, 2022 · 0 comments

Comments

@ryanhz
Copy link

ryanhz commented Apr 20, 2022

I run the following code:

from makeelf.elf import *
elf = ELF.from_file('test.elf')
elf = elf[0]
data_id = elf.append_section('.data', b'\0\0\0\0', 0xfadd)

Then i got the excepion:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.9/site-packages/makeelf/elf.py", line 312, in append_section
    return self._append_section(sec_name, sec_data, sec_addr,
  File "/usr/local/lib/python3.9/site-packages/makeelf/elf.py", line 275, in _append_section
    shstrtab_hdr, shstrtab = self.get_section_by_name('.shstrtab')
  File "/usr/local/lib/python3.9/site-packages/makeelf/elf.py", line 246, in get_section_by_name
    shstrtab_hdr = self.Elf.Shdr_table[shstrtab_idx]
IndexError: list index out of range

Why we need a .shstrtab section first? It could be empty:

readelf -a test.elf
ELF Header:
  Magic:   7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 
  Class:                             ELF32
  Data:                              2's complement, little endian
  Version:                           1 (current)
  OS/ABI:                            UNIX - System V
  ABI Version:                       0
  Type:                              EXEC (Executable file)
  Machine:                           ARM
  Version:                           0x1
  Entry point address:               0x80000bd
  Start of program headers:          71784 (bytes into file)
  Start of section headers:          0 (bytes into file)
  Flags:                             0x5000202, Version5 EABI, soft-float ABI, <unknown>
  Size of this header:               52 (bytes)
  Size of program headers:           32 (bytes)
  Number of program headers:         1
  Size of section headers:           0 (bytes)
  Number of section headers:         0
  Section header string table index: 0

There are no sections in this file.

There are no section groups in this file.

Program Headers:
  Type           Offset   VirtAddr   PhysAddr   FileSiz MemSiz  Flg Align
  LOAD           0x000040 0x08000000 0x08000000 0x11828 0x13714 RWE 0x40

There is no dynamic section in this file.

There are no relocations in this file.

Dynamic symbol information is not available for displaying symbols.

No version information found in this file.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant