Last active
April 7, 2018 15:02
-
-
Save youchan/a5a4dd61546777d4947fe49f8b30cafd to your computer and use it in GitHub Desktop.
This file contains 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
bin = "YARB\u0002\u0000\u0000\u0000\u0005\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000x86_64-darwin16\u0000" | |
putself = 16 | |
putstring = 20 | |
opt_send_without_block = 52 | |
leave = 55 | |
hello = 3 | |
codes = [ | |
putself, | |
putstring, hello, | |
opt_send_without_block, 0, 0, | |
leave | |
] | |
iseq_offset = bin.length | |
bin << codes.pack("q*") | |
insns_info_list = [0, 1, 1, 1, 1, 0] | |
insns_info_size = 2 | |
insns_info_offset = bin.length | |
bin << insns_info_list.pack("I*") | |
local_table_offset = bin.length | |
ci_entries_offset = bin.length | |
ci_entries = [[1, 40, 1]] | |
ci_entries.each do |entry| | |
bin << entry.pack("qI2") | |
end | |
iseq_list = [] | |
iseq_list << bin.length | |
params = [0] * 12 | |
location = [1,2,2,3,1,0,1,20] | |
iseq_info = [ | |
iseq_type = 0, | |
codes.length, | |
iseq_offset, | |
0, | |
params = [0] * 12, | |
location, | |
insns_info_offset, | |
local_table_offset, | |
catch_table_offset = 0, | |
parent_iseq = -1, | |
local_iseq = 0, | |
is_entries = 0, | |
ci_entries_offset, | |
cc_entries = 0, | |
mark_ary = 0, | |
local_table_size = 0, | |
is_size = 0, | |
ci_size = 1, | |
ci_kw_size = 0, | |
insns_info_size, | |
stack_max = 2, | |
].flatten | |
bin << iseq_info.pack("I16q4I4q9I6") | |
iseq_list_offset = bin.length | |
bin << iseq_list.pack("I") | |
id_list_offset = bin.length | |
id_list = [0, 4] | |
bin << id_list.pack("q*") | |
qnil = [17, 8] | |
objpath = [5, 1, 0, 0, ""] | |
label = [5, 2, 0, "<compiled>".yield_self{|x| [x.length, x]}].flatten | |
hello_world = [5, 1, 0, "Hello world".yield_self{|x| [x.length, x]}].flatten | |
puts_ = [5, 2, 0, "puts".yield_self{|x| [x.length, x]}].flatten | |
object_list = [] | |
object_list << bin.length | |
bin << qnil.pack("Iq") | |
object_list << bin.length | |
bin << objpath.pack("Il3xxxxa*") | |
object_list << bin.length | |
bin << label.pack("Il3xxxxa*") | |
object_list << bin.length | |
bin << hello_world.pack("Il3xxxxa*") | |
object_list << bin.length | |
bin << puts_.pack("Il3xxxxa*") | |
object_list_offset = bin.length | |
bin << object_list.pack("I*") | |
size = bin.length | |
object_list_size = object_list.length | |
bin[12,4 * 8] = [ | |
size, | |
extra_size = 0, | |
iseq_list_size = 1, | |
id_list_size = 2, | |
object_list_size, | |
iseq_list_offset, | |
id_list_offset, | |
object_list_offset].pack("I*") | |
bin[16,4] = [0].pack("I") | |
File.write("test3.bin", bin) | |
iseq = RubyVM::InstructionSequence.load_from_binary(bin) | |
iseq.eval |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment