This PR provides a draft implementation for the proposal described at #849.
The transformer.transformGoFile method contains some code that computes the obfuscated identifier for a given types.Object.
This patch does essentially two things:
it refactors the transformer.transformGoFile method, lifting the code segment mentioned above into an independently callable method named transformer.obfuscateObjectName;
it adds a new subcommand garble map that uses the newly added method transformer.obfuscateObjectName to compute the output described at #849.
The refactoring step is necessary to ensure the garble map command stays in sync with the algorithm used by transformGoFile.
I have not added a test yet because I am not familiar with the scripting language and it is also not entirely clear to me what the best approach would be for testing the new command.
The implementation of the new command resembles vaguely that of the reverse subcommand:
it lists all packages provided on the command line, including transitive dependencies;
for each listed and obfuscated package:
it configures a transformer instance, parses and typechecks package files, loads the package cache entry and computes field-to-struct mappings;
it visits the full syntax tree looking for identifiers, skipping statements because local identifiers are not relevant here;
for each identifier it encounters:
it uses type info to resolve the identifier to its types.Object;
it discards invalid identifiers, objects from other packages and duplicates;
it calls transformer.obfuscatedObjectName on the current object;
it uses golang.org/x/tools/go/types/objectpath to compute a path for the current object;
if the current object is obfuscated and has a path, it is recorded onto the result map.
This PR provides a draft implementation for the proposal described at #849.
The
transformer.transformGoFile
method contains some code that computes the obfuscated identifier for a giventypes.Object
.This patch does essentially two things:
transformer.transformGoFile
method, lifting the code segment mentioned above into an independently callable method namedtransformer.obfuscateObjectName
;garble map
that uses the newly added methodtransformer.obfuscateObjectName
to compute the output described at #849.The refactoring step is necessary to ensure the
garble map
command stays in sync with the algorithm used bytransformGoFile
.I have not added a test yet because I am not familiar with the scripting language and it is also not entirely clear to me what the best approach would be for testing the new command.
The implementation of the new command resembles vaguely that of the
reverse
subcommand:types.Object
;transformer.obfuscatedObjectName
on the current object;golang.org/x/tools/go/types/objectpath
to compute a path for the current object;