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

Get ELF dynamic symbol version information #572

Open
NobodyXu opened this issue Aug 27, 2023 · 5 comments
Open

Get ELF dynamic symbol version information #572

NobodyXu opened this issue Aug 27, 2023 · 5 comments

Comments

@NobodyXu
Copy link

NobodyXu commented Aug 27, 2023

I want to get the dynamic symbol version information using object programmatically.

I can currently obtain it via object -T:

DYNAMIC SYMBOL TABLE:

0000000000000000      DF *UND*	0000000000000000 (GLIBC_2.17) error
0000000000000000      DF *UND*	0000000000000000 (GLIBC_2.17) fclose
0000000000000000      DF *UND*	0000000000000000 (GLIBC_2.17) fsync
0000000000000000      DF *UND*	0000000000000000 (GLIBC_2.17) nl_langinfo
0000000000000000      DF *UND*	0000000000000000 (GLIBC_2.17) malloc
0000000000000000      DO *UND*	0000000000000000 (GLIBC_2.17) optind
0000000000000000      DF *UND*	0000000000000000 (GLIBC_2.17) __fprintf_chk
0000000000000000      DF *UND*	0000000000000000 (GLIBC_2.17) sigismember

however object isn't always available and I want to do it in Rust.

I can't find a function/trait doing this and printing symbol_name alone doesn't provide me with the information required.

My goal is to find which glibc version is required for the binary.

@philipc
Copy link
Contributor

philipc commented Aug 27, 2023

Currently the only way is via gnu_verneed. Changing ElfFile::imports may be an option, but I think that will require API changes.

@NobodyXu
Copy link
Author

Thanks that could work for me, but I don't know how to obtain a object::read::elf::SectionTable from read::ElfFile, there doesn't seem to be an API doing that.

@philipc
Copy link
Contributor

philipc commented Aug 28, 2023

Since what you are doing is simple and specific to ELF, I suggest using the low level API instead of ElfFile. Some untested code based on the readobj example:

let elf = object::elf::FileHeader64::<Endianness>::parse(data)?;
let endian = elf.endian()?;
if let Some(sections) = elf.sections(endian, data)? {
    if let Some((mut verneed, _)) = sections.gnu_verneed(endian, data)? {
        ...
    }
}

@NobodyXu
Copy link
Author

Thank you!
BTW, is there anyway to check whether it's Elf32 or Elf64 so that?

Or simply fallback on error is enough?

@philipc
Copy link
Contributor

philipc commented Aug 28, 2023

Use FileKind::parse(data). The readobj example uses this too.

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

2 participants