73 Commits

Author SHA1 Message Date
Serge Lamikhov-Center
c86883b906 Implement free_data() for sections too
free_data() has no effect if is_lazy was not set
2023-10-13 20:03:48 +03:00
Serge Lamikhov-Center
8ae6cec5d6 C++17 refactoring 2023-06-02 17:37:37 +03:00
Nam Cao
d251da09a0 Remove unnecessary initialization that causes GCC warning 2023-02-22 22:25:54 +02:00
Serge Lamikhov-Center
b2901a51b6 Add missed implementation function for insert_data() 2022-11-30 08:25:01 +02:00
Nam Cao
974e1252ee Rewrite append_data() to call insert_data()
append_data() and insert_data() have almost the same implementation.
Change append_data() to simply call insert_data().
2022-11-29 18:24:32 +02:00
Nam Cao
e533985a3c Add insert_data() to section 2022-11-29 18:24:27 +02:00
Serge Lamikhov-Center
259da37f3a Remove dispersed 'noexcept' specifier 2022-11-24 15:56:37 +02:00
Serge Lamikhov-Center
9827eac948 Implement 'lazy' load for sections 2022-11-13 00:05:25 +02:00
Serge Lamikhov-Center
7c0abb1785 'noexcept' is added to section and segment API 2022-11-12 19:03:39 +02:00
Serge Lamikhov-Center
4320ea915e 'noexept' added to upper level API members 2022-11-12 17:00:08 +02:00
Serge Lamikhov-Center
8409f20a7f Remove output to std::cerr 2022-11-11 01:09:12 +02:00
Serge Lamikhov-Center
705a91c568 Use const referencies in set_xxx arguments 2022-11-10 22:37:55 +02:00
Serge Lamikhov-Center
755f81351f Generilize the section compression calls 2022-11-10 19:26:05 +02:00
Nathan Strong
7608269069 Externalize zlib dependency
== DETAILS

- define an interface/abstract class for zlib implementation
- update the code to reference the implementation, remove zlib dependency
- use constructor injection to provide implementations to elfio
- add a test to validate the injected object gets used properly
`
2022-11-04 18:12:15 +02:00
Nathan Strong
04985836db fix mismatched allocator warning 2022-11-04 18:12:15 +02:00
Nathan Strong
ac542cbb8b Add support for writing RPL/RPX
== DETAILS
Honor the compression flag and write compressed section data.
2022-11-04 18:12:15 +02:00
Nathan Strong
582d929d9d Add support for reading Wii U RPX/RPL
== DETAILS
The Wii U uses a slightly customized ELF format which uses
zlib compression on certain section types.

This commit adds the following:
- add `SHT_` constants for the custom ELF sections
- add `SHF_RPX_DEFLATE` flag used to denote a compressed section
- add code in the section `load()` method to detect the `SHF_RPX_DEFLATE` flag
  and decompress the section
2022-11-04 18:12:15 +02:00
bladchan
b996977925 fix alloc-dealloc-mismatch reported in ASAN 2022-09-04 21:20:43 +03:00
Serge Lamikhov-Center
c22276ec1a Modernize 'segment' implementation 2022-08-31 22:14:32 +03:00
Serge Lamikhov-Center
156cac5fa1 Modernize the section implementation 2022-08-30 19:42:28 +03:00
Serge Lamikhov-Center
af080f739e Use unique_ptr instead of raw pointers 2022-08-29 08:20:07 +03:00
Kamay Xutax
7227a0913f Fix sign-compare error
I just noticed that on my compiler;
probably due to recent version, not sure.
2022-07-18 19:01:22 +03:00
Serge Lamikhov-Center
07ef317550 Check out of the file boundary access attemps 2022-06-16 17:30:22 +03:00
Serge Lamikhov-Center
090444309f Address casting on MSVC++ 2022-02-11 09:20:38 +02:00
Serge Lamikhov-Center
ed2523f095 Adjust stream size when section data changes 2022-01-19 01:24:46 +02:00
Serge Lamikhov-Center
0cf852e561 Make get_stream_size() public 2022-01-15 00:16:11 +02:00
Serge Lamikhov-Center
69fc128bd5 Make set_stream_size() public again 2022-01-14 23:43:34 +02:00
Matthew McRaven
0a229d80fd Respect maximum value of size_t in set_stream_size
When size_t is 32-bits (like in a WASM project), passing in a 64-bit constant leads to compile-time warnings.
2022-01-01 08:12:08 -08:00
Serge Lamikhov-Center
766559537a Hide non interface methods 2021-09-20 20:43:27 +03:00
Serge Lamikhov-Center
fbb852198e Use standard defined value for max ULL 2021-09-20 00:44:01 +03:00
Serge Lamikhov-Center
dad4b434c8 Use a different notation for the address translation 2021-09-20 00:03:21 +03:00
Serge Lamikhov-Center
511086598a Implement address translation for segments 2021-09-19 23:26:58 +03:00
Serge Lamikhov-Center
b527ea992a An attempt to implement memory translation for sections 2021-09-19 11:28:35 +03:00
Serge Lamikhov-Center
1343e5f979 modernize-use-equals-default 2021-08-26 13:01:12 +03:00
Serge Lamikhov-Center
da4f857e07 modernize-use-override 2021-08-26 12:57:31 +03:00
Serge Lamikhov-Center
4a84319bb8 modernize-use-nullptr 2021-08-26 12:52:23 +03:00
Serge Lamikhov-Center
becd79d05c Support stringstream by filling gaps in output stream 2021-03-27 21:14:56 +03:00
Serge Lamikhov-Center
57e614a486 Remove postfix underscore in parameter names 2021-02-05 10:40:18 +02:00
Serge Lamikhov-Center
762c59a2bb Change copyright period 2021-01-19 09:43:01 +02:00
Serge Lamikhov-Center
937978973f Remove usage of try/catch blocks 2020-08-28 22:38:40 -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
b1961db18b Fix compilation warnings in VS 2019 v16.7.0 2020-08-07 20:27:13 +03:00
Serge Lamikhov-Center
b56b93de1b Remove implementation functions from section interface 2020-06-09 23:46:41 -07:00
Serge Lamikhov-Center
46d081d5df Add autoxxx tools to the ELFIOTest directory 2020-02-15 23:24:20 +02:00
Serge Lamikhov-Center
cdafaa0abf Prevent potential dereferencing of NULL pointer 2019-04-19 15:05:50 +03:00
Serge Lamikhov-Center
858b7a3b70 Names and tabs refactoring 2019-04-19 14:52:20 +03:00
Tobias Klauser
37ebcd91b8 Fix two gcc -Wignored-qualifiers warnings
Fix the following two gcc warnings:

elfio/elfio_section.hpp:50:36: warning: type qualifiers ignored on function return type [-Wignored-qualifiers]
     const size_t get_stream_size() const
                                    ^
elfio/elfio_segment.hpp:99:23: warning: type qualifiers ignored on function return type [-Wignored-qualifiers]
     get_stream_size() const
2018-05-05 19:30:09 +03:00
alvaro
1a3cb25a7c Fix oob read terminating data with 0
Fix crash e3c41070342cf84dea077356ddbb8ebf4326a601

==12073==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x6110000003bb at pc 0x0000004c234c bp 0x7fcf6359ec30 sp 0x7fcf6359e3
e0
READ of size 11 at 0x6110000003bb thread T0
    #0 0x4c234b in __interceptor_strlen.part.30 /home/alvaro/tools/llvm/llvm/projects/compiler-rt/lib/asan/../sanitizer_common/sanitize
r_common_interceptors.inc:301
    #1 0x7165e6579d87 in std::char_traits<char>::length(char const*) /build/gcc-multilib/src/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3
/include/bits/char_traits.h:269
    #2 0x7165e6579d87 in std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std
::allocator<char> const&) /build/gcc-multilib/src/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/basic_string.h:495
    #3 0x5c3333 in ELFIO::elfio::load_sections(std::istream&) /home/alvaro/fuzzers/elfio/ELFIO/examples/libfuzzer/../../elfio/elfio.hpp
:413:44
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