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

elf: implement file export name extractor #1607

Closed
williballenthin opened this issue Jul 10, 2023 · 7 comments · Fixed by #1662
Closed

elf: implement file export name extractor #1607

williballenthin opened this issue Jul 10, 2023 · 7 comments · Fixed by #1662
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed

Comments

@williballenthin
Copy link
Collaborator

# TODO(williballenthin): implement extract_file_export_names

@williballenthin williballenthin added enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed labels Jul 10, 2023
@Aayush-Goel-04
Copy link
Contributor

I investigated ways to distinguish between import and export symbols. The current implementation identifies symbols as imports solely based on their type and name. However, after careful analysis, I found that the st_shndx field in the symbol entry plays a critical role in differentiating between imports and exports. If symbol.entry.st_shndx = SHN_UNDEF (0x00), it signifies that the symbol is not defined within the ELF file, making it an import. On the other hand, the st_shndx field of export symbols points to the section index of the section where the symbol is defined.

The current extract_file_export_names extracts both import and export name from .dynsym and .symtab. We should consider incorporating the st_shndx field check to accurately identify import and export symbols.

@williballenthin what are your thoughts

@williballenthin
Copy link
Collaborator Author

great find and excellent explanation. do you have any references to the specifications that support these conclusions? it would be great to link to them in the code.

how do you think we should proceed? would you like to propose some updates to the code?

@williballenthin
Copy link
Collaborator Author

this article is very wordy but provides nice clear definitions at the bottom:

http://www.m4b.io/elf/export/binary/analysis/2015/05/25/what-is-an-elf-export.html

it's generally consistent with what you posted @Aayush-Goel-04 though it describes a few edge cases. seems like it shouldn't be too hard to handle.

@Aayush-Goel-04
Copy link
Contributor

Aayush-Goel-04 commented Jul 20, 2023

this article is very wordy but provides nice clear definitions at the bottom:

I was looking at the same paper.
Screenshot 2023-07-20 233703

In above screenshot only the first two points of import and export differ st_value and st_shndx. st_type is same for both export and import.

Some info on SHN_UNDEF. Some more I found https://stackoverflow.com/questions/12666253/elf-imports-and-exports

@williballenthin Shall I proceed with identifying import and exports based on definition given in screenshot above.

@williballenthin
Copy link
Collaborator Author

yes, please!

@Aayush-Goel-04
Copy link
Contributor

Aayush-Goel-04 commented Jul 20, 2023

@williballenthin I think we should look for export symbols in section.name == .dynsym rather than looking at all symbols for isinstance(section, SymbolTableSection). I am not sure if we should also look at .symtab section name . Can you shed some light here.

Also Since #1608 is closely related to this I will get that done as well.

@williballenthin
Copy link
Collaborator Author

i'm willing to go with your recommendation, especially if we can provide references to specifications or example files (for any edge cases we find). i don't have any particular knowledge of the ELF format, so i trust what you learn.

if you need an opinion on which strategy to use, i'm happy to discuss, though i'd appreciate a bit of detail around what you've considered so far.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants