jsobfu 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZDA3YTM4ZTgyNjgyMzJiNDA2NTNhOTRhYmE0YWQ3OWZkMmYyMjI3Yg==
4
+ MzdlMDRlNzdmNTVjM2Y2NTk0NGIyNjZmOGFjMGU4YWZlOGNhNmU5OA==
5
5
  data.tar.gz: !binary |-
6
- MzUyZTBlYTQxMmE4MmJhOTkzZDcyZmFjMzVkYTIyZTk0MGRiNzNiYg==
6
+ MTJjMzU2ZDJjMGU2ODZkZjhkNWNhYjBhYmQ5MWMyNDUwNzY2MWM3Ng==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NWU3ZmM5MjMyNjZiYmE5ZjBkMWE0ZmI5MGVkMjY5MTM3MGIxZTI2YjU1MjM2
10
- ZWMyNWU2YWI4NzI3YWE1YzBmNTI5NmJkZDhkNzE0YjA2NGU0NzFiMjFkMTBm
11
- MGQwYTE5MDkyOGUyMzQ1NzE3OTE4ZjFhZjAwNGE2NDJiZDA2MGU=
9
+ ZmQ0MjBiZWMyZDhkMWJkOWY1MmU3MmRjNmQwNDhhODYyMzFmMDU2ZTY3MzNi
10
+ YmQ2Y2E1MjhlNTI1ZTBhYTZlY2YzYWVlZTUwZmRmZDljNWEwM2M2ZTI0YTRk
11
+ ZGM4MjQwMzhhOTZlMzc0Y2YzYmNmNDcxNmRjYzU1YzY1ZDM1ZmU=
12
12
  data.tar.gz: !binary |-
13
- MDVkNGJjMzhhODA5NGQ0NjBiOGM1ZWEzYzY0MDQ3ZjFjZjI2YmRiMDk1YzVh
14
- MWRjZTcxNjJhZjY1OWU5NmI0Y2UxY2EwNGVkNjVmODdkZjYxMzY1YTUwM2Rk
15
- YTQxM2IxOGFmMjc0NzQ1ODFiYWJlMDVlODAxMDcxMTA1MDAzYTk=
13
+ ZmE4Yjg0YWE4OGNkMTdjYzc0ODg2MmFjZDJlMGEzZDM0YmZkNTQ2ZTAzZGMy
14
+ MDE5YThmNTNlYTg2Y2Q5YjM4MmE1ZDI4Y2NiNTgxMWE4ZjhhZTBmMTYwNzVi
15
+ MTE5NDczMjE0MzcyMGRhZDEyNGZlNmFkZTIxNjE2MGYwNDZkZTI=
@@ -13,10 +13,13 @@ class JSObfu
13
13
  attr_reader :scope
14
14
 
15
15
  # Saves +code+ for later obfuscation with #obfuscate
16
- # @param [#to_s] code the code to obfuscate
17
- def initialize(code)
16
+ # @param code [#to_s] the code to obfuscate
17
+ # @param opts [Hash] the options hash
18
+ # @option opts [Integer] number of times to run the obfuscator on this code (1)
19
+ def initialize(code, opts={})
18
20
  @code = code.to_s
19
21
  @scope = Scope.new
22
+ @iterations = opts.fetch(:iterations, 1).to_i
20
23
  end
21
24
 
22
25
  # Add +str+ to the un-obfuscated code.
@@ -42,13 +45,21 @@ class JSObfu
42
45
  #
43
46
  # @return [String] if successful
44
47
  def obfuscate(opts={})
45
- @obfuscator = JSObfu::Obfuscator.new(scope: @scope)
46
- @code = @obfuscator.accept(ast).to_s
47
- if opts.fetch(:strip_whitespace, true)
48
- @code.gsub!(/(^\s+|\s+$)/, '')
49
- @code.delete!("\n")
50
- @code.delete!("\r")
48
+ @iterations.times do |i|
49
+ @obfuscator = JSObfu::Obfuscator.new(scope: @scope)
50
+ @code = @obfuscator.accept(ast).to_s
51
+ if opts.fetch(:strip_whitespace, true)
52
+ @code.gsub!(/(^\s+|\s+$)/, '')
53
+ @code.delete!("\n")
54
+ @code.delete!("\r")
55
+ end
56
+
57
+ unless i == @iterations-1
58
+ @scope = Scope.new
59
+ @ast = nil
60
+ end
51
61
  end
62
+
52
63
  self
53
64
  end
54
65
 
@@ -94,11 +94,13 @@ module JSObfu::Utils
94
94
  #
95
95
  # @return [String] equivalent variable name
96
96
  def self.random_var_encoding(var_name)
97
- if var_name.length < 3 and rand(6) == 0
98
- to_hex(var_name, "\\u00")
99
- else
100
- var_name
101
- end
97
+ # TODO: add support for this to the rkelly parser, otherwise we can't encode twice
98
+ # if var_name.length < 3 and rand(6) == 0
99
+ # to_hex(var_name, "\\u00")
100
+ # end
101
+
102
+ # For now, do no encoding on var names (they are randomized anyways)
103
+ var_name
102
104
  end
103
105
 
104
106
  # Given a Javascript string +str+ with NO escape characters, returns an
@@ -24,7 +24,7 @@ describe 'Integrations' do
24
24
 
25
25
  num.times do
26
26
  it "#{File.basename(path)} should evaluate to the same value before and after obfuscation" do
27
- ob_js = JSObfu.new(js).obfuscate.to_s
27
+ ob_js = JSObfu.new(js, iterations: 2).obfuscate.to_s
28
28
  expect(ob_js).to evaluate_to js
29
29
  end
30
30
  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.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Lee