javascript-obfuscator / javascript-obfuscator

A powerful obfuscator for JavaScript and Node.js
https://obfuscator.io
BSD 2-Clause "Simplified" License
13.74k stars 1.51k forks source link

Flutter main.dart.js compilation results in runtime exception - Uncaught TypeError: Instance of '_0x25ae98': type '_0x25ae98' is not a subtype of type 'JavaScriptObject' #1150

Open adam-ah opened 1 year ago

adam-ah commented 1 year ago

Flutter can compile the Dart code into a browser compatible JS - main.dart.js

The JS does some preliminary checks before starts running. One of the checks is this:

    _generalAsCheckImplementation(object) {
      var t1, testRti = this;
      if (object == null) {
        t1 = A.isNullable(testRti);
        if (t1)
          return object;
      } else if (testRti._is(object))
        return object;
      A._failedAsCheck(object, testRti);
    },

The new obfuscated types do not pass this test, which results in a runtime Uncaught TypeError: Instance of '_0x25ae98': type '_0x25ae98' is not a subtype of type 'JavaScriptObject' exception.

Expected Behavior

The original code works fine, the obfuscated should work too

Current Behavior

As above

Steps to Reproduce

  1. Compile any small Flutter app into web flutter build web --profile
  2. Obfuscate the .\build\web\main.dart.js file using the "Default" options
  3. Replace the original content with the obfuscated
  4. Serve the project from a default webserver (e.g., python3 -m http.server 8000)

Your Environment

Stack trace

main.dart.js:1 

       Uncaught TypeError: Instance of '_0x25ae98': type '_0x25ae98' is not a subtype of type 'JavaScriptObject'
    at Object.wrapException (main.dart.js:1:943220)
    at Object._failedAsCheck (main.dart.js:1:995356)
    at _0x5608de._generalAsCheckImplementation [as _as] (main.dart.js:1:994996)
    at _0x5608de._installSpecializedAsCheck (main.dart.js:1:992911)
    at _0x40a044.prepareEngineInitializer$0 (main.dart.js:1:2207010)
    at main.dart.js:1:1208674
    at _0x27822e.$protected (main.dart.js:1:1045365)
    at _0x27822e.call$2 (main.dart.js:1:3179002)
    at Object._asyncStartSync (main.dart.js:1:1044061)
    at Object.webOnlyWarmupEngine (main.dart.js:1:1208778)

Minimal working example that will help to reproduce issue

Attached the unobfuscated minimal Dart JS sample

main.dart.js.txt

softworkz commented 1 year ago

Possibly a duplicate of (https://github.com/javascript-obfuscator/javascript-obfuscator/issues/1093). See this comment: https://github.com/javascript-obfuscator/javascript-obfuscator/issues/1093#issuecomment-1613908105