Jump to content
Sign in to follow this  
DavidRM

Packing Observation

Recommended Posts

Not really a *bug*...but it looks like case statements get compiled to if-then-else statements that aren't "packed". That is, each case statement condition is kept on a single line, not combined with the line ahead of it.

Is that by design?

-David

Share this post


Link to post
Share on other sites

For deployment, you can also add extra complexity against preying eyes by using Google's closure-compiler.

  1. Download the latest binary from: https://github.com/google/closure-compiler/wiki/Binary-Downloads
  2. Uncheck "Embed Javascripg into HTML file" in Project options
  3. Select both Code packing and Code obfuscation
  4. Build
  5. Run closure-compiler on the generated main.js:
java -jar closure-compiler.jar --js main.js --js_output_file mainp.js

And then replace main.js with mainp.js. The compiler will give some warnings about unreachable code but they are safe to ignore.

Share this post


Link to post
Share on other sites

I wonder if the not-packing is related to ASM blocks? I have no idea.

I can scroll through my packed-and-obfuscated JS file and see blocks like this:

image.png.83e42ed19ed6daa60c328e582d08e72e.png

I think that's from RTL code, not mine. This is from mine:

image.png.155d111c846b2fe9ddc0fd649c374d8d.png

I don't know that it makes a lot of difference, but there it is.

-David

Share this post


Link to post
Share on other sites

Now I can reproduce the problem. If you compare against string values, they are split on separate lines:

  case Trunc(Now) of
    1: WriteLn('One');
    2: WriteLn('Two');
    3: WriteLn('One');
    else WriteLn('Something else');
  end;

  case IntToStr(Trunc(Now)) of
    '1': WriteLn('One');
    '2': WriteLn('Two');
    '3': WriteLn('One');
    else WriteLn('Something else');
  end;

  case IntToStr(Trunc(Now)) of
    "1": WriteLn('One');
    "2": WriteLn('Two');
    "3": WriteLn('One');
    else WriteLn('Something else');
  end;

That first one is compressed on one line. Other ones are split on multiple lines.

Share this post


Link to post
Share on other sites
On 1/5/2019 at 3:59 AM, jarto said:

For deployment, you can also add extra complexity against preying eyes by using Google's closure-compiler.

  1. Download the latest binary from: https://github.com/google/closure-compiler/wiki/Binary-Downloads
  2. Uncheck "Embed Javascripg into HTML file" in Project options
  3. Select both Code packing and Code obfuscation
  4. Build
  5. Run closure-compiler on the generated main.js:

java -jar closure-compiler.jar --js main.js --js_output_file mainp.js

And then replace main.js with mainp.js. The compiler will give some warnings about unreachable code but they are safe to ignore.

@jarto That does add a bit more obfuscation, yup yup. Thanks! 😃 -David

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×