Skip to content

Conversation

@jonahwilliams
Copy link
Contributor

@jonahwilliams jonahwilliams commented Feb 10, 2020

Description

Previously Dart obfuscation was supported in a somewhat ad-hoc fashion via extra-gen-snapshot-args for Android and tool source code modification for iOS (see https://github.com/flutter/flutter/wiki/Obfuscating-Dart-Code )

This PR adds "complete" support by wiring it up through the existing build flags and infrastructure in a similar manner to the split-debug-info flag.

#50043

My understanding of the obfuscation map is that it would only be necessary if the --obfuscate flag is not combined with the --split-debug-info option. In that case, we might be able to simplify this a bit by constraining obfuscate to require split-debug-info. The user still only has to track one auxiliary file and we in turn simplify the supported configuration. @zanderso for thoughts on command line usability.

@fluttergithubbot fluttergithubbot added tool Affects the "flutter" command-line tool. See also t: labels. work in progress; do not review labels Feb 10, 2020
@zanderso
Copy link
Member

How would deobfuscating work? Also flutter symbolize?

@jonahwilliams
Copy link
Contributor Author

Discussed offline a bit: the obfuscation does not apply to the debug symbols, so the workflow is the same for --split-debug-info with or without --obfuscate. The only time the obfuscation map is needed is if you are not using split-debug-info - but there is basically no reason not to use them together. If you're going to put in the extra work to track an additional file, might as well make your code size smaller too

@jonahwilliams jonahwilliams changed the title [WIP][flutter_tools] wire up complete support for Dart obfuscation [flutter_tools] wire up complete support for Dart obfuscation Feb 21, 2020
@jonahwilliams jonahwilliams marked this pull request as ready for review February 21, 2020 17:14
@fluttergithubbot fluttergithubbot added the c: contributor-productivity Team-specific productivity, code health, technical debt. label Feb 21, 2020
Copy link
Contributor

@dnfield dnfield left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

argParser.addFlag(FlutterOptions.kDartObfuscationOption,
help: 'In a release build, this flag removes identifiers and replaces them '
'with randomized values for the purposes of source code obfuscation. The '
'mapping between the values and the original identifiers is stored the '
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is stored the -> is stored in the

help: 'In a release build, this flag removes identifiers and replaces them '
'with randomized values for the purposes of source code obfuscation. The '
'mapping between the values and the original identifiers is stored the '
'symbol map created with the "--split-debug-info" option. For an app built '
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens when someone passes --obfuscate but not --split-debug-info?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't output the obfuscation map. I think this is okay for now, since we don't actually have a tool to de-obfuscate a stack trace, only flutter symbols. I can document that this should always be combined with split-debug-info

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it should always be paired with --split-debug-info then it would be good to give an error otherwise, or fill in a default value for it, I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated so that obfuscate requires split-debug-info

@jonahwilliams
Copy link
Contributor Author

@zanderso did you have any more comments on this?

Copy link
Member

@zanderso zanderso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@jonahwilliams jonahwilliams merged commit 08d079f into flutter:master Feb 27, 2020
@jonahwilliams jonahwilliams deleted the add_obfuscation_support branch February 27, 2020 16:58
@brunovsiqueira
Copy link

How can I use this feature? I think I'm not getting it correctly.

@MohsinN
Copy link

MohsinN commented Mar 20, 2020

@jonahwilliams Can you please share steps to execute this feature? No updated has been posted on guide.

@jonahwilliams
Copy link
Contributor Author

I've filled an issue to update the documentation: flutter/website#3827

I also tried to make the --obfuscate option documentation fairly complete:

flutter build apk -h:

  --split-debug-info=</project-name/v1.2.3/>    In a release build, this flag reduces application size by storing Dart program
                                                  symbols in a separate file on the host rather than in the application. The value
                                                  of the flag should be a directory where program symbol files can be stored for
                                                  later use. These symbol files contain the information needed to symbolize Dart
                                                  stack traces. For an app built with this flag, the 'flutter symbolize' command
                                                  with the right program symbol file is required to obtain a human readable stack
                                                  trace.

    --[no-]obfuscate                              In a release build, this flag removes identifiers and replaces them with
                                                  randomized values for the purposes of source code obfuscation. This flag must
                                                  always be combined with "--split-debug-info" option, the mapping between the
                                                  values and the original identifiers is stored in the symbol map created in the
                                                  specified directory. For an app built with this flag, the 'flutter symbolize'
                                                  command with the right program symbol file is required to obtain a human readable
                                                  stack trace.
                                                  
                                                  Because all identifiers are renamed, methods like Object.runtimeType,
                                                  Type.toString, Enum.toString, Stacktrace.toString, Symbol.toString (for constant
                                                  symbols or those generated by runtime system) will return obfuscated results. Any
                                                  code or tests that rely on exact names will break.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 1, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

c: contributor-productivity Team-specific productivity, code health, technical debt. tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants