Created
December 12, 2017 02:59
-
-
Save lopex/d6c1f02b30e66888b5956525861855cf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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