Class: W32Evol

Inherits:
Object
  • Object
show all
Defined in:
lib/w32evol.rb

Overview

This class wraps the w32evol obfuscation engine. w32evol

Constant Summary collapse

ENGINE_ROOT =

By default the engine is distributed in the ext folder of this gem. This constant allows us to find the path to the engine executable.

File.expand_path(File.join(File.dirname(__FILE__), '..'))
BINARY =

input is in binary format

true
NOSTDIN =

does not accept standard input

true
PLATFORM =

windows program (requires wine in Linux)

"windows"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ W32Evol

The user can instantiate this class by passing in a Hash of options

Default options:

By default the engine is distributed with this gem in the “ext” folder

:command => File.join(ENGINE_ROOT,"ext","bin","w32evol.exe")


23
24
25
26
27
# File 'lib/w32evol.rb', line 23

def initialize(options = {})
	@name = self.class.to_s.downcase
	@options = default_options.merge(options)
	@command_options = generate_command_options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



14
15
16
# File 'lib/w32evol.rb', line 14

def options
  @options
end

Instance Method Details

#obfuscate(input) ⇒ Object

this method obfuscates code and provides the obfuscated code, errors produced by the engine, and the engine’s exit status

Binary String or filename: input
Binary String: output
String: errors
Integer: exitstatus
obfuscate(input) => output, errors, exitstatus


36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/w32evol.rb', line 36

def obfuscate(input)
	output, errors, exitstatus = "", "", 0

	# if input string contains the \xnn escape sequence, 
	# then we can assume that it is code
	# For example, let input = "\x83\xC0\x0A"
	# Then input.inspect => "\"\\x83\"".
	# Thus, input.inspect =~ /\\x../ => 1
	if (input.inspect =~ /\\x.*/) >= 0
		infile = Tempfile.open(["#{@name}_in",'.bin']) do |f| 
			f.binmode
			f.syswrite input
			f.path
		end 
	else
		raise("#{input}: File does not exists or is not readable") \
			unless File.exist?(input) and File.readable?(input)
	end

	outfile = Tempfile.open(["#{@name}_out",'.bin']) {|f| f.path }	
	return obfuscate_inner(infile, outfile)		
end