research/hhe/dump-strings

79 lines
1.7 KiB
Text
Raw Normal View History

#!/usr/bin/env ruby
require "json"
require "common"
set_config(ARGV[1])
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
def valid_block?(block)
for i in 0...block.length
c = block[i, 1]
if c !~ /[a-zA-Z0-9_= :\\\'\"\-\,\.\(\)\[\]\%\!\n\?\<\>\%\#\@\/\&]/
return false
end
end
true
end
File.open(ARGV[0]) do |file|
current_str = ""
file.seek(STRINGS_OFFSET)
offset = 0
start_offset = nil
until file.eof?
block = read_block(file)
if valid_block?(block)
if start_offset == nil
start_offset = offset
end
current_str += block
# End of string?
if block.length < 4
if current_str.length >= 4
puts " { #{start_offset}, #{current_str.to_json} },"
end
current_str = ""
start_offset = nil
end
else
# Invalid string; start again
# if current_str.length >= 4
# puts "INVALID: #{current_str + block}"
# end
current_str = ""
end
offset += 4
end
end