This commit is contained in:
2026-05-31 11:23:07 +01:00
parent 1d51b29b92
commit 5ea458fb06
18 changed files with 1367 additions and 220 deletions
+22
View File
@@ -5,6 +5,7 @@ import (
"crypto/sha256"
"debug/elf"
"debug/macho"
"debug/pe"
"encoding/binary"
"fmt"
"os"
@@ -97,6 +98,8 @@ func hashTextSection(path string) ([32]byte, error) {
return hashTextELF(path)
case "darwin":
return hashTextMacho(path)
case "windows":
return hashTextPE(path)
default:
return hashWholeFile(path)
}
@@ -139,6 +142,25 @@ func hashTextMacho(path string) ([32]byte, error) {
return hashWholeFile(path)
}
func hashTextPE(path string) ([32]byte, error) {
f, err := pe.Open(path)
if err != nil {
return [32]byte{}, err
}
defer f.Close()
for _, section := range f.Sections {
if section.Name == ".text" {
data, err := section.Data()
if err != nil {
return [32]byte{}, err
}
return sha256.Sum256(data), nil
}
}
return hashWholeFile(path)
}
func hashWholeFile(path string) ([32]byte, error) {
data, err := os.ReadFile(path)
if err != nil {