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 +8 -8
- data/lib/jsobfu.rb +19 -8
- data/lib/jsobfu/utils.rb +7 -5
- data/spec/integration_spec.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MzdlMDRlNzdmNTVjM2Y2NTk0NGIyNjZmOGFjMGU4YWZlOGNhNmU5OA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MTJjMzU2ZDJjMGU2ODZkZjhkNWNhYjBhYmQ5MWMyNDUwNzY2MWM3Ng==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZmQ0MjBiZWMyZDhkMWJkOWY1MmU3MmRjNmQwNDhhODYyMzFmMDU2ZTY3MzNi
|
10
|
+
YmQ2Y2E1MjhlNTI1ZTBhYTZlY2YzYWVlZTUwZmRmZDljNWEwM2M2ZTI0YTRk
|
11
|
+
ZGM4MjQwMzhhOTZlMzc0Y2YzYmNmNDcxNmRjYzU1YzY1ZDM1ZmU=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZmE4Yjg0YWE4OGNkMTdjYzc0ODg2MmFjZDJlMGEzZDM0YmZkNTQ2ZTAzZGMy
|
14
|
+
MDE5YThmNTNlYTg2Y2Q5YjM4MmE1ZDI4Y2NiNTgxMWE4ZjhhZTBmMTYwNzVi
|
15
|
+
MTE5NDczMjE0MzcyMGRhZDEyNGZlNmFkZTIxNjE2MGYwNDZkZTI=
|
data/lib/jsobfu.rb
CHANGED
@@ -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]
|
17
|
-
|
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
|
-
@
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
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
|
|
data/lib/jsobfu/utils.rb
CHANGED
@@ -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
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
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
|
data/spec/integration_spec.rb
CHANGED
@@ -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
|