Skip to content

Instantly share code, notes, and snippets.

@xiaobin83
Created January 5, 2017 08:26
Show Gist options
  • Save xiaobin83/1682dae4ca6e95a5ca4fc47cc8db3d31 to your computer and use it in GitHub Desktop.
Save xiaobin83/1682dae4ca6e95a5ca4fc47cc8db3d31 to your computer and use it in GitHub Desktop.
function HexDump(buf)
local s = {}
s.output = ''
for byte=1, #buf, 16 do
local chunk = buf:sub(byte, byte+15)
s.output = s.output .. string.format('%08X ',byte-1)
chunk:gsub('.', function (c) s.output = s.output .. string.format('%02X ',string.byte(c)) end)
s.output = s.output .. string.rep(' ',3*(16-#chunk))
s.output = s.output .. chunk:gsub('%c','.') .. "\n"
end
return s.output
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment