mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-20 21:33:47 -07:00
wiegand - now uses cli parse
This commit is contained in:
parent
dc9e16a4e1
commit
1267584e3f
2 changed files with 107 additions and 142 deletions
|
@ -13,6 +13,7 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "cmdparser.h" // command_t
|
#include "cmdparser.h" // command_t
|
||||||
|
#include "cliparser.h"
|
||||||
#include "comms.h"
|
#include "comms.h"
|
||||||
#include "pm3_cmd.h"
|
#include "pm3_cmd.h"
|
||||||
#include "protocols.h"
|
#include "protocols.h"
|
||||||
|
@ -24,164 +25,126 @@
|
||||||
|
|
||||||
static int CmdHelp(const char *Cmd);
|
static int CmdHelp(const char *Cmd);
|
||||||
|
|
||||||
static int usage_wiegand_list(void) {
|
static void print_wiegand_code(wiegand_message_t *packed) {
|
||||||
PrintAndLogEx(NORMAL, "List available wiegand formats");
|
const char* s = "Encoded wiegand: ";
|
||||||
return PM3_SUCCESS;
|
|
||||||
}
|
|
||||||
static int usage_wiegand_encode(void) {
|
|
||||||
PrintAndLogEx(NORMAL, "Encode wiegand formatted number to raw hex");
|
|
||||||
PrintAndLogEx(NORMAL, "Usage: wiegand encode [w <format>] [<field> <value (decimal)>] {...}");
|
|
||||||
PrintAndLogEx(NORMAL, "Options:");
|
|
||||||
PrintAndLogEx(NORMAL, " w <format> see `wiegand list` for available formats");
|
|
||||||
PrintAndLogEx(NORMAL, " c <value> card number");
|
|
||||||
PrintAndLogEx(NORMAL, " f <value> facility code");
|
|
||||||
PrintAndLogEx(NORMAL, " i <value> issue Level");
|
|
||||||
PrintAndLogEx(NORMAL, " o <value> OEM code");
|
|
||||||
PrintAndLogEx(NORMAL, "");
|
|
||||||
PrintAndLogEx(NORMAL, "samples:");
|
|
||||||
PrintAndLogEx(NORMAL, " wiegand encode w H10301 f 101 c 1337");
|
|
||||||
return PM3_SUCCESS;
|
|
||||||
}
|
|
||||||
static int usage_wiegand_decode(void) {
|
|
||||||
PrintAndLogEx(NORMAL, "Decode raw hex to wiegand format");
|
|
||||||
PrintAndLogEx(NORMAL, "Usage: wiegand decode [id] <p>");
|
|
||||||
PrintAndLogEx(NORMAL, " p ignore invalid parity");
|
|
||||||
PrintAndLogEx(NORMAL, "");
|
|
||||||
PrintAndLogEx(NORMAL, "Samples:");
|
|
||||||
PrintAndLogEx(NORMAL, " wiegand decode 2006f623ae");
|
|
||||||
return PM3_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void PrintTagId(wiegand_message_t *packed) {
|
|
||||||
if (packed->Top != 0) {
|
if (packed->Top != 0) {
|
||||||
PrintAndLogEx(SUCCESS, "Card ID: %X%08X%08X",
|
PrintAndLogEx(SUCCESS, "%s" _GREEN_("%X%08X%08X"),
|
||||||
(uint32_t)packed->Top,
|
s,
|
||||||
(uint32_t)packed->Mid,
|
(uint32_t)packed->Top,
|
||||||
(uint32_t)packed->Bot)
|
(uint32_t)packed->Mid,
|
||||||
;
|
(uint32_t)packed->Bot
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
PrintAndLogEx(SUCCESS, "Card ID: %X%08X",
|
PrintAndLogEx(SUCCESS, "%s" _YELLOW_("%X%08X"),
|
||||||
(uint32_t)packed->Mid,
|
s,
|
||||||
(uint32_t)packed->Bot)
|
(uint32_t)packed->Mid,
|
||||||
;
|
(uint32_t)packed->Bot
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int CmdWiegandList(const char *Cmd) {
|
int CmdWiegandList(const char *Cmd) {
|
||||||
bool errors = false;
|
|
||||||
char cmdp = 0;
|
CLIParserContext *ctx;
|
||||||
while (param_getchar(Cmd, cmdp) != 0x00 && !errors) {
|
CLIParserInit(&ctx, "wiegand info",
|
||||||
switch (tolower(param_getchar(Cmd, cmdp))) {
|
"List available wiegand formats",
|
||||||
case 'h':
|
"wiegand list"
|
||||||
return usage_wiegand_list();
|
);
|
||||||
default:
|
|
||||||
PrintAndLogEx(WARNING, "Unknown parameter '%c'", param_getchar(Cmd, cmdp));
|
void *argtable[] = {
|
||||||
errors = true;
|
arg_param_begin,
|
||||||
break;
|
arg_param_end
|
||||||
}
|
};
|
||||||
}
|
CLIExecWithReturn(ctx, Cmd, argtable, true);
|
||||||
|
CLIParserFree(ctx);
|
||||||
|
|
||||||
HIDListFormats();
|
HIDListFormats();
|
||||||
return PM3_SUCCESS;
|
return PM3_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CmdWiegandEncode(const char *Cmd) {
|
int CmdWiegandEncode(const char *Cmd) {
|
||||||
|
|
||||||
int format_idx = -1;
|
CLIParserContext *ctx;
|
||||||
char format[16] = {0};
|
CLIParserInit(&ctx, "wiegand encode",
|
||||||
|
"Encode wiegand formatted number to raw hex",
|
||||||
|
"wiegand encode -w H10301 --fc 101 --cn 1337"
|
||||||
|
);
|
||||||
|
|
||||||
|
void *argtable[] = {
|
||||||
|
arg_param_begin,
|
||||||
|
arg_int0(NULL, "fc", "<dec>", "facility number"),
|
||||||
|
arg_int1(NULL, "cn", "<dec>", "card number"),
|
||||||
|
arg_int0(NULL, "issue", "<dec>", "issue level"),
|
||||||
|
arg_int0(NULL, "oem", "<dec>", "OEM code"),
|
||||||
|
arg_strx1("w", "wiegand", "<format>", "see `wiegand list` for available formats"),
|
||||||
|
arg_param_end
|
||||||
|
};
|
||||||
|
CLIExecWithReturn(ctx, Cmd, argtable, true);
|
||||||
|
|
||||||
wiegand_card_t data;
|
wiegand_card_t data;
|
||||||
memset(&data, 0, sizeof(wiegand_card_t));
|
memset(&data, 0, sizeof(wiegand_card_t));
|
||||||
|
|
||||||
bool errors = false;
|
data.FacilityCode = (uint32_t)arg_get_int_def(ctx, 1, 0);
|
||||||
char cmdp = 0;
|
data.CardNumber = (uint64_t)arg_get_int_def(ctx, 2, 0);
|
||||||
while (param_getchar(Cmd, cmdp) != 0x00 && !errors) {
|
data.IssueLevel = (uint32_t)arg_get_int_def(ctx, 3, 0);
|
||||||
switch (tolower(param_getchar(Cmd, cmdp))) {
|
data.OEM = (uint32_t)arg_get_int_def(ctx, 4, 0);
|
||||||
case 'h':
|
|
||||||
return usage_wiegand_encode();
|
int len = 0;
|
||||||
case 'w':
|
char format[16] = {0};
|
||||||
param_getstr(Cmd, cmdp + 1, format, sizeof(format));
|
CLIParamStrToBuf(arg_get_str(ctx, 5), (uint8_t*)format, sizeof(format), &len);
|
||||||
format_idx = HIDFindCardFormat(format);
|
CLIParserFree(ctx);
|
||||||
if (format_idx == -1) {
|
|
||||||
PrintAndLogEx(WARNING, "Unknown format: %s", format);
|
int idx = HIDFindCardFormat(format);
|
||||||
errors = true;
|
if (idx == -1) {
|
||||||
}
|
PrintAndLogEx(WARNING, "Unknown format: %s", format);
|
||||||
cmdp += 2;
|
return PM3_EINVARG;
|
||||||
break;
|
|
||||||
case 'i':
|
|
||||||
data.IssueLevel = param_get32ex(Cmd, cmdp + 1, 0, 10);
|
|
||||||
cmdp += 2;
|
|
||||||
break;
|
|
||||||
case 'f':
|
|
||||||
data.FacilityCode = param_get32ex(Cmd, cmdp + 1, 0, 10);
|
|
||||||
cmdp += 2;
|
|
||||||
break;
|
|
||||||
case 'c':
|
|
||||||
data.CardNumber = param_get64ex(Cmd, cmdp + 1, 0, 10);
|
|
||||||
cmdp += 2;
|
|
||||||
break;
|
|
||||||
case 'o':
|
|
||||||
data.OEM = param_get32ex(Cmd, cmdp + 1, 0, 10);
|
|
||||||
cmdp += 2;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
PrintAndLogEx(WARNING, "Unknown parameter '%c'", param_getchar(Cmd, cmdp));
|
|
||||||
errors = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (errors || cmdp == 0) return usage_wiegand_encode();
|
|
||||||
|
|
||||||
wiegand_message_t packed;
|
wiegand_message_t packed;
|
||||||
memset(&packed, 0, sizeof(wiegand_message_t));
|
memset(&packed, 0, sizeof(wiegand_message_t));
|
||||||
|
|
||||||
if (HIDPack(format_idx, &data, &packed) == false) {
|
if (HIDPack(idx, &data, &packed) == false) {
|
||||||
PrintAndLogEx(WARNING, "The card data could not be encoded in the selected format.");
|
PrintAndLogEx(WARNING, "The card data could not be encoded in the selected format.");
|
||||||
return PM3_ESOFT;
|
return PM3_ESOFT;
|
||||||
}
|
}
|
||||||
|
|
||||||
PrintTagId(&packed);
|
print_wiegand_code(&packed);
|
||||||
return PM3_SUCCESS;
|
return PM3_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CmdWiegandDecode(const char *Cmd) {
|
int CmdWiegandDecode(const char *Cmd) {
|
||||||
|
|
||||||
uint32_t top = 0, mid = 0, bot = 0;
|
CLIParserContext *ctx;
|
||||||
bool ignore_parity = false, gothex = false;
|
CLIParserInit(&ctx, "wiegand decode",
|
||||||
bool errors = false;
|
"Decode raw hex to wiegand format",
|
||||||
char cmdp = 0;
|
"wiegand decode --raw 2006f623ae"
|
||||||
while (param_getchar(Cmd, cmdp) != 0x00 && !errors) {
|
);
|
||||||
uint32_t slen = param_getlength(Cmd, cmdp);
|
|
||||||
slen++; // null termin
|
|
||||||
if (slen > 2) {
|
|
||||||
char *s = calloc(slen, sizeof(uint8_t));
|
|
||||||
param_getstr(Cmd, cmdp, s, slen);
|
|
||||||
hexstring_to_u96(&top, &mid, &bot, s);
|
|
||||||
free(s);
|
|
||||||
gothex = true;
|
|
||||||
cmdp++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
switch (tolower(param_getchar(Cmd, cmdp))) {
|
|
||||||
case 'h':
|
|
||||||
return usage_wiegand_decode();
|
|
||||||
case 'p':
|
|
||||||
ignore_parity = true;
|
|
||||||
cmdp++;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
PrintAndLogEx(WARNING, "Unknown parameter '%c'", param_getchar(Cmd, cmdp));
|
|
||||||
errors = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (gothex == false)
|
|
||||||
errors = true;
|
|
||||||
|
|
||||||
if (errors || cmdp < 1) return usage_wiegand_decode();
|
void *argtable[] = {
|
||||||
|
arg_param_begin,
|
||||||
|
arg_lit0("p", "parity", "ignore invalid parity"),
|
||||||
|
arg_strx1(NULL, "raw", "<hex>", "raw hex to be decoded"),
|
||||||
|
arg_param_end
|
||||||
|
};
|
||||||
|
CLIExecWithReturn(ctx, Cmd, argtable, false);
|
||||||
|
|
||||||
|
bool ignore_parity = arg_get_lit(ctx, 1);
|
||||||
|
int len = 0;
|
||||||
|
char hex[40] = {0};
|
||||||
|
CLIParamStrToBuf(arg_get_str(ctx, 2), (uint8_t*)hex, sizeof(hex), &len);
|
||||||
|
CLIParserFree(ctx);
|
||||||
|
|
||||||
|
if (len == 0) {
|
||||||
|
PrintAndLogEx(ERR, "empty input");
|
||||||
|
return PM3_EINVARG;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t top = 0, mid = 0, bot = 0;
|
||||||
|
hexstring_to_u96(&top, &mid, &bot, hex);
|
||||||
|
|
||||||
wiegand_message_t packed = initialize_message_object(top, mid, bot);
|
wiegand_message_t packed = initialize_message_object(top, mid, bot);
|
||||||
|
|
||||||
HIDTryUnpack(&packed, ignore_parity);
|
HIDTryUnpack(&packed, ignore_parity);
|
||||||
|
|
||||||
return PM3_SUCCESS;
|
return PM3_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -332,23 +332,25 @@ Convert Site & Facility code to Wiegand raw hex
|
||||||
```
|
```
|
||||||
Options
|
Options
|
||||||
---
|
---
|
||||||
w <format> o <OEM> f <FC> c <CN> i <issuelevel>
|
-w <format> --oem <OEM> --fc <FC> --cn <CN> --issue <issuelevel>
|
||||||
w : wiegand format to use
|
|
||||||
o : OEM number / site code
|
|
||||||
f : facility code
|
|
||||||
c : card number
|
|
||||||
i : issue level
|
|
||||||
|
|
||||||
pm3 --> wiegand encode 0 56 150
|
-w : wiegand format to use
|
||||||
|
--oem : OEM number / site code
|
||||||
|
--fc : facility code
|
||||||
|
--cn : card number
|
||||||
|
--issue : issue level
|
||||||
|
|
||||||
|
pm3 --> wiegand encode -w H10301 --oem 0 --fc 56 --cn 150
|
||||||
```
|
```
|
||||||
|
|
||||||
Convert Site & Facility code from Wiegand raw hex to numbers
|
Convert Site & Facility code from Wiegand raw hex to numbers
|
||||||
```
|
```
|
||||||
Options
|
Options
|
||||||
---
|
---
|
||||||
p : ignore parity errors
|
-p : ignore parity errors
|
||||||
|
--raw : raw hex to be decoded
|
||||||
|
|
||||||
pm3 --> wiegand decode 2006f623ae
|
pm3 --> wiegand decode --raw 2006f623ae
|
||||||
```
|
```
|
||||||
|
|
||||||
## HID Prox
|
## HID Prox
|
||||||
|
@ -556,7 +558,7 @@ pm3 --> script list
|
||||||
View lua helptext
|
View lua helptext
|
||||||
|
|
||||||
```
|
```
|
||||||
pm3 --> script run <nameofscript> -h
|
pm3 --> script run <nameofscript> -h
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
@ -599,15 +601,15 @@ Load default keys into flash memory (RDV4 only)
|
||||||
```
|
```
|
||||||
Options
|
Options
|
||||||
---
|
---
|
||||||
o <offset> : offset in memory
|
-o <offset> : offset in memory
|
||||||
f <filename> : file name
|
-f <filename> : file name
|
||||||
m : upload 6 bytes keys (mifare key dictionary)
|
--mfc : upload 6 bytes keys (mifare key dictionary)
|
||||||
i : upload 8 bytes keys (iClass key dictionary)
|
--iclass : upload 8 bytes keys (iClass key dictionary)
|
||||||
t : upload 4 bytes keys (pwd dictionary)
|
--t55xx : upload 4 bytes keys (pwd dictionary)
|
||||||
|
|
||||||
pm3 --> mem load f mfc_default_keys m
|
pm3 --> mem load -f mfc_default_keys --mfc
|
||||||
pm3 --> mem load f t55xx_default_pwds t
|
pm3 --> mem load -f t55xx_default_pwds --t5xx
|
||||||
pm3 --> mem load f iclass_default_keys i
|
pm3 --> mem load -f iclass_default_keys --iclass
|
||||||
```
|
```
|
||||||
|
|
||||||
## Sim Module
|
## Sim Module
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue