Files
lief-project-LIEF/api/python
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
..
2025-04-19 08:32:39 +02:00
2025-02-15 05:33:25 +01:00
2025-04-19 08:32:39 +02:00
2025-04-12 06:31:03 +02:00
2023-11-09 06:26:56 +01:00
2024-12-09 10:46:36 +01:00

About
=====

The purpose of this project is to provide a cross platform library that can parse, modify and
abstract ELF, PE and MachO formats.

Main features:

  * **Parsing**: LIEF can parse ELF, PE, MachO, OAT, DEX, VDEX, ART and provides an user-friendly API to access to format internals.
  * **Modify**: LIEF enables to modify some parts of these formats
  * **Abstract**: Three formats have common features like sections, symbols, entry point... LIEF factors them.
  * **API**: LIEF can be used in C, C++, Python and Rust

LIEF Extended:

  * DWARF/PDB Support
  * Objective-C Metadata
  * dyld shared cache

Checkout: https://lief.re/doc/latest/extended/intro.html for the details

Getting Started
================

.. code-block:: console

  $ pip install lief

.. code-block:: python

  import lief

  elf = lief.ELF.parse("/bin/ls")
  for section in elf.sections:
      print(section.name, len(section.content))

  pe = lief.PE.parse("cmd.exe")
  for imp in pe.imports:
      print(imp.name)

  fat = lief.MachO.parse("/bin/dyld")
  for macho in fat:
      for sym in macho.symbols:
          print(sym)

Documentation
=============

* `Main documentation <https://lief.re/doc/latest/index.html>`_
* `API <https://lief.re/doc/latest/api/python/index.html>`_

Contact
=======

* **Mail**: contact at lief.re
* **Discord**: `LIEF <https://discord.gg/jGQtyAYChJ>`_

Authors
=======

Romain Thomas `@rh0main <https://x.com/rh0main>`_

----

LIEF is provided under the `Apache 2.0 license <https://github.com/lief-project/LIEF/blob/0.15.1/LICENSE>`_