]>
Commit | Line | Data |
---|---|---|
812513bf | 1 | //----------------------------------------------------------------------------- |
2 | // Copyright (C) 2016 iceman | |
3 | // | |
4 | // This code is licensed to you under the terms of the GNU GPL, version 2 or, | |
5 | // at your option, any later version. See the LICENSE.txt file for the text of | |
6 | // the license. | |
7 | //----------------------------------------------------------------------------- | |
8 | // Analyse bytes commands | |
9 | //----------------------------------------------------------------------------- | |
10 | #include "cmdanalyse.h" | |
11 | ||
12 | static int CmdHelp(const char *Cmd); | |
13 | ||
14 | int usage_analyse_lcr(void) { | |
15 | PrintAndLog("Specifying the bytes of a UID with a known LRC will find the last byte value"); | |
16 | PrintAndLog("needed to generate that LRC with a rolling XOR. All bytes should be specified in HEX."); | |
17 | PrintAndLog(""); | |
18 | PrintAndLog("Usage: analyse lcr [h] <bytes>"); | |
19 | PrintAndLog("Options:"); | |
20 | PrintAndLog(" h This help"); | |
21 | PrintAndLog(" <bytes> bytes to calc missing XOR in a LCR"); | |
22 | PrintAndLog(""); | |
23 | PrintAndLog("Samples:"); | |
24 | PrintAndLog(" analyse lcr 04008064BA"); | |
25 | PrintAndLog("expected output: Target (BA) requires final LRC XOR byte value: 5A"); | |
26 | return 0; | |
27 | } | |
28 | static uint8_t calculateLRC( uint8_t* bytes, uint8_t len) { | |
29 | uint8_t LRC = 0; | |
30 | for (uint8_t i = 0; i < len; i++) | |
31 | LRC ^= bytes[i]; | |
32 | return LRC; | |
33 | } | |
34 | ||
35 | int CmdAnalyseLCR(const char *Cmd) { | |
36 | uint8_t data[50]; | |
37 | char cmdp = param_getchar(Cmd, 0); | |
38 | if (strlen(Cmd) == 0|| cmdp == 'h' || cmdp == 'H') return usage_analyse_lcr(); | |
39 | ||
40 | int len = 0; | |
41 | param_gethex_ex(Cmd, 0, data, &len); | |
42 | if ( len%2 ) return usage_analyse_lcr(); | |
43 | len >>= 1; | |
44 | uint8_t finalXor = calculateLRC(data, len); | |
45 | PrintAndLog("Target [%02X] requires final LRC XOR byte value: 0x%02X",data[len-1] ,finalXor); | |
46 | return 0; | |
47 | } | |
48 | ||
5558d935 | 49 | int CmdAnalyseDates(const char *Cmd){ |
50 | // look for datestamps in a given array of bytes | |
51 | PrintAndLog("To be implemented. If you feel to contribute!"); | |
52 | return 0; | |
53 | } | |
54 | ||
812513bf | 55 | static command_t CommandTable[] = { |
5558d935 | 56 | {"help", CmdHelp, 1, "This help"}, |
57 | {"lcr", CmdAnalyseLCR, 0, "Generate final byte for XOR LRC"}, | |
58 | {"dates", CmdAnalyseDates, 0, "Look for datestamps in a given array of bytes"}, | |
812513bf | 59 | {NULL, NULL, 0, NULL} |
60 | }; | |
61 | ||
62 | int CmdAnalyse(const char *Cmd) { | |
63 | clearCommandBuffer(); | |
64 | CmdsParse(CommandTable, Cmd); | |
65 | return 0; | |
66 | } | |
67 | ||
68 | int CmdHelp(const char *Cmd) { | |
69 | CmdsHelp(CommandTable); | |
70 | return 0; | |
71 | } |