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