Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I best obfuscate HTML/Javascript/WebGL code? [closed]

I have some HTML/Javascript/WebGL code that I would like to obfuscate. My code consists of one .html file, several .js files and GLSL code embedded in the .html file.

I have found the tool UglifyJS that I can use to obfuscate the .js files one by one. I have also found the tool GLSL Compiler that I can use to obfuscate the GLSL code.

There is two problems with this approach:

  1. It is partly manual. I have to cut and paste and edit.
  2. Since the GLSL Compiler do not obfuscate .js it can not change the name of uniform variables in the GLSL. Also if I paste one file containing a function into UglifyJS it will not change the name of the function since it does not know where it is called from.

Is there any tool or combination of tools that would give me a less manual and more complete obfuscation?

like image 340
Andy Avatar asked Oct 26 '25 10:10

Andy


1 Answers

For JS I have always loved this script:

http://jsutility.pjoneil.net

I have multiple files of JS, running this as a batch script it combines all the files into a single file, obfuscates them, compacts them and then compresses them. It works great. I have got over 2mb of javascript to compress down to around 350kb using this plus its free!

Quick example, download code from website and then create a wsf file with roughly this.

<job id="ObfuscateJavascript">

    <script language="VBScript">
        Function WSHInputBox(Message, Title, Value)
            WSHInputBox = InputBox(Message, Title, Value)
        End Function
    </script>

    <reference object="Scripting.FileSystemObject" />
    <script language="JScript" src="JSUtility_BatchCodeC.js" />
    <script language="JScript">

        var vbOKOnly = 0;
        var vbInformation = 64;
        var title = "What Project are you building for?";
        var prompt = "Enter a file name:";
        var WshShell = WScript.CreateObject("WScript.Shell");
        var result = WSHInputBox(prompt, title, "FileName");

        if (typeof result != "undefined") {
            InputFiles.push("File1.js");
            InputFiles.push("File2.js");
            InputFiles.push("File3.js");

            // Obfuscation options
            Obfuscate.Options = {
                DefinedGlobalVars: true, 
                ObjectMembers: false, 
                StringVariables: true, 
                MinimumStringLength: 12, 
                RestructureIfStmts: true
            };

            // Compaction options
            Compact.Options = {
                AddMissingSemicolons: true, 
                LeaveNewLines: false, 
                LeaveNewLineAndComment: false, 
                RemoveUnnecessarySemicolons: true
            };

            // Compression options
            Compress.Options = {
                ISO8859Compatable: true, 
                UTF8Compatible: true
            };

            // File output
            OutputFile = result + ".min.js";

            // Operations to apply to javascript
            Operations = {
                Validate: false, 
                Obfuscate: true, 
                Compact: true, 
                Compress: true, 
                StopOnWarning: false
            };

            JSUtilityBatch();
        }

    </script>
</job>

Then I create a bat file with this:

Script WSFFileNameYouUsed.wsf
pause
like image 184
AtheistP3ace Avatar answered Oct 28 '25 22:10

AtheistP3ace