1
0
Fork 0
mirror of https://github.com/notwa/mm synced 2024-11-05 05:59:04 -08:00
mm/patch/patch.lua

23 lines
584 B
Lua
Raw Normal View History

2016-04-02 02:06:46 -07:00
package.path = package.path..";./?/init.lua"
local assemble = require "lips"
local function inject(patch, target)
local f = io.open(target, 'r+b')
local function write(pos, line)
assert(#line == 2, "that ain't const")
-- TODO: write hex dump format of written bytes
--print(("%08X"):format(pos), line)
f:seek('set', pos)
f:write(string.char(tonumber(line, 16)))
end
-- offset assembly labels so they work properly, and assemble!
assemble(patch, write, {unsafe=true, offset=0})
f:close()
end
inject(arg[1], arg[2])