From 985fa5ae14ccfc727f9fa3f50c1eaa02c2a7a27d Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Mon, 12 Aug 2024 12:47:09 +0200 Subject: [PATCH] Improved segment load --- src/os/mac/macho/MachO.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/os/mac/macho/MachO.go b/src/os/mac/macho/MachO.go index d4fc05b..41b47ce 100644 --- a/src/os/mac/macho/MachO.go +++ b/src/os/mac/macho/MachO.go @@ -52,8 +52,9 @@ func (m *MachO) Write(writer io.Writer) { InitProt: 0, }) - codeStart := 32 + m.Header.SizeCommands - codeEnd := uint64(codeStart) + uint64(len(m.Code)) + codeStart := uint64(32 + m.Header.SizeCommands) + codeLength := uint64(len(m.Code)) + codeEnd := codeStart + codeLength dataPadding := elf.Padding(codeEnd, 4096) dataStart := codeEnd + dataPadding @@ -61,13 +62,13 @@ func (m *MachO) Write(writer io.Writer) { LoadCommand: LcSegment64, Length: 0x48, Name: [16]byte{'_', '_', 'T', 'E', 'X', 'T'}, - Address: config.BaseAddress, - SizeInMemory: codeEnd, + Address: config.BaseAddress + codeStart, + SizeInMemory: codeLength, Offset: 0, - SizeInFile: codeEnd, + SizeInFile: codeLength, NumSections: 0, Flag: 0, - MaxProt: ProtReadable | ProtWritable | ProtExecutable, + MaxProt: ProtReadable | ProtExecutable, InitProt: ProtReadable | ProtExecutable, })