mirror of
https://github.com/burrowers/garble.git
synced 2025-12-24 12:58:05 +08:00
This way we can edit it as regular Go code, with the help of an LSP, and we can also test and benchmark it.
51 lines
1.3 KiB
Go
51 lines
1.3 KiB
Go
package main
|
|
|
|
// The "name" internal/abi passes to this function doesn't have to be a simple "someName"
|
|
// it can also be for function names:
|
|
// "*pkgName.FuncName" (obfuscated)
|
|
// or for structs the entire struct definition:
|
|
// "*struct { AQ45rr68K string; ipq5aQSIqN string; hNfiW5O5LVq struct { gPTbGR00hu string } }"
|
|
//
|
|
// Therefore all obfuscated names which occur within name need to be replaced with their "real" equivalents.
|
|
//
|
|
// The code below does a more efficient version of:
|
|
//
|
|
// func _realName(name string) string {
|
|
// for obfName, real := range _nameMap {
|
|
// name = strings.ReplaceAll(name, obfName, real)
|
|
// }
|
|
//
|
|
// return name
|
|
// }
|
|
//
|
|
// The linknames below are only turned on when the code is injected,
|
|
// so that we can test and benchmark this code normally.
|
|
|
|
// Injected code below this line.
|
|
|
|
//disabledgo:linkname _realName internal/abi._realName
|
|
func _realName(name string) string {
|
|
for i := 0; i < len(name); {
|
|
remLen := len(name[i:])
|
|
found := false
|
|
for obfName, real := range _nameMap {
|
|
keyLen := len(obfName)
|
|
if keyLen > remLen {
|
|
continue
|
|
}
|
|
if name[i:i+keyLen] == obfName {
|
|
name = name[:i] + real + name[i+keyLen:]
|
|
found = true
|
|
i += len(real)
|
|
break
|
|
}
|
|
}
|
|
if !found {
|
|
i++
|
|
}
|
|
}
|
|
return name
|
|
}
|
|
|
|
var _nameMap = map[string]string{}
|