Skip to content

Knowing which class it is after obfuscation (willing to PR) #52317

@fzyzcjy

Description

@fzyzcjy

When implementing flutter/flutter#126302, and in many other scenarios, it is common that I want to output the class name. If I simply do thatObject.runtimeType.toString(), after obfuscation, it will become a "random" string. So the question is, how can I print a representation of a class, such that I can still know what it is after obfuscation (probably with demangling)?

Naive thoughts:

  1. Is it possible to demangle the obfuscated class name currently, just like demangling the stack traces nowadays?
  2. Or, can we create a brand new representation, say, "thatObject.runtimeType.getRepresentationId()", and have a table to know which "representation id" is equivalent to which class? (IIRC dart type representation already has a integer id; but this "representation id" may or may not be the same as that)

EDIT: Corresponding discussions in Discord - https://discord.com/channels/608014603317936148/608022273152122881/1105304953829986424


EDIT: Simple demo

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    final message = 'MyApp=$MyApp Scaffold=$Scaffold';
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(),
        body: TextButton(
          onPressed: () => throw Exception(message),
          child: Text('throw Exception($message)'),
        ),
      ),
    );
  }
}

Run it:

bug flutter build apk --obfuscate --split-debug-info=whatever-path

The message looks like MyApp=xo Scaffold=ex. The proposal of this issue is that, by using debug symbols (or whatever), try to convert xo to MyApp and ex to Scaffold.

Naive attempt using flutter symbolize:

(base) ➜  bug flutter symbolize -d ./build/split-debug-info/app.android-arm.symbols
xo
xo
ex
ex
^C% 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions