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,
MicroArchitecture: 3 | 0x80000000,
Type: TypeExecute,
NumCommands: 4,
SizeCommands: 72*3 + 184,
NumCommands: 5,
SizeCommands: 72*4 + 184,
Flags: FlagNoUndefs,
Reserved: 0,
},
@ -53,19 +53,32 @@ func (m *MachO) Write(writer io.Writer) {
})
codePadding := common.Padding(32+m.Header.SizeCommands, config.Align)
codeLength := uint64(len(m.Code))
codeEnd := config.CodeOffset + codeLength
codeEnd := uint64(config.CodeOffset + len(m.Code))
dataPadding := common.Padding(codeEnd, config.Align)
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{
LoadCommand: LcSegment64,
Length: 72,
Name: [16]byte{'_', '_', 'T', 'E', 'X', 'T'},
Address: config.BaseAddress + config.CodeOffset,
SizeInMemory: codeLength,
SizeInMemory: uint64(len(m.Code)),
Offset: config.CodeOffset,
SizeInFile: codeLength,
SizeInFile: uint64(len(m.Code)),
NumSections: 0,
Flag: 0,
MaxProt: ProtReadable | ProtExecutable,