Skip to content

Instantly share code, notes, and snippets.

@lopex
Created December 12, 2017 02:59
Show Gist options
  • Save lopex/d6c1f02b30e66888b5956525861855cf to your computer and use it in GitHub Desktop.
Save lopex/d6c1f02b30e66888b5956525861855cf to your computer and use it in GitHub Desktop.
# coding: utf-8
repo_path = ARGV.first || '/usr/src/ruby-2.4.2' # path to ruby repo
section_name = "rdata"
def process_binary obj_name, section_name
binary = open(obj_name, "rb"){|f|f.read}
offset = `objdump -h -j .#{section_name} #{obj_name}`[/\.#{section_name}.*?(\w+)\s+\S+$/, 1].to_i(16)
`nm --defined-only #{obj_name}`.split("\n").map{|s|s.split(/\s+/)}.each do |address, _, name|
yield name, binary, address.to_i(16) + offset
end
end
process_binary "#{repo_path}/enc/unicode.o", section_name do |name, binary, address|
if name =~ /CR_*/
size = binary[address, 4].unpack("l")
address += 4
open("test/" + name, "wb") do |f|
f << [size[0] * 2 + 1].pack("N")
f << size.pack("N")
address.step(address + (size[0] * 2 * 4 - 1), 4).each do |adr|
f << binary[adr, 4].unpack("l").pack("N")
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment