]> git.zerfleddert.de Git - proxmark3-svn/blob - client/cmdlfhid.c
Added block command for T55xx and support for cloning HID long format
[proxmark3-svn] / client / cmdlfhid.c
1 //-----------------------------------------------------------------------------
2 // Copyright (C) 2010 iZsh <izsh at fail0verflow.com>
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 // Low frequency HID commands
9 //-----------------------------------------------------------------------------
10
11 #include <stdio.h>
12 #include "proxusb.h"
13 #include "ui.h"
14 #include "graph.h"
15 #include "cmdparser.h"
16 #include "cmdlfhid.h"
17
18 static int CmdHelp(const char *Cmd);
19
20 int CmdHIDDemod(const char *Cmd)
21 {
22 if (GraphTraceLen < 4800) {
23 PrintAndLog("too short; need at least 4800 samples");
24 return 0;
25 }
26
27 GraphTraceLen = 4800;
28 for (int i = 0; i < GraphTraceLen; ++i) {
29 if (GraphBuffer[i] < 0) {
30 GraphBuffer[i] = 0;
31 } else {
32 GraphBuffer[i] = 1;
33 }
34 }
35 RepaintGraphWindow();
36 return 0;
37 }
38
39 int CmdHIDDemodFSK(const char *Cmd)
40 {
41 UsbCommand c={CMD_HID_DEMOD_FSK};
42 SendCommand(&c);
43 return 0;
44 }
45
46 int CmdHIDSim(const char *Cmd)
47 {
48 unsigned int hi = 0, lo = 0;
49 int n = 0, i = 0;
50
51 while (sscanf(&Cmd[i++], "%1x", &n ) == 1) {
52 hi = (hi << 4) | (lo >> 28);
53 lo = (lo << 4) | (n & 0xf);
54 }
55
56 PrintAndLog("Emulating tag with ID %x%16x", hi, lo);
57
58 UsbCommand c = {CMD_HID_SIM_TAG, {hi, lo, 0}};
59 SendCommand(&c);
60 return 0;
61 }
62
63 int CmdHIDClone(const char *Cmd)
64 {
65 unsigned int hi2 = 0, hi = 0, lo = 0;
66 int n = 0, i = 0;
67 UsbCommand c;
68
69 if (strchr(Cmd,'l') != 0) {
70 while (sscanf(&Cmd[i++], "%1x", &n ) == 1) {
71 hi2 = (hi2 << 4) | (hi >> 28);
72 hi = (hi << 4) | (lo >> 28);
73 lo = (lo << 4) | (n & 0xf);
74 }
75
76 PrintAndLog("Cloning tag with long ID %x%08x%08x", hi2, hi, lo);
77
78 c.d.asBytes[0] = 1;
79 }
80 else {
81 while (sscanf(&Cmd[i++], "%1x", &n ) == 1) {
82 hi = (hi << 4) | (lo >> 28);
83 lo = (lo << 4) | (n & 0xf);
84 }
85
86 PrintAndLog("Cloning tag with ID %x%08x", hi, lo);
87
88 hi2 = 0;
89 c.d.asBytes[0] = 0;
90 }
91
92 c.cmd = CMD_HID_CLONE_TAG;
93 c.arg[0] = hi2;
94 c.arg[1] = hi;
95 c.arg[2] = lo;
96
97 SendCommand(&c);
98 return 0;
99 }
100
101 static command_t CommandTable[] =
102 {
103 {"help", CmdHelp, 1, "This help"},
104 {"demod", CmdHIDDemod, 1, "Demodulate HID Prox Card II (not optimal)"},
105 {"fskdemod", CmdHIDDemodFSK, 1, "Realtime HID FSK demodulator"},
106 {"sim", CmdHIDSim, 1, "<ID> -- HID tag simulator"},
107 {"clone", CmdHIDClone, 1, "<ID> ['l'] -- Clone HID to T55x7 (tag must be in antenna)(option 'l' for 84bit ID)"},
108 {NULL, NULL, 0, NULL}
109 };
110
111 int CmdLFHID(const char *Cmd)
112 {
113 CmdsParse(CommandTable, Cmd);
114 return 0;
115 }
116
117 int CmdHelp(const char *Cmd)
118 {
119 CmdsHelp(CommandTable);
120 return 0;
121 }
Impressum, Datenschutz