Skip to content
This repository was archived by the owner on Dec 9, 2025. It is now read-only.

Commit 48e2ca4

Browse files
committed
Updated to use the javascript-obfuscator@0.10.0 which includes the new Dead Code Injection option.
1 parent a4fa0f4 commit 48e2ca4

8 files changed

Lines changed: 444 additions & 73 deletions

File tree

App/actions/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,8 @@ export const setControlFlowFlatteningThreshold = (threshold) => ({
8787
'type': types.SET_CONTROL_FLOW_FLATTENING_THRESHOLD,
8888
threshold
8989
});
90+
91+
export const setDeadCodeInjectionThreshold = (threshold) => ({
92+
'type': types.SET_DEAD_CODE_INJECTION_THRESHOLD,
93+
threshold
94+
});

App/constants/ActionTypes.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,8 @@ export const SET_SEED = 'SET_SEED'
3232

3333
export const SET_CONTROL_FLOW_FLATTENING_THRESHOLD = 'SET_CONTROL_FLOW_FLATTENING_THRESHOLD'
3434
export const TOGGLE_CONTROL_FLOW_FLATTENING = 'TOGGLE_CONTROL_FLOW_FLATTENING'
35+
36+
export const SET_DEAD_CODE_INJECTION_THRESHOLD = 'SET_DEAD_CODE_INJECTION_THRESHOLD'
37+
export const TOGGLE_DEAD_CODE_INJECTION = 'TOGGLE_DEAD_CODE_INJECTION'
38+
39+
export const TOGGLE_MANGLE = 'TOGGLE_MANGLE'

App/containers/OptionsContainer.js

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ const Options = ({dispatch, options}) =>
4242
checked={options.selfDefending}
4343
onChange={() => dispatch(actions.toggleOption(types.TOGGLE_SELF_DEFENDING)) } />
4444

45+
<Form.Checkbox
46+
label='Mangle Variable Names'
47+
checked={options.mangle}
48+
onChange={() => dispatch(actions.toggleOption(types.TOGGLE_MANGLE)) } />
4549
<Divider />
4650

4751
<Form.Checkbox
@@ -61,14 +65,21 @@ const Options = ({dispatch, options}) =>
6165

6266
<Divider />
6367

68+
<Form.Checkbox
69+
label='Dead Code Injection'
70+
checked={options.deadCodeInjection}
71+
onChange={() => dispatch(actions.toggleOption(types.TOGGLE_DEAD_CODE_INJECTION)) } />
72+
6473
<Form.Input
6574
type='number'
66-
label='Seed'
67-
defaultValue={options.seed}
75+
label='Dead Code Injection Threshold'
76+
defaultValue={options.deadCodeInjectionThreshold}
6877
min="0"
69-
max="99999999"
70-
step="1"
71-
onChange={(event) => dispatch(actions.setSeed(parseInt(event.target.value))) } />
78+
max="1"
79+
step="0.1"
80+
onChange={(event) => dispatch(actions.setDeadCodeInjectionThreshold(parseFloat(event.target.value))) }
81+
disabled={!options.deadCodeInjection} />
82+
7283

7384
</Segment>
7485
</Grid.Column>
@@ -172,6 +183,17 @@ const Options = ({dispatch, options}) =>
172183
defaultValue={options.sourceMapFileName}
173184
placeholder='example' />
174185

186+
<Divider />
187+
188+
<Form.Input
189+
type='number'
190+
label='Seed'
191+
defaultValue={options.seed}
192+
min="0"
193+
max="99999999"
194+
step="1"
195+
onChange={(event) => dispatch(actions.setSeed(parseInt(event.target.value))) } />
196+
175197
</Segment>
176198
</Grid.Column>
177199

App/index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ if (process.env.NODE_ENV !== 'production') {
2424

2525
const persistedState = loadState();
2626

27+
// should not be in the localState, but was saved there by a bug
28+
// now we need this here because some users will have this on their localState.
29+
delete persistedState.options.hydrated;
30+
2731
const store = createStore(
2832
reducer,
2933
persistedState,
@@ -33,8 +37,10 @@ const store = createStore(
3337
// There's no need to throttle the saveState function because
3438
// we don't change the state very often
3539
store.subscribe(() => {
40+
const options = store.getState().options;
41+
delete options.hydrated;
3642
saveState({
37-
options: store.getState().options
43+
options,
3844
});
3945
})
4046

App/reducers/options.js

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ const initialState = {
3434

3535
controlFlowFlatteningThreshold: 0.75,
3636
controlFlowFlattening: false,
37+
38+
deadCodeInjectionThreshold: 0.4,
39+
deadCodeInjection: false,
40+
41+
mangle: false,
3742
}
3843

3944
export const options = (state = initialState, action) => {
@@ -48,43 +53,47 @@ export const options = (state = initialState, action) => {
4853

4954
switch (action.type) {
5055

51-
case types.TOGGLE_COMPACT_CODE:
56+
case types.TOGGLE_COMPACT_CODE: {
5257
const compact = !state.compact;
5358
return {
5459
...state,
5560
compact,
5661
selfDefending: state.selfDefending && compact,
5762
}
63+
}
5864

59-
case types.TOGGLE_SELF_DEFENDING:
65+
case types.TOGGLE_SELF_DEFENDING: {
6066
const selfDefending = !state.selfDefending;
6167
return {
6268
...state,
6369
selfDefending,
6470
compact: state.compact || selfDefending,
6571
}
72+
}
6673

6774
case types.TOGGLE_DISABLE_CONSOLE_OUTPUT:
6875
return {
6976
...state,
7077
disableConsoleOutput: !state.disableConsoleOutput,
7178
}
7279

73-
case types.TOGGLE_DEBUG_PROTECTION:
80+
case types.TOGGLE_DEBUG_PROTECTION: {
7481
const debugProtection = !state.debugProtection;
7582
return {
7683
...state,
7784
debugProtection,
7885
debugProtectionInterval: state.debugProtectionInterval && debugProtection,
7986
}
87+
}
8088

8189
case types.TOGGLE_DEBUG_PROTECTION_INTERVAL:
8290
return {
8391
...state,
8492
debugProtectionInterval: !state.debugProtectionInterval,
8593
}
8694

87-
case types.TOGGLE_STRING_ARRAY:
95+
case types.TOGGLE_STRING_ARRAY: {
96+
// Also change the TOGGLE_DEAD_CODE_INJECTION below if changed
8897
const stringArray = !state.stringArray;
8998
return {
9099
...state,
@@ -93,6 +102,7 @@ export const options = (state = initialState, action) => {
93102
stringArrayThresholdEnabled: stringArray,
94103
stringArrayEncodingEnabled: stringArray,
95104
}
105+
}
96106

97107
case types.TOGGLE_ROTATE_STRING_ARRAY:
98108
return {
@@ -112,14 +122,15 @@ export const options = (state = initialState, action) => {
112122
stringArrayThreshold: action.threshold
113123
}
114124

115-
case types.SET_SOURCEMAP_MODE:
125+
case types.SET_SOURCEMAP_MODE: {
116126
const mode = action.mode;
117127
return {
118128
...state,
119129
sourceMap: mode !== SOURCEMAP_OFF,
120130
sourceMapMode: mode,
121131
sourceMapSeparate: mode === SOURCEMAP_SEPARATE
122132
}
133+
}
123134

124135
case types.SET_SOURCEMAP_BASE_URL:
125136
return {
@@ -133,7 +144,7 @@ export const options = (state = initialState, action) => {
133144
sourceMapFileName: action.fileName
134145
}
135146

136-
case types.ADD_DOMAIN_LOCK:
147+
case types.ADD_DOMAIN_LOCK: {
137148
const domain = action.domain;
138149
if (state.domainLock.indexOf(domain) !== -1)
139150
return state;
@@ -142,14 +153,15 @@ export const options = (state = initialState, action) => {
142153
...state,
143154
domainLock: [...state.domainLock, domain],
144155
}
156+
}
145157

146158
case types.REMOVE_DOMAIN_LOCK:
147159
return {
148160
...state,
149161
domainLock: state.domainLock.filter((domain) => domain !== action.domain),
150162
}
151163

152-
case types.ADD_RESERVED_NAME:
164+
case types.ADD_RESERVED_NAME: {
153165
const name = action.name;
154166
if (state.reservedNames.indexOf(name) !== -1)
155167
return state;
@@ -158,6 +170,7 @@ export const options = (state = initialState, action) => {
158170
...state,
159171
reservedNames: [...state.reservedNames, name],
160172
}
173+
}
161174

162175
case types.REMOVE_RESERVED_NAME:
163176
return {
@@ -183,6 +196,32 @@ export const options = (state = initialState, action) => {
183196
controlFlowFlattening: !state.controlFlowFlattening
184197
}
185198

199+
case types.SET_DEAD_CODE_INJECTION_THRESHOLD:
200+
return {
201+
...state,
202+
deadCodeInjectionThreshold: action.threshold
203+
}
204+
205+
case types.TOGGLE_DEAD_CODE_INJECTION: {
206+
// Also change the TOGGLE_STRING_ARRAY above if changed
207+
const deadCodeInjection = !state.deadCodeInjection;
208+
const stringArray = state.stringArray || deadCodeInjection;
209+
return {
210+
...state,
211+
stringArray,
212+
deadCodeInjection: deadCodeInjection,
213+
rotateStringArrayEnabled: stringArray,
214+
stringArrayThresholdEnabled: stringArray,
215+
stringArrayEncodingEnabled: stringArray
216+
}
217+
}
218+
219+
case types.TOGGLE_MANGLE:
220+
return {
221+
...state,
222+
mangle: !state.mangle
223+
}
224+
186225
default:
187226
return state
188227
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"extract-text-webpack-plugin": "^2.0.0-beta",
3131
"graceful-fs": "^4.1.9",
3232
"inert": "^4.0.2",
33-
"javascript-obfuscator": "0.9.1",
33+
"javascript-obfuscator": "0.10.0",
3434
"less": "^2.7.1",
3535
"less-loader": "^2.2.3",
3636
"react": "^15.3.1",

templates/index.html

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
<div class="column">
2828
<div class="ui basic segment">
2929
<h1>JavaScript Obfuscator Tool</h1>
30-
<p>A free and efficient obfuscator for JavaScript (including ES6). Make your code harder to copy and prevent people from stealing your work. This tool is a Web UI to the excellent (and open source) <a href="https://github.com/javascript-obfuscator/javascript-obfuscator" target="_new">JavaScript Obfuscator</a> created by Timofey Kachalov.</p>
30+
<p>A free and efficient obfuscator for JavaScript (including ES6). Make your code harder to copy and prevent people from stealing your work. This tool is a Web UI to the excellent (and open source) <code><a href="https://github.com/javascript-obfuscator/javascript-obfuscator" target="_new">JavaScript Obfuscator</a>@0.10.0</code> created by Timofey Kachalov.</p>
3131
</div>
3232
</div>
3333
</div>
@@ -88,6 +88,13 @@ <h3>Sounds great!</h3>
8888
</td>
8989
</tr>
9090

91+
<tr>
92+
<td class="collapsing">Mangle Variable Names</td>
93+
<td>
94+
Mangles the variable names. (For instance, instead of having this random pattern <code>0x123456</code>, they become <code>a</code>, <code>b</code>, and so on.)
95+
</td>
96+
</tr>
97+
9198
<tr>
9299
<td class="collapsing">Control Flow Flattening</td>
93100
<td>
@@ -118,9 +125,32 @@ <h3>Sounds great!</h3>
118125
</tr>
119126

120127
<tr>
121-
<td class="collapsing">Seed</td>
128+
<td class="collapsing">Dead Code Injection</td>
122129
<td>
123-
<p>By default (<code>seed = 0</code>), each time you obfuscate your code you'll get a new result (i.e: different variable names, different variables inserted into the <code>stringArray</code>, etc). If you want repeatable results, set the <code>seed</code> to a specific integer.</p>
130+
131+
<div class="ui tiny message">
132+
<p><i class="warning sign icon"></i> This option increases the size of the obfuscated code greatly (up to 200%).</p>
133+
</div>
134+
135+
<p>
136+
This feature adds random blocks of dead code (i.e: code that won't be executed) to the obfuscated output, making it harder to be reverserd-engineered. See the docs on <a href="https://github.com/javascript-obfuscator/javascript-obfuscator#deadcodeinjection" target="_new">JavaScript's obfuscator GH page</a> for an example of how this feature works.
137+
</p>
138+
139+
<p><small>requires the <strong>String Array</strong> option.</small></p>
140+
141+
<table class="ui definition table">
142+
<tbody>
143+
144+
<tr>
145+
<td class="collapsing">Dead Code Injection Threshold</td>
146+
<td>
147+
<p>You can use this setting to adjust the probability (from 0 to 1) that a node will be affected by the <code>deadCodeInjection</code> option.</p>
148+
</td>
149+
</tr>
150+
151+
</tbody>
152+
</table>
153+
124154
</td>
125155
</tr>
126156

@@ -240,6 +270,14 @@ <h3>Sounds great!</h3>
240270
</td>
241271
</tr>
242272

273+
<tr>
274+
<td class="collapsing">Seed</td>
275+
<td>
276+
<p>By default (<code>seed = 0</code>), each time you obfuscate your code you'll get a new result (i.e: different variable names, different variables inserted into the <code>stringArray</code>, etc). If you want repeatable results, set the <code>seed</code> to a specific integer.</p>
277+
</td>
278+
</tr>
279+
280+
243281
</tbody>
244282
</table>
245283

0 commit comments

Comments
 (0)