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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- OWVkOTRmZDM5ZDZmYzkwOGFhNGM4MDk0ZjQ3NzljZWVkMWI4OWQwMg==
4
+ ZjMwNzdiYThlZjA5YzdlZDVhZmUwYWE5MThhNzY1MDBiOGQ2ZTAxMg==
5
5
  data.tar.gz: !binary |-
6
- MGQzZGZkMTAxZDUxZmJjZjNhNzc0YzE0NDFkNDQ0MzI4ZjJiYTc4MQ==
6
+ ZTY0ZDAyNDllMmRiNDRjZDkyYTFjOWYyNzllZGM3ZGYxNTRkMGVlYQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZjA5NzRkNWZmMzQ0MDA0ZTkxZWRjMjYyYzc1NWEwZDE5YzcwMDNlZTZiN2E3
10
- YTczZmQzZGMxODk1MzBlOTY5NjQwYzIxNTNmZTk5MjdlMzBlZmQ1ZGFiODRm
11
- YThhYjAyMjhlYzhiZjliNzg2ZGZlOTc2ZmEwNDliZWNlOTg4MzU=
9
+ ZDA0Mjg0Y2YyODg1YTAxYmE2YzlmNDQ3NDllMzI0ZDE5YTgxZjdiYjM0OGU2
10
+ M2VkMzdhZDE3ZjI0MjA2OThkOGFkZWM4NGZhM2E3OTdmMWVmYzcxNDljMTYw
11
+ YTM0Zjg5NzJhZTU4MzA5NjA3OTc2NDdiNzY1MzgzMjRmYzJmNDk=
12
12
  data.tar.gz: !binary |-
13
- NzhkYTM0OTRlM2EwYzgwNzQ2NmI2MGNhOTUzMDVmMjYzYzk4YmQyOTk3Y2Y2
14
- ZmJiMTQyZDAwZGJhZGM2YzhlMzQzODAxMjA1MjlhYjE5NDA2NWEzODI0MWQ2
15
- M2JmMzEzMjkyMzhjMWJkNWMwMmQyODU1Zjg4MzcyZWU1MTRjMzQ=
13
+ MjRkMmJhMDhjZDVjZjBjNjIzYWFlMjUwYmU0Y2VjYTgzZTdiODcwZDhmMDQ5
14
+ YjNjNTRlNWUwOWJiYmE4ZDVmZWMxNjVmZTg1ZTFmYjkwZDVjYThjNGViYTY2
15
+ YjhlOTgyOGQ2MDNjZTA5ZWIwOGJkZDljN2IxYTNlNjlmNGEwZGQ=
@@ -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 = 'window'
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jsobfu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Lee