-
Notifications
You must be signed in to change notification settings - Fork 28
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
Link program headers to sections #18
base: master
Are you sure you want to change the base?
Conversation
This is the minimal change needed to solve a problem of mine, which was to generate core dump files from scratch. If you'd like some testcase, example usage or fancier implementation I'm open to suggestions of course :) |
Yes, would be great if you provide some test vector for that. I am not developing this project actively, so I guess it would be easier for you than for me at the moment. |
Been a while, sorry for the long wait - here's a test :) Let me know what you think. |
I also suggest to add function that maps sections to segments to allow changing sizes of sections without segments offsets breaking. It makes "one allocated section -> one loaded segment" assumption though ## Try to find a mapping from sections to segments to allow to move them around
def map_sections_to_segments(self):
def intersects(a, b):
a1, a2 = a
b1, b2 = b
res = a2 > b1 and b2 > a1
return res
sec: Elf32_Shdr
seg: Elf32_Phdr
for i, sec in enumerate(self.Elf.Shdr_table[1:], 1):
if sec.sh_flags & SHF.SHF_ALLOC == 0:
continue
sec_rg = (sec.sh_addr, sec.sh_addr + sec.sh_size)
for j, seg in enumerate(self.Elf.Phdr_table[1:], 1):
if seg.p_type != PT.PT_LOAD:
continue
seg_rg = (seg.p_vaddr, seg.p_vaddr + seg.p_memsz)
if not intersects(sec_rg, seg_rg):
continue
assert sec_rg[0] >= seg_rg[0] and sec_rg[1] <= seg_rg[1], "Sections cannot span multiple segments!"
seg.sections.append(i)
break |
Allow the caller to specify a section to associate a program header to. This will allow the ELF writer to determine a correct file offset for the program header (the file offset of the lowest associated section).
May I ask you to add that via a PR of your own? I'm glad I had the time to add test vectors for my change, and I have a feeling @v3l0c1r4pt0r will be (rightfully) asking for test vectors for your function as well :) |
Allow the caller to specify a section to associate a program header to.
This will allow the ELF writer to determine a correct file offset for
the program header (the file offset of the lowest associated section).