Class: ZSteg::Checker::WBStego::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/zsteg/checker/wbstego.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Result

Returns a new instance of Result.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/zsteg/checker/wbstego.rb', line 17

def initialize *args
  super
  if self.size.is_a?(String)
    self.size = (self.size[0,3] + "\x00").unpack('V')[0]
  end
  self.even ||= false
  #self.encrypted ||= false
  if ext[0,2] == "\x00\xff"
    # wbStego 4.x header
    self.hdr  = data[0,ext[2].ord] # 3rd ext byte is hdr len
    self.data = data[hdr.size..-1]
    self.ext  = nil                # encrypted files have no ext
    self.enc  = ENCRYPTIONS[hdr[0].ord] || "unknown ##{hdr[0].ord}"
  elsif (cb=ext[0].ord) & 0xc0 != 0
    # wbStego 2.x/3.x controlbyte
    self.controlbyte = ext[0]
    self.data = ext[1..-1] + data
    self.ext  = nil                # have ext but its encrypted/mixed with data
    self.mix  = true if cb & 0x40 != 0
    self.enc  = "wbStego 2.x/3.x" if cb & 0x80 != 0
  end
end

Instance Attribute Details

#colorObject

Returns the value of attribute color.



15
16
17
# File 'lib/zsteg/checker/wbstego.rb', line 15

def color
  @color
end

Instance Method Details

#to_sObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/zsteg/checker/wbstego.rb', line 40

def to_s
  s = inspect.
      sub("#<struct #{self.class.to_s}", "<wbStego").
      gsub(/, \w+=nil/,'')

  color = @color

  if ext && !valid_ext?
    s.sub!(data.inspect, data[0,10].inspect+"...") if data && data.size>13
    color ||= :gray
  else
    s.sub!(data.inspect, data[0,10].inspect+"...") if data && data.size>13 && enc
    color ||= :bright_red
  end
  s.send(color)
end

#valid_ext?Boolean

XXX require that file extension be 7-bit ASCII

Returns:

  • (Boolean)


58
59
60
# File 'lib/zsteg/checker/wbstego.rb', line 58

def valid_ext?
  ext =~ /\A[\x20-\x7e]+\Z/ && !ext['*'] && !ext['?']
end