Module | Origami::Obfuscator |
In: |
sources/parser/obfuscation.rb
|
WHITECHARS | = | [ " ", "\t", "\r", "\n", "\0" ] |
OBJECTS | = | [ Array, Boolean, Dictionary, Integer, Name, Null, Stream, String, Real, Reference ] |
MAX_INT | = | 0xFFFFFFFF |
PRINTABLE | = | ("!".."9").to_a + (':'..'Z').to_a + ('['..'z').to_a + ('{'..'~').to_a |
FILTERS | = | [ :FlateDecode, :RunLengthDecode, :LZWDecode, :ASCIIHexDecode, :ASCII85Decode ] |
# File sources/parser/obfuscation.rb, line 40 40: def self.junk_array(max_size = 5) 41: length = rand(max_size) + 1 42: 43: ::Array.new(length) { 44: obj = Obfuscator.junk_object until (not obj.nil? and not obj.is_a?(Stream)) ; obj 45: }.to_o 46: end
# File sources/parser/obfuscation.rb, line 48 48: def self.junk_boolean 49: Boolean.new(rand(2).zero?) 50: end
# File sources/parser/obfuscation.rb, line 17 17: def self.junk_comment(max_size = 15) 18: length = rand(max_size) + 1 19: 20: junk_comment = ::Array.new(length) { 21: byte = rand(256).chr until (not byte.nil? and byte != "\n" and byte != "\r"); byte 22: }.join 23: 24: "%#{junk_comment}#{EOL}" 25: end
# File sources/parser/obfuscation.rb, line 52 52: def self.junk_dictionary(max_size = 5) 53: length = rand(max_size) + 1 54: 55: hash = Hash.new 56: length.times do 57: obj = Obfuscator.junk_object 58: hash[Obfuscator.junk_name] = obj unless obj.is_a?(Stream) 59: end 60: 61: hash.to_o 62: end
# File sources/parser/obfuscation.rb, line 64 64: def self.junk_integer(max = MAX_INT) 65: Integer.new(rand(max + 1)) 66: end
# File sources/parser/obfuscation.rb, line 68 68: def self.junk_name(max_size = 8) 69: length = rand(max_size) + 1 70: 71: Name.new(::Array.new(length) { PRINTABLE[rand(PRINTABLE.size)] }.join) 72: end
# File sources/parser/obfuscation.rb, line 27 27: def self.junk_object(type = nil) 28: 29: if type.nil? 30: type = OBJECTS[rand(OBJECTS.size)] 31: end 32: 33: unless type.include?(Origami::Object) 34: raise TypeError, "Not a valid object type" 35: end 36: 37: Obfuscator.send("junk_#{type.to_s.split('::').last.downcase}") 38: end
# File sources/parser/obfuscation.rb, line 102 102: def self.junk_real 103: Real.new(rand * rand(MAX_INT + 1)) 104: end
# File sources/parser/obfuscation.rb, line 106 106: def self.junk_reference(max_no = 300, max_gen = 1) 107: no = rand(max_no) + 1 108: gen = rand(max_gen) 109: 110: Reference.new(no, gen) 111: end
# File sources/parser/obfuscation.rb, line 11 11: def self.junk_spaces(max_size = 3) 12: length = rand(max_size) + 1 13: 14: ::Array.new(length) { WHITECHARS[rand(WHITECHARS.size)] }.join 15: end
# File sources/parser/obfuscation.rb, line 78 78: def self.junk_stream(max_data_size = 200) 79: 80: chainlen = rand(2) + 1 81: chain = ::Array.new(chainlen) { FILTERS[rand(FILTERS.size)] } 82: 83: length = rand(max_data_size) + 1 84: junk_data = ::Array.new(length) { rand(256).chr }.join 85: 86: stm = Stream.new 87: stm.dictionary = Obfuscator.junk_dictionary(5) 88: stm.setFilter(chain) 89: stm.data = junk_data 90: 91: stm 92: end