This commit is contained in:
2026-05-31 19:48:56 +01:00
parent 7f32417736
commit 68f8904282
39 changed files with 4519 additions and 5 deletions
+57
View File
@@ -0,0 +1,57 @@
//go:build darwin
package pclntab
import (
"debug/macho"
"fmt"
)
func readPclntabSection(binaryPath string) ([]byte, error) {
f, err := macho.Open(binaryPath)
if err != nil {
return nil, fmt.Errorf("pclntab: failed to open Mach-O: %w", err)
}
defer f.Close()
sectionNames := []string{
"__gopclntab",
"__pclntab",
}
for _, section := range f.Sections {
for _, name := range sectionNames {
if section.Name == name {
data, err := section.Data()
if err != nil {
return nil, fmt.Errorf("pclntab: failed to read section %s: %w", name, err)
}
buf := make([]byte, len(data))
copy(buf, data)
return buf, nil
}
}
}
for _, section := range f.Sections {
data, err := section.Data()
if err != nil {
continue
}
if len(data) >= 8 {
for _, magic := range pclntabMagics {
if len(data) >= len(magic) && bytesEqual(data[:len(magic)], magic) {
buf := make([]byte, len(data))
copy(buf, data)
return buf, nil
}
}
}
}
return nil, nil
}
func WriteCorruptedPclntab(binaryPath string, corrupted []byte, outputPath string) error {
return fmt.Errorf("pclntab: offline Mach-O patching not yet implemented; use runtime corruption instead")
}