]> cvs.zerfleddert.de Git - proxmark3-svn/blob - client/cmdanalyse.c
CHG: added an entry to copy the 77-mm-usb-device-blacklist.rules file into /etc...
[proxmark3-svn] / client / cmdanalyse.c
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
49 static command_t CommandTable[] = {
50 {"help", CmdHelp, 1, "This help"},
51 {"lcr", CmdAnalyseLCR, 0, "Generate final byte for XOR LRC"},
52 {NULL, NULL, 0, NULL}
53 };
54
55 int CmdAnalyse(const char *Cmd) {
56 clearCommandBuffer();
57 CmdsParse(CommandTable, Cmd);
58 return 0;
59 }
60
61 int CmdHelp(const char *Cmd) {
62 CmdsHelp(CommandTable);
63 return 0;
64 }
Impressum, Datenschutz