]>
Commit | Line | Data |
---|---|---|
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 <string.h> | |
13 | #include "proxmark3.h" | |
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 | int findone=0; | |
43 | if(Cmd[0]=='1') findone=1; | |
44 | UsbCommand c={CMD_HID_DEMOD_FSK}; | |
45 | c.arg[0]=findone; | |
46 | SendCommand(&c); | |
47 | return 0; | |
48 | } | |
49 | ||
50 | int CmdHIDSim(const char *Cmd) | |
51 | { | |
52 | unsigned int hi = 0, lo = 0; | |
53 | int n = 0, i = 0; | |
54 | ||
55 | while (sscanf(&Cmd[i++], "%1x", &n ) == 1) { | |
56 | hi = (hi << 4) | (lo >> 28); | |
57 | lo = (lo << 4) | (n & 0xf); | |
58 | } | |
59 | ||
60 | PrintAndLog("Emulating tag with ID %x%16x", hi, lo); | |
61 | PrintAndLog("Press pm3-button to abort simulation"); | |
62 | ||
63 | UsbCommand c = {CMD_HID_SIM_TAG, {hi, lo, 0}}; | |
64 | SendCommand(&c); | |
65 | return 0; | |
66 | } | |
67 | ||
68 | int CmdHIDClone(const char *Cmd) | |
69 | { | |
70 | unsigned int hi2 = 0, hi = 0, lo = 0; | |
71 | int n = 0, i = 0; | |
72 | UsbCommand c; | |
73 | ||
74 | if (strchr(Cmd,'l') != 0) { | |
75 | while (sscanf(&Cmd[i++], "%1x", &n ) == 1) { | |
76 | hi2 = (hi2 << 4) | (hi >> 28); | |
77 | hi = (hi << 4) | (lo >> 28); | |
78 | lo = (lo << 4) | (n & 0xf); | |
79 | } | |
80 | ||
81 | PrintAndLog("Cloning tag with long ID %x%08x%08x", hi2, hi, lo); | |
82 | ||
83 | c.d.asBytes[0] = 1; | |
84 | } | |
85 | else { | |
86 | while (sscanf(&Cmd[i++], "%1x", &n ) == 1) { | |
87 | hi = (hi << 4) | (lo >> 28); | |
88 | lo = (lo << 4) | (n & 0xf); | |
89 | } | |
90 | ||
91 | PrintAndLog("Cloning tag with ID %x%08x", hi, lo); | |
92 | ||
93 | hi2 = 0; | |
94 | c.d.asBytes[0] = 0; | |
95 | } | |
96 | ||
97 | c.cmd = CMD_HID_CLONE_TAG; | |
98 | c.arg[0] = hi2; | |
99 | c.arg[1] = hi; | |
100 | c.arg[2] = lo; | |
101 | ||
102 | SendCommand(&c); | |
103 | return 0; | |
104 | } | |
105 | ||
106 | static command_t CommandTable[] = | |
107 | { | |
108 | {"help", CmdHelp, 1, "This help"}, | |
109 | {"demod", CmdHIDDemod, 1, "Demodulate HID Prox Card II (not optimal)"}, | |
110 | {"fskdemod", CmdHIDDemodFSK, 0, "['1'] Realtime HID FSK demodulator (option '1' for one tag only)"}, | |
111 | {"sim", CmdHIDSim, 0, "<ID> -- HID tag simulator"}, | |
112 | {"clone", CmdHIDClone, 0, "<ID> ['l'] -- Clone HID to T55x7 (tag must be in antenna)(option 'l' for 84bit ID)"}, | |
113 | {NULL, NULL, 0, NULL} | |
114 | }; | |
115 | ||
116 | int CmdLFHID(const char *Cmd) | |
117 | { | |
118 | CmdsParse(CommandTable, Cmd); | |
119 | return 0; | |
120 | } | |
121 | ||
122 | int CmdHelp(const char *Cmd) | |
123 | { | |
124 | CmdsHelp(CommandTable); | |
125 | return 0; | |
126 | } |