@ -19,21 +19,21 @@ func abiNamePatch(path string) (string, error) {
}
find := ` return unsafe.String(n.DataChecked(1+i, "non-empty string"), l) `
replace := ` return _ realName (unsafe.String(n.DataChecked(1+i, "non-empty string"), l))`
replace := ` return _ originalNames (unsafe.String(n.DataChecked(1+i, "non-empty string"), l))`
str := strings . Replace ( string ( data ) , find , replace , 1 )
realname := `
//go:linkname _ realName
func _ realName ( name string ) string
originalNames := `
//go:linkname _ originalNames
func _ originalNames ( name string ) string
`
return str + realname , nil
return str + originalNames , nil
}
var reflectPatchFile = ""
// reflectMainPrePatch adds the initial empty name mapping and _ realName implementation
// reflectMainPrePatch adds the initial empty name mapping and _ originalNames implementation
// to a file in the main package. The name mapping will be populated later after
// analyzing the main package, since we need to know all obfuscated names that need mapping.
// We split this into pre/post steps so that all variable names in the generated code
@ -59,21 +59,21 @@ func reflectMainPrePatch(path string) ([]byte, error) {
// reflectMainPostPatch populates the name mapping with the final obfuscated->real name
// mappings after all packages have been analyzed.
func reflectMainPostPatch ( file [ ] byte , lpkg * listedPackage , pkg pkgCache ) [ ] byte {
obfVarName := hashWithPackage ( lpkg , "_ re alNamePairs")
name Map := fmt . Sprintf ( "%s = [][2]string{" , obfVarName )
obfVarName := hashWithPackage ( lpkg , "_ origin alNamePairs")
name Pairs := fmt . Appendf ( nil , "%s = [][2]string{" , obfVarName )
var b strings . Builder
keys := slices . SortedFunc ( maps . Keys ( pkg . ReflectObjectNames ) , func ( a , b string ) int {
if c := cmp . Compare ( len ( a ) , len ( b ) ) ; c != 0 {
return c
}
return cmp . Compare ( a , b )
} )
namePairsFilled := bytes . Clone ( namePairs )
for _ , obf := range keys {
b. WriteString ( fmt . Sprintf ( "{%q, %q}," , obf , pkg . ReflectObjectNames [ obf ] ) )
namePairsFilled = fmt . Appendf ( namePairsFilled , "{%q, %q}," , obf , pkg . ReflectObjectNames [ obf ] )
}
return bytes . Replace ( file , [ ] byte ( nameMap ) , [ ] byte ( nameMap + b . String ( ) ) , 1 )
return bytes . Replace ( file , namePairs , namePairsFilled , 1 )
}
//go:embed reflect_abi_code.go