Module: ZSteg::Checker::WBStego
- Defined in:
- lib/zsteg/checker/wbstego.rb
Defined Under Namespace
Classes: Result
Constant Summary collapse
- ENCRYPTIONS =
[ nil, # 0 "Blowfish", # 1 "Twofish", # 2 "CAST128", # 3 "Rijndael", # 4 ]
Class Method Summary collapse
-
.calc_avail_size(image) ⇒ Object
from wbStego4open sources.
- .check(data, params = {}) ⇒ Object
- .used_colors ⇒ Object
Class Method Details
.calc_avail_size(image) ⇒ Object
from wbStego4open sources
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/zsteg/checker/wbstego.rb', line 69 def calc_avail_size image space = 0 biHeader = image.hdr if biHeader.biCompression == 0 case biHeader.biBitCount when 4 space = 2*image.imagedata_size if used_colors < 9 when 8 space = image.imagedata_size if used_colors < 129 when 24 space = image.imagedata_size end else raise "TODO" # if biHeader.biBitCount=4 then begin # if UsedColors<9 then space:=GetAvailSizeRLE else space:=0; # end; # if biHeader.biBitCount=8 then begin # if UsedColors<129 then space:=GetAvailSizeRLE else space:=0; # end; end space/8 end |
.check(data, params = {}) ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/zsteg/checker/wbstego.rb', line 93 def check data, params = {} return if data.size < 4 return if params[:bit_order] != :lsb force_color = nil if params[:image].format == :bmp return if params[:order] !~ /b/i else # PNG return if Array(params[:channels]).join != 'bgr' force_color = :gray if params[:order] != 'xY' end size1 = (data[0,3] + "\x00").unpack('V')[0] avail_size = if params[:image].format == :bmp calc_avail_size(params[:image]) else params[:max_hidden_size] end return if size1 == 0 || size1 > avail_size # check if too many zeroes, prevent false positive nzeroes = data[3..-1].count("\x00") return if nzeroes > 10 && data.size-3-nzeroes < 4 result = nil size2 = (data[3,3] + "\x00").unpack('V')[0] # p [size1, size2, avail_size] if size2 < avail_size && size2 > 0 spacing = 1.0*avail_size/(size2+5) - 1 # puts "[d] spacing=#{spacing}" if spacing > 0 error = 0 r = '' 6.upto(data.size-1) do |idx| if error < 1 r << data[idx] error += spacing else error -= 1 end end if r.size > 4 ext = r[0,3] result = Result.new(size2, ext, r[3..-1], true) end end end # no even distribution #return unless valid_ext?(data[3,3]) result ||= Result.read(data) result.color = force_color if result && force_color result rescue STDERR.puts "[!] wbStego: #{$!.inspect}".red end |
.used_colors ⇒ Object
64 65 66 |
# File 'lib/zsteg/checker/wbstego.rb', line 64 def used_colors raise "TODO" end |