15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/fileshunter/Decoders/ICO.rb', line 15
def decode(offset)
ending_offset = nil
extension = ((@data[offset+2] == "\x01") ? :ico : :cur)
nbr_images = BinData::Uint16le.read(@data[offset+4..offset+5])
invalid_data("@#{offset} - Number of images is 0") if (nbr_images == 0)
cursor = offset + 6
images = []
nbr_images.times do |idx_image|
nbr_colors = @data[cursor+2].ord
invalid_data("@#{cursor} - Invalid ICONDIRENTRY header") if (@data[cursor+3].ord != 0)
color_planes = BinData::Uint16le.read(@data[cursor+4..cursor+5])
invalid_data("@#{cursor} - Invalid color planes") if ((extension == :ico) and (color_planes > 1))
bpp = BinData::Uint16le.read(@data[cursor+6..cursor+7])
invalid_data("@#{cursor} - Invalid bpp value") if ((extension == :ico) and (!ALLOWED_BPP_VALUES.include?(bpp)))
invalid_data("@#{cursor} - Invalid number of colors") if ((extension == :ico) and (bpp >= 8) and (nbr_colors != 0))
image_size = BinData::Uint32le.read(@data[cursor+8..cursor+11])
invalid_data("@#{cursor} - Invalid image size") if (image_size == 0)
image_offset = BinData::Uint32le.read(@data[cursor+12..cursor+15])
images << [ image_offset, image_size ]
cursor += 16
end
progress(cursor)
next_offset_min = cursor-offset
images.sort.each do |image_offset, image_size|
invalid_data("@#{cursor} - Invalid image offset: #{image_offset} could not be before #{next_offset_min} as it belongs to another image") if (image_offset < next_offset_min)
next_offset_min += image_size
end
log_debug "@#{cursor} - #{extension.to_s} file with #{nbr_images} images."
found_relevant_data(extension)
metadata(
:nbr_images => nbr_images
)
cursor = offset + next_offset_min
progress(cursor)
ending_offset = cursor
return ending_offset
end
|