Merge remote-tracking branch 'origin/master' into emrtd
This commit is contained in:
@@ -53,7 +53,7 @@ int CmdHFSearch(const char *Cmd) {
|
||||
"Will try to find a HF read out of the unknown tag.\n"
|
||||
"Continues to search for all different HF protocols.",
|
||||
"hf sniff"
|
||||
);
|
||||
);
|
||||
void *argtable[] = {
|
||||
arg_param_begin,
|
||||
arg_param_end
|
||||
@@ -219,7 +219,7 @@ int CmdHFTune(const char *Cmd) {
|
||||
uint32_t max = 0xFFFF;
|
||||
bool first = true;
|
||||
|
||||
print_progress(0, max, style);
|
||||
print_progress(0, max, style);
|
||||
|
||||
// loop forever (till button pressed) if iter = 0 (default)
|
||||
for (uint8_t i = 0; iter == 0 || i < iter; i++) {
|
||||
@@ -244,7 +244,7 @@ int CmdHFTune(const char *Cmd) {
|
||||
max = (volt * 1.03);
|
||||
first = false;
|
||||
}
|
||||
if ( volt > max) {
|
||||
if (volt > max) {
|
||||
max = (volt * 1.03);
|
||||
}
|
||||
print_progress(volt, max, style);
|
||||
@@ -274,7 +274,7 @@ int CmdHFSniff(const char *Cmd) {
|
||||
"Press button to quit the sniffing.",
|
||||
"hf sniff\n"
|
||||
"hf sniff --sp 1000 --st 0 -> skip 1000 pairs, skip 0 triggers"
|
||||
);
|
||||
);
|
||||
void *argtable[] = {
|
||||
arg_param_begin,
|
||||
arg_u64_0(NULL, "sp", "<dec>", "skip sample pairs"),
|
||||
|
||||
@@ -2001,7 +2001,7 @@ int infoHF14A(bool verbose, bool do_nack_test, bool do_aid_search) {
|
||||
|
||||
if (do_aid_search) {
|
||||
|
||||
|
||||
|
||||
PrintAndLogEx(INFO, "-------------------- " _CYAN_("AID Search") " --------------------");
|
||||
|
||||
bool found = false;
|
||||
|
||||
@@ -82,9 +82,9 @@ static void hf14b_aid_search(bool verbose) {
|
||||
bool activate_field = true;
|
||||
for (elmindx = 0; elmindx < json_array_size(root); elmindx++) {
|
||||
|
||||
if (kbd_enter_pressed()) {
|
||||
break;
|
||||
}
|
||||
if (kbd_enter_pressed()) {
|
||||
break;
|
||||
}
|
||||
|
||||
json_t *data = AIDSearchGetElm(root, elmindx);
|
||||
uint8_t vaid[200] = {0};
|
||||
|
||||
@@ -1017,7 +1017,7 @@ int dumpHF_EMRTD(char *documentnumber, char *dob, char *expiry, bool BAC_availab
|
||||
// Add EF_SOD to the list
|
||||
filelist[filelistlen++] = 0x77;
|
||||
// Dump all files in the file list
|
||||
for (size_t i = 0; i < filelistlen; i++) {
|
||||
for (int i = 0; i < filelistlen; i++) {
|
||||
emrtd_dg_t *dg = emrtd_tag_to_dg(filelist[i]);
|
||||
if (dg == NULL) {
|
||||
PrintAndLogEx(INFO, "File tag not found, skipping: %02X", filelist[i]);
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
#include <inttypes.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h> // tolower
|
||||
|
||||
#include "cliparser.h"
|
||||
#include "cmdparser.h" // command_t
|
||||
#include "commonutil.h" // ARRAYLEN
|
||||
#include "comms.h" // clearCommandBuffer
|
||||
@@ -24,35 +24,28 @@
|
||||
|
||||
static int CmdHelp(const char *Cmd);
|
||||
|
||||
static int usage_epa_collect(void) {
|
||||
PrintAndLogEx(NORMAL, "Tries to collect nonces when doing part of PACE protocol.\n"
|
||||
"\n"
|
||||
"Usage: hf epa cnonces <m> <n> <d>\n"
|
||||
"Options:\n"
|
||||
"\t<m> nonce size\n"
|
||||
"\t<n> number of nonces to collect\n"
|
||||
"\t<d> delay between\n"
|
||||
"\n"
|
||||
"Example:\n"
|
||||
_YELLOW_("\thf epa cnonces 4 4 1")
|
||||
);
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
|
||||
// Perform (part of) the PACE protocol
|
||||
static int CmdHFEPACollectPACENonces(const char *Cmd) {
|
||||
CLIParserContext *ctx;
|
||||
CLIParserInit(&ctx, "hf epa cnonces",
|
||||
"Tries to collect nonces when doing part of PACE protocol.",
|
||||
"hf epa cnonces --size 4 --num 4 --delay 1");
|
||||
|
||||
char cmdp = tolower(param_getchar(Cmd, 0));
|
||||
if (cmdp == 'h') return usage_epa_collect();
|
||||
void *argtable[] = {
|
||||
arg_param_begin,
|
||||
arg_int1(NULL, "size", "<dec>", "nonce size"),
|
||||
arg_int1(NULL, "num", "<dec>", "number of nonces to collect"),
|
||||
arg_int1("d", "delay", "<dec>", "delay between attempts"),
|
||||
arg_param_end
|
||||
};
|
||||
CLIExecWithReturn(ctx, Cmd, argtable, false);
|
||||
|
||||
// requested nonce size
|
||||
uint32_t m = 0;
|
||||
// requested number of Nonces
|
||||
uint32_t n = 0;
|
||||
// delay between requests
|
||||
uint32_t d = 0;
|
||||
|
||||
sscanf(Cmd, "%u %u %u", &m, &n, &d);
|
||||
int m = arg_get_int_def(ctx, 1, 0);
|
||||
int n = arg_get_int_def(ctx, 2, 0);
|
||||
int d = arg_get_int_def(ctx, 3, 0);
|
||||
|
||||
CLIParserFree(ctx);
|
||||
|
||||
// values are expected to be > 0
|
||||
m = m > 0 ? m : 1;
|
||||
@@ -99,54 +92,51 @@ static int CmdHFEPACollectPACENonces(const char *Cmd) {
|
||||
|
||||
// perform the PACE protocol by replaying APDUs
|
||||
static int CmdHFEPAPACEReplay(const char *Cmd) {
|
||||
// the 4 APDUs which are replayed + their lengths
|
||||
uint8_t msesa_apdu[41] = {0}, gn_apdu[8] = {0}, map_apdu[75] = {0};
|
||||
uint8_t pka_apdu[75] = {0}, ma_apdu[18] = {0}, apdu_lengths[5] = {0};
|
||||
CLIParserContext *ctx;
|
||||
CLIParserInit(&ctx, "hf epa preplay",
|
||||
"Perform PACE protocol by replaying given APDUs",
|
||||
"hf epa preplay --mse 0022C1A4 --get 1068000000 --map 1086000002 --pka 1234ABCDEF --ma 1A2B3C4D");
|
||||
|
||||
void *argtable[] = {
|
||||
arg_param_begin,
|
||||
arg_str1(NULL, "mse", "<hex>", "msesa APDU"),
|
||||
arg_str1(NULL, "get", "<hex>", "gn APDU"),
|
||||
arg_str1(NULL, "map", "<hex>", "map APDU"),
|
||||
arg_str1(NULL, "pka", "<hex>", "pka APDU"),
|
||||
arg_str1(NULL, "ma", "<hex>", "ma APDU"),
|
||||
arg_param_end
|
||||
};
|
||||
CLIExecWithReturn(ctx, Cmd, argtable, false);
|
||||
|
||||
int msesa_len = 0;
|
||||
uint8_t msesa_apdu[41] = {0};
|
||||
CLIGetHexWithReturn(ctx, 1, msesa_apdu, &msesa_len);
|
||||
|
||||
int gn_len = 0;
|
||||
uint8_t gn_apdu[8] = {0};
|
||||
CLIGetHexWithReturn(ctx, 2, gn_apdu, &gn_len);
|
||||
|
||||
int map_len = 0;
|
||||
uint8_t map_apdu[75] = {0};
|
||||
CLIGetHexWithReturn(ctx, 3, map_apdu, &map_len);
|
||||
|
||||
int pka_len = 0;
|
||||
uint8_t pka_apdu[75] = {0};
|
||||
CLIGetHexWithReturn(ctx, 4, pka_apdu, &pka_len);
|
||||
|
||||
int ma_len = 0;
|
||||
uint8_t ma_apdu[18] = {0};
|
||||
CLIGetHexWithReturn(ctx, 5, ma_apdu, &ma_len);
|
||||
|
||||
CLIParserFree(ctx);
|
||||
|
||||
uint8_t apdu_lengths[5] = {msesa_len, gn_len, map_len, pka_len, ma_len};
|
||||
// pointers to the arrays to be able to iterate
|
||||
uint8_t *apdus[] = {msesa_apdu, gn_apdu, map_apdu, pka_apdu, ma_apdu};
|
||||
|
||||
// usage message
|
||||
static const char *usage_msg =
|
||||
"Please specify 5 APDUs separated by spaces. "
|
||||
"Example:\n preplay 0022C1A4 1068000000 1086000002 1234ABCDEF 1A2B3C4D";
|
||||
|
||||
// Proxmark response
|
||||
PacketResponseNG resp;
|
||||
|
||||
int skip = 0, skip_add = 0, scan_return;
|
||||
// for each APDU
|
||||
for (int i = 0; i < ARRAYLEN(apdu_lengths); i++) {
|
||||
// scan to next space or end of string
|
||||
while (Cmd[skip] != ' ' && Cmd[skip] != '\0') {
|
||||
// convert
|
||||
scan_return = sscanf(Cmd + skip,
|
||||
"%2" SCNx8 "%n",
|
||||
apdus[i] + apdu_lengths[i],
|
||||
&skip_add
|
||||
);
|
||||
|
||||
if (scan_return < 1) {
|
||||
PrintAndLogEx(INFO, (char *)usage_msg);
|
||||
PrintAndLogEx(WARNING, "Not enough APDUs! Try again!");
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
skip += skip_add;
|
||||
apdu_lengths[i]++;
|
||||
}
|
||||
|
||||
// break on EOF
|
||||
if (Cmd[skip] == '\0') {
|
||||
if (i < ARRAYLEN(apdu_lengths) - 1) {
|
||||
|
||||
PrintAndLogEx(INFO, (char *)usage_msg);
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
break;
|
||||
}
|
||||
// skip the space
|
||||
skip++;
|
||||
}
|
||||
|
||||
// transfer the APDUs to the Proxmark
|
||||
uint8_t data[PM3_CMD_DATA_SIZE];
|
||||
// fast push mode
|
||||
@@ -205,8 +195,8 @@ static int CmdHFEPAPACEReplay(const char *Cmd) {
|
||||
|
||||
static command_t CommandTable[] = {
|
||||
{"help", CmdHelp, AlwaysAvailable, "This help"},
|
||||
{"cnonces", CmdHFEPACollectPACENonces, IfPm3Iso14443, "<m> <n> <d> Acquire n>0 encrypted PACE nonces of size m>0 with d sec pauses"},
|
||||
{"preplay", CmdHFEPAPACEReplay, IfPm3Iso14443, "<mse> <get> <map> <pka> <ma> Perform PACE protocol by replaying given APDUs"},
|
||||
{"cnonces", CmdHFEPACollectPACENonces, IfPm3Iso14443, "Acquire encrypted PACE nonces of specific size"},
|
||||
{"preplay", CmdHFEPAPACEReplay, IfPm3Iso14443, "Perform PACE protocol by replaying given APDUs"},
|
||||
{NULL, NULL, NULL, NULL}
|
||||
};
|
||||
|
||||
|
||||
@@ -48,10 +48,18 @@ static int cmd_hf_fido_list(const char *Cmd) {
|
||||
return CmdTraceList(args);
|
||||
}
|
||||
|
||||
static int cmd_hf_fido_info(const char *cmd) {
|
||||
static int cmd_hf_fido_info(const char *Cmd) {
|
||||
CLIParserContext *ctx;
|
||||
CLIParserInit(&ctx, "hf fido info",
|
||||
"Get info from Fido tags",
|
||||
"hf fido info");
|
||||
|
||||
if (cmd && strlen(cmd) > 0)
|
||||
PrintAndLogEx(WARNING, "WARNING: command doesn't have any parameters.\n");
|
||||
void *argtable[] = {
|
||||
arg_param_begin,
|
||||
arg_param_end
|
||||
};
|
||||
CLIExecWithReturn(ctx, Cmd, argtable, true);
|
||||
CLIParserFree(ctx);
|
||||
|
||||
// info about 14a part
|
||||
infoHF14A(false, false, false);
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
#include "cmdparser.h" // command_t
|
||||
#include "commonutil.h" // ARRAYLEN
|
||||
#include "cmdtrace.h"
|
||||
#include "cliparser.h"
|
||||
#include "util_posix.h"
|
||||
#include "comms.h"
|
||||
#include "des.h"
|
||||
|
||||
@@ -306,7 +306,7 @@ static int CmdLFTune(const char *Cmd) {
|
||||
uint32_t max = 71000;
|
||||
bool first = true;
|
||||
|
||||
print_progress(0, max, style);
|
||||
print_progress(0, max, style);
|
||||
|
||||
// loop forever (till button pressed) if iter = 0 (default)
|
||||
for (uint8_t i = 0; iter == 0 || i < iter; i++) {
|
||||
@@ -328,11 +328,11 @@ static int CmdLFTune(const char *Cmd) {
|
||||
|
||||
uint32_t volt = resp.data.asDwords[0];
|
||||
if (first) {
|
||||
max = (volt * 1.03);
|
||||
max = (volt * 1.03);
|
||||
first = false;
|
||||
}
|
||||
if ( volt > max) {
|
||||
max = (volt * 1.03);
|
||||
if (volt > max) {
|
||||
max = (volt * 1.03);
|
||||
}
|
||||
print_progress(volt, max, style);
|
||||
}
|
||||
|
||||
@@ -286,7 +286,7 @@ int CmdEM4x50EView(const char *Cmd) {
|
||||
PrintAndLogEx(WARNING, "Fail, transfer from device time-out");
|
||||
return PM3_ETIMEOUT;
|
||||
}
|
||||
|
||||
|
||||
// valid em4x50 data?
|
||||
uint32_t serial = bytes_to_num(data + 4 * EM4X50_DEVICE_SERIAL, 4);
|
||||
uint32_t device_id = bytes_to_num(data + 4 * EM4X50_DEVICE_ID, 4);
|
||||
|
||||
@@ -175,7 +175,7 @@ int CmdRem(const char *Cmd) {
|
||||
};
|
||||
CLIExecWithReturn(ctx, Cmd, argtable, false);
|
||||
|
||||
struct arg_str* foo = arg_get_str(ctx, 1);
|
||||
struct arg_str *foo = arg_get_str(ctx, 1);
|
||||
size_t count = 0;
|
||||
size_t len = 0;
|
||||
do {
|
||||
|
||||
@@ -314,7 +314,7 @@ void preferences_load_callback(json_t *root) {
|
||||
if (json_unpack_ex(root, &up_error, 0, "{s:b}", "os.supports.colors", &b1) == 0)
|
||||
session.supports_colors = (bool)b1;
|
||||
|
||||
// bar mode
|
||||
// bar mode
|
||||
if (json_unpack_ex(root, &up_error, 0, "{s:s}", "show.bar.mode", &s1) == 0) {
|
||||
strncpy(tempStr, s1, sizeof(tempStr) - 1);
|
||||
str_lower(tempStr);
|
||||
|
||||
@@ -14,7 +14,9 @@
|
||||
#if !defined(_WIN32)
|
||||
#define _POSIX_C_SOURCE 200112L
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_READLINE
|
||||
#include <readline/readline.h>
|
||||
#endif
|
||||
#include "ui.h"
|
||||
#include "commonutil.h" // ARRAYLEN
|
||||
|
||||
@@ -625,58 +627,84 @@ void iceSimple_Filter(int *data, const size_t len, uint8_t k) {
|
||||
}
|
||||
|
||||
void print_progress(size_t count, uint64_t max, barMode_t style) {
|
||||
int cols = 100 + 35;
|
||||
#ifdef HAVE_READLINE
|
||||
static int prev_cols = 0;
|
||||
int rows;
|
||||
rl_reset_screen_size(); // refresh Readline idea of the actual screen width
|
||||
rl_get_screen_size(&rows, &cols);
|
||||
(void) rows;
|
||||
if (prev_cols > cols) {
|
||||
PrintAndLogEx(NORMAL, _CLEAR_ _TOP_ "");
|
||||
}
|
||||
prev_cols = cols;
|
||||
#endif
|
||||
int width = cols - 35;
|
||||
#define PERCENTAGE(V, T) ((V * width) / T)
|
||||
// x/8 fractional part of the percentage
|
||||
#define PERCENTAGEFRAC(V, T) ((int)(((((float)V * width) / T) - ((V * width) / T)) * 8))
|
||||
|
||||
#define PERCENTAGE(V, T) (100 - (((T - V) * 100) / T))
|
||||
|
||||
/*
|
||||
typedef struct smooth_s {
|
||||
const char *bar;
|
||||
} smooth_t;
|
||||
|
||||
static smooth_t smoothtable[] = {
|
||||
{"\xe2\x96\x8F"},
|
||||
{"\xe2\x96\x8E"},
|
||||
{"\xe2\x96\x8D"},
|
||||
{"\xe2\x96\x8C"},
|
||||
{"\xe2\x96\x8B"},
|
||||
{"\xe2\x96\x8A"},
|
||||
{"\xe2\x96\x89"},
|
||||
{"\xe2\x96\x88"},
|
||||
const char *smoothtable[] = {
|
||||
"\xe2\x80\x80",
|
||||
"\xe2\x96\x8F",
|
||||
"\xe2\x96\x8E",
|
||||
"\xe2\x96\x8D",
|
||||
"\xe2\x96\x8C",
|
||||
"\xe2\x96\x8B",
|
||||
"\xe2\x96\x8A",
|
||||
"\xe2\x96\x89",
|
||||
"\xe2\x96\x88",
|
||||
};
|
||||
*/
|
||||
|
||||
uint8_t mode = session.emoji_mode == EMOJI;
|
||||
const char *block[] = {"#", "\xe2\x96\x88"};
|
||||
// use a 3-byte space in emoji mode to ease computations
|
||||
const char *space[] = {" ", "\xe2\x80\x80"};
|
||||
uint8_t unit = strlen(block[mode]);
|
||||
// +1 for \0
|
||||
char *bar = calloc(100 + 1, sizeof(uint8_t));
|
||||
char *bar = calloc(unit * width + 1, sizeof(uint8_t));
|
||||
|
||||
uint8_t value = PERCENTAGE(count, max);
|
||||
|
||||
int i = 0;
|
||||
// prefix is added already.
|
||||
memset(bar + strlen(bar), 0x23, value);
|
||||
|
||||
for (; i < unit * value; i += unit) {
|
||||
memcpy(bar + i, block[mode], unit);
|
||||
}
|
||||
// add last block
|
||||
if (mode == 1) {
|
||||
memcpy(bar + i, smoothtable[PERCENTAGEFRAC(count, max)], unit);
|
||||
} else {
|
||||
memcpy(bar + i, space[mode], unit);
|
||||
}
|
||||
i += unit;
|
||||
// add spaces
|
||||
memset(bar + strlen(bar), 0x2E, 100 - value);
|
||||
|
||||
for (; i < unit * width; i += unit) {
|
||||
memcpy(bar + i, space[mode], unit);
|
||||
}
|
||||
// color buffer
|
||||
uint8_t collen = 100 + 1 + 40;
|
||||
size_t collen = strlen(bar) + 40;
|
||||
char *cbar = calloc(collen, sizeof(uint8_t));
|
||||
|
||||
// Add colors
|
||||
snprintf(cbar, collen, _GREEN_("%.*s"), 60, bar);
|
||||
snprintf(cbar + strlen(cbar), collen - strlen(cbar), _CYAN_("%.*s"), 20, bar + 60);
|
||||
snprintf(cbar + strlen(cbar), collen - strlen(cbar), _YELLOW_("%.*s"), 20, bar + 80);
|
||||
int p60 = unit * (width * 60 / 100);
|
||||
int p20 = unit * (width * 20 / 100);
|
||||
snprintf(cbar, collen, _GREEN_("%.*s"), p60, bar);
|
||||
snprintf(cbar + strlen(cbar), collen - strlen(cbar), _CYAN_("%.*s"), p20, bar + p60);
|
||||
snprintf(cbar + strlen(cbar), collen - strlen(cbar), _YELLOW_("%.*s"), unit * width - p60 - p20, bar + p60 + p20);
|
||||
|
||||
uint8_t len = collen + 1 + 1 + 30;
|
||||
size_t len = strlen(cbar) + 32;
|
||||
char *buffer = calloc(len, sizeof(uint8_t));
|
||||
|
||||
switch(style) {
|
||||
switch (style) {
|
||||
case STYLE_BAR: {
|
||||
sprintf(buffer, "%s", cbar);
|
||||
sprintf(buffer, "%s", cbar);
|
||||
printf("\b%c[2K\r[" _YELLOW_("=")"] %s", 27, buffer);
|
||||
break;
|
||||
}
|
||||
case STYLE_MIXED: {
|
||||
sprintf(buffer, "%s [ %zu mV / %3u V ]", cbar, count, (uint32_t)(count / 1000));
|
||||
printf("\b%c[2K\r[" _YELLOW_("=")"] %s ", 27, buffer);
|
||||
printf("\b%c[2K\r[" _YELLOW_("=")"] %s ", 27, buffer);
|
||||
break;
|
||||
}
|
||||
case STYLE_VALUE: {
|
||||
@@ -685,8 +713,8 @@ void print_progress(size_t count, uint64_t max, barMode_t style) {
|
||||
}
|
||||
}
|
||||
|
||||
fflush(stdout);
|
||||
free(buffer);
|
||||
fflush(stdout);
|
||||
free(buffer);
|
||||
free(bar);
|
||||
free(cbar);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user