Skip to content

Commit

Permalink
fix: replace func BuildVersion with BuildVersions because MachOs can …
Browse files Browse the repository at this point in the history
…have multiple LC_BUILD_VERSIONs
  • Loading branch information
blacktop committed Apr 28, 2024
1 parent d839502 commit b2dcde3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
14 changes: 7 additions & 7 deletions export.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,8 @@ func (f *File) CodeSign(config *codesign.Config) error {
if config.RuntimeVersion == 0 {
if cs.CodeDirectories[0].Header.Runtime != 0 {
config.RuntimeVersion = cs.CodeDirectories[0].Header.Runtime
} else if bv := f.BuildVersion(); bv != nil {
config.RuntimeVersion = bv.Sdk
} else if bvs := f.BuildVersions(); len(bvs) > 0 {
config.RuntimeVersion = bvs[0].Sdk
} else if vm := f.VersionMin(); vm != nil {
config.RuntimeVersion = vm.Sdk
}
Expand All @@ -298,10 +298,10 @@ func (f *File) CodeSign(config *codesign.Config) error {
return fmt.Errorf("you must supply an ID")
}
// infer runtime version from build or min version load commands if necessary
if config.Flags & ctypes.RUNTIME != 0 {
if config.Flags&ctypes.RUNTIME != 0 {
if config.RuntimeVersion == 0 {
if bv := f.BuildVersion(); bv != nil {
config.RuntimeVersion = bv.Sdk
if bvs := f.BuildVersions(); len(bvs) > 0 {
config.RuntimeVersion = bvs[0].Sdk
} else if vm := f.VersionMin(); vm != nil {
config.RuntimeVersion = vm.Sdk
}
Expand All @@ -325,14 +325,14 @@ func (f *File) CodeSign(config *codesign.Config) error {
config.CodeSize = uint64(cs.Offset)

// cache __LINKEDIT data (up to but not including any existing code signature) for saving later
ledata := make([]byte, uint64(cs.Offset) - linkedit.Offset)
ledata := make([]byte, uint64(cs.Offset)-linkedit.Offset)
if _, err := f.cr.ReadAtAddr(ledata, linkedit.Addr); err != nil {
return fmt.Errorf("failed to read __LINKEDIT data: %v", err)
}
f.ledata = bytes.NewBuffer(ledata)

// update __LINKEDIT segment sizes
linkedit.Filesz = pageAlign(uint64(len(ledata)) + codesign.EstimateCodeSignatureSize(config), 0x4000)
linkedit.Filesz = pageAlign(uint64(len(ledata))+codesign.EstimateCodeSignatureSize(config), 0x4000)
linkedit.Memsz = pageAlign(linkedit.Filesz, 0x8000)
// update LC_CODE_SIGNATURE size
cs.Size = uint32((linkedit.Offset + linkedit.Filesz) - uint64(cs.Offset))
Expand Down
9 changes: 5 additions & 4 deletions file.go
Original file line number Diff line number Diff line change
Expand Up @@ -1750,14 +1750,15 @@ func (f *File) SourceVersion() *SourceVersion {
return nil
}

// BuildVersion returns the build version load command, or nil if no build version exists.
func (f *File) BuildVersion() *BuildVersion {
// BuildVersions returns the build version load commands as an array.
func (f *File) BuildVersions() []*BuildVersion {
var builds []*BuildVersion
for _, l := range f.Loads {
if s, ok := l.(*BuildVersion); ok {
return s
builds = append(builds, s)
}
}
return nil
return builds
}

// VersionMin returns the minimum-version load command, or nil if no minimum-version exists.
Expand Down
4 changes: 2 additions & 2 deletions types/objc/type_encoding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func Test_decodeType(t *testing.T) {
args: args{
encType: "^{OutterStruct=(InnerUnion=q{InnerStruct=ii})b1b2b10b1q}",
},
want: "struct OutterStruct { union InnerUnion { long long x0; struct InnerStruct { int x0; int x1; } x1; } x0; unsigned int x1 :1; unsigned int x2 :2; unsigned int x3 :10; unsigned int x4 :1; long long x5; } *",
want: "struct OutterStruct { union InnerUnion { long long x0; struct InnerStruct { int x0; int x1; } x1; } x0; unsigned int x1:1; unsigned int x2:2; unsigned int x3:10; unsigned int x4:1; long long x5; } *",
},
{
name: "Test array",
Expand All @@ -30,7 +30,7 @@ func Test_decodeType(t *testing.T) {
args: args{
encType: "b13",
},
want: "unsigned int x :13",
want: "unsigned int x:13",
},
{
name: "Test struct",
Expand Down

0 comments on commit b2dcde3

Please sign in to comment.