]>
Commit | Line | Data |
---|---|---|
2e163546 | 1 | local getopt = require('getopt') |
2 | local utils = require('utils') | |
3 | ||
53ee28cb | 4 | example = "script calculates many different checksums (CRC) over the provided hex input" |
2e163546 | 5 | author = "Iceman" |
6 | desc = | |
7 | [[ | |
53ee28cb | 8 | This script calculates many checksums (CRC) over the provided hex input. |
2e163546 | 9 | |
10 | Arguments: | |
11 | -b data in hex | |
53ee28cb | 12 | -w bitwidth of the CRC family of algorithm. <optional> defaults to all known CRC presets. |
2e163546 | 13 | Examples : |
14 | script run e -b 010203040506070809 | |
15 | script run e -b 010203040506070809 -w 16 | |
16 | ]] | |
17 | ||
18 | --- | |
19 | -- A debug printout-function | |
20 | function dbg(args) | |
21 | if DEBUG then | |
22 | print("###", args) | |
23 | end | |
24 | end | |
25 | --- | |
26 | -- This is only meant to be used when errors occur | |
27 | function oops(err) | |
28 | print("ERROR: ",err) | |
29 | return nil,err | |
30 | end | |
31 | --- | |
32 | -- Usage help | |
33 | function help() | |
34 | print(desc) | |
35 | print("Example usage") | |
36 | print(example) | |
37 | end | |
38 | --- | |
39 | -- The main entry point | |
40 | function main(args) | |
41 | ||
53ee28cb | 42 | local data |
2e163546 | 43 | local width = 0 |
44 | ||
45 | -- Read the parameters | |
46 | for o, a in getopt.getopt(args, 'hb:w:') do | |
47 | if o == "h" then return help() end | |
53ee28cb | 48 | if o == "b" then data = a end |
2e163546 | 49 | if o == "w" then width = a end |
50 | end | |
51 | ||
53ee28cb | 52 | data = data or '01020304' |
2e163546 | 53 | |
53ee28cb | 54 | print( string.rep('-',60) ) |
55 | print('Bit width of CRC | '..width) | |
56 | print('Bytes | '..data) | |
57 | print('') | |
58 | print( ('%-20s| %-16s| %s'):format('Model','CRC', 'CRC reverse')) | |
59 | print( string.rep('-',60) ) | |
2e163546 | 60 | local lists = core.reveng_models(width) |
61 | for _,i in pairs(lists) do | |
53ee28cb | 62 | local one = core.reveng_runmodel(i, data, false, '0') |
63 | local two = core.reveng_runmodel(i, data, true, '0') | |
64 | print( ('%-20s| %-16s| %s'):format(i, one:upper(), two:upper()) ) | |
2e163546 | 65 | end |
2e163546 | 66 | end |
67 | ||
68 | main(args) |