Sha256: 0c922b96b300c8398321b45f629440af8ecdcc117b7d3bb7d60eeb735eb36d73
Contents?: true
Size: 1.43 KB
Versions: 1
Compression:
Stored size: 1.43 KB
Contents
require 'fileutils' require 'encryptor' require 'digest/sha2' require 'base64' abort "USAGE: obfuscator [encryption_key] [filename]" if(ARGV.size < 2) key = ARGV[0] salt = Time.now.to_i.to_s iv = OpenSSL::Cipher::Cipher.new('aes-256-cbc').random_iv Encryptor.default_options.merge!(:key => key, :iv => iv, :salt => salt) keyword = '__obfuscated' source_file_path = ARGV[1] temp_file_path = "#{source_file_path}.tmp" abort "FATAL: File #{source_file_path} not found!" unless File.exist? source_file_path File.delete(temp_file_path) if File.exist?(temp_file_path) source_file = File.open(source_file_path, 'r') dest_file = File.open(temp_file_path, 'w') while !source_file.eof? line = source_file.readline if line.include? keyword unencrypted_string = line.scan(/@"(.*)"\s*;/).last.first if unencrypted_string.empty? puts "ERROR: Found occurence of __obfuscated string but can't replace!!!" else puts "INFO: File: #{source_file_path}" puts "INFO: Found occurence of __obfuscated string: '#{unencrypted_string}'. Replacing..." end encrypted = "#{Base64.strict_encode64(unencrypted_string.encrypt)}-#{Base64.strict_encode64(iv)}-#{Base64.strict_encode64(salt)}" line.slice! keyword line = line.gsub(unencrypted_string, encrypted) end dest_file.puts line end source_file.close dest_file.close FileUtils.mv source_file_path, "#{source_file_path}.bak" FileUtils.mv temp_file_path, source_file_path
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
objc-obfuscator-0.1.0 | lib/obfuscator.rb |