jsobfu 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/jsobfu/obfuscator.rb +12 -1
- data/spec/jsobfu/obfuscator_spec.rb +16 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZjMwNzdiYThlZjA5YzdlZDVhZmUwYWE5MThhNzY1MDBiOGQ2ZTAxMg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZTY0ZDAyNDllMmRiNDRjZDkyYTFjOWYyNzllZGM3ZGYxNTRkMGVlYQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZDA0Mjg0Y2YyODg1YTAxYmE2YzlmNDQ3NDllMzI0ZDE5YTgxZjdiYjM0OGU2
|
10
|
+
M2VkMzdhZDE3ZjI0MjA2OThkOGFkZWM4NGZhM2E3OTdmMWVmYzcxNDljMTYw
|
11
|
+
YTM0Zjg5NzJhZTU4MzA5NjA3OTc2NDdiNzY1MzgzMjRmYzJmNDk=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MjRkMmJhMDhjZDVjZjBjNjIzYWFlMjUwYmU0Y2VjYTgzZTdiODcwZDhmMDQ5
|
14
|
+
YjNjNTRlNWUwOWJiYmE4ZDVmZWMxNjVmZTg1ZTFmYjkwZDVjYThjNGViYTY2
|
15
|
+
YjhlOTgyOGQ2MDNjZTA5ZWIwOGJkZDljN2IxYTNlNjlmNGEwZGQ=
|
data/lib/jsobfu/obfuscator.rb
CHANGED
@@ -12,7 +12,10 @@ class JSObfu::Obfuscator < JSObfu::ECMANoWhitespaceVisitor
|
|
12
12
|
attr_reader :global
|
13
13
|
|
14
14
|
# unresolved lookups are rewritten as property lookups on the global object
|
15
|
-
DEFAULT_GLOBAL
|
15
|
+
DEFAULT_GLOBAL = 'window'
|
16
|
+
|
17
|
+
# some "global" functions are actually keywords, like void(5)
|
18
|
+
BUILTIN_METHODS = ['void']
|
16
19
|
|
17
20
|
# @param opts [Hash] the options hash
|
18
21
|
# @option opts [JSObfu::Scope] :scope the optional scope to save vars to
|
@@ -86,6 +89,10 @@ class JSObfu::Obfuscator < JSObfu::ECMANoWhitespaceVisitor
|
|
86
89
|
# object (like "document"), and hence will not be obfuscated.
|
87
90
|
#
|
88
91
|
def visit_ResolveNode(o)
|
92
|
+
if is_builtin_method?(o.value)
|
93
|
+
return super
|
94
|
+
end
|
95
|
+
|
89
96
|
new_val = rename_var(o.value, :generate => false)
|
90
97
|
|
91
98
|
if new_val
|
@@ -151,4 +158,8 @@ class JSObfu::Obfuscator < JSObfu::ECMANoWhitespaceVisitor
|
|
151
158
|
@renames[var_name] = scope.rename_var(var_name, opts)
|
152
159
|
end
|
153
160
|
|
161
|
+
def is_builtin_method?(method)
|
162
|
+
BUILTIN_METHODS.include?(method)
|
163
|
+
end
|
164
|
+
|
154
165
|
end
|
@@ -31,4 +31,20 @@ describe JSObfu::Obfuscator do
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
+
describe 'when encountering the void() keyword' do
|
35
|
+
|
36
|
+
let(:opts) { { iterations: 3 } }
|
37
|
+
let(:simple_js) { "void(null);" }
|
38
|
+
let(:simple_ast) { RKelly::Parser.new.parse(simple_js) }
|
39
|
+
|
40
|
+
it 'does not rewrite the void() call as a global property lookup' do
|
41
|
+
expect(obfuscator.accept(simple_ast).to_s).not_to include("window")
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'does not obfuscate the keyword void' do
|
45
|
+
expect(obfuscator.accept(simple_ast).to_s).to include("void")
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
34
50
|
end
|