Skip to content

Commit 9f8003d

Browse files
committed
Update lief
This change updates lief to lief-project/LIEF@b183666. This contains lief-project/LIEF#780, which is a requirement for #8. Signed-off-by: Darshan Sen <raisinten@gmail.com>
1 parent 31cc446 commit 9f8003d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+465
-179
lines changed

DEPENDENCIES

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
lief https://github.com/lief-project/LIEF/ 9cf3b56cf004407c56695a61688ecc8ac511ef0e
1+
lief https://github.com/lief-project/LIEF/ b183666a082d19ffc91ed0763f49e1d4f3814a59
22
vendorpull https://github.com/jviotti/vendorpull 8445d0d0b15d308906ee395cc3313cba461865c4

vendor/lief/CMakeLists.txt

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
cmake_minimum_required(VERSION 3.5)
22

3+
# Avoid warning about DOWNLOAD_EXTRACT_TIMESTAMP in CMake 3.24:
4+
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")
5+
cmake_policy(SET CMP0135 NEW)
6+
endif()
7+
38
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
49

510
# Modules
@@ -464,15 +469,6 @@ endif()
464469

465470
target_compile_definitions(LIB_LIEF PUBLIC -D_GLIBCXX_USE_CXX11_ABI=1)
466471

467-
# Enable support for MD2 and MD4 for parsing the Authenticode sigs of older
468-
# executables. Also, some older signed executables use certs with the
469-
# SpcSpAgencyInfo Critical Extension, which mbed TLS doesn't support, so set
470-
# MBEDTLS_X509_ALLOW_UNSUPPORTED_CRITICAL_EXTENSION to have it skip this
471-
# extension.
472-
add_definitions(-DMBEDTLS_FS_IO -DMBEDTLS_PEM_PARSE_C -DMBEDTLS_BIGNUM_C
473-
-DMBEDTLS_X509_CRT_PARSE_C -DMBEDTLS_PEM_WRITE_C
474-
-DMBEDTLS_PKCS1_V15 -DMBEDTLS_PKCS1_V21)
475-
476472
# LIEF Sanitizer options
477473
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
478474
set(SANITIZER_FLAGS -fno-omit-frame-pointer -g -O1)

vendor/lief/api/c/MachO/Parser.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,27 @@ using namespace LIEF::MachO;
2525

2626
Macho_Binary_t** macho_parse(const char *file) {
2727
FatBinary* fat = Parser::parse(file).release();
28+
if (fat == nullptr) {
29+
return nullptr;
30+
}
31+
32+
size_t nb_bin = fat->size();
2833

2934
auto** c_macho_binaries = static_cast<Macho_Binary_t**>(
3035
malloc((fat->size() + 1) * sizeof(Macho_Binary_t**)));
3136

32-
for (size_t i = 0; i < fat->size(); ++i) {
37+
for (size_t i = 0; i < nb_bin; ++i) {
3338
Binary* binary = fat->at(i);
3439
if (binary != nullptr) {
3540
c_macho_binaries[i] = static_cast<Macho_Binary_t*>(malloc(sizeof(Macho_Binary_t)));
3641
init_c_binary(c_macho_binaries[i], binary);
3742
}
3843
}
3944

40-
c_macho_binaries[fat->size()] = nullptr;
45+
fat->release_all_binaries();
46+
47+
c_macho_binaries[nb_bin] = nullptr;
48+
delete fat;
4149

4250
return c_macho_binaries;
4351
}

vendor/lief/api/python/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
cmake_minimum_required(VERSION 3.1)
2+
3+
# Avoid warning about DOWNLOAD_EXTRACT_TIMESTAMP in CMake 3.24:
4+
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")
5+
cmake_policy(SET CMP0135 NEW)
6+
endif()
7+
28
include(ExternalProject)
39
include(CheckCXXCompilerFlag)
410
include(CheckCCompilerFlag)

vendor/lief/api/python/DEX/objects/pyType.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ void create<Type>(py::module& m) {
7373

7474
case Type::TYPES::CLASS:
7575
{
76-
return py::cast(type.cls());
76+
return py::cast(type.cls(), py::return_value_policy::reference);
7777
}
7878

7979
case Type::TYPES::PRIMITIVE:

vendor/lief/api/python/ELF/objects/pyBinary.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ void create<Binary>(py::module& m) {
500500
"permutation"_a)
501501

502502
.def("write",
503-
&Binary::write,
503+
static_cast<void (Binary::*)(const std::string&)>(&Binary::write),
504504
"Rebuild the binary and write it in a file",
505505
"output"_a,
506506
py::return_value_policy::reference_internal)

vendor/lief/api/python/ELF/objects/pyBuilder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ void create<Builder>(py::module& m) {
6868
py::return_value_policy::reference_internal)
6969

7070
.def("write",
71-
&Builder::write,
71+
static_cast<void (Builder::*)(const std::string&) const>(&Builder::write),
7272
"Write the build result into the ``output`` file",
7373
"output"_a)
7474

vendor/lief/api/python/MachO/objects/pyBinary.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ void create<Binary>(py::module& m) {
424424
"address"_a)
425425

426426
.def("write",
427-
&Binary::write,
427+
static_cast<void (Binary::*)(const std::string&)>(&Binary::write),
428428
"Rebuild the binary and write and write its content if the file given in parameter",
429429
"output"_a,
430430
py::return_value_policy::reference_internal)
@@ -584,7 +584,9 @@ void create<Binary>(py::module& m) {
584584
py::return_value_policy::reference_internal)
585585

586586
.def("shift",
587-
&Binary::shift,
587+
[] (Binary& self, size_t width) {
588+
return error_or(&Binary::shift, self, width);
589+
},
588590
R"delim(
589591
Shift the content located right after the Load commands table.
590592
This operation can be used to add a new command

vendor/lief/api/python/PE/objects/pyBinary.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ void create<Binary>(py::module& m) {
405405
"Remove all imported libraries")
406406

407407
.def("write",
408-
&Binary::write,
408+
static_cast<void (Binary::*)(const std::string&)>(&Binary::write),
409409
"Build the binary and write the result to the given ``output`` file",
410410
"output_path"_a)
411411

vendor/lief/api/python/PE/objects/pyBuilder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ void create<Builder>(py::module& m) {
9494
py::return_value_policy::reference)
9595

9696
.def("write",
97-
&Builder::write,
97+
static_cast<void (Builder::*)(const std::string&) const>(&Builder::write),
9898
"Write the build result into the ``output`` file",
9999
"output"_a)
100100

vendor/lief/cmake/LIEFOptions.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ cmake_dependent_option(LIEF_OAT "Build LIEF with OAT module" ON
3434
"LIEF_ELF;LIEF_DEX" OFF)
3535

3636
# VDEX format depends on the DEX module
37-
cmake_dependent_option(LIEF_VDEX "Build LIEF with DEX module" ON
37+
cmake_dependent_option(LIEF_VDEX "Build LIEF with VDEX module" ON
3838
"LIEF_DEX" OFF)
3939

4040
# Sanitizer

vendor/lief/doc/sphinx/changelog.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ Changelog
66

77
:ELF:
88

9+
* Fix a heap overflow found by :github_user:`CCWANG19` (:issue:`763`)
10+
* :github_user:`aeflores` fixed an issue when there are multiple versions associated with a symbol
11+
(see: :issue:`749` for the details).
12+
* Handle binaries compiled with the `-static-pie` flag correctly (see: :issue:`747`)
913
* Add support for modifying section-less binaries. The ELF :class:`~lief.ELF.Section` objects gain
1014
the :meth:`lief.ELF.Section.as_frame` method which defines the section as a *framed* section.
1115

@@ -27,6 +31,7 @@ Changelog
2731
2832
:MachO:
2933

34+
* Fix a segfault when the Mach-O binary does not have segments (found by :github_user:`CCWANG19` via :issue:`764`)
3035
* Enable to create exports
3136
* Fix the layout of the binaries modified by LIEF such as they can be (re)signed.
3237
* Add support for `LC_DYLD_CHAINED_FIXUPS` and `LC_DYLD_EXPORTS_TRIE`
@@ -56,6 +61,8 @@ Changelog
5661

5762
:General Design:
5863

64+
* :github_user:`ZehMatt` added the support to write LIEF binaries object through a `std::ostream` interface
65+
(:commit:`9d55f538602989c69454639565910884c5c5ac7c`)
5966
* Remove the exceptions
6067

6168

vendor/lief/doc/sphinx/tutorials/03_elf_change_symbols.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ Basically, this program takes an integer as argument and performs some computati
6666

6767
.. code-block:: console
6868
69-
$ hasme 123
69+
$ hashme 123
7070
228886645.836282
7171
7272
.. image:: ../_static/tutorial/03/hashme.png
@@ -86,7 +86,7 @@ First we have to load both the library and the binary:
8686
import lief
8787
8888
89-
hasme = lief.parse("hasme")
89+
hashme = lief.parse("hashme")
9090
libm = lief.parse("/usr/lib/libm.so.6")
9191
9292
Then when change the name of the two imported functions in the **binary**:
@@ -109,7 +109,7 @@ finally we swap ``log`` with ``sin`` and ``pow`` with ``cos`` in the **library**
109109
import lief
110110
111111
112-
hasme = lief.parse("hasme")
112+
hashme = lief.parse("hashme")
113113
libm = lief.parse("/usr/lib/libm.so.6")
114114
115115

vendor/lief/include/LIEF/Abstract/Binary.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ class LIEF_API Binary : public Object {
183183
virtual uint64_t imagebase() const = 0;
184184

185185
//! Constructor functions that are called prior any other functions
186-
virtual LIEF::Binary::functions_t ctor_functions() const = 0;
186+
virtual functions_t ctor_functions() const = 0;
187187

188188
//! Convert the given offset into a virtual address.
189189
//!
@@ -195,6 +195,7 @@ class LIEF_API Binary : public Object {
195195

196196
//! Build & transform the Binary object representation into a *real* executable
197197
virtual void write(const std::string& name) = 0;
198+
virtual void write(std::ostream& os) = 0;
198199

199200
LIEF_API friend std::ostream& operator<<(std::ostream& os, const Binary& binary);
200201

vendor/lief/include/LIEF/BinaryStream/BinaryStream.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,10 @@ class BinaryStream {
8282
}
8383
// Even though offset + size < ... => offset < ...
8484
// the addition could overflow so it's worth checking both
85-
const bool read_ok = offset <= this->size() && (offset + size) <= this->size();
85+
const bool read_ok = offset <= this->size() && (offset + size) <= this->size()
86+
/* Check for an overflow */
87+
&& (static_cast<int64_t>(offset) >= 0 && static_cast<int64_t>(size) >= 0)
88+
&& (static_cast<int64_t>(offset + size) >= 0);
8689
if (!read_ok) {
8790
return make_error_code(lief_errors::read_error);
8891
}

vendor/lief/include/LIEF/DEX/Class.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
#ifndef LIEF_DEX_CLASS_H_
1717
#define LIEF_DEX_CLASS_H_
1818

19+
#include <climits>
20+
1921
#include "LIEF/visibility.h"
2022
#include "LIEF/Object.hpp"
2123
#include "LIEF/iterators.hpp"
@@ -129,7 +131,7 @@ class LIEF_API Class : public Object {
129131
fields_t fields_;
130132
std::string source_filename_;
131133

132-
uint32_t original_index_ = -1u;
134+
uint32_t original_index_ = UINT_MAX;
133135
};
134136

135137
} // Namespace DEX

vendor/lief/include/LIEF/DEX/Field.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
#ifndef LIEF_DEX_FIELD_H_
1616
#define LIEF_DEX_FIELD_H_
1717

18+
#include <climits>
19+
1820
#include "LIEF/DEX/enums.hpp"
1921

2022
#include "LIEF/visibility.h"
@@ -84,7 +86,7 @@ class LIEF_API Field : public Object {
8486
Class* parent_ = nullptr;
8587
Type* type_ = nullptr;
8688
uint32_t access_flags_ = 0;
87-
uint32_t original_index_ = -1u;
89+
uint32_t original_index_ = UINT_MAX;
8890
bool is_static_ = false;
8991
};
9092

vendor/lief/include/LIEF/DEX/Method.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#ifndef LIEF_DEX_METHOD_H_
1717
#define LIEF_DEX_METHOD_H_
1818

19+
#include <climits>
1920

2021
#include "LIEF/visibility.h"
2122
#include "LIEF/Object.hpp"
@@ -99,7 +100,7 @@ class LIEF_API Method : public Object {
99100
Class* parent_ = nullptr;
100101
Prototype* prototype_ = nullptr;
101102
uint32_t access_flags_ = ACCESS_FLAGS::ACC_UNKNOWN;
102-
uint32_t original_index_ = -1u;
103+
uint32_t original_index_ = UINT_MAX;
103104
bool is_virtual_ = false;
104105

105106
uint64_t code_offset_ = 0;

vendor/lief/include/LIEF/ELF/Binary.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,11 @@ class LIEF_API Binary : public LIEF::Binary {
565565
//! @param filename Path for the written ELF binary
566566
void write(const std::string& filename) override;
567567

568+
//! Reconstruct the binary object and write it in `os` stream
569+
//!
570+
//! @param Output stream for the written ELF binary
571+
void write(std::ostream& os) override;
572+
568573
//! Reconstruct the binary object and return its content as a byte vector
569574
std::vector<uint8_t> raw();
570575

vendor/lief/include/LIEF/ELF/Builder.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ class LIEF_API Builder {
102102
//! Write the built ELF binary in the ``filename`` given in parameter
103103
void write(const std::string& filename) const;
104104

105+
//! Write the built ELF binary in the stream ``os`` given in parameter
106+
void write(std::ostream& os) const;
107+
105108
protected:
106109
template<typename ELF_T>
107110
ok_error_t build();

vendor/lief/include/LIEF/MachO/Binary.hpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
/* Copyright 2017 - 2022 R. Thomas
23
* Copyright 2017 - 2022 Quarkslab
34
*
@@ -226,6 +227,11 @@ class LIEF_API Binary : public LIEF::Binary {
226227
//! @param filename Path to write the reconstructed binary
227228
void write(const std::string& filename) override;
228229

230+
//! Reconstruct the binary object and write the result in the given `os` stream
231+
//!
232+
//! @param os Output stream to write the reconstructed binary
233+
void write(std::ostream& os) override;
234+
229235
//! Reconstruct the binary object and return its content as bytes
230236
std::vector<uint8_t> raw();
231237

@@ -642,7 +648,7 @@ class LIEF_API Binary : public LIEF::Binary {
642648

643649
//! Shift the content located right after the Load commands table.
644650
//! This operation can be used to add a new command
645-
void shift(size_t value);
651+
ok_error_t shift(size_t value);
646652

647653
//! Shift the position on the __LINKEDIT data by `width`
648654
ok_error_t shift_linkedit(size_t width);
@@ -661,7 +667,7 @@ class LIEF_API Binary : public LIEF::Binary {
661667
//! Default constructor
662668
Binary();
663669

664-
void shift_command(size_t width, size_t from_offset);
670+
void shift_command(size_t width, uint64_t from_offset);
665671

666672
//! Insert a Segment command in the cache field (segments_)
667673
//! and keep a consistent state of the indexes.

vendor/lief/include/LIEF/MachO/BinaryParser.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@ class LIEF_API BinaryParser : public LIEF::Parser {
7474
friend class MachO::Parser;
7575

7676
//! Maximum number of relocations
77-
constexpr static size_t MAX_RELOCATIONS = std::numeric_limits<uint16_t>::max();
77+
constexpr static size_t MAX_RELOCATIONS = (std::numeric_limits<uint16_t>::max)();
7878

7979
//! Maximum number of MachO LoadCommand
80-
constexpr static size_t MAX_COMMANDS = std::numeric_limits<uint16_t>::max();
80+
constexpr static size_t MAX_COMMANDS = (std::numeric_limits<uint16_t>::max)();
8181

8282
public:
8383
static std::unique_ptr<Binary> parse(const std::string& file);

vendor/lief/include/LIEF/MachO/Builder.hpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,19 +73,26 @@ class LIEF_API Builder {
7373
static ok_error_t write(Binary& binary, std::vector<uint8_t>& out);
7474
static ok_error_t write(Binary& binary, std::vector<uint8_t>& out, config_t config);
7575

76+
static ok_error_t write(Binary& binary, std::ostream& out);
77+
static ok_error_t write(Binary& binary, std::ostream& out, config_t config);
78+
7679
static ok_error_t write(FatBinary& fat, const std::string& filename);
7780
static ok_error_t write(FatBinary& fat, const std::string& filename, config_t config);
7881

7982
static ok_error_t write(FatBinary& fat, std::vector<uint8_t>& out);
8083
static ok_error_t write(FatBinary& fat, std::vector<uint8_t>& out, config_t config);
8184

85+
static ok_error_t write(FatBinary& fat, std::ostream& out);
86+
static ok_error_t write(FatBinary& fat, std::ostream& out, config_t config);
87+
8288
~Builder();
8389
private:
8490
ok_error_t build();
8591

8692
const std::vector<uint8_t>& get_build();
8793
ok_error_t write(const std::string& filename) const;
88-
94+
ok_error_t write(std::ostream& os) const;
95+
8996
Builder(Binary& binary, config_t config);
9097
Builder(std::vector<Binary*> binaries, config_t config);
9198

vendor/lief/include/LIEF/MachO/FatBinary.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ class LIEF_API FatBinary {
6969
it_binaries end();
7070
it_const_binaries end() const;
7171

72+
void release_all_binaries();
73+
7274
//! Get a pointer to the last MachO::Binary object presents in this Fat Binary.
7375
//! It returns a nullptr if no binary are present.
7476
std::unique_ptr<Binary> pop_back();

0 commit comments

Comments
 (0)