mirror of
https://github.com/lukaszraczylo/go-obfuscation.git
synced 2026-10-14 05:48:22 +00:00
v0.0.2
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user