Skip to content

In-memory Dwarf Execution - #2

Open
sfc-gh-rwincey wants to merge 6 commits into
pwardle:mainfrom
sfc-gh-rwincey:dwarf_exec
Open

In-memory Dwarf Execution#2
sfc-gh-rwincey wants to merge 6 commits into
pwardle:mainfrom
sfc-gh-rwincey:dwarf_exec

Conversation

@sfc-gh-rwincey

Copy link
Copy Markdown

Proof of concept for loading and executing Mach-O executables (MH_EXECUTE) entirely from memory, analogous to what ulexecve does for ELF binaries on Linux.

This extends the existing ReflectiveLoader (which handles dylibs/bundles) to also support standalone executables.

- Patched ImageLoaderMachO to skip __PAGEZERO in assignSegmentAddresses,
  mapSegments vm_copy, and mapSegments segProtect
- Removed MH_EXECUTE rejection in instantiateFromMemory
- Added custom_dlopen_executable_from_memory() and custom_dlget_entry() APIs
- Implemented doApplyChainedFixupsManual() for UNSIGN_TOLERANT mode:
  supports DYLD_CHAINED_PTR_64_OFFSET, DYLD_CHAINED_PTR_64, and ARM64E formats
- Uses resolve() for proper two-level namespace symbol resolution
- PoC_exec: test harness with forked/in-process modes, fat binary extraction
- Tested: custom binaries (with/without chained fixups), Homebrew binaries (jq)
- Fix PAC instruction detection masks for BRAA/BRAB/BLRAA/BLRAB (Group 4):
  mask was clearing the distinguishing bit, causing zero matches
- Fix PAC detection for BLRAAZ/BLRABZ (Group 3): mask preserved BL flag,
  preventing BLR auth-Z variants from matching
- Fix BL flag extraction: was checking bit 25 (always 1 in branch-register
  encoding group) instead of bit 21 (actual BR vs BLR discriminator)
- Fix ARM64E chained fixup chain walk: next field is at bits 51-61 (shift
  by 51), not bits 52-62 (shift by 52). The off-by-one caused the first
  fixup to compute next=1024 instead of 1, skipping all remaining entries
  in __auth_got/__got

Tested: whoami, id, ls, ps, uname, hostname, echo — all arm64e system
binaries now load and execute correctly from memory
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant