Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft implementation: new subcommand for computing obfuscation map #850

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

fbbdev
Copy link

@fbbdev fbbdev commented May 13, 2024

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:

  1. it refactors the transformer.transformGoFile method, lifting the code segment mentioned above into an independently callable method named transformer.obfuscateObjectName;
  2. it adds a new subcommand garble map that uses the newly added method transformer.obfuscateObjectName to compute the output described at Feature proposal: new subcommand for computing obfuscation map #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.
  • finally, it converts the result map to JSON.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant