What is Obfuscator.io?
Obfuscator.io, powered by the open-source javascript-obfuscator npm package, is the most widely used JavaScript obfuscation tool in the world. Created by Timofey Kachalov, it provides a comprehensive set of code transformation options that can convert readable JavaScript into nearly impenetrable obfuscated output. The tool is available both as a web interface at obfuscator.io and as an npm package for integration into build pipelines.
Because of its popularity and open-source nature, understanding how to deobfuscate code processed by obfuscator.io is one of the most valuable skills for security researchers, malware analysts, and developers. This guide covers every major configuration option, explains the obfuscation technique behind each, and provides step-by-step deobfuscation approaches using AST transformations.
Configuration Options Explained
Obfuscator.io provides numerous configuration options. Understanding each option is key to recognizing and reversing its effects.
Identifier Generation
The identifierNamesGenerator option controls how variable and function names are transformed:
- hexadecimal: Names like _0x1a2b3c -- the most recognizable signature of obfuscator.io
- mangled: Short names like a, b, c -- similar to minification
- mangled-shuffled: Short names in non-sequential order
- dictionary: Custom dictionary-based names
1// Original
2function calculateTotal(price, quantity, tax) {
3 var subtotal = price * quantity;
4 var taxAmount = subtotal * tax;
5 return subtotal + taxAmount;
6}
7
8// hexadecimal identifiers
9function _0x1a2b(_0x3c4d, _0x5e6f, _0x7a8b) {
10 var _0x9c0d = _0x3c4d * _0x5e6f;
11 var _0xe1f2 = _0x9c0d * _0x7a8b;
12 return _0x9c0d + _0xe1f2;
13}
14
15// mangled identifiers
16function a(b, c, d) {
17 var e = b * c;
18 var f = e * d;
19 return e + f;
20}String Array
The stringArray option is the cornerstone of obfuscator.io's protection. When enabled, all string literals are extracted into a single array, and references throughout the code are replaced with function calls that retrieve strings by index.
1// Original
2console.log('Hello World');
3document.getElementById('myElement');
4
5// With stringArray enabled
6var _0x1234 = ['log', 'Hello\x20World',
7 'getElementById', 'myElement'];
8console[_0x1234[0]](_0x1234[1]);
9document[_0x1234[2]](_0x1234[3]);String Array Rotation
The rotateStringArray option adds a self-executing function that shuffles the string array at startup, making the original index positions invalid in the static source.
1// String array with rotation
2var _0xabcd = [
3 'Hello\x20World', 'log', 'getElementById',
4 'Done', 'textContent', 'myElement'
5];
6
7// Rotation IIFE - shuffles the array
8(function(_0xarr, _0xcount) {
9 var _0xrotate = function(_0xnum) {
10 while (--_0xnum) {
11 _0xarr['push'](_0xarr['shift']());
12 }
13 };
14 _0xrotate(++_0xcount);
15})(_0xabcd, 0xb3);
16
17// Accessor function
18var _0xget = function(_0xidx) {
19 return _0xabcd[_0xidx - 0x0];
20};
21
22// After rotation, indices no longer match
23// the original static positions
24console[_0xget(0x4)](_0xget(0x0));String Array Encoding
The stringArrayEncoding option adds an encoding layer on top of the string array:
- none: Strings stored as plaintext in the array
- base64: Strings are base64 encoded and decoded at access time
- rc4: Strings are encrypted with RC4 cipher using per-string keys
1// With base64 encoding
2var _0xget = function(_0xidx) {
3 var _0xval = _0xabcd[_0xidx];
4 // Base64 decode
5 return atob(_0xval);
6};
7
8// With RC4 encoding
9var _0xget = function(_0xidx, _0xkey) {
10 var _0xval = _0xabcd[_0xidx];
11 // RC4 decrypt with per-string key
12 if (_0xget['initialized'] === undefined) {
13 _0xget['rc4'] = function(_0xstr, _0xk) {
14 var s = [], j = 0, res = '';
15 for (var i = 0; i < 256; i++) {
16 s[i] = i;
17 }
18 for (var i = 0; i < 256; i++) {
19 j = (j + s[i] + _0xk.charCodeAt(
20 i % _0xk.length
21 )) % 256;
22 var temp = s[i];
23 s[i] = s[j];
24 s[j] = temp;
25 }
26 // ... RC4 decryption continues
27 return res;
28 };
29 _0xget['initialized'] = true;
30 }
31 return _0xget['rc4'](atob(_0xval), _0xkey);
32};Control Flow Flattening
The controlFlowFlattening option transforms the program's logical flow into a state machine controlled by a switch statement. This is one of the most impactful obfuscation techniques.
How It Works
1// Original code
2function processOrder(order) {
3 var validated = validateOrder(order);
4 if (!validated) {
5 return { error: 'Invalid order' };
6 }
7 var total = calculateTotal(order.items);
8 var discount = applyDiscount(total, order.coupon);
9 var finalPrice = total - discount;
10 return { success: true, price: finalPrice };
11}
12
13// After control flow flattening
14function processOrder(order) {
15 var _0xseq = '4|0|1|5|2|3'.split('|');
16 var _0xidx = 0;
17 var validated, total, discount, finalPrice;
18 while (true) {
19 switch (_0xseq[_0xidx++]) {
20 case '0':
21 if (!validated) {
22 return { error: 'Invalid order' };
23 }
24 continue;
25 case '1':
26 total = calculateTotal(order.items);
27 continue;
28 case '2':
29 finalPrice = total - discount;
30 continue;
31 case '3':
32 return { success: true, price: finalPrice };
33 case '4':
34 validated = validateOrder(order);
35 continue;
36 case '5':
37 discount = applyDiscount(
38 total, order.coupon
39 );
40 continue;
41 }
42 break;
43 }
44}Deobfuscation Strategy
To reverse control flow flattening:
- Identify the sequence string (e.g., '4|0|1|5|2|3')
- Split it to determine execution order
- Extract the code from each case in order
- Reconstruct the sequential code flow
- Remove the while/switch wrapper
1// AST transformation for CFF reversal
2traverse(ast, {
3 WhileStatement(path) {
4 var switchStmt = path.node.body.body[0];
5 if (!t.isSwitchStatement(switchStmt)) return;
6
7 // Find the sequence string
8 var seqStr = findSequenceString(path);
9 if (!seqStr) return;
10
11 var order = seqStr.split('|');
12 var cases = {};
13
14 // Map case values to their code blocks
15 switchStmt.cases.forEach(function(c) {
16 var caseVal = c.test.value;
17 cases[caseVal] = c.consequent.filter(
18 function(s) {
19 return !t.isContinueStatement(s);
20 }
21 );
22 });
23
24 // Rebuild in correct order
25 var rebuilt = [];
26 order.forEach(function(idx) {
27 rebuilt.push.apply(rebuilt, cases[idx]);
28 });
29
30 // Replace the while loop with sequential code
31 path.replaceWithMultiple(rebuilt);
32 }
33});Dead Code Injection
The deadCodeInjection option inserts unreachable code blocks that look like real code, increasing file size and confusing analysis.
1// Dead code injection example
2if (false) {
3 var data = fetchUserData(userId);
4 processPayment(data.card, amount);
5 sendConfirmation(data.email);
6}
7
8// More sophisticated with opaque predicates
9var _0x1 = 'abc';
10if (_0x1 === 'xyz') {
11 // Never true, but harder to prove statically
12 doSomethingFake();
13}
14
15// AST-based removal:
16traverse(ast, {
17 IfStatement(path) {
18 var test = path.get('test');
19 var result = test.evaluateTruthy();
20 if (result === false) {
21 if (path.node.alternate) {
22 path.replaceWithMultiple(
23 path.node.alternate.body ||
24 [path.node.alternate]
25 );
26 } else {
27 path.remove();
28 }
29 } else if (result === true) {
30 path.replaceWithMultiple(
31 path.node.consequent.body ||
32 [path.node.consequent]
33 );
34 }
35 }
36});Debug Protection
The debugProtection option prevents users from using browser DevTools to analyze the code.
1// Debug protection implementation
2(function() {
3 function debuggerTrap() {
4 // Uses Function constructor to create debugger
5 // statement dynamically
6 (function() {
7 return false;
8 })['constructor']('debugger')['call']();
9 }
10
11 // With debugProtectionInterval, runs repeatedly
12 setInterval(function() {
13 debuggerTrap();
14 }, 4000);
15})();
16
17// Deobfuscation: Remove debugger traps
18traverse(ast, {
19 CallExpression(path) {
20 if (isDebuggerTrap(path)) {
21 path.remove();
22 }
23 },
24 DebuggerStatement(path) {
25 path.remove();
26 }
27});Self-Defending Code
The selfDefending option adds code that crashes the application if the source is reformatted. It works by checking the code's own formatting using toString() and RegExp tests.
1// Self-defending mechanism (simplified)
2var selfDefend = function() {
3 var rfn = function() {
4 var fn = rfn.toString();
5 // Check if source matches expected format
6 // (compressed, single line)
7 if (!fn.match(/\\w+ *\\(\\) *\\{/)) {
8 // Code has been beautified
9 // Enter infinite loop to crash
10 while (true) {}
11 }
12 };
13 rfn();
14};
15
16// Deobfuscation: Identify and remove by finding
17// the toString() + RegExp pattern
18traverse(ast, {
19 FunctionDeclaration(path) {
20 if (isSelfDefending(path)) {
21 path.remove();
22 }
23 }
24});Domain Lock
The domainLock option restricts code execution to specific domains by checking window.location and refusing to run on unauthorized domains.
1// Domain lock implementation
2(function() {
3 var allowedDomains = ['example.com'];
4 var currentDomain = window.location.hostname;
5 var authorized = false;
6
7 for (var i = 0; i < allowedDomains.length; i++) {
8 if (currentDomain === allowedDomains[i] ||
9 currentDomain.endsWith(allowedDomains[i])) {
10 authorized = true;
11 break;
12 }
13 }
14
15 if (!authorized) {
16 while (true) {} // crash
17 }
18})();Console Output Disabling
The disableConsoleOutput option replaces all console methods with empty functions, preventing any debug output.
1// Console disabling
2var _0xConsole = function() {
3 var console = {};
4 var methods = [
5 'log', 'warn', 'error', 'info',
6 'debug', 'table', 'trace', 'dir',
7 'group', 'groupEnd', 'time', 'timeEnd'
8 ];
9 methods.forEach(function(method) {
10 console[method] = function() {};
11 });
12 return console;
13};
14window.console = _0xConsole();Step-by-Step Deobfuscation Guide
Here is the recommended order for deobfuscating obfuscator.io code:
Step 1: Remove Debug Protection
Always start by removing debug protection and self-defending code. This allows you to use DevTools for further analysis without crashes or infinite loops.
Step 2: Decode the String Array
This is the single most impactful transformation. Once strings are decoded and inlined, the code becomes dramatically more readable.
1// Before string decoding:
2console[_0x3f('0x0')](_0x3f('0x1'));
3document[_0x3f('0x2')](_0x3f('0x3'));
4
5// After string decoding:
6console.log('Hello World');
7document.getElementById('myElement');Step 3: Remove Dead Code
Eliminate unreachable code blocks, always-false conditions, and injected dummy code.
Step 4: Restore Control Flow
Reverse control flow flattening by analyzing the sequence strings and reconstructing sequential logic.
Step 5: Simplify Expressions
Fold constant expressions, inline simple variables, and simplify boolean logic.
1// Before simplification:
2var _0x1 = ![];
3// ![] is false
4var _0x2 = !![];
5// !![] is true
6var _0x3 = 0x5 + 0x3;
7// Hex arithmetic
8
9// After simplification:
10var _0x1 = false;
11var _0x2 = true;
12var _0x3 = 8;Step 6: Rename Identifiers
While original names cannot be recovered, meaningful names can be inferred from context and usage patterns.
Automated Deobfuscation with Astify
Astify automates the entire deobfuscation process for obfuscator.io code:
- Automatic detection: Astify's analyzer identifies the obfuscator.io signature pattern (hex identifiers, string array, rotation IIFE) within seconds
- String array resolution: The AI engine extracts the string array, handles rotation and encoding (base64 or RC4), and replaces all accessor calls with decoded values
- Control flow restoration: The flattened state machines are analyzed and rebuilt into sequential code
- Dead code removal: Unreachable branches and injected dummy code are identified and removed
- Protection stripping: Debug protection, self-defending code, domain locks, and console disabling are all removed
- Expression simplification: Constant folding, boolean simplification, and hex-to-decimal conversion produce clean output
Before and After Examples
Example: Simple Function
1// OBFUSCATED (obfuscator.io high preset)
2var _0xa1b2 = ['push','shift','map','length',
3 'Hello\x20from\x20','reduce'];
4(function(_0x1,_0x2){var _0x3=function(_0x4){
5 while(--_0x4){_0x1['push'](_0x1['shift']());}
6};_0x3(++_0x2);})(_0xa1b2,0x6f);
7var _0x4c=function(_0x1){_0x1=_0x1-0x0;
8 return _0xa1b2[_0x1];};
9function _0x5a(_0x6,_0x7){
10 var _0x8='3|1|0|2|4'['split']('|'),_0x9=0x0;
11 while(!![]){switch(_0x8[_0x9++]){
12 case'0':_0xa=_0x6[_0x4c('0x2')];continue;
13 case'1':var _0xa;continue;
14 case'2':var _0xb=_0x6[_0x4c('0x4')](
15 function(_0xc,_0xd){return _0xc+_0xd;},0x0);
16 continue;
17 case'3':if(!_0x6||!_0x6[_0x4c('0x3')])return;
18 continue;
19 case'4':return _0x4c('0x0')+_0x7+': '+_0xb;
20 continue;}break;}}
21
22// DEOBFUSCATED (after Astify processing)
23function processArray(arr, name) {
24 if (!arr || !arr.length) return;
25 var count = arr.length;
26 var sum = arr.reduce(
27 function(acc, val) { return acc + val; }, 0
28 );
29 return 'Hello from ' + name + ': ' + sum;
30}Identifying Obfuscation Strength
Obfuscator.io provides preset configurations that combine multiple options:
Low Obfuscation
Typically just identifier renaming and string array without encoding. Quick to deobfuscate -- a single string decoding pass restores most readability.
Medium Obfuscation
Adds base64 string encoding, string array rotation, and some dead code. Requires string decoding with rotation handling, followed by dead code removal.
High Obfuscation
Adds RC4 string encoding, control flow flattening, dead code injection at a higher threshold, and debug protection. Requires multiple deobfuscation passes and careful ordering of transformations.
Maximum Obfuscation
All features enabled: RC4 encoding, high control flow flattening threshold, aggressive dead code injection, self-defending code, domain lock, debug protection with interval, and console disabling. This is the most challenging to deobfuscate and typically requires Astify's multi-round processing pipeline for clean results.
Common Pitfalls in Manual Deobfuscation
- Wrong transformation order: Decoding strings before handling rotation produces incorrect results. Always resolve rotation first.
- Ignoring self-defending code: Reformatting the code before removing self-defending checks causes the code to crash when tested.
- Incomplete alias tracking: The string accessor function may be aliased multiple times. Missing an alias leaves some strings unresolved.
- RC4 key handling: Each string in an RC4-encoded array has its own key. The key is typically the second argument to the accessor function.
Conclusion
Obfuscator.io remains the most commonly encountered JavaScript obfuscation tool in the wild. Its open-source nature means that both the obfuscation techniques and their reversals are well-understood. By following the systematic deobfuscation approach outlined in this guide -- removing protections first, decoding strings, restoring control flow, and simplifying expressions -- you can effectively reverse any level of obfuscator.io protection. For automated processing, Astify handles every obfuscator.io configuration option and produces clean, readable output in seconds.