Repository navigation
Load a Mach-O relocatable object - #787
Conversation
|
Corpus decompilation diffs can be found at angr/dec-snapshots@master...angr/cle_787 |
|
THIS MESSAGE WAS GENERATED BY AN AUTOMATED PROCESS Validation record for head
Caveats: these are focused and cle-only runs; the full workspace gate was not rerun against this head. Runs were inside the workspace What this closes of the refused Mach-O population (measured 2026-08-28)Private corpus; objects are cited by architecture, container format and sha256 only.
The filetype histogram was derived twice and reconciled: once from the recorded refusal message, parsed with an anchored regex and compared as a whole field, and once from the object bytes, reading
This change covers MH_OBJECT and only MH_OBJECT: 9,005 of the 9,018. In the sample, 473 of 477 load — 120/120 aarch64, 120/120 x86_64, 120/120 x86, 113/114 arm, 0/3 CaRT — and every MH_BUNDLE, MH_KEXT_BUNDLE and MH_DSYM is still refused at the same line. The 13 residual objects are counted over the whole population rather than extrapolated, and are two distinct defects, neither of them this change's subject:
Every fat container in this population is homogeneous, so a per-slice refusal never kills a mixed file here: all 2,339 universal2 objects are 32-bit fat with exactly two slices, 2,293 of them (MH_BUNDLE, MH_BUNDLE) and 46 (MH_DSYM, MH_DSYM). That matters because Loading is not vacuous downstream: 45 of the loaded objects run through Merge order, recorded in the same words on #728, #674 and #787. These three Mach-O changes complement rather than replace each other; the intended order is cle 728, then cle 674, then cle 787, and each closes a case the others leave standing. Measured on one stratified sample of 1,191 objects, one variable at a time, each build differing only in which cle worktree the editable install resolves to:
The two bundle residuals are each exactly what the other change repairs: #728 leaves 3 fat bundles at #787 is disjoint from both. It accepts #727 and #780 edit the same twenty lines of that chain, so whichever of these lands first, those two want the same rebase treatment. Caveat on #674: its base is four months behind #728's, so its residual is not strictly comparable to a run at #728's base; the two failure classes above are nonetheless distinct and each was reproduced against its own head. Note on the cle baseline named above. |
|
THIS MESSAGE WAS GENERATED BY AN AUTOMATED PROCESS Both import cle
ld = cle.Loader(path, auto_load_libs=False)
m = ld.main_object
print(type(m).__name__, m.arch, hex(m.min_addr), hex(m.max_addr))
print([(s.name, hex(s.vaddr), hex(s.memsize)) for s in m.sections])
print([(s.name, hex(s.rebased_addr)) for s in m.symbols])Before — the filetype is refused, so nothing is loaded: angr/cle masterAfter — both objects load, with their sections and symbols: with this change |
ce23051 to
56adbd2
Compare
MH_OBJECT was refused as an unsupported file type. The gate it fell through only chooses a base-address policy; every load command, segment and section path after it is already shared. A relocatable object is linked against 0 and carries one unnamed segment holding every section, so it needs the same treatment as a dylib loaded as the main object. Relocations are not applied, which matches how ELF ET_REL and COFF objects are already handled.
56adbd2 to
20ab5b3
Compare
The mach-o backend chose a base address with a chain of filetype tests whose else arm refused everything it had no rule for, so MH_BUNDLE, MH_KEXT_BUNDLE and MH_DSYM were all rejected as unsupported even though nothing after that block reads the filetype at all. Bundles and kexts want the base address dylibs already get, because their segment vaddrs are relative to 0 as well, so give the three of them one branch. MH_DSYM stays refused, but now says it carries debug information rather than inviting a support request that should not be granted. MH_OBJECT is not in that set: #787 gave it an arm of its own, because a relocatable object is never loaded as a dependency and so zeroes its base address unconditionally. The refusal named the filetype by number because IntEnum.__str__ has been int.__str__ since Python 3.11, and a filetype outside the enum escaped as a bare ValueError raised while formatting that same message. Parse the field into the enum once, where an unknown value becomes a CLECompatibilityError like every other malformed header this backend reports. A bundle binds its undefined symbols against the executable that dlopen-ed it, which both the symbol table and the chained fixup imports encode as library ordinal 255. That ordinal does not index imported_libraries, so resolving such a symbol raised IndexError out of Loader.__init__. Handle it beside the dynamic-lookup ordinal, which has the same shape. pic was computed with a bitwise and against MH_DYLIB on a field that holds an ordinal rather than a bitmask, so it was true for every filetype but MH_OBJECT, MH_BUNDLE and MH_DYLIB_STUB, including non-PIE executables that the loader then treated as rebasable. Test membership of the same zero-based filetypes instead, and let the executable branch stand on the filetype alone, which is what kept the wrong pic harmless there. tests/aarch64/IPwnKit.macho.kext has sat in the binaries repository unused since commit 2705d97 because it could not be loaded; it covers MH_KEXT_BUNDLE now. The other cases rewrite one header field of an existing fixture in a temporary copy.
THIS MESSAGE WAS GENERATED BY AN AUTOMATED PROCESS
Problem
A Mach-O
MH_OBJECTis refused outright. On the aarch64 and x86_64relocatable-object fixtures added by angr/binaries#193 the load ends here:
Nothing downstream sees the file at all — no sections, no symbols, no arch.
Root cause
The gate that raises only chooses a base-address policy; every load command,
segment and section path after it is already shared with the filetypes that do
load. A relocatable object is linked against 0 and carries one unnamed segment
holding every section, so its situation is the same as a dylib loaded as the
main object, which that same gate already admits.
Fix
Admit
MH_OBJECTon the dylib branch of that gate. Relocations aredeliberately not applied, so an intra-object call still reads as a branch to
itself; that matches how ELF
ET_RELand COFF objects are already handledhere, rather than being new behaviour.
Testing
tests/test_macho.py::test_relocatable_objectloads both fixtures and assertsthe sections and symbols; on master it fails with the
CLECompatibilityErrorabove. After the change the aarch64 object maps[0x0:0x1e7]and the x86_64 one[0x0:0x1c7], each with__textfollowed by__bssand the four symbols_keccak_init,_keccak_absorb,_keccak_squeezeand_state.Needs those fixtures.
These three Mach-O changes complement rather than replace each other; the
intended order is cle 728, then cle 674, then cle 787, and each closes a case
the others leave standing.
Validation: #787 (comment)
session: sharpen