#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
exit 1 if ARGV.size<2
File.open(ARGV[0]) {|f|
data = f.read.unpack("B*")[0]
puts "<wxHexEditor_XML_TAG><filename>"
ARGV[1..-1].each {|ss|
pos = 0
sbs = (eval ss).to_s(2)
note_colour = sprintf("#%02X%02X%02X", *(1..3).map{rand(0x7f)+0x80})
while m = data.match(sbs, pos) do
puts %Q{ <TAG>
<start_offset>#{m.begin(0)/8}</start_offset>
<end_offset>#{m.end(0)/8}</end_offset>
<tag_text>#{sprintf("0x%08X(%d) : %s [%s]", m.begin(0)/8, m.begin(0)%8, ss, sbs)}</tag_text>
<note_colour>#{note_colour}</note_colour>
</TAG>}
pos = m.begin(0) + 1
end
}
puts "</filename></wxHexEditor_XML_TAG>"
}
IyEvdXNyL2Jpbi9lbnYgcnVieQojIC0qLSBjb2Rpbmc6IHV0Zi04IC0qLQoKZXhpdCAxIGlmIEFSR1Yuc2l6ZTwyCkZpbGUub3BlbihBUkdWWzBdKSB7fGZ8CgogIGRhdGEgPSBmLnJlYWQudW5wYWNrKCJCKiIpWzBdCgogIHB1dHMgIjx3eEhleEVkaXRvcl9YTUxfVEFHPjxmaWxlbmFtZT4iCiAgQVJHVlsxLi4tMV0uZWFjaCB7fHNzfAogICAgcG9zID0gMAogICAgc2JzID0gKGV2YWwgc3MpLnRvX3MoMikKICAgIG5vdGVfY29sb3VyID0gc3ByaW50ZigiIyUwMlglMDJYJTAyWCIsICooMS4uMykubWFwe3JhbmQoMHg3ZikrMHg4MH0pCiAgCiAgICB3aGlsZSBtID0gZGF0YS5tYXRjaChzYnMsIHBvcykgZG8KICAgICAgcHV0cyAlUXsgICAgPFRBRz4KICAgICAgPHN0YXJ0X29mZnNldD4je20uYmVnaW4oMCkvOH08L3N0YXJ0X29mZnNldD4KICAgICAgPGVuZF9vZmZzZXQ+I3ttLmVuZCgwKS84fTwvZW5kX29mZnNldD4KICAgICAgPHRhZ190ZXh0PiN7c3ByaW50ZigiMHglMDhYKCVkKSA6ICVzIFslc10iLCBtLmJlZ2luKDApLzgsIG0uYmVnaW4oMCklOCwgc3MsIHNicyl9PC90YWdfdGV4dD4KICAgICAgPG5vdGVfY29sb3VyPiN7bm90ZV9jb2xvdXJ9PC9ub3RlX2NvbG91cj4KICAgIDwvVEFHPn0KICAgICAgcG9zID0gbS5iZWdpbigwKSArIDEKICAgIGVuZAoKICB9CiAgcHV0cyAiPC9maWxlbmFtZT48L3d4SGV4RWRpdG9yX1hNTF9UQUc+IgoKfQo=