Commit Graph

66 Commits

Author SHA1 Message Date
Serge Lamikhov-Center
e18e5bc261 Use a header for version information 2020-08-24 10:24:09 -07:00
Serge Lamikhov-Center
b4c245f5a8 Add .modinfo section accessor 2020-08-22 15:11:58 -07:00
Serge Lamikhov-Center
9c739b49a0 Reformat sources by using clang-format
It is not perfect (and, probably, it is worser than it was before), but, it is automatic
2020-08-21 07:56:08 -07:00
Serge Lamikhov-Center
c6e5eb0aad Update Copyright period 2020-08-19 13:47:20 -07:00
Serge Lamikhov-Center
d2c3fb6a14 Refactoring - remove unnecessary check 2020-08-15 18:56:13 +03:00
Serge Lamikhov-Center
a59cbf6674 Alighn code with whitespaces 2020-08-08 09:55:42 -07:00
Serge Lamikhov-Center
b1961db18b Fix compilation warnings in VS 2019 v16.7.0 2020-08-07 20:27:13 +03:00
Serge Lamikhov-Center
a735f412ec Remove unused header 2020-06-10 08:01:20 -07:00
Pierre Bélissent
6e237576f0 Issue serge1/ELFIO#19: Test case to reproduce, and correction 2020-06-06 22:26:12 +03:00
Serge Lamikhov-Center
3e4a2fabfd Add tests for the new flavor of get_symbol() 2020-02-22 11:31:27 +02:00
Alfred Bratterud
d8e8a4cbb4 Added get_symbol by value and generic linear search 2020-02-15 23:10:01 +02:00
Serge Lamikhov-Center
858b7a3b70 Names and tabs refactoring 2019-04-19 14:52:20 +03:00
Gleb Struchalin
a314b28193 Replaced tabs by spaces 2019-04-19 13:55:00 +03:00
Gleb Struchalin
925af0d3d5 Added overload to elfio::save which accepts std::ostream 2019-04-19 13:55:00 +03:00
Pavel I. Kryukov
6a2e8c78b0 Avoid hiding local variable by another local variable in elfio::load_sections 2018-08-25 22:40:00 +03:00
Jingxuan He
4b9ff89770 modify get_ordered_segments 2018-05-05 19:32:49 +03:00
alvaro
bc5f17b0fc Fix more NULL dereferences
Crash 7d695153fd8052529d480c2352d4ada33a44bada
2017-10-04 20:47:51 +03:00
alvaro
abab994411 Fix NULL deference for no ELF files
Fix crash 060833f08dc14d1712428742b3cad7af17b36bb7
2017-10-04 20:47:51 +03:00
alvaro
39f8614f17 Added stream_size into section
This will allow to perform some security checks when reading size values
from ELF file

Fix crash e1ce7cecf01cf800397a4302854d9d76fa19763c
2017-10-04 20:47:51 +03:00
Vašek Potoček
972f89e022 Better support for read-only ELF access 2017-10-04 20:33:10 +03:00
Martin Bickel
b4127676ba Fix calculation of section alignment 2017-03-06 22:28:46 +02:00
Martin Bickel
3385408d6b Rephrase condition of is_sect_in_seg() to make it more intuitive 2017-03-06 22:28:46 +02:00
Martin Bickel
fe78d06e81 Segment align updated when saving, not loading
After loading, the data model in memory should resemble the original ELF file as closely as possible,
so that ELF viewers based on elfio will print out the original values, not the calculated ones.
2017-02-18 19:25:21 +02:00
Martin Bickel
6c19078803 Fixed section to segment mapping for 0-length sections 2017-02-18 19:25:21 +02:00
Martin Bickel
d800c7b295 When saving a previously loaded ELF file, don't shrink segments' memory size 2017-01-16 20:38:37 +02:00
Martin Bickel
213dbedac2 Add sanity check when calculating alignment 2017-01-16 20:38:37 +02:00
Martin Bickel
fb5ec079ba new method for validating the loaded ELF file 2017-01-16 20:38:37 +02:00
Martin Bickel
a0de1960d6 Check for errors when loading segments 2017-01-16 20:38:37 +02:00
Serge Lamikhov-Center
878247108f Ignore sections of zero size. Thanks to Martin Bickel 2016-12-20 20:11:20 +02:00
Serge Lamikhov-Center
8e7a29e128 Refactoring 2016-04-23 17:58:34 +03:00
Serge Lamikhov-Center
69b6177bd6 Make '.shstrtab' section be explicitly aligned to 1 2015-09-26 15:01:56 +03:00
Serge Lamikhov-Center
f2e17bac87 Fix offset calculation for the case where section's align field is zero 2015-09-26 11:07:26 +03:00
Serge Lamikhov-Center
3429026ab7 Include <iterator> header file 2015-08-22 20:04:02 +03:00
Serge Lamikhov-Center
8290078a64 Relocation entry endianness fix; Warnings elimination 2015-02-13 20:47:37 +02:00
Mario Werner
91e61ec4b2 use the NULL section instead of offset == 0
This change makes it possible to use the regular API to build up
elf files which include the file header.
2014-12-03 10:38:44 +01:00
Mario Werner
1676247836 fix alignment of segments during saving -> copied elfs are working
The old implementation aligned the segment start. However, the
intended behaviour is to align the offset and the vaddr
(p_vaddr % p_align == p_offset % p_align). This is required for the
loader which can then operate on memory pages.
2014-12-03 09:27:56 +01:00
Mario Werner
fe0c85995d add 4 byte alignment for the section table
this is probably not required but definitely does not hurt
2014-12-03 09:24:21 +01:00
Serge Lamikhov-Center
1db119a8ca Refactoring - a nicer code for is_subsequence_of()
Conflicts:
	elf_examples/asm_copy
2014-11-23 00:53:19 +02:00
Mario Werner
b91a43b378 special support for PHDR segments and segments which include the elf header
Only elf files with strange GNU_RELRO segments fail the load, save, cycle.

It would maybe a good idea to separate the layout functionality from the
current save. The current coupling of layout and save make it
impossible to build layouts which contain the elf header via the public
API.
2014-11-15 22:08:52 +01:00
Mario Werner
755b92c580 move the section table to the end of the elf file 2014-11-14 13:40:25 +01:00
Mario Werner
c743d0bf74 separated layout generation and saving
Many example elfs (hello_32, hello_64, asm ...) require that the
first section directly follows the program header table. The
section header is then placed between segments or at the end.

This change prepares the late placement of section header table.
2014-11-14 13:06:39 +01:00
Mario Werner
55c2841e47 changed order in which the sections are emitted
The fact that segments can contain header information as well as
sections requires that sections within segments are emitted first.
2014-11-14 10:37:50 +01:00
Mario Werner
0ece76b5eb rewrote the segment save logic to not only care about alignment
The initial implementation only made sure that all sections and segments
are properly aligned. This is enough for simple embedded applications
but can not deal with more complex layouts.

The new implementation should be more generic given that it respects the
virtual addresses of the individual sections.

One thing which is currently not supported by this rewrite are segments
which contain the program/segment header or even the whole elf header.
2014-11-14 08:27:36 +01:00
Mario Werner
e5592ddfdd fix: make segment loading similar to readelf's algorithm
ALLOC sections are now matched against the virtual address space of
the segment. Non ALLOC sections still use the offset approach.
2014-11-14 08:04:55 +01:00
Serge Lamikhov-Center
7dd7dade6f Non-significant formatting 2014-08-09 10:56:18 +03:00
Vincent Huang
6d713f4d0a Added iterator for segments and sections
segments and sections were already stored as std::vector<T>.
This change simply exposes the std::vector<T>::iterator functions.
2014-08-07 23:12:35 -04:00
Serge Lamikhov-Center
33dcaf063f Use [i|o]stream instead of [i|o]fstream; The patch was provided by Jason Hiser
Test's fixes
2014-02-26 18:02:30 +02:00
Serge Lamikhov-Center
17f03740e6 Using macros for header fields access functions
Set segment's index upon its creation
Move to VS2013 projects
2014-02-26 17:30:43 +02:00
Mario Werner
1d2930abc7 redesigned save_segments_and_their_sections
We have some elf files where a section (.ARM.exidx) is located in multiple segments.
To keep this property it is necessary to keep track of the emitted sections.
Furthermore, the correct sequence for the segment emission has to be determined.
This is done by postponing segments which are actually a subsequence of another segment.

Additionally the alignment is not considered as part of the file size of a segment anymore.
2014-02-17 11:52:25 +01:00
Mario Werner
5dd8ba29bd assign sections to the segments during load based on the offsets 2014-02-13 18:59:16 +01:00