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, })