Created
November 15, 2013 14:59
-
-
Save Youngv/7485626 to your computer and use it in GitHub Desktop.
这是一个在JPG图片中隐藏Zip压缩文件的脚本。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'rubygems' | |
require 'zip' | |
class HideSecretInJpg | |
def file_to_zip(filename) | |
floder = File.expand_path(File.dirname(filename)) | |
zipfile = File.basename(filename, ".*") + ".zip" | |
#zipfile = filename.sub(/\.\w+$/,"") + ".zip" | |
input_filenames = [filename] | |
Zip::File.open(zipfile, Zip::File::CREATE) do |zf| | |
input_filenames.each do |fn| | |
zf.add(fn, floder + '/' + fn) | |
end | |
end | |
return zipfile | |
end | |
def zip_to_jpg(zip_file, jpg_file = "default.jpg") | |
jpg = File.open(jpg_file, 'rb') { |f| f.read } | |
zip = File.open(zip_file, 'rb') { |f| f.read } | |
jpg_zip = jpg + zip | |
File.open(File.basename(zip_file, ".*") + ".jpg", 'w') { |f| f.write(jpg_zip) } | |
end | |
def hide_secret_in_jpg(input_file, jpg_file = "default.jpg") | |
if input_file | |
if File.exist?(input_file) | |
zip_to_jpg(file_to_zip(input_file)) | |
File.delete(input_file.sub(/\.\w+$/,"") + ".zip") | |
else | |
puts "#{input_file} doesn't exist in current directory!" | |
end | |
else | |
puts "You haven't choose which file to hide!" | |
end | |
end | |
end | |
file = HideSecretInJpg.new | |
file.hide_secret_in_jpg(ARGV[0]) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment