Skip to content

Commit

Permalink
WIP: revised reflection handling
Browse files Browse the repository at this point in the history
Instead of excluding specific names from obfuscation "all" names are now  obfuscated.

For reflected names, a mapping to the original name is injected in internal/abi to resolve them correctly.

Fixes #884, and probably most issues caused by selectively not obfuscating certain names.
  • Loading branch information
lu4p committed Nov 23, 2024
1 parent b0d3563 commit 08fb9b4
Show file tree
Hide file tree
Showing 10 changed files with 756 additions and 264 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/garble
/test
/bincmp_output/
debug
2 changes: 1 addition & 1 deletion AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ Daniel Martí <mvdan@mvdan.cc>
Emmanuel Chee-zaram Okeke <ecokeke21@gmail.com>
NHAS <jordanatararimu@gmail.com>
Nicholas Jones <me@nicholasjon.es>
Paul Scheduikat <lu4p@pm.me>
Zachary Wasserman <zachwass2000@gmail.com>
lu4p <lu4p@pm.me>
pagran <pagran@protonmail.com>
shellhazard <shellhazard@tutanota.com>
xuannv <xuan11290@gmail.com>
24 changes: 9 additions & 15 deletions hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func encodeBuildIDHash(h [sha256.Size]byte) string {
return base64.RawURLEncoding.EncodeToString(h[:buildIDHashLength])
}

func alterToolVersion(tool string, args []string) error {
func alterToolVersion(tool string, args []string, pre bool) error {
cmd := exec.Command(args[0], args[1:]...)
out, err := cmd.Output()
if err != nil {
Expand Down Expand Up @@ -83,6 +83,10 @@ func alterToolVersion(tool string, args []string) error {
// The slashes let us imitate a full binary build ID, but we assume that
// the other hashes such as the action ID are not necessary, since the
// only reader here is cmd/go and it only consumes the content ID.
if pre {
fmt.Printf("%s +pre-garble buildID=_/_/_/%s\n", line, encodeBuildIDHash(contentID))
return nil
}
fmt.Printf("%s +garble buildID=_/_/_/%s\n", line, encodeBuildIDHash(contentID))
return nil
}
Expand Down Expand Up @@ -223,15 +227,7 @@ func entryOffKey() uint32 {
return runtimeHashWithCustomSalt([]byte("entryOffKey"))
}

func hashWithPackage(tf *transformer, pkg *listedPackage, name string) string {

// In some places it is not appropriate to access the transformer
if tf != nil {
// If the package is marked as "in-use" by reflection, the private structures are not obfuscated, so dont return them as a hash. Fixes #882
if _, ok := tf.curPkgCache.ReflectObjects[pkg.ImportPath+"."+name]; ok {
return name
}
}
func hashWithPackage(pkg *listedPackage, name string) string {
// If the user provided us with an obfuscation seed,
// we use that with the package import path directly..
// Otherwise, we use GarbleActionID as a fallback salt.
Expand Down Expand Up @@ -412,11 +408,9 @@ func hashWithCustomSalt(salt []byte, name string) string {
// Turn "afoo" into "Afoo".
b64Name[0] = toUpper(b64Name[0])
}
} else {
if isUpper(b64Name[0]) {
// Turn "Afoo" into "afoo".
b64Name[0] = toLower(b64Name[0])
}
} else if isUpper(b64Name[0]) {
// Turn "Afoo" into "afoo".
b64Name[0] = toLower(b64Name[0])
}
}
return string(b64Name)
Expand Down
Loading

0 comments on commit 08fb9b4

Please sign in to comment.