This is the 19th day of my participation in the August More Text Challenge

Code confusion

The code of Flutter is confused

Obfuscation of the FLUTTER code is obfuscation of the DART code. Code obfuscation is the process of modifying application binaries to make them harder for people to understand. Obfuscation hides function and class names in compiled Dart code, making it difficult for an attacker to reverse-engineer your proprietary application.

Practice of Flutter code obfuscation

Flutter version is less than 1.16

Android

Add the following line to the < ProjectRoot > / android/gradle. Properties:

extra-gen-snapshot-options=--obfuscate
Copy the code

For information about obfuscating Android hosts, see Enabling Proguard in “Preparing to Publish Android Apps.”

iOS

  1. Modify thebuild aotcall

Add the following flags to the build aot call in the /packages/ Flutter_tools /bin/xcode_backend.sh file:

${extra_gen_snapshot_options_or_none}
Copy the code

Define this flag as follows:

local extra_gen_snapshot_options_or_none=""
if [[ -n "$EXTRA_GEN_SNAPSHOT_OPTIONS" ]]; then
  extra_gen_snapshot_options_or_none="--extra-gen-snapshot-options=$EXTRA_GEN_SNAPSHOT_OPTIONS"
fi
Copy the code

Modify thexcode_backend.shwhenRemember whenbuild aotAdd “\” to the first line of the.

2. Modify the Release configuration in < ProjectRoot > / ios/Flutter/the xcconfig, add the following line:

EXTRA_GEN_SNAPSHOT_OPTIONS=--obfuscate
Copy the code

Flutter 1.16.2 or later

To obfuscate applications, build distributions using a combination of the –obfuscate flag and the — split-Debug-info flag.

The –split-debug-info flag specifies the directory in which Flutter can output debug files. This command generates a symbol graph. Currently supports apk, appbundle, ios and ios framework targets. (The Master and Dev channels support MacOS and AAR.) Such as:

flutter build apk --obfuscate --split-debug-info=/<project-name>/<directory>
Copy the code

After obfuscating the binary, save the symbol file. You will need this file if you want to unscramble the stack trace later.

Please note that,--split-debug-infoThe logo can also be used alone. In fact, it can significantly reduce code size. For more information about application size, seeMeasure the size of the application.

Read the confused stack trace

To debug a stack trace created by an obfuscated application, use the following steps to make it easy to read:

  1. Find the matching symbol file. For example, crashes from Android ARM64 devices will be requiredapp.android-arm64.symbols.
  2. toflutter symbolizeCommands provide stack traces (stored in files) and symbol files. Such as:
flutter symbolize -i <stack trace file> -d /out/android/app.android-arm64.symbols
Copy the code

⚠ ️ warning

Here are a few things to keep in mind when writing applications that will end up as confusing binaries.

  • Code that depends on matching a specific class, function, or library name will fail. For example, the following pairsExpect()The call to binary will not work in an obfuscated binary:
expect(foo.runtimeType.toString(), equals('Foo'))
Copy the code

Reference links:

Obfuscating Dart code

flutter wiki