From 6e7b60f7bf1bb8ffd08b8ee476cad7946f02c301 Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Tue, 5 Aug 2025 15:53:22 +0200 Subject: [PATCH] Added build version information for Mac builds --- src/macho/BuildVersion.go | 13 +++++++++++++ src/macho/Constants.go | 4 ++-- src/macho/LoadCommand.go | 1 + src/macho/MachO.go | 26 ++++++++++++++++++-------- src/macho/Platform.go | 9 +++++++++ src/macho/Version.go | 6 ++++++ 6 files changed, 49 insertions(+), 10 deletions(-) create mode 100644 src/macho/BuildVersion.go create mode 100644 src/macho/Platform.go create mode 100644 src/macho/Version.go diff --git a/src/macho/BuildVersion.go b/src/macho/BuildVersion.go new file mode 100644 index 0000000..b5c17ce --- /dev/null +++ b/src/macho/BuildVersion.go @@ -0,0 +1,13 @@ +package macho + +const BuildVersionSize = 24 + +// BuildVersion is the structure of the LC_BUILD_VERSION load command. +type BuildVersion struct { + LoadCommand + Length uint32 + Platform Platform + MinOS uint32 + Sdk uint32 + NumTools uint32 +} \ No newline at end of file diff --git a/src/macho/Constants.go b/src/macho/Constants.go index a24abf6..5d5306d 100644 --- a/src/macho/Constants.go +++ b/src/macho/Constants.go @@ -2,7 +2,7 @@ package macho const ( BaseAddress = 0x1000000 - NumCommands = 7 - SizeCommands = Segment64Size*3 + Section64Size + DyldInfoCommandSize + MainSize + DylinkerCommandSize + len(LinkerString) + DylibCommandSize + len(LibSystemString) + NumCommands = 8 + SizeCommands = Segment64Size*3 + Section64Size + DyldInfoCommandSize + MainSize + BuildVersionSize + DylinkerCommandSize + len(LinkerString) + DylibCommandSize + len(LibSystemString) HeaderEnd = HeaderSize + SizeCommands ) \ No newline at end of file diff --git a/src/macho/LoadCommand.go b/src/macho/LoadCommand.go index 6b2f806..c2cf453 100644 --- a/src/macho/LoadCommand.go +++ b/src/macho/LoadCommand.go @@ -31,4 +31,5 @@ const ( LcEncryptionInfo64 LoadCommand = 0x2C LcVersionMinTvos LoadCommand = 0x2F LcVersionMinWatchos LoadCommand = 0x30 + LcBuildVersion LoadCommand = 0x32 ) \ No newline at end of file diff --git a/src/macho/MachO.go b/src/macho/MachO.go index 4ac3720..3470230 100644 --- a/src/macho/MachO.go +++ b/src/macho/MachO.go @@ -11,14 +11,15 @@ import ( // MachO is the executable format used on MacOS. type MachO struct { Header - PageZero Segment64 - CodeSegment Segment64 - CodeSection Section64 - DataSegment Segment64 - MainHeader Main - InfoHeader DyldInfoCommand - LinkerHeader DylinkerCommand - LibSystemHeader DylibCommand + PageZero Segment64 + CodeSegment Segment64 + CodeSection Section64 + DataSegment Segment64 + MainHeader Main + BuildVersionHeader BuildVersion + InfoHeader DyldInfoCommand + LinkerHeader DylinkerCommand + LibSystemHeader DylibCommand } // Write writes the Mach-O format to the given writer. @@ -92,6 +93,14 @@ func Write(writer io.WriteSeeker, build *config.Build, codeBytes []byte, dataByt EntryFileOffset: uint64(code.MemoryOffset), StackSize: 0, }, + BuildVersionHeader: BuildVersion{ + LoadCommand: LcBuildVersion, + Length: BuildVersionSize, + Platform: PlatformMacOS, + MinOS: Version(10, 7, 5), + Sdk: 0, + NumTools: 0, + }, InfoHeader: DyldInfoCommand{ LoadCommand: LcDyldInfoOnly, Length: DyldInfoCommandSize, @@ -114,6 +123,7 @@ func Write(writer io.WriteSeeker, build *config.Build, codeBytes []byte, dataByt binary.Write(writer, binary.LittleEndian, &m.CodeSection) binary.Write(writer, binary.LittleEndian, &m.DataSegment) binary.Write(writer, binary.LittleEndian, &m.MainHeader) + binary.Write(writer, binary.LittleEndian, &m.BuildVersionHeader) binary.Write(writer, binary.LittleEndian, &m.InfoHeader) binary.Write(writer, binary.LittleEndian, &m.LinkerHeader) writer.Write([]byte(LinkerString)) diff --git a/src/macho/Platform.go b/src/macho/Platform.go new file mode 100644 index 0000000..52b0458 --- /dev/null +++ b/src/macho/Platform.go @@ -0,0 +1,9 @@ +package macho + +type Platform uint32 + +const ( + PlatformInvalid Platform = iota + PlatformMacOS + PlatformIOS +) \ No newline at end of file diff --git a/src/macho/Version.go b/src/macho/Version.go new file mode 100644 index 0000000..6320d46 --- /dev/null +++ b/src/macho/Version.go @@ -0,0 +1,6 @@ +package macho + +// Version creates the version for the build version load command. +func Version(major uint32, minor uint32, patch uint32) uint32 { + return major<<24 | minor<<16 | patch<<8 +} \ No newline at end of file -- 2.51.2