diff --git a/reflect_abi_code.go b/reflect_abi_code.go index 7619bbb..dab25ec 100644 --- a/reflect_abi_code.go +++ b/reflect_abi_code.go @@ -25,12 +25,23 @@ package main //disabledgo:linkname _realName internal/abi._realName func _realName(name string) string { - for i := 0; i < len(name); { + if len(name) < minHashLength { + // The name is too short to be obfuscated. + return name + } + // We can stop once there aren't enough bytes to fit another obfuscated name. + for i := 0; i <= len(name)-minHashLength; { + switch name[i] { + case ' ', '.', '*', '{', '}', '[', ']': + // These characters never start an obfuscated name. + i++ + continue + } remLen := len(name[i:]) found := false for obfName, real := range _nameMap { keyLen := len(obfName) - if keyLen > remLen { + if remLen < keyLen { continue } if name[i:i+keyLen] == obfName { diff --git a/reflect_abi_patch.go b/reflect_abi_patch.go index 96d67fb..0856547 100644 --- a/reflect_abi_patch.go +++ b/reflect_abi_patch.go @@ -7,6 +7,7 @@ import ( "maps" "os" "slices" + "strconv" "strings" ) @@ -49,6 +50,8 @@ func reflectMainPrePatch(path string) ([]byte, error) { } _, code, _ := strings.Cut(reflectAbiCode, "// Injected code below this line.") code = strings.ReplaceAll(code, "//disabledgo:", "//go:") + // This constant is declared in our hash.go file. + code = strings.ReplaceAll(code, "minHashLength", strconv.Itoa(minHashLength)) return append(content, []byte(code)...), nil }