LIEF icon indicating copy to clipboard operation
LIEF copied to clipboard

support archives/static libraries

Open SSE4 opened this issue 7 years ago • 13 comments

I found it useful for my needs to parse also archives/static libraries, as well as corresponding object files (e.g. in COFF or ELF formats). at very least, to obtain list of exported and imported symbols. does it sound as useful addition for this project? if yes, I may try to prototype this.

SSE4 avatar Nov 06 '18 18:11 SSE4

Yes It's completely in the scope of this project so feel free to make a PR for these features

romainthomas avatar Nov 07 '18 07:11 romainthomas

So glad to hear this is in-scope!

mingwandroid avatar Dec 10 '18 03:12 mingwandroid

Hello @romainthomas and @SSE4, do either of you know if anyone has done any work on this yet? I may take a go at it if not, hopefully I can figure it out.

mingwandroid avatar Dec 10 '18 03:12 mingwandroid

@mingwandroid I have started any work yet, feel free to take it

SSE4 avatar Dec 10 '18 05:12 SSE4

Nice! I'm quite busy with other stuff but feel free to ask questions if you have some

romainthomas avatar Dec 10 '18 06:12 romainthomas

Hi @romainthomas, I have been hacking about with some Python code to handle archives (I hope to convert it to C++ and make a PR at some point). I can give you a URL if you wish, the code is currently in a branch in my own fork of conda-build.

It works to a degree on Linux. Since an .ar is just an archive of .elf files (with some indexes), to get the final symbols (and rich information about them) I use lief.elf.parse(raw=ar_file[elf_start_index:elf_end_index]).

On Windows, calling lief.PE.parse(raw=ar_file[coff_start_index:coff_end_index]) does not work since a COFF file isn't the same as a PE file. I get the following error:

'C:\Users\rdonnelly\conda\conda-build\mingw-w64-libz.dll.a\d000103.o' is not an PE

Do you have any recommendations for how to proceed at this point? Would the code that deals with COFF be callable here?

Many thanks!

mingwandroid avatar Jan 09 '19 05:01 mingwandroid

Hi @mingwandroid Thank you very much for your contribution! I'm interested in your code (I didn't find the branch in conda-build)

Regarding COFF file, I think it would require to refactor some part of the PE module of LIEF since PE format is a specialization of COFF. One way to do to would be to have a LIEF::COFF::Binary object and LIEF::PE::Binary would inherit this class. There is a similar example with OAT format and ELF file:

https://github.com/lief-project/LIEF/blob/13ad81e7432fe850102a04026e48d93109863ebc/include/LIEF/ELF/Binary.hpp#L57

https://github.com/lief-project/LIEF/blob/13ad81e7432fe850102a04026e48d93109863ebc/include/LIEF/OAT/Binary.hpp#L39

romainthomas avatar Jan 09 '19 06:01 romainthomas

Hi @romainthomas, thanks. Hopefully I can get this done!

My (very WIP) python code can be seen here. These line numbers may change today though as I'll be trying to fix/add macOS/BSD support. The function in question is get_static_lib_exports. You can see for the non-COFF case that I just let LIEF do the heavy lifting and that's working well.

Thank you for your recommendation. I was under the impression that a COFF file is essentially embedded in a PE file, given what you said, I guess that's not correct?

mingwandroid avatar Jan 09 '19 16:01 mingwandroid

Hey @romainthomas, I'm starting to look into some LIEF issues now. Are there any channels (gitter/IRC) where hacking on LIEF gets discussed?

mingwandroid avatar Jan 14 '19 19:01 mingwandroid

Hi @mingwandroid, Sorry I mess your latest message.

Thank you for your recommendation. I was under the impression that a COFF file is essentially embedded in a PE file, given what you said, I guess that's not correct? PE files implement COFF spec so that a PE file should be COFF file (If I'm not wrong)

Are there any channels (gitter/IRC) where hacking on LIEF gets discussed?

Yes there is a Gitter Channel here: https://gitter.im/lief-project

romainthomas avatar Jan 14 '19 21:01 romainthomas

PE and COFF share the same specification, that's true, but COFF is not embedded in PE or vice versa. they have different set of headers, and headers have different set of fields depending if it's COFF or PE file, also some fields may have different meaning.

SSE4 avatar Jan 16 '19 00:01 SSE4

Is this still being worked on?

aeflores avatar Feb 26 '21 18:02 aeflores

@aeflores not from my side

romainthomas avatar Feb 26 '21 18:02 romainthomas