You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently ELFIO succeeds in parsing the header of a memory-mapped ELF dump file, but fails to parse other elements of the ELF file that are present also in memory such as segment headers and .dynsym symbols.
For some of these structures no changes in parsing code need to be made since fields in the header point to them even in memory (segment headers, for example). For others (symbols, for example), different parsing logic is needed so I suggest adding a flag to elfio's load() function that specifies if the elf passed to it was dumped from memory or not.
I am not sure what you call “memory-mapped ELF dump file”.
An ELF file loaded to memory has limited amount of information available. Even file sections names are not available due to the lack of string tables. Basically, in common case which includes bare metal images, only segment data payload is accessible. You still may use ELFIO library for parsing original file and dump memory by following virtual memory locations.
@serge1 What I mean by “memory-mapped ELF dump file” is reading from the /proc/PID/mem of a process the segments that contain the loaded ELF file and writing them into a new file - a dump of the loaded ELF file.
As for the lack of information - you are right. There's less information to recover in memory-mapped ELFs. But there's still some interesting data to get such as the header, the segment headers and their content, the .dynsym section etc... (try using readelf on a dump file. You'll see all section data is screwed-up but you'll also see that some data is still present).
In elfio most of the parsing logic combines parsing data that's present only in the original file (such as section headers) with parsing of data that can be found in both regular files and dump files (such as segment headers). This entanglement prevents the parsing of all available data from dump files.
Here's a short python script I found here. It dumps all the used parts of a process memory. This is a little extensive since all we need is the mapping of the process exe file (the first mapped file shown in `/proc/PID/maps), so it needs a little editing in order to extract only the relevant parts.
My attempt to implement this request is located at branch 'translate_offset'. Specifically the commit b527ea9.
Please take a look at the new example file "examples/proc_mem/proc_mem.cpp".
It is able to take the translation table located in /proc/pid/maps and use it to access ELF file components located in memory. For example, for /usr/bin/base file I got the following:
So, without section header information, no interesting data can be retrieved from memory.
You were interested in content of ".dynsym" section. But, the content cannot be retrieved by regular ELF parsing from memory. Sure, it is available in the original file itself.
Please let me know if I am missing something essential, but, I didn't find any info that cannot be taken from the original ELF file.
I stuck with the section header and didn't continue implementation of the similar translation mechanism for segments
Activity
serge1 commentedon Sep 15, 2021
I am not sure what you call “memory-mapped ELF dump file”.
An ELF file loaded to memory has limited amount of information available. Even file sections names are not available due to the lack of string tables. Basically, in common case which includes bare metal images, only segment data payload is accessible. You still may use ELFIO library for parsing original file and dump memory by following virtual memory locations.
galjs commentedon Sep 16, 2021
@serge1 What I mean by “memory-mapped ELF dump file” is reading from the /proc/PID/mem of a process the segments that contain the loaded ELF file and writing them into a new file - a dump of the loaded ELF file.
As for the lack of information - you are right. There's less information to recover in memory-mapped ELFs. But there's still some interesting data to get such as the header, the segment headers and their content, the
.dynsymsection etc... (try usingreadelfon a dump file. You'll see all section data is screwed-up but you'll also see that some data is still present).In
elfiomost of the parsing logic combines parsing data that's present only in the original file (such as section headers) with parsing of data that can be found in both regular files and dump files (such as segment headers). This entanglement prevents the parsing of all available data from dump files.serge1 commentedon Sep 16, 2021
The idea of dump file processing sounds interesting. Would you please advise which tool can I use to produce an example of such file?
Edit: I have managed to produce the dump by using 'gcore' utility
galjs commentedon Sep 16, 2021
Here's a short python script I found here. It dumps all the used parts of a process memory. This is a little extensive since all we need is the mapping of the process exe file (the first mapped file shown in `/proc/PID/maps), so it needs a little editing in order to extract only the relevant parts.
serge1 commentedon Sep 19, 2021
My attempt to implement this request is located at branch 'translate_offset'. Specifically the commit b527ea9.
Please take a look at the new example file "examples/proc_mem/proc_mem.cpp".
It is able to take the translation table located in /proc/pid/maps and use it to access ELF file components located in memory. For example, for /usr/bin/base file I got the following:
Reading afterwards from /proc/pid/mem gives:
vs. the content located in the original ELF file:
Segment data is also looks in sync. For example:
vs. the same segment data in the file:
So, nothing interesting so far.
I am stuck with the section header content. While the file contains:
corresponding information is not available in memory:
So, without section header information, no interesting data can be retrieved from memory.
You were interested in content of ".dynsym" section. But, the content cannot be retrieved by regular ELF parsing from memory. Sure, it is available in the original file itself.
Please let me know if I am missing something essential, but, I didn't find any info that cannot be taken from the original ELF file.
I stuck with the section header and didn't continue implementation of the similar translation mechanism for segments
serge1 commentedon Sep 19, 2021
I am moving the issue to "Discussions"