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

Is it possible to have the size of an ELF file on disk #451

Open
LafLaurine opened this issue Nov 10, 2022 · 3 comments
Open

Is it possible to have the size of an ELF file on disk #451

LafLaurine opened this issue Nov 10, 2022 · 3 comments

Comments

@LafLaurine
Copy link

Hi,
I was wondering if it's possible to have the size of an ELF file on the disk, based on the information in its header ?
If I understood well, e_shoff + (e_shentsize * e_shnum) is not always equal to the size on the disk.
Thanks!

@mzpqnxow
Copy link
Contributor

mzpqnxow commented Nov 11, 2022

Randomly saw this issue at the top of my feed- I'm wondering what you intend to use this for. I ask because for certain use-cases, exposing this as a calculated value based on abstracted header values could be a bit dangerous if not very carefully and clearly documented

I'm thinking specifically of cases involving forensic analysis, where malware could take advantage of this behavior to fool analysis logic

I'm not associated with the pyelftools project, so feel free to ignore my question- I'm just curious :)

@davea42
Copy link

davea42 commented Jun 24, 2023

The OP's reference to e_shoff + (e_shentsize * e_shnum) is misguided. That just calculates
the size of the section headers in total. Referring to those section headers
one gets more relevant data but one has to be aware of the Elf ABI rules. For example
SHT_NOBITS sh_type has no bits at all though it may have a large sh_size.
All this is well documented on the web.

@sevaa
Copy link
Contributor

sevaa commented Oct 22, 2024

@LafLaurine No. The ELF format perfectly allows for arbitrary gaps (past the header) and arbitrary trailing space. The loader is not supposed to read it sequentially.

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

4 participants