2010-04-18 13:47:54 +00:00
|
|
|
#!/usr/bin/env ruby
|
|
|
|
|
|
|
|
require "common.rb"
|
|
|
|
|
|
|
|
# Generate string -> offset lookup tables for each executable.
|
|
|
|
|
|
|
|
def load_string_lookups(exe_files)
|
|
|
|
string_lookups = []
|
|
|
|
|
|
|
|
CONFIGS.each_with_index do |config, i|
|
|
|
|
strings = find_strings(exe_files[i], config)
|
2010-04-18 14:06:50 +00:00
|
|
|
string_lookups.push(strings)
|
2010-04-18 13:47:54 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
string_lookups
|
|
|
|
end
|
|
|
|
|
|
|
|
# Load list of "good" strings.
|
|
|
|
|
|
|
|
def load_good_strings(filename)
|
|
|
|
File.readlines(filename).map do |string|
|
|
|
|
JSON::load("["+ string.chomp + "]")[0]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-04-18 14:06:50 +00:00
|
|
|
# Look up a string's offset, removing it from the specified lookup table.
|
|
|
|
# This is done because a string can appear multiple times at different offsets.
|
|
|
|
|
|
|
|
def lookup_string(lookup_table, string)
|
|
|
|
lookup_table.each_with_index do |entry, i|
|
|
|
|
if entry[1] == string
|
|
|
|
lookup_table.delete_at(i)
|
|
|
|
return entry[0]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
2010-04-18 13:47:54 +00:00
|
|
|
# Find offsets for the specified string.
|
|
|
|
|
|
|
|
def get_string_offsets(string, string_lookups)
|
|
|
|
string_lookups.map do |lookup|
|
2010-04-18 14:06:50 +00:00
|
|
|
offset = lookup_string(lookup, string)
|
|
|
|
|
|
|
|
if offset != nil
|
|
|
|
offset
|
|
|
|
else
|
|
|
|
0
|
|
|
|
end
|
2010-04-18 13:47:54 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def format_offsets(offsets)
|
|
|
|
formatted_offsets = offsets.map do |offset|
|
|
|
|
sprintf("%5i", offset)
|
|
|
|
end
|
|
|
|
|
|
|
|
"{ " + formatted_offsets.join(", ") + " }"
|
|
|
|
end
|
|
|
|
|
2010-04-18 14:06:50 +00:00
|
|
|
# Print strings left over in the specified lookup table
|
|
|
|
# that were not in the good strings list.
|
2010-04-18 13:47:54 +00:00
|
|
|
|
2010-04-18 15:13:16 +00:00
|
|
|
def print_unsupported_strings(name, strings)
|
2010-04-18 14:06:50 +00:00
|
|
|
|
2010-04-18 15:13:16 +00:00
|
|
|
unsupported_offsets = strings.map do |entry|
|
2010-04-18 14:06:50 +00:00
|
|
|
entry[0]
|
2010-04-18 13:47:54 +00:00
|
|
|
end
|
|
|
|
|
2010-04-18 15:13:16 +00:00
|
|
|
puts "static int #{name}[] = {"
|
2010-04-18 13:47:54 +00:00
|
|
|
|
|
|
|
numbers = 0
|
|
|
|
|
2010-04-18 15:31:30 +00:00
|
|
|
for offset in unsupported_offsets.sort + [ -1 ]
|
2010-04-18 15:13:16 +00:00
|
|
|
if numbers == 0
|
|
|
|
print " "
|
|
|
|
else
|
|
|
|
print " "
|
|
|
|
end
|
2010-04-18 13:47:54 +00:00
|
|
|
|
2010-04-18 15:13:16 +00:00
|
|
|
printf "%5i,", offset
|
2010-04-18 13:47:54 +00:00
|
|
|
numbers += 1
|
|
|
|
|
|
|
|
if numbers >= 8
|
|
|
|
print "\n"
|
|
|
|
numbers = 0
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if numbers > 0
|
|
|
|
print "\n"
|
|
|
|
end
|
|
|
|
|
|
|
|
puts "};"
|
|
|
|
puts
|
|
|
|
end
|
|
|
|
|
|
|
|
string_lookups = load_string_lookups(ARGV)
|
|
|
|
good_strings = load_good_strings("good-strings.txt")
|
|
|
|
|
|
|
|
# Output list of supported strings with their offset for each version
|
|
|
|
|
2010-04-18 14:52:14 +00:00
|
|
|
puts "static hhe_string_t strings[] = {"
|
2010-04-18 13:47:54 +00:00
|
|
|
|
|
|
|
for string in good_strings
|
|
|
|
|
|
|
|
offsets = get_string_offsets(string, string_lookups)
|
|
|
|
|
|
|
|
print " { " + format_offsets(offsets) + ", "
|
|
|
|
# print "\n "
|
|
|
|
print string.to_json + " },\n"
|
|
|
|
end
|
|
|
|
|
|
|
|
puts "};"
|
|
|
|
puts
|
|
|
|
|
|
|
|
# Output strings that appear in HHE but are not supported (ie. in good_strings)
|
|
|
|
|
|
|
|
CONFIGS.each_with_index do |config, i|
|
2010-04-18 15:13:16 +00:00
|
|
|
name = "unsupported_strings_#{config::SUFFIX}"
|
|
|
|
print_unsupported_strings(name, string_lookups[i])
|
2010-04-18 13:47:54 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|