8000 Dart code obfuscation is impossible with reflective approach · Issue #208 · google/reflectable.dart · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Dart code obfuscation is impossible with reflective approach #208

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

Open
k-paxian opened this issue Apr 20, 2020 · 4 comments
Open

Dart code obfuscation is impossible with reflective approach #208

k-paxian opened this issue Apr 20, 2020 · 4 comments

Comments

@k-paxian
Copy link

Dart code obfuscation is impossible with reflective approach, shouldn't it to be considered to be added to a list of known limitations?

After doing that on Flutter project
extra-gen-snapshot-options=--obfuscate

OR theoretically is it possible to re-run reflectable generator after obfuscation?

@eernstg
Copy link
Collaborator
eernstg commented Apr 20, 2020

The (non-flutter) Dart tools do not recognize the option --obfuscate, and the documentation does not provide enough information to determine what it does. This linked page says that the build aot call in <FlutterRoot>/packages/flutter_tools/bin/xcode_backend.sh should be modified, but said file does not contain 'aot' (nor, of course, anything like 'build aot').

So I'll use this issue to keep track of the fact that we don't support the use of --obfuscate with Flutter, and then we may later determine whether or not it can be supported.

@2ZeroSix
Copy link

I assume it doesn't support dart2js/aot with minification as well.

It seems that Mockito had similar issue and that's how they managed to solve it:

https://github.com/dart-lang/mockito/blob 8000 /928566acaed994de85d8b8899fa53e7a0770895e/lib/src/invocation_matcher.dart#L122-L127

  // This will give is a mangled symbol in dart2js/aot with minification
  // enabled, but it's safe to assume very few people will use the invocation
  // matcher in a production test anyway due to noSuchMethod.
  static String _symbolToString(Symbol symbol) {
    return symbol.toString().split('"')[1];
  }

@gbaccetta
Copy link

is flutter --obfuscate still not supported ?

@eernstg
Copy link
Collaborator
eernstg commented Jan 15, 2025

No, unfortunately, nothing has happened in this area.

It is not obvious how it could be done. For example, reflective invocation of a member foo occurs by invoking a function literal (dynamic instance) => instance.foo which yields a function object which is subsequently called (passing type arguments, if any, and value arguments).

If you can obtain a guarantee that obfuscation/minification will transform the name foo into some other identifier (say, a7), and if this is true for all member names spelled foo in your program then it would be possible to transform the generated code. For instance, the function literal (instance) => instance.foo which is used to tear off a foo method which may then subsequently be invoked could be transformed into (instance) => instance.a7. However, I don't think it is guaranteed that every name foo is transformed into the same obfuscated/minified name, in which case it can never work to tear off those members using the same expression.

On the other hand, if you can create your program without obfuscation/minification, including *.reflectable.dart which contains all the generated code from the reflectable code generator then it should be possible to minify/obfuscate the entire program using any tool which will minify/obfuscate whole programs as a separate (manual) step.

If it works on general Dart code then it should also work on generated Dart code—there's nothing magical about the code that the reflectable code generator generates.

So do you have access to a stand-alone minifier/obfuscator, rather than using flutter --obfuscate? That might do it.

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

No branches or pull requests

4 participants
0