Skip to content

Instantly share code, notes, and snippets.

@miau
Created June 19, 2011 08:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miau/1033982 to your computer and use it in GitHub Desktop.
Save miau/1033982 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
class String
# offset 文字目から val の長さぶん val で置き換える
def write(offset, val)
self[offset, val.length] = val
end
end
def compile(lines)
ret = ""
lines.each_with_index do |line, i|
line.strip!
case line
when /^let eax (.+)$/
ret << [0xb8, $1.to_i].pack("CI")
when /^exit$/
ret << [0xc3].pack("C")
else
puts "can't compile(line #{i+1}): #{line}"
exit 1
end
end
ret
end
source = [
"let eax 123",
"exit",
]
base = File.open("base.exe", "rb").read
text = compile(source)
base.write(0x180, [text.length].pack("I"))
base.write(0x200, text)
File.open("output.exe", "wb").write(base)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment