mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-19 21:03:48 -07:00
style
This commit is contained in:
parent
0446509d1e
commit
a776f9a0bd
10 changed files with 231 additions and 187 deletions
|
@ -186,6 +186,7 @@ static void fill_grabber(const char *string) {
|
||||||
g_grabbed_output.ptr = tmp;
|
g_grabbed_output.ptr = tmp;
|
||||||
g_grabbed_output.size += MAX_PRINT_BUFFER;
|
g_grabbed_output.size += MAX_PRINT_BUFFER;
|
||||||
}
|
}
|
||||||
|
|
||||||
int len = snprintf(g_grabbed_output.ptr + g_grabbed_output.idx, MAX_PRINT_BUFFER, "%s", string);
|
int len = snprintf(g_grabbed_output.ptr + g_grabbed_output.idx, MAX_PRINT_BUFFER, "%s", string);
|
||||||
if (len < 0 || len > MAX_PRINT_BUFFER) {
|
if (len < 0 || len > MAX_PRINT_BUFFER) {
|
||||||
// We leave current g_grabbed_output_len untouched
|
// We leave current g_grabbed_output_len untouched
|
||||||
|
@ -196,25 +197,35 @@ static void fill_grabber(const char *string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrintAndLogOptions(const char *str[][2], size_t size, size_t space) {
|
void PrintAndLogOptions(const char *str[][2], size_t size, size_t space) {
|
||||||
|
|
||||||
char buff[2000] = "Options:\n";
|
char buff[2000] = "Options:\n";
|
||||||
char format[2000] = "";
|
char format[2000] = "";
|
||||||
size_t counts[2] = {0, 0};
|
size_t counts[2] = {0, 0};
|
||||||
for (size_t i = 0; i < size; i++)
|
|
||||||
for (size_t j = 0 ; j < 2 ; j++)
|
for (size_t i = 0; i < size; i++) {
|
||||||
|
for (size_t j = 0 ; j < 2 ; j++) {
|
||||||
if (counts[j] < strlen(str[i][j])) {
|
if (counts[j] < strlen(str[i][j])) {
|
||||||
counts[j] = strlen(str[i][j]);
|
counts[j] = strlen(str[i][j]);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (size_t i = 0; i < size; i++) {
|
for (size_t i = 0; i < size; i++) {
|
||||||
|
|
||||||
for (size_t j = 0; j < 2; j++) {
|
for (size_t j = 0; j < 2; j++) {
|
||||||
if (j == 0)
|
if (j == 0) {
|
||||||
snprintf(format, sizeof(format), "%%%zus%%%zus", space, counts[j]);
|
snprintf(format, sizeof(format), "%%%zus%%%zus", space, counts[j]);
|
||||||
else
|
} else {
|
||||||
snprintf(format, sizeof(format), "%%%zus%%-%zus", space, counts[j]);
|
snprintf(format, sizeof(format), "%%%zus%%-%zus", space, counts[j]);
|
||||||
|
}
|
||||||
|
|
||||||
snprintf(buff + strlen(buff), sizeof(buff) - strlen(buff), format, " ", str[i][j]);
|
snprintf(buff + strlen(buff), sizeof(buff) - strlen(buff), format, " ", str[i][j]);
|
||||||
}
|
}
|
||||||
if (i < size - 1)
|
|
||||||
|
if (i < size - 1) {
|
||||||
strncat(buff, "\n", sizeof(buff) - strlen(buff) - 1);
|
strncat(buff, "\n", sizeof(buff) - strlen(buff) - 1);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
PrintAndLogEx(NORMAL, "%s", buff);
|
PrintAndLogEx(NORMAL, "%s", buff);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -223,12 +234,14 @@ static uint8_t PrintAndLogEx_spinidx = 0;
|
||||||
void PrintAndLogEx(logLevel_t level, const char *fmt, ...) {
|
void PrintAndLogEx(logLevel_t level, const char *fmt, ...) {
|
||||||
|
|
||||||
// skip debug messages if client debugging is turned off i.e. 'DATA SETDEBUG -0'
|
// skip debug messages if client debugging is turned off i.e. 'DATA SETDEBUG -0'
|
||||||
if (g_debugMode == 0 && level == DEBUG)
|
if (g_debugMode == 0 && level == DEBUG) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// skip HINT messages if client has hints turned off i.e. 'HINT 0'
|
// skip HINT messages if client has hints turned off i.e. 'HINT 0'
|
||||||
if (g_session.show_hints == false && level == HINT)
|
if (g_session.show_hints == false && level == HINT) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
char prefix[40] = {0};
|
char prefix[40] = {0};
|
||||||
char buffer[MAX_PRINT_BUFFER] = {0};
|
char buffer[MAX_PRINT_BUFFER] = {0};
|
||||||
|
@ -242,17 +255,19 @@ void PrintAndLogEx(logLevel_t level, const char *fmt, ...) {
|
||||||
};
|
};
|
||||||
switch (level) {
|
switch (level) {
|
||||||
case ERR:
|
case ERR:
|
||||||
if (g_session.emoji_mode == EMO_EMOJI)
|
if (g_session.emoji_mode == EMO_EMOJI) {
|
||||||
strncpy(prefix, "[" _RED_("!!") "] :rotating_light: ", sizeof(prefix) - 1);
|
strncpy(prefix, "[" _RED_("!!") "] :rotating_light: ", sizeof(prefix) - 1);
|
||||||
else
|
} else {
|
||||||
strncpy(prefix, "[" _RED_("!!") "] ", sizeof(prefix) - 1);
|
strncpy(prefix, "[" _RED_("!!") "] ", sizeof(prefix) - 1);
|
||||||
|
}
|
||||||
stream = stderr;
|
stream = stderr;
|
||||||
break;
|
break;
|
||||||
case FAILED:
|
case FAILED:
|
||||||
if (g_session.emoji_mode == EMO_EMOJI)
|
if (g_session.emoji_mode == EMO_EMOJI) {
|
||||||
strncpy(prefix, "[" _RED_("-") "] :no_entry: ", sizeof(prefix) - 1);
|
strncpy(prefix, "[" _RED_("-") "] :no_entry: ", sizeof(prefix) - 1);
|
||||||
else
|
} else {
|
||||||
strncpy(prefix, "[" _RED_("-") "] ", sizeof(prefix) - 1);
|
strncpy(prefix, "[" _RED_("-") "] ", sizeof(prefix) - 1);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case DEBUG:
|
case DEBUG:
|
||||||
strncpy(prefix, "[" _BLUE_("#") "] ", sizeof(prefix) - 1);
|
strncpy(prefix, "[" _BLUE_("#") "] ", sizeof(prefix) - 1);
|
||||||
|
@ -264,10 +279,11 @@ void PrintAndLogEx(logLevel_t level, const char *fmt, ...) {
|
||||||
strncpy(prefix, "[" _GREEN_("+") "] ", sizeof(prefix) - 1);
|
strncpy(prefix, "[" _GREEN_("+") "] ", sizeof(prefix) - 1);
|
||||||
break;
|
break;
|
||||||
case WARNING:
|
case WARNING:
|
||||||
if (g_session.emoji_mode == EMO_EMOJI)
|
if (g_session.emoji_mode == EMO_EMOJI) {
|
||||||
strncpy(prefix, "[" _CYAN_("!") "] :warning: ", sizeof(prefix) - 1);
|
strncpy(prefix, "[" _CYAN_("!") "] :warning: ", sizeof(prefix) - 1);
|
||||||
else
|
} else {
|
||||||
strncpy(prefix, "[" _CYAN_("!") "] ", sizeof(prefix) - 1);
|
strncpy(prefix, "[" _CYAN_("!") "] ", sizeof(prefix) - 1);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case INFO:
|
case INFO:
|
||||||
strncpy(prefix, "[" _YELLOW_("=") "] ", sizeof(prefix) - 1);
|
strncpy(prefix, "[" _YELLOW_("=") "] ", sizeof(prefix) - 1);
|
||||||
|
@ -276,14 +292,16 @@ void PrintAndLogEx(logLevel_t level, const char *fmt, ...) {
|
||||||
if (g_session.emoji_mode == EMO_EMOJI) {
|
if (g_session.emoji_mode == EMO_EMOJI) {
|
||||||
strncpy(prefix, spinner_emoji[PrintAndLogEx_spinidx], sizeof(prefix) - 1);
|
strncpy(prefix, spinner_emoji[PrintAndLogEx_spinidx], sizeof(prefix) - 1);
|
||||||
PrintAndLogEx_spinidx++;
|
PrintAndLogEx_spinidx++;
|
||||||
if (PrintAndLogEx_spinidx >= ARRAYLEN(spinner_emoji))
|
if (PrintAndLogEx_spinidx >= ARRAYLEN(spinner_emoji)) {
|
||||||
PrintAndLogEx_spinidx = 0;
|
PrintAndLogEx_spinidx = 0;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
strncpy(prefix, spinner[PrintAndLogEx_spinidx], sizeof(prefix) - 1);
|
strncpy(prefix, spinner[PrintAndLogEx_spinidx], sizeof(prefix) - 1);
|
||||||
PrintAndLogEx_spinidx++;
|
PrintAndLogEx_spinidx++;
|
||||||
if (PrintAndLogEx_spinidx >= ARRAYLEN(spinner))
|
if (PrintAndLogEx_spinidx >= ARRAYLEN(spinner)) {
|
||||||
PrintAndLogEx_spinidx = 0;
|
PrintAndLogEx_spinidx = 0;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case NORMAL:
|
case NORMAL:
|
||||||
// no prefixes for normal
|
// no prefixes for normal
|
||||||
|
@ -306,8 +324,9 @@ void PrintAndLogEx(logLevel_t level, const char *fmt, ...) {
|
||||||
const char delim[2] = "\n";
|
const char delim[2] = "\n";
|
||||||
|
|
||||||
// line starts with newline
|
// line starts with newline
|
||||||
if (buffer[0] == '\n')
|
if (buffer[0] == '\n') {
|
||||||
fPrintAndLog(stream, "");
|
fPrintAndLog(stream, "");
|
||||||
|
}
|
||||||
|
|
||||||
token = strtok_r(buffer, delim, &tmp_ptr);
|
token = strtok_r(buffer, delim, &tmp_ptr);
|
||||||
|
|
||||||
|
@ -315,16 +334,21 @@ void PrintAndLogEx(logLevel_t level, const char *fmt, ...) {
|
||||||
|
|
||||||
size_t size = strlen(buffer2);
|
size_t size = strlen(buffer2);
|
||||||
|
|
||||||
if (strlen(token))
|
if (strlen(token)) {
|
||||||
snprintf(buffer2 + size, sizeof(buffer2) - size, "%s%s\n", prefix, token);
|
snprintf(buffer2 + size, sizeof(buffer2) - size, "%s%s\n", prefix, token);
|
||||||
else
|
} else {
|
||||||
snprintf(buffer2 + size, sizeof(buffer2) - size, "\n");
|
snprintf(buffer2 + size, sizeof(buffer2) - size, "\n");
|
||||||
|
}
|
||||||
|
|
||||||
token = strtok_r(NULL, delim, &tmp_ptr);
|
token = strtok_r(NULL, delim, &tmp_ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
fPrintAndLog(stream, "%s", buffer2);
|
fPrintAndLog(stream, "%s", buffer2);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
snprintf(buffer2, sizeof(buffer2), "%s%s", prefix, buffer);
|
snprintf(buffer2, sizeof(buffer2), "%s%s", prefix, buffer);
|
||||||
|
|
||||||
if (level == INPLACE) {
|
if (level == INPLACE) {
|
||||||
// ignore INPLACE if rest of output is grabbed
|
// ignore INPLACE if rest of output is grabbed
|
||||||
if (!(g_printAndLog & PRINTANDLOG_GRAB)) {
|
if (!(g_printAndLog & PRINTANDLOG_GRAB)) {
|
||||||
|
@ -354,6 +378,7 @@ static void fPrintAndLog(FILE *stream, const char *fmt, ...) {
|
||||||
if (logging && g_session.incognito) {
|
if (logging && g_session.incognito) {
|
||||||
logging = 0;
|
logging = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((g_printAndLog & PRINTANDLOG_LOG) && logging && !logfile) {
|
if ((g_printAndLog & PRINTANDLOG_LOG) && logging && !logfile) {
|
||||||
char *my_logfile_path = NULL;
|
char *my_logfile_path = NULL;
|
||||||
char filename[40];
|
char filename[40];
|
||||||
|
@ -361,11 +386,15 @@ static void fPrintAndLog(FILE *stream, const char *fmt, ...) {
|
||||||
time_t now = time(NULL);
|
time_t now = time(NULL);
|
||||||
timenow = gmtime(&now);
|
timenow = gmtime(&now);
|
||||||
strftime(filename, sizeof(filename), PROXLOG, timenow);
|
strftime(filename, sizeof(filename), PROXLOG, timenow);
|
||||||
|
|
||||||
if (searchHomeFilePath(&my_logfile_path, LOGS_SUBDIR, filename, true) != PM3_SUCCESS) {
|
if (searchHomeFilePath(&my_logfile_path, LOGS_SUBDIR, filename, true) != PM3_SUCCESS) {
|
||||||
|
|
||||||
printf(_YELLOW_("[-]") " Logging disabled!\n");
|
printf(_YELLOW_("[-]") " Logging disabled!\n");
|
||||||
my_logfile_path = NULL;
|
my_logfile_path = NULL;
|
||||||
logging = 0;
|
logging = 0;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
logfile = fopen(my_logfile_path, "a");
|
logfile = fopen(my_logfile_path, "a");
|
||||||
if (logfile == NULL) {
|
if (logfile == NULL) {
|
||||||
printf(_YELLOW_("[-]") " Can't open logfile %s, logging disabled!\n", my_logfile_path);
|
printf(_YELLOW_("[-]") " Can't open logfile %s, logging disabled!\n", my_logfile_path);
|
||||||
|
@ -411,14 +440,17 @@ static void fPrintAndLog(FILE *stream, const char *fmt, ...) {
|
||||||
linefeed = false;
|
linefeed = false;
|
||||||
buffer[strlen(buffer) - 1] = 0;
|
buffer[strlen(buffer) - 1] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool filter_ansi = !g_session.supports_colors;
|
bool filter_ansi = !g_session.supports_colors;
|
||||||
memcpy_filter_ansi(buffer2, buffer, sizeof(buffer), filter_ansi);
|
memcpy_filter_ansi(buffer2, buffer, sizeof(buffer), filter_ansi);
|
||||||
if (g_printAndLog & PRINTANDLOG_PRINT) {
|
|
||||||
|
if ((g_printAndLog & PRINTANDLOG_PRINT) == PRINTANDLOG_PRINT) {
|
||||||
memcpy_filter_emoji(buffer3, buffer2, sizeof(buffer2), g_session.emoji_mode);
|
memcpy_filter_emoji(buffer3, buffer2, sizeof(buffer2), g_session.emoji_mode);
|
||||||
fprintf(stream, "%s", buffer3);
|
fprintf(stream, "%s", buffer3);
|
||||||
if (linefeed)
|
if (linefeed) {
|
||||||
fprintf(stream, "\n");
|
fprintf(stream, "\n");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef RL_STATE_READCMD
|
#ifdef RL_STATE_READCMD
|
||||||
// We are using GNU readline. libedit (OSX) doesn't support this flag.
|
// We are using GNU readline. libedit (OSX) doesn't support this flag.
|
||||||
|
@ -433,33 +465,44 @@ static void fPrintAndLog(FILE *stream, const char *fmt, ...) {
|
||||||
|
|
||||||
if (((g_printAndLog & PRINTANDLOG_LOG) && logging && logfile) ||
|
if (((g_printAndLog & PRINTANDLOG_LOG) && logging && logfile) ||
|
||||||
(g_printAndLog & PRINTANDLOG_GRAB)) {
|
(g_printAndLog & PRINTANDLOG_GRAB)) {
|
||||||
|
|
||||||
memcpy_filter_emoji(buffer3, buffer2, sizeof(buffer2), EMO_ALTTEXT);
|
memcpy_filter_emoji(buffer3, buffer2, sizeof(buffer2), EMO_ALTTEXT);
|
||||||
|
|
||||||
if (filter_ansi == false) {
|
if (filter_ansi == false) {
|
||||||
memcpy_filter_ansi(buffer, buffer3, sizeof(buffer3), true);
|
memcpy_filter_ansi(buffer, buffer3, sizeof(buffer3), true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((g_printAndLog & PRINTANDLOG_LOG) && logging && logfile) {
|
if ((g_printAndLog & PRINTANDLOG_LOG) && logging && logfile) {
|
||||||
|
|
||||||
if (filter_ansi) {
|
if (filter_ansi) {
|
||||||
fprintf(logfile, "%s", buffer3);
|
fprintf(logfile, "%s", buffer3);
|
||||||
} else {
|
} else {
|
||||||
fprintf(logfile, "%s", buffer);
|
fprintf(logfile, "%s", buffer);
|
||||||
}
|
}
|
||||||
if (linefeed)
|
|
||||||
|
if (linefeed) {
|
||||||
fprintf(logfile, "\n");
|
fprintf(logfile, "\n");
|
||||||
|
}
|
||||||
fflush(logfile);
|
fflush(logfile);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (g_printAndLog & PRINTANDLOG_GRAB) {
|
if (g_printAndLog & PRINTANDLOG_GRAB) {
|
||||||
|
|
||||||
if (filter_ansi) {
|
if (filter_ansi) {
|
||||||
fill_grabber(buffer3);
|
fill_grabber(buffer3);
|
||||||
} else {
|
} else {
|
||||||
fill_grabber(buffer);
|
fill_grabber(buffer);
|
||||||
}
|
}
|
||||||
if (linefeed)
|
|
||||||
|
if (linefeed) {
|
||||||
fill_grabber("\n");
|
fill_grabber("\n");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (flushAfterWrite)
|
if (flushAfterWrite) {
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
}
|
||||||
|
|
||||||
//release lock
|
//release lock
|
||||||
pthread_mutex_unlock(&g_print_lock);
|
pthread_mutex_unlock(&g_print_lock);
|
||||||
|
@ -478,9 +521,10 @@ void memcpy_filter_rlmarkers(void *dest, const void *src, size_t n) {
|
||||||
uint8_t *rsrc = (uint8_t *)src;
|
uint8_t *rsrc = (uint8_t *)src;
|
||||||
uint16_t si = 0;
|
uint16_t si = 0;
|
||||||
for (size_t i = 0; i < n; i++) {
|
for (size_t i = 0; i < n; i++) {
|
||||||
if ((rsrc[i] == '\001') || (rsrc[i] == '\002'))
|
if ((rsrc[i] == '\001') || (rsrc[i] == '\002')) {
|
||||||
// skip readline special markers
|
// skip readline special markers
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
rdest[si++] = rsrc[i];
|
rdest[si++] = rsrc[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5047,7 +5047,7 @@
|
||||||
"-v, --verbose verbose output",
|
"-v, --verbose verbose output",
|
||||||
"-f, --file <fn> Specify a filename for dump file",
|
"-f, --file <fn> Specify a filename for dump file",
|
||||||
"--emu from emulator memory",
|
"--emu from emulator memory",
|
||||||
"--start <dec> index of block to start writing (default 0)",
|
"--start <dec> index of block to start writing (def 0)",
|
||||||
"--end <dec> index of block to end writing (default last block)"
|
"--end <dec> index of block to end writing (default last block)"
|
||||||
],
|
],
|
||||||
"usage": "hf mf gload [-hv] [--mini] [--1k] [--1k+] [--2k] [--4k] [-p <hex>] [-f <fn>] [--emu] [--start <dec>] [--end <dec>]"
|
"usage": "hf mf gload [-hv] [--mini] [--1k] [--1k+] [--2k] [--4k] [-p <hex>] [-f <fn>] [--emu] [--start <dec>] [--end <dec>]"
|
||||||
|
@ -10992,8 +10992,8 @@
|
||||||
"-r, --reset Reset configuration to default values",
|
"-r, --reset Reset configuration to default values",
|
||||||
"-p, --pwd <hex> Password, 7bytes, LSB-order",
|
"-p, --pwd <hex> Password, 7bytes, LSB-order",
|
||||||
"-d, --delay <dec> Tag initialization delay (in us)",
|
"-d, --delay <dec> Tag initialization delay (in us)",
|
||||||
"--lw <dec> offset, low pulses width (in us)",
|
"--lw <dec> offset, low pulses width (in us), optional!",
|
||||||
"--lp <dec> offset, low pulses position (in us)"
|
"--lp <dec> offset, low pulses position (in us), optional!"
|
||||||
],
|
],
|
||||||
"usage": "lf pcf7931 config [-hr] [-p <hex>] [-d <dec>] [--lw <dec>] [--lp <dec>]"
|
"usage": "lf pcf7931 config [-hr] [-p <hex>] [-d <dec>] [--lw <dec>] [--lp <dec>]"
|
||||||
},
|
},
|
||||||
|
@ -13232,6 +13232,6 @@
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"commands_extracted": 760,
|
"commands_extracted": 760,
|
||||||
"extracted_by": "PM3Help2JSON v1.00",
|
"extracted_by": "PM3Help2JSON v1.00",
|
||||||
"extracted_on": "2025-03-12T15:46:33"
|
"extracted_on": "2025-03-18T06:54:58"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue