module Origami::Obfuscator

Constants

FILTERS
MAX_INT
OBJECTS
PRINTABLE
WHITECHARS

Public Class Methods

junk_array(max_size = 5) click to toggle source
# File lib/origami/obfuscation.rb, line 60
def self.junk_array(max_size = 5)
    length = rand(max_size) + 1

    ::Array.new(length) {
        obj = Obfuscator.junk_object until (not obj.nil? and not obj.is_a?(Stream)) ; obj
    }.to_o
end
junk_boolean() click to toggle source
# File lib/origami/obfuscation.rb, line 68
def self.junk_boolean
    Boolean.new(rand(2).zero?)
end
junk_comment(max_size = 15) click to toggle source
# File lib/origami/obfuscation.rb, line 38
def self.junk_comment(max_size = 15)
    length = rand(max_size) + 1

    junk_comment = ::Array.new(length) {
        byte = rand(256).chr until (not byte.nil? and byte != "\n" and byte != "\r"); byte
    }.join

    "%#{junk_comment}#{EOL}"
end
junk_dictionary(max_size = 5) click to toggle source
# File lib/origami/obfuscation.rb, line 72
def self.junk_dictionary(max_size = 5)
    length = rand(max_size) + 1

    hash = Hash.new
    length.times do
        obj = Obfuscator.junk_object
        hash[Obfuscator.junk_name] = obj unless obj.is_a?(Stream)
    end

    hash.to_o
end
junk_integer(max = MAX_INT) click to toggle source
# File lib/origami/obfuscation.rb, line 84
def self.junk_integer(max = MAX_INT)
    Integer.new(rand(max + 1))
end
junk_name(max_size = 8) click to toggle source
# File lib/origami/obfuscation.rb, line 88
def self.junk_name(max_size = 8)
    length = rand(max_size) + 1

    Name.new(::Array.new(length) { PRINTABLE[rand(PRINTABLE.size)] }.join)
end
junk_null() click to toggle source
# File lib/origami/obfuscation.rb, line 94
def self.junk_null
    Null.new
end
junk_object(type = nil) click to toggle source
# File lib/origami/obfuscation.rb, line 48
def self.junk_object(type = nil)
    if type.nil?
        type = OBJECTS[rand(OBJECTS.size)]
    end

    unless type.include?(Origami::Object)
        raise TypeError, "Not a valid object type"
    end

    Obfuscator.send("junk_#{type.to_s.split('::').last.downcase}")
end
junk_real() click to toggle source
# File lib/origami/obfuscation.rb, line 122
def self.junk_real
    Real.new(rand * rand(MAX_INT + 1))
end
junk_reference(max_no = 300, max_gen = 1) click to toggle source
# File lib/origami/obfuscation.rb, line 126
def self.junk_reference(max_no = 300, max_gen = 1)
    no = rand(max_no) + 1
    gen = rand(max_gen)

    Reference.new(no, gen)
end
junk_spaces(max_size = 3) click to toggle source
# File lib/origami/obfuscation.rb, line 32
def self.junk_spaces(max_size = 3)
    length = rand(max_size) + 1

    ::Array.new(length) { WHITECHARS[rand(WHITECHARS.size)] }.join
end
junk_stream(max_data_size = 200) click to toggle source
# File lib/origami/obfuscation.rb, line 98
def self.junk_stream(max_data_size = 200)

    chainlen = rand(2) + 1
    chain = ::Array.new(chainlen) { FILTERS[rand(FILTERS.size)] }

    length = rand(max_data_size) + 1
    junk_data = ::Array.new(length) { rand(256).chr }.join

    stm = Stream.new
    stm.dictionary = Obfuscator.junk_dictionary(5)
    stm.setFilter(chain)
    stm.data = junk_data

    stm
end
junk_string(max_size = 10) click to toggle source
# File lib/origami/obfuscation.rb, line 114
def self.junk_string(max_size = 10)
    length = rand(max_size) + 1

    strtype = (rand(2).zero?) ? LiteralString : HexaString

    strtype.new(::Array.new(length) { PRINTABLE[rand(PRINTABLE.size)] }.join)
end