w32evol_ruby 0.0.1

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.
data/README.rdoc ADDED
@@ -0,0 +1,75 @@
1
+ = w32evol_wrapper -- w32evol obfuscation engine wrapped in Ruby
2
+
3
+ == Table of Contents
4
+ 1. Introduction
5
+ 2. Dependencies
6
+ 3. Installation
7
+ 4. Usage
8
+ 5. Development
9
+
10
+ == 1. Introduction
11
+ <b>Does not contain a virus</b>
12
+
13
+ This is a Ruby wrapper for the obfuscation engine
14
+ {w32evol}[https://bitbucket.org/martinvelez/w32evol].
15
+
16
+ The {w32evol}[https://bitbucket.org/martinvelez/w32evol] obfuscation engine
17
+ has a command line interface. This wrapper allows you to use the obfuscation
18
+ engine within your Ruby scripts.
19
+
20
+ == 2. Dependencies
21
+
22
+ * {Ruby 1.9.2}[http://www.ruby-lang.org/en/downloads/] or greater
23
+ * {wine}[http://www.winehq.org/download] (1.3 or greater, may work with 1.2)
24
+ * {w32evol}[https://bitbucket.org/martinvelez/w32evol/downloads]
25
+ (v0.1.0 is include in this gem's ext folder)
26
+
27
+ == 3. Installation
28
+
29
+ === Rubygems:
30
+ You might need to use sudo.
31
+ gem install w32evol_ruby
32
+
33
+ === Not Rubygems:
34
+ 1. Download w32evol_ruby[http://bitbucket.org/martinvelez/w32evol_ruby/downloads]
35
+ 2. Require the w32evol Ruby class file in your program (lib folder)
36
+ * The w32evol.exe engine is located in this gems ext folder.
37
+
38
+ == 4. Usage
39
+
40
+ === Example 1
41
+ This example is found in the examples directory.
42
+ #!/usr/bin/env ruby
43
+
44
+ require 'w32evol_ruby'
45
+
46
+ ARGF.binmode
47
+ input = ARGF.read
48
+ # Assuming engine is installed in this gem's "ext" folder.
49
+ # Otherwise, you must pass the engine's executable path to the class's
50
+ # constructor.
51
+ # For example:
52
+ # engine = W32Evol.new({:command => "/path/to/engine"})
53
+ engine = W32Evol.new
54
+
55
+ output, errors, status = engine.obfuscate(input)
56
+
57
+ puts "INPUT:", input.inspect
58
+ puts "STATUS:", status
59
+ puts "ERRORS: ", errors
60
+ puts "OUTPUT:", output.inspect
61
+
62
+
63
+ == 5. Development
64
+
65
+ Author:: {Martin Velez}[http://www.martinvelez.com]
66
+ Copyright:: Copyright (C) 2012 {Martin Velez}[http://www.martinvelez.com]
67
+ License:: GPL[http://www.gnu.org/copyleft/gpl.html]
68
+
69
+ === Source
70
+ Bitbucket[https://bitbucket.org/martinvelez/w32evol_ruby/src] is hosting this code.
71
+ http://bitbucket.org/martinvelez/w32evol_ruby/src
72
+
73
+ === Issues and Bug Reports
74
+ Provide feedback, get help, request features, and reports bugs here:
75
+ https://bitbucket.org/martinvelez/w32evol_ruby/issues?status=new?status=open
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ #require 'w32evol_ruby'
4
+ require '../lib/w32evol.rb'
5
+
6
+ ARGF.binmode
7
+ input = ARGF.read
8
+ # Assuming engine is installed in this gem's "ext" folder.
9
+ # Otherwise, you must pass the engine's executable path to the class's
10
+ # constructor.
11
+ # For example:
12
+ # engine = W32Evol.new({:command => "/path/to/engine"})
13
+ engine = W32Evol.new
14
+
15
+ output, errors, status = engine.obfuscate(input)
16
+
17
+ puts "INPUT:", input.inspect
18
+ puts "STATUS:", status
19
+ puts "ERRORS: ", errors
20
+ puts "OUTPUT:", output.inspect
data/examples/in.bin ADDED
@@ -0,0 +1 @@
1
+ ��
data/ext/w32evol.exe ADDED
Binary file
data/lib/w32evol.rb ADDED
@@ -0,0 +1,112 @@
1
+ require 'tempfile'
2
+
3
+ # This class wraps the w32evol obfuscation engine.
4
+ # {w32evol}[https://github.com/martinvelez/w32evol]
5
+ class W32Evol
6
+
7
+ # By default the engine is distributed in the ext folder of this gem.
8
+ # This constant allows us to find the path to the engine executable.
9
+ ENGINE_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
10
+ BINARY = true # input is in binary format
11
+ NOSTDIN = true # does not accept standard input
12
+ PLATFORM = "windows" # windows program (requires wine in Linux)
13
+
14
+ attr_reader :options
15
+
16
+ # The user can instantiate this class by passing in a Hash of options
17
+ #
18
+ # Default options:
19
+ #
20
+ # By default the engine is distributed with this gem in the "ext" folder
21
+ # :command => File.join(ENGINE_ROOT,"ext","bin","w32evol.exe")
22
+ #
23
+ def initialize(options = {})
24
+ @name = self.class.to_s.downcase
25
+ @options = default_options.merge(options)
26
+ @command_options = generate_command_options
27
+ end
28
+
29
+ # this method obfuscates code and provides the obfuscated code, errors
30
+ # produced by the engine, and the engine's exit status
31
+ # Binary String or filename: input
32
+ # Binary String: output
33
+ # String: errors
34
+ # Integer: exitstatus
35
+ # obfuscate(input) => output, errors, exitstatus
36
+ def obfuscate(input)
37
+ output, errors, exitstatus = "", "", 0
38
+
39
+ # if input string contains the \xnn escape sequence,
40
+ # then we can assume that it is code
41
+ # For example, let input = "\x83\xC0\x0A"
42
+ # Then input.inspect => "\"\\x83\"".
43
+ # Thus, input.inspect =~ /\\x../ => 1
44
+ if (input.inspect =~ /\\x.*/) >= 0
45
+ infile = Tempfile.open(["#{@name}_in",'.bin']) do |f|
46
+ f.binmode
47
+ f.syswrite input
48
+ f.path
49
+ end
50
+ else
51
+ raise("#{input}: File does not exists or is not readable") \
52
+ unless File.exist?(input) and File.readable?(input)
53
+ end
54
+
55
+ outfile = Tempfile.open(["#{@name}_out",'.bin']) {|f| f.path }
56
+ return obfuscate_inner(infile, outfile)
57
+ end
58
+
59
+ private
60
+ # This method defines the default options in a Hash
61
+ #
62
+ # By default, the engine is expected to be in the "ext" folder.
63
+ #
64
+ def default_options
65
+ {
66
+ # By default the engine is in the ext folder of this gem
67
+ # This assumes that the wine command in in your PATH
68
+ :command => File.join(ENGINE_ROOT,"ext","#{@name}.exe")
69
+ }
70
+ end
71
+
72
+ # This method converts the options Hash into a string of flags for the
73
+ # command line call.
74
+ #
75
+ # Example output:
76
+ # "--x cpp --x iso --x motif --x posix2 --x stl --x unix95 --x xpg4"
77
+ def generate_command_options
78
+ command_options = ""
79
+ @options.each do |key, value|
80
+ if key.to_s != "command"
81
+ if value.kind_of?(Array)
82
+ value.each{|val| command_options += "#{key} #{val} "}
83
+ elsif
84
+ command_options += "#{key} #{value} "
85
+ end
86
+ end
87
+ end
88
+ command_options.rstrip
89
+ end
90
+
91
+ # This method obfuscate the code in infile and stores in outfile
92
+ #
93
+ # It is used for engines with a command line interface which requires an input
94
+ # file name, and an output file name.
95
+ def obfuscate_inner(infile, outfile)
96
+ # This engine does not output to stderr, it only returns an exit code if it
97
+ # fails.
98
+ output, errors, exitstatus = "", "", 0
99
+ cmd = "#{@options[:command]} #{infile} #{outfile}"
100
+ cmd.insert(0, "wine ") if (PLATFORM == 'windows' and RUBY_PLATFORM =~ /linux/)
101
+ system(cmd)
102
+ exitstatus = $?.exitstatus
103
+ if exitstatus == 0 # if engine success
104
+ f = File.new(outfile)
105
+ output = f.sysread(f.size)
106
+ f.close
107
+ end
108
+ return output, errors, exitstatus
109
+ end
110
+
111
+ end
112
+
@@ -0,0 +1,18 @@
1
+ require 'minitest/autorun'
2
+ require 'w32evol'
3
+
4
+ class TestW32Evol < MiniTest::Unit::TestCase
5
+
6
+ def setup
7
+ @engine = W32Evol.new
8
+ @input = "\x83\xC0\x0A"
9
+ end
10
+
11
+ def test_obfuscate
12
+ output, errors, status = @engine.obfuscate(@input)
13
+ assert_equal "\x81\xC0\x0A\x00\x00\x00", output
14
+ assert_equal "", errors
15
+ assert_equal 0, status
16
+ end
17
+ end
18
+
metadata ADDED
@@ -0,0 +1,69 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: w32evol_ruby
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Martin Velez
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2012-01-31 00:00:00 -08:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: Provides a Ruby wrapper for the w32evol obfuscation engine
22
+ email: mvelez999@gmail.com
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files: []
28
+
29
+ files:
30
+ - lib/w32evol.rb
31
+ - ext/w32evol.exe
32
+ - examples/in.bin
33
+ - examples/example.rb
34
+ - test/test_w32evol.rb
35
+ - README.rdoc
36
+ has_rdoc: true
37
+ homepage: http://bitbucket.org/martinvelez/w32evol
38
+ licenses: []
39
+
40
+ post_install_message:
41
+ rdoc_options: []
42
+
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ none: false
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ segments:
51
+ - 0
52
+ version: "0"
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ segments:
59
+ - 0
60
+ version: "0"
61
+ requirements: []
62
+
63
+ rubyforge_project:
64
+ rubygems_version: 1.3.7
65
+ signing_key:
66
+ specification_version: 3
67
+ summary: A Ruby wrapper for the w32evol obfuscation engine
68
+ test_files: []
69
+