Fixed MacOS executables

This commit is contained in:
Eduard Urbach 2024-08-14 19:35:03 +02:00
parent b1b83201eb
commit 35eeb420e1
Signed by: akyoto
GPG Key ID: C874F672B1AF20C0

View File

@ -24,8 +24,8 @@ func New(code []byte, data []byte) *MachO {
Architecture: CPU_X86_64, Architecture: CPU_X86_64,
MicroArchitecture: 3 | 0x80000000, MicroArchitecture: 3 | 0x80000000,
Type: TypeExecute, Type: TypeExecute,
NumCommands: 4, NumCommands: 5,
SizeCommands: 72*3 + 184, SizeCommands: 72*4 + 184,
Flags: FlagNoUndefs, Flags: FlagNoUndefs,
Reserved: 0, Reserved: 0,
}, },
@ -53,19 +53,32 @@ func (m *MachO) Write(writer io.Writer) {
}) })
codePadding := common.Padding(32+m.Header.SizeCommands, config.Align) codePadding := common.Padding(32+m.Header.SizeCommands, config.Align)
codeLength := uint64(len(m.Code)) codeEnd := uint64(config.CodeOffset + len(m.Code))
codeEnd := config.CodeOffset + codeLength
dataPadding := common.Padding(codeEnd, config.Align) dataPadding := common.Padding(codeEnd, config.Align)
dataStart := codeEnd + dataPadding dataStart := codeEnd + dataPadding
binary.Write(writer, binary.LittleEndian, &Segment64{
LoadCommand: LcSegment64,
Length: 72,
Name: [16]byte{'_', '_', 'H', 'E', 'A', 'D'},
Address: config.BaseAddress,
SizeInMemory: config.CodeOffset,
Offset: 0,
SizeInFile: config.CodeOffset,
NumSections: 0,
Flag: 0,
MaxProt: ProtReadable | ProtExecutable,
InitProt: ProtReadable | ProtExecutable,
})
binary.Write(writer, binary.LittleEndian, &Segment64{ binary.Write(writer, binary.LittleEndian, &Segment64{
LoadCommand: LcSegment64, LoadCommand: LcSegment64,
Length: 72, Length: 72,
Name: [16]byte{'_', '_', 'T', 'E', 'X', 'T'}, Name: [16]byte{'_', '_', 'T', 'E', 'X', 'T'},
Address: config.BaseAddress + config.CodeOffset, Address: config.BaseAddress + config.CodeOffset,
SizeInMemory: codeLength, SizeInMemory: uint64(len(m.Code)),
Offset: config.CodeOffset, Offset: config.CodeOffset,
SizeInFile: codeLength, SizeInFile: uint64(len(m.Code)),
NumSections: 0, NumSections: 0,
Flag: 0, Flag: 0,
MaxProt: ProtReadable | ProtExecutable, MaxProt: ProtReadable | ProtExecutable,