2010-02-08 20:08:40 +00:00
|
|
|
#!/usr/bin/env ruby
|
|
|
|
|
|
|
|
require "json"
|
2010-04-17 23:05:39 +00:00
|
|
|
require "common"
|
|
|
|
|
2010-04-18 00:06:32 +00:00
|
|
|
# HHE seems to stop when it has found this many strings:
|
|
|
|
|
|
|
|
NUM_STRINGS=785
|
|
|
|
|
2010-04-17 23:05:39 +00:00
|
|
|
set_config(ARGV[1])
|
2010-02-08 20:08:40 +00:00
|
|
|
|
|
|
|
def read_block(file)
|
|
|
|
result = ""
|
|
|
|
|
|
|
|
4.times do
|
|
|
|
break if file.eof?
|
|
|
|
c = file.readchar
|
|
|
|
result += sprintf("%c", c)
|
|
|
|
end
|
|
|
|
|
|
|
|
end_index = result.index(0)
|
|
|
|
if end_index
|
|
|
|
result = result[0, end_index]
|
|
|
|
end
|
|
|
|
|
|
|
|
result
|
|
|
|
end
|
|
|
|
|
2010-04-18 00:06:32 +00:00
|
|
|
def bad_string?(str)
|
|
|
|
str.each_byte do |b|
|
|
|
|
if b >= 0x80
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
2010-02-08 20:08:40 +00:00
|
|
|
|
2010-04-18 00:06:32 +00:00
|
|
|
return false
|
2010-02-08 20:08:40 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
File.open(ARGV[0]) do |file|
|
|
|
|
current_str = ""
|
|
|
|
|
2010-04-17 23:05:39 +00:00
|
|
|
file.seek(STRINGS_OFFSET)
|
2010-02-08 20:08:40 +00:00
|
|
|
|
|
|
|
offset = 0
|
|
|
|
start_offset = nil
|
2010-04-18 00:06:32 +00:00
|
|
|
num_strings = 0
|
2010-02-08 20:08:40 +00:00
|
|
|
|
2010-04-18 00:06:32 +00:00
|
|
|
while num_strings < NUM_STRINGS
|
2010-02-08 20:08:40 +00:00
|
|
|
block = read_block(file)
|
|
|
|
|
2010-04-18 00:06:32 +00:00
|
|
|
if start_offset == nil
|
|
|
|
start_offset = offset
|
|
|
|
end
|
|
|
|
|
|
|
|
current_str += block
|
|
|
|
|
|
|
|
# End of string?
|
|
|
|
|
|
|
|
if block.length < 4
|
|
|
|
|
|
|
|
# Extended-ASCII characters cannot be output
|
|
|
|
# to JSON.
|
|
|
|
|
|
|
|
if bad_string?(current_str)
|
|
|
|
current_str = "XXXXX BAD STRING"
|
2010-02-08 20:08:40 +00:00
|
|
|
end
|
2010-04-18 00:06:32 +00:00
|
|
|
|
|
|
|
printf " { %6i, %s },\n", start_offset,
|
|
|
|
current_str.to_json
|
|
|
|
current_str = ""
|
|
|
|
start_offset = nil
|
|
|
|
num_strings += 1
|
|
|
|
end
|
2010-02-08 20:08:40 +00:00
|
|
|
|
|
|
|
offset += 4
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|