Skip to content

Commit

Permalink
Fix truncated nlist_t.n_type in Mach-O rewriting
Browse files Browse the repository at this point in the history
  • Loading branch information
romainthomas committed Feb 22, 2025
1 parent 0397b96 commit 2cdd2ae
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
4 changes: 4 additions & 0 deletions doc/sphinx/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@

* Fix export forwarding issue (:issue:`1168`)

:MachO:

* Fix truncated ``nlist_t.n_type`` when rewriting a Mach-O binary

0.16.3 - February 1st, 2025
---------------------------

Expand Down
2 changes: 1 addition & 1 deletion src/MachO/Builder.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ inline ok_error_t write_symbol(vector_iostream& nlist_table, Symbol& sym,

nlist_t nl;
nl.n_strx = static_cast<uint32_t>(it_name->second);
nl.n_type = static_cast<uint8_t>(sym.type());
nl.n_type = static_cast<uint8_t>(sym.raw_type());
nl.n_sect = static_cast<uint32_t>(sym.numberof_sections());
nl.n_desc = static_cast<uint16_t>(sym.description());
nl.n_value = static_cast<typename MACHO_T::uint>(sym.value());
Expand Down
13 changes: 12 additions & 1 deletion tests/macho/test_issues.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python
import lief
from utils import get_sample
import pytest
from utils import get_sample, has_private_samples
from pathlib import Path

def test_945():
Expand Down Expand Up @@ -57,3 +58,13 @@ def test_1132():
if can_cache_segment(seg):
assert binary.segment_from_offset(seg.file_offset) == seg

@pytest.mark.skipif(not has_private_samples(), reason="need private samples")
def test_issue_ntype(tmp_path: Path):
macho = lief.MachO.parse(get_sample('private/MachO/amfid.arm64e')).at(0)
output = tmp_path / "amfid_out.arm64e"

assert macho.symbols[0].raw_type == 60

macho.write(output.as_posix())
new = lief.MachO.parse(output).at(0)
assert new.symbols[0].raw_type == 60

0 comments on commit 2cdd2ae

Please sign in to comment.