jsobfu 0.1.5 → 0.1.6
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/hoister.rb +9 -6
- data/lib/jsobfu/obfuscator.rb +0 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NGMzMzBiOTBjMWE5OThjNzQyOWU3OThjZjFmOTlmNGE3ZmYwMzI5YQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NDM0ZmU2ZDk4OWRkMjU3YjEzNmEyZjRhOTYwYmE2OTIxZDZiNjlkZQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MjRlNWFmZGYyN2VmNzA1YmZiM2UzYTc5ZWY1NjhiYmI4ZTllZmRiZGVjOGNl
|
10
|
+
MjNmMmViZTkxOTExOGU1MjlmNWQ0MzU5OGFkZjlmNzA4MDIwY2QwMWEzYTli
|
11
|
+
ZmRlZTc1OWZkNTlhMDRlYzhlM2FiYmQyMjBhMTg1ZmVjMmRlMDI=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
Mjg5ZTYwODcyNjg2ODU3OTgyNjA1NTQ1MWI3MTE0YzMzZmIwYmMwMTllMGMw
|
14
|
+
YTE3NGYxOTdlYzk3NDBiMWFhMDhmZDFiNWFkODI3MTVjMTNjODkxNDA0Nzcy
|
15
|
+
YzQ2OTA0M2NlNmM1YWQ1YzhjNzY5OGQ3Y2M3MTE1NDE4MjgzZWE=
|
data/lib/jsobfu/hoister.rb
CHANGED
@@ -3,6 +3,9 @@
|
|
3
3
|
# root scope, which is useful for "hoisting" var and function
|
4
4
|
# declaration to the top of the function.
|
5
5
|
#
|
6
|
+
# Although the auto-hoisting is no longer used, this class is used
|
7
|
+
# to "discover" a function's variables and scope.
|
8
|
+
#
|
6
9
|
class JSObfu::Hoister < RKelly::Visitors::Visitor
|
7
10
|
|
8
11
|
# @return [Hash] the scope maintained while walking the ast
|
@@ -11,12 +14,14 @@ class JSObfu::Hoister < RKelly::Visitors::Visitor
|
|
11
14
|
# @return [Array<String>] the function names in the first level of this closure
|
12
15
|
attr_reader :functions
|
13
16
|
|
17
|
+
# @param opts [Hash] the options hash
|
18
|
+
# @option opts [Integer] :max_depth the maximum depth to hoist (1)
|
19
|
+
# @option opts [Scope] :parent_scope the owner's scope
|
14
20
|
def initialize(opts={})
|
15
21
|
@parent_scope = opts.fetch(:parent_scope, nil)
|
16
22
|
@max_depth = 1
|
17
23
|
@depth = 0
|
18
24
|
@scope = {}
|
19
|
-
@resolves = []
|
20
25
|
@functions = []
|
21
26
|
super()
|
22
27
|
end
|
@@ -33,7 +38,7 @@ class JSObfu::Hoister < RKelly::Visitors::Visitor
|
|
33
38
|
end
|
34
39
|
|
35
40
|
def visit_FunctionDeclNode(o)
|
36
|
-
|
41
|
+
functions << o.value
|
37
42
|
scope[o.value] = o
|
38
43
|
end
|
39
44
|
|
@@ -69,16 +74,14 @@ class JSObfu::Hoister < RKelly::Visitors::Visitor
|
|
69
74
|
keys = keys.shuffle
|
70
75
|
end
|
71
76
|
|
72
|
-
keys.delete_if { |k|
|
77
|
+
keys.delete_if { |k| functions.include? k }
|
73
78
|
|
74
79
|
if @parent_scope
|
75
80
|
keys.delete_if { |k| @parent_scope.has_key? k }
|
76
81
|
keys.map! { |k| @parent_scope.renames[k.to_s] || k }
|
77
82
|
end
|
78
83
|
|
79
|
-
|
80
|
-
# puts str if str.length>0
|
81
|
-
str
|
84
|
+
if keys.empty? then '' else "var #{keys.join(",")};" end
|
82
85
|
end
|
83
86
|
|
84
87
|
end
|
data/lib/jsobfu/obfuscator.rb
CHANGED