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

Commit db21be6

Browse files
committed
Updated to use the javascript-obfuscator@0.9.1 which includes the new Control Flow Flattening option.
1 parent 68a43f4 commit db21be6

7 files changed

Lines changed: 140 additions & 49 deletions

File tree

App/actions/index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,9 @@ export const setSourceMapFileName = (fileName) => ({
8181
export const setSeed = (seed) => ({
8282
'type': types.SET_SEED,
8383
seed
84-
});
84+
});
85+
86+
export const setControlFlowFlatteningThreshold = (threshold) => ({
87+
'type': types.SET_CONTROL_FLOW_FLATTENING_THRESHOLD,
88+
threshold
89+
});

App/constants/ActionTypes.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,7 @@ export const REMOVE_DOMAIN_LOCK = 'REMOVE_DOMAIN_LOCK'
2828
export const ADD_RESERVED_NAME = 'ADD_RESERVED_NAME'
2929
export const REMOVE_RESERVED_NAME = 'REMOVE_RESERVED_NAME'
3030

31-
export const SET_SEED = 'SET_SEED'
31+
export const SET_SEED = 'SET_SEED'
32+
33+
export const SET_CONTROL_FLOW_FLATTENING_THRESHOLD = 'SET_CONTROL_FLOW_FLATTENING_THRESHOLD'
34+
export const TOGGLE_CONTROL_FLOW_FLATTENING = 'TOGGLE_CONTROL_FLOW_FLATTENING'

App/containers/OptionsContainer.js

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,17 @@ const Options = ({dispatch, options}) =>
6262
disabled={!options.debugProtection}
6363
onChange={() => dispatch(actions.toggleOption(types.TOGGLE_DEBUG_PROTECTION_INTERVAL)) } />
6464

65+
<Divider />
66+
67+
<Form.Input
68+
type='number'
69+
label='Seed'
70+
defaultValue={options.seed || 0}
71+
min="0"
72+
max="99999999"
73+
step="1"
74+
onChange={(event) => dispatch(actions.setSeed(parseInt(event.target.value))) } />
75+
6576
</Segment>
6677
</Grid.Column>
6778

@@ -128,6 +139,21 @@ const Options = ({dispatch, options}) =>
128139
<Grid.Column>
129140
<Segment basic>
130141

142+
<Form.Checkbox
143+
label='Control Flow Flatteing'
144+
checked={options.controlFlowFlattening}
145+
onChange={() => dispatch(actions.toggleOption(types.TOGGLE_CONTROL_FLOW_FLATTENING)) } />
146+
147+
<Form.Input
148+
type='number'
149+
label='Control Flow Flattening Threshold'
150+
defaultValue={options.controlFlowFlatteningThreshold}
151+
min="0"
152+
max="1"
153+
step="0.1"
154+
onChange={(event) => dispatch(actions.setControlFlowFlatteningThreshold(parseFloat(event.target.value))) }
155+
disabled={!options.controlFlowFlattening} />
156+
131157
<EntryInputContainer
132158
label='Add a domain lock'
133159
actionAddEntryToState={(domain) => dispatch(actions.addDomainLock(domain)) }
@@ -144,15 +170,6 @@ const Options = ({dispatch, options}) =>
144170
entries={options.reservedNames}
145171
buttonIcon="plus" />
146172

147-
<Form.Input
148-
type='number'
149-
label='Seed'
150-
defaultValue={options.seed || 0}
151-
min="0"
152-
max="99999999"
153-
step="1"
154-
onChange={(event) => dispatch(actions.setSeed(parseInt(event.target.value))) } />
155-
156173
</Segment>
157174
</Grid.Column>
158175

@@ -171,4 +188,4 @@ const mapStateToProps = (state) => {
171188
}
172189
}
173190

174-
export default connect(mapStateToProps)(Options);
191+
export default connect(mapStateToProps)(Options);

App/reducers/options.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,21 @@ const initialState = {
3131
reservedNames: [],
3232

3333
seed: 0,
34+
35+
controlFlowFlatteningThreshold: 0.75,
36+
controlFlowFlattening: false,
3437
}
3538

3639
export const options = (state = initialState, action) => {
3740

41+
// this is necessary because new options need to be filled with their
42+
// default values and them merged with the state from the localStorage
43+
// which can be outdated when new options are added
44+
// from https://github.com/reactjs/redux/issues/433#issuecomment-129188687
45+
if (!state.hydrated) {
46+
state = { ...initialState, ...state, hydrated: true };
47+
}
48+
3849
switch (action.type) {
3950

4051
case types.TOGGLE_COMPACT_CODE:
@@ -160,6 +171,18 @@ export const options = (state = initialState, action) => {
160171
seed: action.seed
161172
}
162173

174+
case types.SET_CONTROL_FLOW_FLATTENING_THRESHOLD:
175+
return {
176+
...state,
177+
controlFlowFlatteningThreshold: action.threshold
178+
}
179+
180+
case types.TOGGLE_CONTROL_FLOW_FLATTENING:
181+
return {
182+
...state,
183+
controlFlowFlattening: !state.controlFlowFlattening
184+
}
185+
163186
default:
164187
return state
165188
}

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.8.6",
33+
"javascript-obfuscator": "0.9.1",
3434
"less": "^2.7.1",
3535
"less-loader": "^2.2.3",
3636
"react": "^15.3.1",

templates/index.html

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,13 @@ <h3>Sounds great!</h3>
120120
</td>
121121
</tr>
122122

123+
<tr>
124+
<td class="collapsing">Seed</td>
125+
<td>
126+
<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>
127+
</td>
128+
</tr>
129+
123130
<tr>
124131
<td class="collapsing">String Array</td>
125132
<td>
@@ -187,6 +194,37 @@ <h3>Sounds great!</h3>
187194
</td>
188195
</tr>
189196

197+
<tr>
198+
<td class="collapsing">Control Flow Flattening</td>
199+
<td>
200+
201+
<div class="ui tiny message">
202+
<p><i class="warning sign icon"></i> This option will decrease the performance of your code.</p>
203+
</div>
204+
205+
<p>
206+
Control flow flattening is a structure transformation of the source code that hinders program comprehension by removing functions definitions from its original locations and placing them inside a dispatch table. Arguments from those functions are also hidden inside a string array.
207+
</p>
208+
209+
<p>Since this transformation makes the affected nodes' function calls dynamic, it will likely disable optimizations that the JavaScript engine can do and will slow down your code.</p>
210+
211+
<table class="ui definition table">
212+
<tbody>
213+
214+
<tr>
215+
<td class="collapsing">Control Flow Flattening Threshold</td>
216+
<td>
217+
<p>You can use this setting to adjust the probability (from 0 to 1) that a <code>controlFlowFlattening</code> transformation will be applied to a node.</p>
218+
<p>In larger codebases it's advised to lower this value, because larger amounts of control flow transformations will increase the size of your code and slow it down significantly.</p>
219+
</td>
220+
</tr>
221+
222+
</tbody>
223+
</table>
224+
225+
</td>
226+
</tr>
227+
190228
<tr>
191229
<td class="collapsing">Domain Lock</td>
192230
<td>
@@ -204,12 +242,6 @@ <h3>Sounds great!</h3>
204242
</td>
205243
</tr>
206244

207-
<tr>
208-
<td class="collapsing">Seed</td>
209-
<td>
210-
<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>
211-
</td>
212-
</tr>
213245

214246
</tbody>
215247
</table>

yarn.lock

Lines changed: 41 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -760,14 +760,6 @@ babel-plugin-transform-strict-mode@^6.8.0:
760760
babel-runtime "^6.0.0"
761761
babel-types "^6.8.0"
762762

763-
babel-polyfill@6.16.0:
764-
version "6.16.0"
765-
resolved "https://registry.yarnpkg.com/babel-polyfill/-/babel-polyfill-6.16.0.tgz#2d45021df87e26a374b6d4d1a9c65964d17f2422"
766-
dependencies:
767-
babel-runtime "^6.9.1"
768-
core-js "^2.4.0"
769-
regenerator-runtime "^0.9.5"
770-
771763
babel-preset-es2015@^6.14.0:
772764
version "6.16.0"
773765
resolved "https://registry.yarnpkg.com/babel-preset-es2015/-/babel-preset-es2015-6.16.0.tgz#59acecd1efbebaf48f89404840f2fe78c4d2ad5c"
@@ -1151,9 +1143,9 @@ clap@^1.0.9:
11511143
dependencies:
11521144
chalk "^1.1.3"
11531145

1154-
class-validator@0.6.6:
1155-
version "0.6.6"
1156-
resolved "https://registry.yarnpkg.com/class-validator/-/class-validator-0.6.6.tgz#84221d189da302e31d2e630e11950508a278e83a"
1146+
class-validator@0.6.8:
1147+
version "0.6.8"
1148+
resolved "https://registry.yarnpkg.com/class-validator/-/class-validator-0.6.8.tgz#af34fa10f99ecb86679d291d73ef8076d9ab8b95"
11571149
dependencies:
11581150
validator ">=5.0.0"
11591151

@@ -1730,9 +1722,9 @@ esprima@^2.6.0, esprima@^2.7.1:
17301722
version "2.7.3"
17311723
resolved "https://registry.yarnpkg.com/esprima/-/esprima-2.7.3.tgz#96e3b70d5779f6ad49cd032673d1c312767ba581"
17321724

1733-
esprima@3.1.1:
1734-
version "3.1.1"
1735-
resolved "https://registry.yarnpkg.com/esprima/-/esprima-3.1.1.tgz#02dbcc5ac3ece81070377f99158ec742ab5dda06"
1725+
esprima@3.1.3:
1726+
version "3.1.3"
1727+
resolved "https://registry.yarnpkg.com/esprima/-/esprima-3.1.3.tgz#fdca51cee6133895e3c88d535ce49dbff62a4633"
17361728

17371729
esrecurse@^4.1.0:
17381730
version "4.1.0"
@@ -1947,10 +1939,6 @@ form-data@~2.0.0:
19471939
combined-stream "^1.0.5"
19481940
mime-types "^2.1.11"
19491941

1950-
format-unicorn@1.1.0:
1951-
version "1.1.0"
1952-
resolved "https://registry.yarnpkg.com/format-unicorn/-/format-unicorn-1.1.0.tgz#cc75fb10399314b14af6a324652579ac0615b457"
1953-
19541942
forwarded@~0.1.0:
19551943
version "0.1.0"
19561944
resolved "https://registry.yarnpkg.com/forwarded/-/forwarded-0.1.0.tgz#19ef9874c4ae1c297bcf078fde63a09b66a84363"
@@ -1963,7 +1951,7 @@ fs.realpath@^1.0.0:
19631951
version "1.0.0"
19641952
resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f"
19651953

1966-
fsevents, fsevents@^1.0.0:
1954+
fsevents@^1.0.0:
19671955
version "1.0.14"
19681956
resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-1.0.14.tgz#558e8cc38643d8ef40fe45158486d0d25758eee4"
19691957
dependencies:
@@ -2276,6 +2264,10 @@ invariant@^2.0.0, invariant@^2.2.0:
22762264
dependencies:
22772265
loose-envify "^1.0.0"
22782266

2267+
inversify@3.0.0:
2268+
version "3.0.0"
2269+
resolved "https://registry.yarnpkg.com/inversify/-/inversify-3.0.0.tgz#b0e5f7e48f6a3535014b2f12e23385cae3894dab"
2270+
22792271
invert-kv@^1.0.0:
22802272
version "1.0.0"
22812273
resolved "https://registry.yarnpkg.com/invert-kv/-/invert-kv-1.0.0.tgz#104a8e4aaca6d3d8cd157a8ef8bfab2d7a3ffdb6"
@@ -2444,20 +2436,23 @@ items@2.x.x:
24442436
version "2.1.1"
24452437
resolved "https://registry.yarnpkg.com/items/-/items-2.1.1.tgz#8bd16d9c83b19529de5aea321acaada78364a198"
24462438

2447-
javascript-obfuscator@0.8.6:
2448-
version "0.8.6"
2449-
resolved "https://registry.yarnpkg.com/javascript-obfuscator/-/javascript-obfuscator-0.8.6.tgz#6ce17ab4d7e21961c0ceeaec68f967f8d9751dad"
2439+
javascript-obfuscator@0.9.1:
2440+
version "0.9.1"
2441+
resolved "https://registry.yarnpkg.com/javascript-obfuscator/-/javascript-obfuscator-0.9.1.tgz#68f4e4adc4bac4a0b2b6d13edcde225f83f69be3"
24502442
dependencies:
2451-
babel-polyfill "6.16.0"
24522443
chance "1.0.4"
2453-
class-validator "0.6.6"
2444+
class-validator "0.6.8"
24542445
commander "2.9.0"
24552446
escodegen "1.8.1"
2456-
esprima "3.1.1"
2447+
esprima "3.1.3"
24572448
estraverse "4.2.0"
2458-
format-unicorn "1.1.0"
2449+
inversify "3.0.0"
2450+
lodash "4.17.4"
24592451
mkdirp "0.5.1"
2460-
source-map-support "0.4.6"
2452+
reflect-metadata "0.1.9"
2453+
source-map-support "0.4.11"
2454+
string-template "1.0.0"
2455+
tslib "1.5.0"
24612456

24622457
jodid25519@^1.0.0:
24632458
version "1.0.2"
@@ -2672,6 +2667,10 @@ lodash@^4.14.0:
26722667
version "4.17.2"
26732668
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.2.tgz#34a3055babe04ce42467b607d700072c7ff6bf42"
26742669

2670+
lodash@4.17.4:
2671+
version "4.17.4"
2672+
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae"
2673+
26752674
longest@^1.0.1:
26762675
version "1.0.1"
26772676
resolved "https://registry.yarnpkg.com/longest/-/longest-1.0.1.tgz#30a0b2da38f73770e8294a0d22e6625ed77d0097"
@@ -3554,6 +3553,10 @@ redux@^3.6.0:
35543553
loose-envify "^1.1.0"
35553554
symbol-observable "^1.0.2"
35563555

3556+
reflect-metadata@0.1.9:
3557+
version "0.1.9"
3558+
resolved "https://registry.yarnpkg.com/reflect-metadata/-/reflect-metadata-0.1.9.tgz#987238dc87a516895fe457f130435ffbd763a4d4"
3559+
35573560
regenerate@^1.2.1:
35583561
version "1.3.1"
35593562
resolved "https://registry.yarnpkg.com/regenerate/-/regenerate-1.3.1.tgz#0300203a5d2fdcf89116dce84275d011f5903f33"
@@ -3796,9 +3799,9 @@ source-map-support@^0.4.2:
37963799
dependencies:
37973800
source-map "^0.5.3"
37983801

3799-
source-map-support@0.4.6:
3800-
version "0.4.6"
3801-
resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.4.6.tgz#32552aa64b458392a85eab3b0b5ee61527167aeb"
3802+
source-map-support@0.4.11:
3803+
version "0.4.11"
3804+
resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.4.11.tgz#647f939978b38535909530885303daf23279f322"
38023805
dependencies:
38033806
source-map "^0.5.3"
38043807

@@ -3864,6 +3867,10 @@ string_decoder@~0.10.25, string_decoder@~0.10.x:
38643867
version "0.10.31"
38653868
resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-0.10.31.tgz#62e203bc41766c6c28c9fc84301dab1c5310fa94"
38663869

3870+
string-template@1.0.0:
3871+
version "1.0.0"
3872+
resolved "https://registry.yarnpkg.com/string-template/-/string-template-1.0.0.tgz#9e9f2233dc00f218718ec379a28a5673ecca8b96"
3873+
38673874
string-width@^1.0.1, string-width@^1.0.2:
38683875
version "1.0.2"
38693876
resolved "https://registry.yarnpkg.com/string-width/-/string-width-1.0.2.tgz#118bdf5b8cdc51a2a7e70d211e07e2b0b9b107d3"
@@ -3996,6 +4003,10 @@ tryit@^1.0.1:
39964003
version "1.0.2"
39974004
resolved "https://registry.yarnpkg.com/tryit/-/tryit-1.0.2.tgz#c196b0073e6b1c595d93c9c830855b7acc32a453"
39984005

4006+
tslib@1.5.0:
4007+
version "1.5.0"
4008+
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.5.0.tgz#3bb50f871e5fdf9a4555a9ff237b730860048fea"
4009+
39994010
tty-browserify@0.0.0:
40004011
version "0.0.0"
40014012
resolved "https://registry.yarnpkg.com/tty-browserify/-/tty-browserify-0.0.0.tgz#a157ba402da24e9bf957f9aa69d524eed42901a6"

0 commit comments

Comments
 (0)