forked from DFHack/scripts
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbinpatch.lua
More file actions
Latest commit
51 lines (44 loc) · 1.17 KB
/
Copy pathbinpatch.lua
File metadata and controls
51 lines (44 loc) · 1.17 KB
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`.
]====]
localbp=require('binpatch')
functionrun_command(cmd,name)
localpfix=name..': '
localpatch, err=bp.load_dif_file(name)
ifnotpatchthen
dfhack.printerr(pfix..err)
return
end
ifcmd=='check' then
localstatus, addr=patch:status()
ifstatus=='conflict' then
dfhack.printerr(string.format('%sconflict at address %x', pfix, addr))
else
print(pfix..'patch is '..status)
end
elseifcmd=='apply' then
localok, msg=patch:apply()
ifokthen
print(pfix..msg)
else
dfhack.printerr(pfix..msg)
end
elseifcmd=='remove' then
localok, msg=patch:remove()
ifokthen
print(pfix..msg)
else
dfhack.printerr(pfix..msg)
end
else
qerror('Invalid command: '..cmd)
end
end
localcmd,name=...
ifnotcmdornotnamethen
qerror('Usage: binpatch check/apply/remove <patchname>')
end
run_command(cmd, name)