forked from DFHack/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
binpatch.lua
51 lines (44 loc) · 1.17 KB
/
binpatch.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
-- Apply or remove binary patches at runtime.
--[====[
binpatch
========
Implements functions for in-memory binpatches. See `binpatches`.
]====]
local bp = require('binpatch')
function run_command(cmd,name)
local pfix = name..': '
local patch, err = bp.load_dif_file(name)
if not patch then
dfhack.printerr(pfix..err)
return
end
if cmd == 'check' then
local status, addr = patch:status()
if status == 'conflict' then
dfhack.printerr(string.format('%sconflict at address %x', pfix, addr))
else
print(pfix..'patch is '..status)
end
elseif cmd == 'apply' then
local ok, msg = patch:apply()
if ok then
print(pfix..msg)
else
dfhack.printerr(pfix..msg)
end
elseif cmd == 'remove' then
local ok, msg = patch:remove()
if ok then
print(pfix..msg)
else
dfhack.printerr(pfix..msg)
end
else
qerror('Invalid command: '..cmd)
end
end
local cmd,name = ...
if not cmd or not name then
qerror('Usage: binpatch check/apply/remove <patchname>')
end
run_command(cmd, name)