Skip to content

Commit e111886

Browse files
committed
Fix truncated nlist_t.n_type in Mach-O rewriting
1 parent 19cad8d commit e111886

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

doc/sphinx/changelog.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919

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

22+
:MachO:
23+
24+
* Fix truncated ``nlist_t.n_type`` when rewriting a Mach-O binary
25+
2226
0.16.3 - February 1st, 2025
2327
---------------------------
2428

src/MachO/Builder.tcc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ inline ok_error_t write_symbol(vector_iostream& nlist_table, Symbol& sym,
588588

589589
nlist_t nl;
590590
nl.n_strx = static_cast<uint32_t>(it_name->second);
591-
nl.n_type = static_cast<uint8_t>(sym.type());
591+
nl.n_type = static_cast<uint8_t>(sym.raw_type());
592592
nl.n_sect = static_cast<uint32_t>(sym.numberof_sections());
593593
nl.n_desc = static_cast<uint16_t>(sym.description());
594594
nl.n_value = static_cast<typename MACHO_T::uint>(sym.value());

tests/macho/test_issues.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env python
22
import lief
3-
from utils import get_sample
3+
import pytest
4+
from utils import get_sample, has_private_samples
45
from pathlib import Path
56

67
def test_945():
@@ -57,3 +58,13 @@ def test_1132():
5758
if can_cache_segment(seg):
5859
assert binary.segment_from_offset(seg.file_offset) == seg
5960

61+
@pytest.mark.skipif(not has_private_samples(), reason="need private samples")
62+
def test_issue_ntype(tmp_path: Path):
63+
macho = lief.MachO.parse(get_sample('private/MachO/amfid.arm64e')).at(0)
64+
output = tmp_path / "amfid_out.arm64e"
65+
66+
assert macho.symbols[0].raw_type == 60
67+
68+
macho.write(output.as_posix())
69+
new = lief.MachO.parse(output).at(0)
70+
assert new.symbols[0].raw_type == 60

0 commit comments

Comments
 (0)