Decompile my_app.dart.js

1,141 views
Skip to first unread message

Pascal Myrta

unread,
Nov 30, 2014, 4:11:44 AM11/30/14
to w...@dartlang.org
Hello everybody

Once you have compiled dart code into JavaScript with dart2js tool, is there a possibility to do the opposite operation, from compiled JS to Dart original code?

More specifically: let's say you have created an app, and you want to put online only the my_app.dart.js file (not the my_app.dart). Is there a mean that someone decompile the code to obtain the original my_app.dart?

You understand that I am expecting to protect my original my_app.dart online.

IceMage

unread,
Dec 1, 2014, 12:02:51 PM12/1/14
to w...@dartlang.org
There is this (https://code.google.com/p/jsparser/) but I dunno how good it is. Maybe Florian himself or someone else can tell you how good it is.
To be honest though, I doubt it would be helpful to try to "decompile" in this way since generating JS through pub build creates highly optimised code at the cost of readability with something of an assumption I guess that (typically) you  shouldn't need to read the file anyway...though of course there is option not to minify JS output to make it a bit more readable. What I'm getting at is, if this "JS Parser" can generate error-free Dart code from a typical .dart.js file the Dart code would possibly be overly verbose due to optimisations, I think.
Addendum: God damn it. For some reason when I last tried to reply to this from mail it created a new topic >.>

Günter Zöchbauer

unread,
Dec 1, 2014, 12:17:49 PM12/1/14
to w...@dartlang.org
When you run `pub build` from the command line, minification is enabled by default and minification makes the code less readable because short but meaningless names are assigned to identifiers.

- tree-shaking removes code that is not referenced from the JavaScript output 
- minification shortens identifiers

I guess it is possible to generate a runnable Dart program from the generated JavaScript, but it will be very hard to read and will not resemble the original Dart code much.

Bob Nystrom

unread,
Dec 1, 2014, 12:57:57 PM12/1/14
to web
On Sun, Nov 30, 2014 at 1:11 AM, Pascal Myrta <tibicina...@gmail.com> wrote:
Hello everybody

Once you have compiled dart code into JavaScript with dart2js tool, is there a possibility to do the opposite operation, from compiled JS to Dart original code?

No. In general, the compiled output contains less information than the original Dart source code. Tree-shaking eliminates much of the unused code, and minification discards identifiers.
 
You understand that I am expecting to protect my original my_app.dart online.

While compilation means you can't get back to the original Dart source code, the compiled JavaScript does still implement the same behavior as your original program. If you're trying to obscure how your program works from malicious users, compiling it to JavaScript will not do that. It makes it harder to understand, but not impossible. If you truly need to protect your algorithms, you need to ensure the user does not have access to the code locally at all.

Cheers,

- bob
Reply all
Reply to author
Forward
0 new messages