Commit Graph

243 Commits

Author SHA1 Message Date
Romain Thomas 6374b6b11c Add enums for dyld 1284.13 2025-08-10 13:20:33 +02:00
Romain Thomas 5b851c9839 LLVM 21 update 2025-08-10 13:20:26 +02:00
Romain Thomas 08df4324b8 Fix type 2025-07-26 13:24:47 +02:00
Romain Thomas 5fb4f0cfa0 Add support for LC_FUNCTION_VARIANTS/LC_FUNCTION_VARIANT_FIXUPS
Note that this support is partially incomplete especially for writing
back Mach-O binaries.
2025-07-26 13:03:39 +02:00
Romain Thomas f999e49345 Bootstrap new MachO segmented chained fixups 2025-07-26 11:26:14 +02:00
Romain Thomas 6afae6c314 Enhance Mach-O support 2025-07-26 07:33:04 +02:00
Romain Thomas 1f0dff6c67 Add additional constants 2025-07-26 06:05:04 +02:00
Romain Thomas c40dcea762 Add support for contextual assembly patching 2025-07-13 18:09:50 +02:00
Romain Thomas 5c7c8222ce Improve Rust API to remove dynamic entries 2025-07-12 20:38:50 +02:00
Romain Thomas 6f48fb1216 Update doc 2025-07-12 12:39:57 +02:00
Romain Thomas 0762ca3cf4 Resolve #1233 2025-07-12 11:39:49 +02:00
Romain Thomas 7fce27408a Provide lief-patchelf: a LIEF-based implementation of NixOS's patchelf
Related: NixOS/patchelf#568
Support: NixOS/patchelf#596
2025-07-12 10:01:33 +02:00
Romain Thomas 9599415297 Fix typing 2025-07-12 06:06:25 +02:00
Romain Thomas baa063c823 Add support to remove version from .gnu.version_r 2025-06-29 19:05:06 +02:00
Romain Thomas 836620bfbb Add API to remove a version requirement from a symbol 2025-06-29 17:34:58 +02:00
Romain Thomas 497b95e3de Add support for SH4 2025-06-28 09:35:21 +02:00
Romain Thomas e661bb7422 Improve page size support 2025-06-24 16:48:02 +02:00
Romain Thomas d585c1e5ae API updates 2025-06-24 16:03:34 +02:00
Romain Thomas 1b18d17a7e Add doc about Mach-O library/rpath modification 2025-06-24 06:05:26 +02:00
Romain Thomas a8097e5def Export write_to_bytes for ELF & Mach-O 2025-06-14 20:08:08 +02:00
Romain Thomas 024916cf18 Use pointers instead of plain objects 2025-06-14 07:50:01 +02:00
Romain Thomas 2babf12d93 Add support to access and disassemble COFF functions 2025-06-14 07:32:21 +02:00
Romain Thomas d9e949a463 Fix typing 2025-06-09 06:31:22 +02:00
Romain Thomas 84f963a716 Initial support for the COFF format
Resolve #1091
2025-06-08 20:01:21 +02:00
Romain Thomas 9260bae262 Fix #define conflicts 2025-06-07 11:50:27 +02:00
Romain Thomas 14bbcabac8 Rename enum to avoid compilation issue 2025-06-07 10:14:23 +02:00
Romain Thomas 968d9c24ab Support Mach-O modifications that need to extend commands size
Resolve #1204, resolve #1125
2025-05-30 10:59:35 +02:00
Romain Thomas a1ec0f815f Fix missing PPC64 (resolve #1217) 2025-05-29 13:27:52 +02:00
Romain Thomas 5a19dc9d73 Add support for creating DWARF files
This commit also bootstraps plugin for Ghidra and BinaryNinja

Related to NationalSecurityAgency/ghidra#2687
2025-05-27 14:48:07 +02:00
Romain Thomas c4069b6b81 Resolve #1200 2025-05-02 16:46:28 +02:00
kovalev0 c93ee79b2a Hash 9d9cfbb3 fix build warnings (#1195)
* Remove unused variables

Remove unused variables is_arithmetic, is_flag and size
from various files to address compiler warnings.

```
/usr/src/RPM/BUILD/liblief-0.17.0/api/python/src/enums_wrapper.hpp:42:20:
warning: unused variable ‘is_arithmetic’ [-Wunused-variable]
   42 |     constexpr bool is_arithmetic = (std::is_same_v<nanobind::is_arithmetic, Extra> || ...);
      |                    ^~~~~~~~~~~~~

/usr/src/RPM/BUILD/liblief-0.17.0/api/python/src/enums_wrapper.hpp:43:20:
warning: unused variable ‘is_flag’ [-Wunused-variable]
   43 |     constexpr bool is_flag = (std::is_same_v<nanobind::is_flag, Extra> || ...);
      |                    ^~~~~~~

/usr/src/RPM/BUILD/liblief-0.17.0/api/python/src/nanobind/extra/stl/u16string.h:15:20:
warning: unused variable ‘size’ [-Wunused-variable]
   15 |         Py_ssize_t size;
      |                    ^~~~
```

* Fix(asm): Provide namespace-scope declarations for Operand::Iterator op==

Resolves compiler warnings by adding forward declarations for
`LIEF::assembly::{arch}::operator==(const Operand::Iterator&, const Operand::Iterator&)`
in the corresponding header files. The operators were previously only
declared via `friend` declarations inside the Iterator class.

```
[646/872] Building CXX object CMakeFiles/LIB_LIEF.dir/src/asm/asm.cpp.o
/usr/src/RPM/BUILD/liblief-0.17.0/src/asm/asm.cpp:395:6:
warning: ‘bool LIEF::assembly::x86::operator==(const Operand::Iterator&, const Operand::Iterator&)’
	 has not been declared within ‘LIEF::assembly::x86’
  395 | bool x86::operator==(const x86::Operand::Iterator&, const x86::Operand::Iterator&) {
      |      ^~~
In file included from /usr/src/RPM/BUILD/liblief-0.17.0/include/LIEF/asm/x86/Instruction.hpp:21,
                 from /usr/src/RPM/BUILD/liblief-0.17.0/src/asm/asm.cpp:27:
/usr/src/RPM/BUILD/liblief-0.17.0/include/LIEF/asm/x86/Operand.hpp:60:26: note: only here as a ‘friend’
   60 |     friend LIEF_API bool operator==(const Iterator& LHS, const Iterator& RHS);
      |                          ^~~~~~~~
/usr/src/RPM/BUILD/liblief-0.17.0/src/asm/asm.cpp:490:6:
warning: ‘bool LIEF::assembly::aarch64::operator==(const Operand::Iterator&, const Operand::Iterator&)’
	 has not been declared within ‘LIEF::assembly::aarch64’
  490 | bool aarch64::operator==(const aarch64::Operand::Iterator&, const aarch64::Operand::Iterator&) {
      |      ^~~~~~~
In file included from /usr/src/RPM/BUILD/liblief-0.17.0/include/LIEF/asm/aarch64/Instruction.hpp:21,
                 from /usr/src/RPM/BUILD/liblief-0.17.0/src/asm/asm.cpp:18:
/usr/src/RPM/BUILD/liblief-0.17.0/include/LIEF/asm/aarch64/Operand.hpp:60:26: note: only here as a ‘friend’
   60 |     friend LIEF_API bool operator==(const Iterator& LHS, const Iterator& RHS);
      |                          ^~~~~~~~
```

* Fix MachO ChainedPointerAnalysis pointer interpretation issues

Addresses strict aliasing warnings in getter methods by replacing
`reinterpret_cast` with `memcpy` and returning structures by value.

```
/usr/src/RPM/BUILD/liblief-0.17.0/include/LIEF/MachO/ChainedPointerAnalysis.hpp:
In member function ‘const LIEF::MachO::ChainedPointerAnalysis::dyld_chained_ptr_arm64e_rebase_t
	LIEF::MachO::ChainedPointerAnalysis::dyld_chained_ptr_arm64e_rebase() const’:
/usr/src/RPM/BUILD/liblief-0.17.0/include/LIEF/MachO/ChainedPointerAnalysis.hpp:307:13:
warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
  307 |     return *reinterpret_cast<const dyld_chained_ptr_arm64e_rebase_t*>(&value_);
      |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

...

/usr/src/RPM/BUILD/liblief-0.17.0/include/LIEF/MachO/ChainedPointerAnalysis.hpp:
In member function ‘const LIEF::MachO::ChainedPointerAnalysis::dyld_chained_ptr_32_firmware_rebase_t
	LIEF::MachO::ChainedPointerAnalysis::dyld_chained_ptr_32_firmware_rebase() const’:
/usr/src/RPM/BUILD/liblief-0.17.0/include/LIEF/MachO/ChainedPointerAnalysis.hpp:355:13:
warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
  355 |     return *reinterpret_cast<const dyld_chained_ptr_32_firmware_rebase_t*>(&value_);
      |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
```

* Fix PE layout check sign comparison for section index

Addresses Werror=sign-compare in LayoutChecker::check_load_config by
correctly handling potentially negative section index value when
comparing with vector size.

```
/usr/src/RPM/BUILD/liblief-0.17.0/src/PE/layout_check.cpp:447:22:
warning: comparison of integer expressions of different signedness:
  ‘int’ and ‘size_t’ {aka ‘long unsigned int’} [-Wsign-compare]
  447 |     if ((*value - 1) >= pe.sections().size()) {
      |         ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
```

* Fix PE: Rename conflicting local reloc_t structs

Renames local struct 'reloc_t' in DynamicFixupARM64Kernel.cpp and
DynamicFixupControlTransfer.cpp to 'arm64e_kernel_reloc_t' and
'control_transfer_reloc_t' respectively to fix One Definition Rule violations.

```
/usr/src/RPM/BUILD/liblief-0.17.0/src/PE/LoadConfigurations/DynamicRelocation/DynamicFixupARM64Kernel.cpp:35:
warning: type ‘struct reloc_t’ violates the C++ One Definition Rule [-Wodr]
   35 | struct reloc_t {
/usr/src/RPM/BUILD/liblief-0.17.0/src/PE/LoadConfigurations/DynamicRelocation/DynamicFixupControlTransfer.cpp:31:
note: a different type is defined in another translation unit
   31 | struct reloc_t {
```
2025-05-01 17:16:55 +02:00
Romain Thomas d717340c92 Improve the logic of sections insertion in ELF binaries 2025-04-19 08:32:37 +02:00
Romain Thomas fc7cc1c8a3 Update to LLVM 20.1.2 2025-03-29 05:28:19 +01:00
Romain Thomas 68738194c9 Fix whitespace warning 2025-03-29 05:27:20 +01:00
Romain Thomas 0b386c22ba Add named logger API 2025-03-15 06:32:18 +01:00
Romain Thomas 3f35394efa Make sure we raise an exception if the value is not valid 2025-02-22 07:42:10 +01:00
Romain Thomas 45ddb0ecf7 Fix enum conflict with Windows 2025-02-22 06:10:09 +01:00
Romain Thomas 0614b7f2cf Add support for PDB build metadata 2025-02-22 04:45:58 +01:00
Romain Thomas 86760c53d8 Fix Windows conflict 2025-02-15 18:06:55 +01:00
willboka f97627cd58 Dex: add getter for registers count (#1171)
* Add getters for the register count

* Add tests for the getter for the number of registers

* Fix: use const ref to avoid unecessary copy

---------

Co-authored-by: willboka <willbaka>
2025-02-15 17:56:36 +01:00
Romain Thomas eb8fd41011 Fix reference issue 2025-02-15 17:49:52 +01:00
Romain Thomas c000b17be0 Enhance PE parser/builder
close #1021
close #1118
close #192
close #276
close #358
close #642
close #746
close #777
resolve #1043
resolve #109
resolve #114
resolve #1167
resolve #124
resolve #137
resolve #140
resolve #277
resolve #472
resolve #473
resolve #517
resolve #523
resolve #528
resolve #530
resolve #546
resolve #69
resolve #876
2025-02-15 05:33:25 +01:00
Romain Thomas cc288c7215 Add support for pretty printing PDB debug info 2025-02-15 04:15:03 +01:00
Romain Thomas 8cae0420d9 Make sure ELF, PE, and Mach-O parser can consume bytes.
Related to #1167
2025-02-04 12:40:32 +01:00
Romain Thomas b086796f43 Resolve #1165 2025-02-01 20:45:31 +01:00
Romain Thomas 94275484bd Resolve #1164 and resolve #1163 2025-01-25 06:16:11 +01:00
bhoehl ac3b57deb1 add support for spc link / urls in spc indirect data 2025-01-25 05:16:29 +01:00
Romain Thomas 2c0bf31cc0 ++year 2025-01-01 09:49:21 +01:00
Richard Dzenis 259bf7091f MachO::binary: add extend_section (#1137)
* MachO::Binary::add_section: respect alignment of empty sections

* MachO/layout_check: relax offset continuity requirement for __text section

Sections in MachO are prepended, but __text section is not moved.
Due to this there might be redundant gap between __text section and a
section that comes before __text.

Note: we don't want to alter distance between __DATA and __text, because
there might be position relative references in metadata.

* tests/macho: use lief.MachO.check_layout

* MachO::binary: add extend_section

This commit adds member function MachO::Binary::extend_section that is
able to extend sections from the first segment in MachO.

* macho/test_builder: add test_extend_section
2024-12-24 09:58:47 +01:00
Romain Thomas 2cd4d99fc6 Enhance Mach-O layout checks 2024-12-15 08:04:34 +01:00