### Build React Project (Shell) Source: https://github.com/javascript-obfuscator/javascript-obfuscator-ui/blob/master/README.md Commands to install dependencies, update semantic UI, and start the development server for the React frontend of the JavaScript Obfuscator UI. Assumes Yarn or npm is installed. ```sh $ yarn # or npm install $ npm run updatesemantic $ npm run webpack:dev ``` -------------------------------- ### Initialize and Start Ad Blocker Detection Source: https://github.com/javascript-obfuscator/javascript-obfuscator-ui/blob/master/templates/index.html Initializes a component responsible for detecting ad or script blocking software. It sets up necessary elements, loads external scripts, and initiates the detection process. If ad blockers are detected, it may trigger specific actions. ```javascript ob.prototype.start=function(){pb(this)}; function pb(a){qb(a);Za(a.o,a.u,3,!1,function(){a:{var b=a.j;var c=p.btoa(b);if(c=p[c]){try{var d=Sa(p.atob(c))}catch(e){b=!1;break a}b=b===Na(d,1)}else b=!1}b?Z(a ``` -------------------------------- ### Run Express Server (JavaScript) Source: https://github.com/javascript-obfuscator/javascript-obfuscator-ui/blob/master/README.md Node.js command to start the Express server for the JavaScript Obfuscator UI. This server handles requests and serves the obfuscated JavaScript code. It runs on http://localhost:3000/. ```javascript node server.js ``` -------------------------------- ### Manage Obfuscation State with Redux Reducer Source: https://context7.com/javascript-obfuscator/javascript-obfuscator-ui/llms.txt This code illustrates the state structure and action flow for managing the JavaScript obfuscation process within a Redux store. It defines the initial state for code, output, source maps, and processing status, along with the expected state transitions for pending, fulfilled, and rejected obfuscation actions. A `mapStateToProps` example shows how to access this state in a component. ```javascript // State structure in Redux store const codeState = { code: '// Paste your JavaScript code here\nfunction hi() {\n console.log("Hello World!");\n}\nhi();', outputFileName: 'obfuscated.js', obfuscatedCode: '', sourceMap: '', obfuscating: false, // true during processing obfuscated: false, // true when complete error: false // true on failure }; // Action flow for obfuscation: // 1. OBFUSCATE_PENDING: obfuscating=true, clears previous results // 2. OBFUSCATE_FULFILLED: obfuscating=false, obfuscated=true, sets results // 3. OBFUSCATE_REJECTED: obfuscating=false, error=true, clears results // Access in component: const mapStateToProps = (state) => ({ sourceCode: state.code.code, result: state.code.obfuscatedCode, isProcessing: state.code.obfuscating, hasError: state.code.error }); ``` -------------------------------- ### Configure Source Map Generation for Obfuscated JavaScript Source: https://context7.com/javascript-obfuscator/javascript-obfuscator-ui/llms.txt This section details how to configure source map generation for debugging obfuscated JavaScript code using Redux actions. It covers enabling source maps, setting their output mode ('inline' or 'separate'), and specifying base URLs or filenames for separate source maps. Examples illustrate the output format for both modes. ```javascript import { toggleOption, setSourceMapMode, setSourceMapBaseUrl, setSourceMapFileName } from './App/actions'; import * as types from './App/constants/ActionTypes'; // Enable source map generation dispatch(toggleOption(types.TOGGLE_SOURCEMAP)); // Set source map mode: 'inline' or 'separate' dispatch(setSourceMapMode('separate')); // Configure separate source map options dispatch(setSourceMapBaseUrl('https://cdn.example.com/maps')); dispatch(setSourceMapFileName('app.min.js.map')); // Example obfuscated output with inline source map: // var _0x1234=function(){...}; // //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLi4u // Example with separate source map: // var _0x1234=function(){...}; // //# sourceMappingURL=https://cdn.example.com/maps/app.min.js.map // Download source map separately using: // downloadFile({ // mime: 'application/octet-stream', // filename: 'app.min.js.map', // contents: state.code.sourceMap // }) ``` -------------------------------- ### Load Obfuscation Options Preset Source: https://context7.com/javascript-obfuscator/javascript-obfuscator-ui/llms.txt Loads predefined obfuscation configurations from the JavaScript Obfuscator library using Redux actions. This simplifies setting up common obfuscation profiles. The function fetches presets from a worker, which in turn calls `JavaScriptObfuscator.getOptionsByPreset(preset)`. ```javascript import { setOptionsPreset } from './App/actions'; // Available presets: // - 'default': Balanced obfuscation with minimal performance impact // - 'low-obfuscation': Light obfuscation, better performance // - 'medium-obfuscation': Moderate obfuscation and performance // - 'high-obfuscation': Maximum obfuscation, slower performance dispatch(setOptionsPreset('high-obfuscation')); // This fetches the preset from the worker and updates Redux state // The worker calls JavaScriptObfuscator.getOptionsByPreset(preset) // Returns options like: // { // compact: true, // controlFlowFlattening: true, // controlFlowFlatteningThreshold: 1, // deadCodeInjection: true, // deadCodeInjectionThreshold: 1, // stringArray: true, // stringArrayThreshold: 1, // selfDefending: true // } ``` -------------------------------- ### Google Analytics gtag.js Configuration Source: https://github.com/javascript-obfuscator/javascript-obfuscator-ui/blob/master/templates/index.html This snippet configures Google Analytics using the gtag.js library. It initializes the dataLayer and sets up event tracking for a specific tracking ID. Ensure gtag.js is loaded before this script for it to function correctly. ```javascript window.dataLayer = window.dataLayer || []; function gtag() { dataLayer.push(arguments); } gtag('js', new Date()); gtag('config', 'UA-116652505-1'); ``` -------------------------------- ### Create and Load Script Asynchronously Source: https://github.com/javascript-obfuscator/javascript-obfuscator-ui/blob/master/templates/index.html Asynchronously loads an external script into the document's head. It handles success and error callbacks, including retry logic for script loading. This function is essential for dynamic script injection. ```javascript function Za(a,b,c,d,e,f){try{var g=a.g,h=Ya(g);h.async=!0;Xa(h,b);g.head.appendChild(h);h.addEventListener("load",function(){e();d&&g.head.removeChild(h)});h.addEventListener("error",function(){0>11&1023;return 0===a?536870912:a}; ``` -------------------------------- ### Download Utility for Obfuscated Code and Source Maps Source: https://context7.com/javascript-obfuscator/javascript-obfuscator-ui/llms.txt A utility function that creates and triggers browser downloads for obfuscated JavaScript code or source maps. It uses the Blob API to generate downloadable files with specified MIME types and filenames. ```javascript import { downloadFile } from './App/util/downloadFile'; // Download obfuscated JavaScript const codeData = { mime: 'application/javascript', filename: 'obfuscated.js', contents: 'var _0x1234=function(){console.log("obfuscated")};_0x1234();' }; downloadFile(codeData); // Download source map const sourceMapData = { mime: 'application/octet-stream', filename: 'obfuscated.js.map', contents: '{\"version\":3,\"sources\":[\"original.js\"],\"names\":[],\"mappings\":\"AAAA\"}' }; downloadFile(sourceMapData); // The function creates a temporary blob URL and triggers a download // The file is automatically removed from memory after download ``` -------------------------------- ### Manage Domain Lock for Obfuscated Code Source: https://context7.com/javascript-obfuscator/javascript-obfuscator-ui/llms.txt Restricts obfuscated code execution to specific domains for enhanced security using Redux actions. It allows adding and removing domains from an allowed list and setting a redirect URL for unauthorized access attempts. The obfuscated code verifies `window.location.hostname` against the whitelist. ```javascript import { addDomainLock, removeDomainLock, setDomainLockRedirectUrl } from './App/actions'; // Add allowed domain dispatch(addDomainLock('example.com')); dispatch(addDomainLock('subdomain.example.com')); // Remove domain from whitelist dispatch(removeDomainLock('example.com')); // Set redirect URL for unauthorized domains dispatch(setDomainLockRedirectUrl('https://example.com/unauthorized')); // Current state structure: // state.options.domainLock = ['example.com', 'subdomain.example.com'] // state.options.domainLockRedirectUrl = 'https://example.com/unauthorized' // The obfuscated code will check window.location.hostname // and redirect if not in the whitelist ``` -------------------------------- ### Create HTML Element Source: https://github.com/javascript-obfuscator/javascript-obfuscator-ui/blob/master/templates/index.html Creates an HTML element of a specified tag name. It handles content type differences, particularly for 'application/xhtml+xml', by converting the tag name to lowercase. This ensures proper element creation across different XML-based content types. ```javascript function Va(a,b){b=String(b);"application/xhtml+xml"===a.contentType&&(b=b.toLowerCase());return a.createElement(b)} ``` -------------------------------- ### Web Worker Message Handling for Obfuscation and Presets Source: https://context7.com/javascript-obfuscator/javascript-obfuscator-ui/llms.txt Handles obfuscation requests and preset retrieval within a Web Worker to maintain UI responsiveness. It processes messages for code obfuscation with specific options and for retrieving obfuscation settings based on predefined presets. ```javascript // From App/workers/obfuscation-worker.js // This worker processes two types of events: // 1. Obfuscate code event const obfuscateMessage = { type: 'OBFUSCATOR_WORKER_OBFUSCATE_EVENT', payload: { code: 'function test() { console.log("Hello"); }', options: { compact: true, stringArray: true, stringArrayThreshold: 0.75 } } }; // Worker returns: // { // code: "obfuscated code here", // sourceMap: "source map if enabled" // } // 2. Get options by preset event const presetMessage = { type: 'OBFUSCATOR_WORKER_GET_OPTIONS_BY_PRESET_EVENT', payload: { optionsPreset: 'high-obfuscation' } }; // Worker returns preset options object // { compact: true, selfDefending: true, ... } ``` -------------------------------- ### Object and Array Manipulation Utilities Source: https://github.com/javascript-obfuscator/javascript-obfuscator-ui/blob/master/templates/index.html This JavaScript code provides utility functions for object and array manipulation, including checking if a variable is a plain object (`N`) and creating frozen arrays (`O`). It also defines a function `Q` for creating instances with a constructor and optional arguments, and `R` for handling default arguments and error checking. ```javascript var M={}; function N(a){return null!==a&&"object"===typeof a&&!Array.isArray(a)&&a.constructor===Object} var O,ya=[]; I(ya,39); O=Object.freeze(ya); var P; function Q(a,b){P=b;a=new a(b);P=void 0;return a} function R(a,b,c){null==a&&(a=P);P=void 0;if(null==a){var d=96;c?(a=[c],d|=512):a=[];b&&(d=d&-2095105|(b&1023)<<11)}else{if(!Array.isArray(a))throw Error();d=H(a);if(d&64)return a;d|=64;if(c&&(d|=512,c!==a[0]))throw Error();a:{c=a;var e=c.length;if(e){var f=e-1,g ``` -------------------------------- ### Set Numeric Thresholds and String Configuration Source: https://context7.com/javascript-obfuscator/javascript-obfuscator-ui/llms.txt Updates numeric thresholds and string configuration for obfuscation options using Redux actions. This allows fine-grained control over probabilities and settings like string array encoding and identifier naming strategies. It also includes setting the target environment. ```javascript import { setStringArrayThreshold, setControlFlowFlatteningThreshold, setDeadCodeInjectionThreshold, setSeed, setStringArrayEncoding, setIdentifierNamesGenerator, setTarget } from './App/actions'; // Set string array threshold (0 to 1) // Controls probability a string literal is placed in array dispatch(setStringArrayThreshold(0.8)); // Set control flow flattening threshold (0 to 1) dispatch(setControlFlowFlatteningThreshold(0.5)); // Set dead code injection threshold (0 to 1) dispatch(setDeadCodeInjectionThreshold(0.3)); // Set obfuscation seed for reproducible results dispatch(setSeed(12345)); // Set string array encoding methods dispatch(setStringArrayEncoding(['base64', 'rc4'])); // Set identifier naming strategy dispatch(setIdentifierNamesGenerator('hexadecimal')); // Options: 'dictionary', 'hexadecimal', 'mangled', 'mangled-shuffled' // Set target environment dispatch(setTarget('browser')); // Options: 'browser', 'browser-no-eval', 'node' ``` -------------------------------- ### Dispatch Obfuscation Action using Redux Source: https://context7.com/javascript-obfuscator/javascript-obfuscator-ui/llms.txt Dispatches the obfuscation request to a Web Worker and manages the asynchronous obfuscation process using Redux promise middleware. It takes the JavaScript code and an options object as input and updates the Redux state with the obfuscated code, source map, and loading status. ```javascript import { obfuscateCode } from './App/actions'; // Example usage in a React component const code = "\nfunction calculateTotal(price, quantity) {\n return price * quantity;\n}\nconsole.log(calculateTotal(10, 5));\n"; const options = { compact: true, controlFlowFlattening: true, controlFlowFlatteningThreshold: 0.75, deadCodeInjection: true, deadCodeInjectionThreshold: 0.4, stringArray: true, stringArrayThreshold: 0.75, stringArrayEncoding: ['base64'], splitStrings: true, splitStringsChunkLength: 10 }; // Dispatch the obfuscation action dispatch(obfuscateCode(code, options)); // The result will be available in Redux state at: // state.code.obfuscatedCode (the obfuscated JavaScript) // state.code.sourceMap (optional source map if enabled) // state.code.obfuscating (boolean for loading state) // state.code.obfuscated (boolean for completion state) ``` -------------------------------- ### JavaScript Obfuscation Core Logic (Internal) Source: https://github.com/javascript-obfuscator/javascript-obfuscator-ui/blob/master/templates/index.html This complex JavaScript code appears to be part of an internal obfuscation engine or library. It defines utility functions for object manipulation, property definition, and type checking, likely used during the obfuscation process. It sets up environment checks and polyfills for older JavaScript environments. ```javascript var ba="function"==typeof Object.defineProperties?Object.defineProperty:function(a,b,c){if(a==Array.prototype||a==Object.prototype)return a;a[b]=c.value;return a}; function ea(a){a=["object"==typeof globalThis&&globalThis,a,"object"==typeof window&&window,"object"==typeof self&&self,"object"==typeof global&&global];for(var b=0;b { const options = store.getState().options; delete options.hydrated; // Remove transient properties saveState({ options }); }); // The saved state structure: // localStorage.getItem('state') // {"options":{"compact":true,"stringArray":true,"stringArrayThreshold":0.75}} ``` -------------------------------- ### Reset Obfuscation Options to Default Source: https://context7.com/javascript-obfuscator/javascript-obfuscator-ui/llms.txt This snippet shows how to reset all JavaScript obfuscation options to their default values using a `resetOptions` action. This action not only reverts configuration settings like reserved names and string arrays but also applies the default preset, clears custom configurations, resets thresholds, and disables advanced features such as self-defending and dead code injection. ```javascript import { resetOptions } from './App/actions'; // Reset all options to initial state dispatch(resetOptions()); // This action: // 1. Resets all options to initialState values // 2. Automatically applies 'default' preset // 3. Clears any custom configurations: // - domainLock array // - reservedNames array // - reservedStrings array // - forceTransformStrings array // - identifiersDictionary array // 4. Resets all thresholds to defaults: // - stringArrayThreshold: 0.75 // - controlFlowFlatteningThreshold: 0.75 // - deadCodeInjectionThreshold: 0.4 // 5. Disables advanced features: // - selfDefending: false // - debugProtection: false // - deadCodeInjection: false ``` -------------------------------- ### Create HTML Element with Random ID Source: https://github.com/javascript-obfuscator/javascript-obfuscator-ui/blob/master/templates/index.html Creates a generic HTML DIV element with a randomly generated ID. This function is a helper for creating unique elements that can be styled or manipulated later. ```javascript function X(a){a=Va(a.l.g,"DIV");a.className=Ua();return a} ``` -------------------------------- ### Generate Random String for IDs Source: https://github.com/javascript-obfuscator/javascript-obfuscator-ui/blob/master/templates/index.html Generates a random alphanumeric string used for unique element IDs. This function utilizes Math.random() and toString(36) to create a base-36 encoded string, ensuring uniqueness for DOM elements. ```javascript function Ua(){return Math.floor(2147483648*Math.random()).toString(36)+Math.abs(Math.floor(2147483648*Math.random())^Date.now()).toString(36)} ``` -------------------------------- ### Inject Trusted Types Script URL Source: https://github.com/javascript-obfuscator/javascript-obfuscator-ui/blob/master/templates/index.html Creates a TrustedResourceUrl object from a given string, using a Trusted Types policy if available. This is a security measure to prevent DOM-based XSS attacks by ensuring that script URLs are validated. ```javascript function nb(a){a=Na(a,4)||"";if(void 0===U){var b=null;var c=p.trustedTypes;if(c&&c.createPolicy){try{b=c.createPolicy("goog#html",{createHTML:q,createScript:q,createScriptURL:q})}catch(d){p.console&&p.console.error(d.message)}U=b}else U=b}a=(b=U)?b.createScriptURL(a):a;return new V(a,Ta)} ``` -------------------------------- ### Toggle Individual Obfuscation Features Source: https://context7.com/javascript-obfuscator/javascript-obfuscator-ui/llms.txt Enables or disables individual obfuscation features through Redux actions by toggling their boolean state. These actions may have cascading effects on other options. For instance, disabling 'compact' might force 'selfDefending' to false, and enabling 'selfDefending' forces 'compact' to true. ```javascript import { toggleOption } from './App/actions'; import * as types from './App/constants/ActionTypes'; // Toggle compact code dispatch(toggleOption(types.TOGGLE_COMPACT_CODE)); // Toggle self-defending code dispatch(toggleOption(types.TOGGLE_SELF_DEFENDING)); // Toggle string array obfuscation dispatch(toggleOption(types.TOGGLE_STRING_ARRAY)); // Toggle control flow flattening dispatch(toggleOption(types.TOGGLE_CONTROL_FLOW_FLATTENING)); // Toggle dead code injection dispatch(toggleOption(types.TOGGLE_DEAD_CODE_INJECTION)); // Toggle debug protection dispatch(toggleOption(types.TOGGLE_DEBUG_PROTECTION)); // Each toggle inverts the current boolean state // Some toggles have cascading effects: // - Disabling compact forces selfDefending to false // - Enabling selfDefending forces compact to true // - Disabling stringArray disables related encoding options ``` -------------------------------- ### Update Source Code in Redux State Source: https://context7.com/javascript-obfuscator/javascript-obfuscator-ui/llms.txt Updates the source code in the Redux state and clears previous obfuscation results. This action is crucial for reflecting user edits and preparing for a new obfuscation process. It impacts multiple state properties related to the code and its obfuscation status. ```javascript import { updateCode } from './App/actions'; // Update source code const newCode = ` function greet(name) { return "Hello, " + name + "!"; } greet("World"); `; dispatch(updateCode(newCode)); // This action: // 1. Updates state.code.code with the new source // 2. Clears state.code.obfuscatedCode // 3. Clears state.code.sourceMap // 4. Sets state.code.obfuscated to false // 5. Sets state.code.error to false ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.