Skip to content

Instantly share code, notes, and snippets.

@ExtReMLapin
Created December 9, 2020 11:52
Show Gist options
  • Save ExtReMLapin/09feab989bc32a6888fdc9d932a46ddd to your computer and use it in GitHub Desktop.
Save ExtReMLapin/09feab989bc32a6888fdc9d932a46ddd to your computer and use it in GitHub Desktop.
assert(#arg == 2)
local source
local dest
local f1 = assert(io.open(arg[1], "rb"), "cannot open " .. arg[1])
source = f1:read("*all")
f1:close()
local f2 = assert(io.open(arg[2], "rb"), "cannot open " .. arg[2])
dest = f2:read("*all")
f2:close()
assert(#source == #dest)
print("ok")
print[[
| Position | OriginalBytes | PatchedBytes |
|----------|:-------------:|--------------:|]]
local i = 1
local max = #source
while (i <= max) do
if source:sub(i, i) ~= dest:sub(i, i) then
local i2 = 0
local tmpTbl = {}
while (source:sub(i + i2, i + i2) ~= dest:sub(i + i2, i + i2)) do
table.insert(tmpTbl, { string.format('%02X',(source:sub(i + i2, i + i2):byte())), string.format('%02X',(dest:sub(i + i2, i + i2):byte()))})
i2 = i2 + 1
end
local originalBytes = ""
local patchedBytes = ""
for k, v in ipairs(tmpTbl) do
originalBytes = originalBytes .. v[1] .. " "
patchedBytes = patchedBytes .. v[2] .. " "
end
print(string.format("| 0x%s | %s | %s |", string.format('%08X', i), originalBytes, patchedBytes))
i = i + i2
end
i = i + 1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment