Class: ZSteg::FileCmd
- Inherits:
-
Object
- Object
- ZSteg::FileCmd
- Defined in:
- lib/zsteg/file_cmd.rb
Defined Under Namespace
Classes: Result
Constant Summary collapse
- IGNORES =
[ 'data', 'empty', 'Sendmail frozen configuration', 'DBase 3 data file', 'DOS executable', 'Dyalog APL', '8086 relocatable', 'SysEx File', 'COM executable', 'Non-ISO extended-ASCII text', 'ISO-8859 text', 'very short file', 'International EBCDIC text', 'lif file', 'AmigaOS bitmap font', 'a python script text executable' # common false positive ]
- MIN_DATA_SIZE =
5
Instance Method Summary collapse
- #check_data(data) ⇒ Object
- #check_file(fname) ⇒ Object
-
#data2result(data) ⇒ Object
checks data and resurns Result, if any.
- #start! ⇒ Object
- #stop! ⇒ Object
Instance Method Details
#check_data(data) ⇒ Object
76 77 78 79 80 81 82 |
# File 'lib/zsteg/file_cmd.rb', line 76 def check_data data @tempfile ||= Tempfile.new('zsteg', :encoding => 'binary') @tempfile.rewind @tempfile.write data @tempfile.flush check_file @tempfile.path end |
#check_file(fname) ⇒ Object
70 71 72 73 74 |
# File 'lib/zsteg/file_cmd.rb', line 70 def check_file fname @stdin.puts fname r = @stdout.gets.force_encoding('binary').strip IGNORES.any?{ |x| r.index(x) == 0 } ? nil : r end |
#data2result(data) ⇒ Object
checks data and resurns Result, if any
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/zsteg/file_cmd.rb', line 85 def data2result data return if data.size < MIN_DATA_SIZE title = check_data data return unless title if title[/UTF-8 Unicode text/i] begin t = data.force_encoding("UTF-8") rescue t = data.force_encoding('binary') end if t.size >= Checker::DEFAULT_MIN_STR_LEN ZSteg::Result::UnicodeText.new(t,0) end else Result.new(title,data) end end |
#start! ⇒ Object
66 67 68 |
# File 'lib/zsteg/file_cmd.rb', line 66 def start! @stdin, @stdout, @stderr, @wait_thr = Open3.popen3("file -n -b -f -") end |
#stop! ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/zsteg/file_cmd.rb', line 105 def stop! @stdin.close @stdout.close @stderr.close ensure if @tempfile @tempfile.close @tempfile.unlink @tempfile = nil end end |