jsobfu 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/jsobfu.rb +7 -0
- data/lib/jsobfu/disable.rb +26 -0
- data/spec/jsobfu/disable_spec.rb +33 -0
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YmYzNDQzNTA3YzQ3NGMwMDY1YzViYTkxOGYzYzVmM2Q5MzI5OGRlOA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MWM3MDA4ZDg3MmY2ZDE2MWMzODcyMzY3Y2YzMTdhNzY3MWQ4Njk3Mw==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZjdkNDdjYjQ1ODliNmYwMTY5MTAxYzQyOTE0M2IzZWIxYzI2OGE0YTU2ZTQx
|
10
|
+
ZDY2M2E2MDc4MTBlMGVhZmU1ZmQ5NzFlZTc1NjAxZjVjOWQ5ODFhMGMxMDdl
|
11
|
+
MTM5ODIyZWU1YzQ4OGE1ZmM1MGQ0ZTJjMzc4NGE4MTQ1YWExMjU=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NDhiYzNjMzliYmI1ZjZlMzZkYTk4NjBlNzM2NjQ1M2FkZTM0NTM2YTY5ODFj
|
14
|
+
MmYxMmRlZDIwNDFhYzYwMTYyZTRkYjQ1NDIzM2YzYzY4OWRjZjcwM2MxZjk3
|
15
|
+
YWI0MTQ1MzdhMGM4OWNlMDY3OGNlM2Y1YWU5YzVkMjkzOTM5ODI=
|
data/lib/jsobfu.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'rkelly'
|
2
2
|
|
3
|
+
#
|
3
4
|
# The primary class, used to parse and obfuscate Javascript code.
|
5
|
+
#
|
4
6
|
class JSObfu
|
5
7
|
|
6
8
|
require_relative 'jsobfu/scope'
|
@@ -8,6 +10,9 @@ class JSObfu
|
|
8
10
|
require_relative 'jsobfu/ecma_tight'
|
9
11
|
require_relative 'jsobfu/hoister'
|
10
12
|
require_relative 'jsobfu/obfuscator'
|
13
|
+
require_relative 'jsobfu/disable'
|
14
|
+
|
15
|
+
include JSObfu::Disable
|
11
16
|
|
12
17
|
# @return [JSObfu::Scope] the global scope
|
13
18
|
attr_reader :scope
|
@@ -44,6 +49,8 @@ class JSObfu
|
|
44
49
|
# obfuscator on this code (1)
|
45
50
|
# @return [String] if successful
|
46
51
|
def obfuscate(opts={})
|
52
|
+
return self if JSObfu.disabled?
|
53
|
+
|
47
54
|
iterations = opts.fetch(:iterations, 1).to_i
|
48
55
|
strip_whitespace = opts.fetch(:strip_whitespace, true)
|
49
56
|
|
@@ -0,0 +1,26 @@
|
|
1
|
+
#
|
2
|
+
# Behavior for disabling JSObfu during spec runs
|
3
|
+
#
|
4
|
+
module JSObfu::Disable
|
5
|
+
|
6
|
+
module ClassMethods
|
7
|
+
# Set up some class variables for allowing specs
|
8
|
+
@@lock = Mutex.new
|
9
|
+
@@disabled = false
|
10
|
+
|
11
|
+
# Disables obfuscation globally, useful for unit tests etc
|
12
|
+
def disabled=(val)
|
13
|
+
@@lock.synchronize { @@disabled = val }
|
14
|
+
end
|
15
|
+
|
16
|
+
# Disables obfuscation globally, useful for unit tests etc
|
17
|
+
def disabled?
|
18
|
+
@@disabled
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.included(base)
|
23
|
+
base.extend(ClassMethods)
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe JSObfu::Disable do
|
4
|
+
|
5
|
+
let(:test_str) { 'alert("JOE");' }
|
6
|
+
let(:signature) { 'JOE' }
|
7
|
+
|
8
|
+
context 'before calling JSObfu.disabled = true' do
|
9
|
+
it 'obfuscates the string' do
|
10
|
+
expect(JSObfu.new(test_str).obfuscate.to_s).not_to include(signature)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
context 'after calling JSObfu.disabled = true' do
|
15
|
+
|
16
|
+
before { JSObfu.disabled = true }
|
17
|
+
after { JSObfu.disabled = false }
|
18
|
+
|
19
|
+
it 'does not obfuscate the string' do
|
20
|
+
expect(JSObfu.new(test_str).obfuscate.to_s).to include(signature)
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'and then calling JSObfu.disabled = false' do
|
24
|
+
before { JSObfu.disabled = false }
|
25
|
+
|
26
|
+
it 'obfuscates the string' do
|
27
|
+
expect(JSObfu.new(test_str).obfuscate.to_s).not_to include(signature)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
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.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Lee
|
@@ -88,6 +88,7 @@ extensions: []
|
|
88
88
|
extra_rdoc_files: []
|
89
89
|
files:
|
90
90
|
- lib/jsobfu.rb
|
91
|
+
- lib/jsobfu/disable.rb
|
91
92
|
- lib/jsobfu/ecma_tight.rb
|
92
93
|
- lib/jsobfu/hoister.rb
|
93
94
|
- lib/jsobfu/obfuscator.rb
|
@@ -95,6 +96,7 @@ files:
|
|
95
96
|
- lib/jsobfu/utils.rb
|
96
97
|
- samples/basic.rb
|
97
98
|
- spec/integration_spec.rb
|
99
|
+
- spec/jsobfu/disable_spec.rb
|
98
100
|
- spec/jsobfu/hoister_spec.rb
|
99
101
|
- spec/jsobfu/scope_spec.rb
|
100
102
|
- spec/jsobfu/utils_spec.rb
|