symbol_inject: add step to codesign Mach-O binaries.
The adhoc codesign of Macho-O binaries is broken after symbol injection. MacOS refuses to run the binaries unless we sign them again. Bug: 241493489 Test: build and run simpleperf_ndk64 on MacOS Change-Id: I25ef5c6413bd97e1bfa0a4ec5d04eaefb6fea54c
This commit is contained in:
@@ -94,4 +94,13 @@ func main() {
|
|||||||
os.Remove(*output)
|
os.Remove(*output)
|
||||||
os.Exit(5)
|
os.Exit(5)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if file.IsMachoFile {
|
||||||
|
err = symbol_inject.CodeSignMachoFile(*output)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintln(os.Stderr, err.Error())
|
||||||
|
os.Remove(*output)
|
||||||
|
os.Exit(6)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -18,6 +18,7 @@ import (
|
|||||||
"debug/macho"
|
"debug/macho"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"os/exec"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
@@ -40,7 +41,7 @@ func extractMachoSymbols(machoFile *macho.File) (*File, error) {
|
|||||||
return symbols[i].Value < symbols[j].Value
|
return symbols[i].Value < symbols[j].Value
|
||||||
})
|
})
|
||||||
|
|
||||||
file := &File{}
|
file := &File{IsMachoFile: true}
|
||||||
|
|
||||||
for _, section := range machoFile.Sections {
|
for _, section := range machoFile.Sections {
|
||||||
file.Sections = append(file.Sections, &Section{
|
file.Sections = append(file.Sections, &Section{
|
||||||
@@ -95,3 +96,8 @@ func dumpMachoSymbols(r io.ReaderAt) error {
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func CodeSignMachoFile(path string) error {
|
||||||
|
cmd := exec.Command("/usr/bin/codesign", "--force", "-s", "-", path)
|
||||||
|
return cmd.Run()
|
||||||
|
}
|
||||||
|
@@ -161,9 +161,10 @@ func findSymbol(file *File, symbolName string) (uint64, uint64, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type File struct {
|
type File struct {
|
||||||
r io.ReaderAt
|
r io.ReaderAt
|
||||||
Symbols []*Symbol
|
Symbols []*Symbol
|
||||||
Sections []*Section
|
Sections []*Section
|
||||||
|
IsMachoFile bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type Symbol struct {
|
type Symbol struct {
|
||||||
|
Reference in New Issue
Block a user