jsobfu 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe JSObfu do
4
+
5
+ TEST_STRING = 'var x; function y() {};'
6
+
7
+ subject(:jsobfu) do
8
+ instance = described_class.new(TEST_STRING)
9
+ instance.obfuscate
10
+ instance
11
+ end
12
+
13
+ describe '#sym' do
14
+ context 'when given the string "x"' do
15
+ it 'returns some string' do
16
+ expect(jsobfu.sym('x')).not_to be_nil
17
+ end
18
+ end
19
+
20
+ context 'when given the string "YOLOSWAG"' do
21
+ it 'returns nil' do
22
+ expect(jsobfu.sym('YOLOSWAG')).to be_nil
23
+ end
24
+ end
25
+ end
26
+
27
+ end
@@ -0,0 +1,68 @@
1
+ require 'simplecov'
2
+ require 'rspec/core'
3
+ require 'rspec/mocks'
4
+ require 'jsobfu'
5
+
6
+ # Requires supporting ruby files with custom matchers and macros, etc,
7
+ # in spec/support/ and its subdirectories.
8
+ spec_pathname = Pathname.new(__FILE__).dirname
9
+ root_pathname = spec_pathname.join('..').expand_path
10
+ support_glob = root_pathname.join('spec', 'support', '**', '*.rb')
11
+ Dir.glob(support_glob) do |path|
12
+ require path
13
+ end
14
+
15
+ # Copied from Luke's blogpost about setting up a gem:
16
+ # https://community.rapid7.com/community/metasploit/blog/2014/09/16/ \
17
+ # metasploit-gems-from-scratch
18
+ RSpec.configure do |config|
19
+ # Use color in STDOUT
20
+ config.color = true
21
+
22
+ # Use color not only in STDOUT but also in pagers and files
23
+ config.tty = true
24
+
25
+ # Use the specified formatter
26
+ config.formatter = :documentation
27
+
28
+ # These two settings work together to allow you to limit a spec run
29
+ # to individual examples or groups you care about by tagging them with
30
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
31
+ # get run.
32
+ config.filter_run :focus
33
+ config.run_all_when_everything_filtered = true
34
+
35
+ # allow more verbose output when running an individual spec file.
36
+ if config.files_to_run.one?
37
+ # RSpec filters the backtrace by default so as not to be so noisy.
38
+ # This causes the full backtrace to be printed when running a single
39
+ # spec file (e.g. to troubleshoot a particular spec failure).
40
+ config.full_backtrace = true
41
+ end
42
+
43
+ # Run specs in random order to surface order dependencies. If you find an
44
+ # order dependency and want to debug it, you can fix the order by providing
45
+ # the seed, which is printed after each run.
46
+ # --seed 1234
47
+ config.order = :random
48
+
49
+ # Seed global randomization in this process using the `--seed` CLI option.
50
+ # Setting this allows you to use `--seed` to deterministically reproduce
51
+ # test failures related to randomization by passing the same `--seed` value
52
+ # as the one that triggered the failure.
53
+ Kernel.srand config.seed
54
+
55
+ config.expect_with :rspec do |expectations|
56
+ # Enable only the newer, non-monkey-patching expect syntax.
57
+ expectations.syntax = :expect
58
+ end
59
+
60
+ # rspec-mocks config goes here. You can use an alternate test double
61
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
62
+ config.mock_with :rspec do |mocks|
63
+ # Enable only the newer, non-monkey-patching expect syntax.
64
+ # For more details, see:
65
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
66
+ mocks.syntax = :expect
67
+ end
68
+ end
@@ -0,0 +1,5 @@
1
+ RSpec::Matchers.define :be_in_charset do |charset|
2
+ match do |string|
3
+ string.chars.all? { |c| charset.include?(c) }
4
+ end
5
+ end
@@ -0,0 +1,41 @@
1
+ require 'json'
2
+
3
+ RSpec::Matchers.define :evaluate_to do |expected|
4
+ match do |observed|
5
+ begin
6
+ @expected_output = ExecJS.compile(expected).call('test')
7
+ rescue ExecJS::ProgramError => e
8
+ @example_failed = e
9
+ @bail = true
10
+ end
11
+
12
+ begin
13
+ @observed_output = ExecJS.compile(observed).call('test')
14
+ rescue ExecJS::ProgramError => e
15
+ @compiled_failed = e
16
+ @bail = true
17
+ end
18
+
19
+ if @observed_output.nil? or @expected_output.nil?
20
+ @output_nil = true
21
+ @bail = true
22
+ end
23
+
24
+ unless @bail
25
+ expect(@observed_output).to eq @expected_output
26
+ end
27
+ end
28
+
29
+ failure_message do |observed|
30
+ if @example_failed
31
+ "runtime error while evaluating:\n\n#{expected}\n\n#{@example_failed}"
32
+ elsif @compiled_failed
33
+ "runtime error while evaluating:\n\n#{observed}\n\n#{@compiled_failed}"
34
+ elsif @output_nil
35
+ "output was nil:\n\nexpected: #{@expected_output}\n\nobserved: #{@observed_output}"
36
+ else
37
+ "expected that the code:\n\n#{expected}:\n\n=> #{@expected_output}\n\n"+
38
+ "evaluate to the same result as :\n\n#{observed}\n\n=> #{@observed_output}"
39
+ end
40
+ end
41
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jsobfu
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - James Lee
8
+ - Joe Vennix
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-04-09 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rkelly-remix
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ~>
19
+ - !ruby/object:Gem::Version
20
+ version: 0.0.6
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ version: 0.0.6
28
+ - !ruby/object:Gem::Dependency
29
+ name: rspec
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ~>
33
+ - !ruby/object:Gem::Version
34
+ version: '3.1'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ~>
40
+ - !ruby/object:Gem::Version
41
+ version: '3.1'
42
+ - !ruby/object:Gem::Dependency
43
+ name: simplecov
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ! '>='
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: execjs
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: rake
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ! '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ description:
85
+ email: joev@metasploit.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - lib/jsobfu.rb
91
+ - lib/jsobfu/ecma_tight.rb
92
+ - lib/jsobfu/hoister.rb
93
+ - lib/jsobfu/obfuscator.rb
94
+ - lib/jsobfu/scope.rb
95
+ - lib/jsobfu/utils.rb
96
+ - samples/basic.rb
97
+ - spec/integration_spec.rb
98
+ - spec/jsobfu/hoister_spec.rb
99
+ - spec/jsobfu/scope_spec.rb
100
+ - spec/jsobfu/utils_spec.rb
101
+ - spec/jsobfu_spec.rb
102
+ - spec/spec_helper.rb
103
+ - spec/support/matchers/be_in_charset.rb
104
+ - spec/support/matchers/evaluate_to.rb
105
+ homepage: https://github.com/rapid7/jsobfu
106
+ licenses:
107
+ - BSD-3-Clause
108
+ metadata: {}
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ! '>='
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubyforge_project:
125
+ rubygems_version: 2.2.2
126
+ signing_key:
127
+ specification_version: 4
128
+ summary: A Javascript code obfuscator
129
+ test_files: []
130
+ has_rdoc: