2015-06-09 19:31:53 +08:00
|
|
|
local getopt = require('getopt')
|
|
|
|
local utils = require('utils')
|
|
|
|
|
2015-06-10 03:28:06 +08:00
|
|
|
example = "script calculates many different checksums (CRC) over the provided hex input"
|
2015-06-09 19:31:53 +08:00
|
|
|
author = "Iceman"
|
|
|
|
desc =
|
|
|
|
[[
|
2015-06-10 03:28:06 +08:00
|
|
|
This script calculates many checksums (CRC) over the provided hex input.
|
2015-06-09 19:31:53 +08:00
|
|
|
|
|
|
|
Arguments:
|
|
|
|
-b data in hex
|
2015-06-10 03:28:06 +08:00
|
|
|
-w bitwidth of the CRC family of algorithm. <optional> defaults to all known CRC presets.
|
2015-06-09 19:31:53 +08:00
|
|
|
Examples :
|
|
|
|
script run e -b 010203040506070809
|
|
|
|
script run e -b 010203040506070809 -w 16
|
|
|
|
]]
|
|
|
|
|
|
|
|
---
|
|
|
|
-- A debug printout-function
|
|
|
|
function dbg(args)
|
|
|
|
if DEBUG then
|
|
|
|
print("###", args)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
---
|
|
|
|
-- This is only meant to be used when errors occur
|
|
|
|
function oops(err)
|
|
|
|
print("ERROR: ",err)
|
|
|
|
return nil,err
|
|
|
|
end
|
|
|
|
---
|
|
|
|
-- Usage help
|
|
|
|
function help()
|
|
|
|
print(desc)
|
|
|
|
print("Example usage")
|
|
|
|
print(example)
|
|
|
|
end
|
|
|
|
---
|
|
|
|
-- The main entry point
|
|
|
|
function main(args)
|
|
|
|
|
2015-06-10 03:46:22 +08:00
|
|
|
local data
|
2015-06-09 19:31:53 +08:00
|
|
|
local width = 0
|
|
|
|
|
|
|
|
-- Read the parameters
|
|
|
|
for o, a in getopt.getopt(args, 'hb:w:') do
|
|
|
|
if o == "h" then return help() end
|
2015-06-10 03:28:06 +08:00
|
|
|
if o == "b" then data = a end
|
2015-06-09 19:31:53 +08:00
|
|
|
if o == "w" then width = a end
|
|
|
|
end
|
|
|
|
|
2015-06-10 03:46:22 +08:00
|
|
|
data = data or '01020304'
|
|
|
|
|
2015-06-10 03:28:06 +08:00
|
|
|
print( string.rep('-',60) )
|
|
|
|
print('Bit width of CRC | '..width)
|
|
|
|
print('Bytes | '..data)
|
2015-06-09 19:31:53 +08:00
|
|
|
print('')
|
2015-06-10 03:28:06 +08:00
|
|
|
print( ('%-20s| %-16s| %s'):format('Model','CRC', 'CRC reverse'))
|
|
|
|
print( string.rep('-',60) )
|
2015-06-09 19:31:53 +08:00
|
|
|
local lists = core.reveng_models(width)
|
|
|
|
for _,i in pairs(lists) do
|
2015-06-14 23:19:41 +08:00
|
|
|
local a1 = core.reveng_runmodel(i, data, false, '0')
|
|
|
|
local a2 = core.reveng_runmodel(i, data, true, '0')
|
|
|
|
local a3 = core.reveng_runmodel(i, data, false, 'b')
|
|
|
|
local a4 = core.reveng_runmodel(i, data, false, 'B')
|
|
|
|
local a5 = core.reveng_runmodel(i, data, false, 'l')
|
|
|
|
local a6 = core.reveng_runmodel(i, data, false, 'L')
|
|
|
|
print( ('%-20s| %-16s| %-16s| %-16s| %-16s| %-16s| %-16s'):format(i, a1:upper(), a2:upper(),a3:upper(),a4:upper(),a5:upper(),a6:upper() ) )
|
2015-06-09 19:31:53 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
main(args)
|