1
0
Fork 0
mirror of https://github.com/notwa/mm synced 2024-07-05 23:29:58 -07:00
mm/patch/patch.lua

23 lines
584 B
Lua

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])