This commit is contained in:
iceman1001 2025-03-18 08:11:06 +01:00
commit a776f9a0bd
10 changed files with 231 additions and 187 deletions

View file

@ -359,15 +359,15 @@ typedef struct _em4x70_transmit_log_t {
em4x70_sublog_t receive;
} em4x70_transmitted_data_log_t;
em4x70_transmitted_data_log_t g_not_used_directly; // change to bigbuff allocation?
em4x70_transmitted_data_log_t* g_Log = &g_not_used_directly;
em4x70_transmitted_data_log_t *g_Log = &g_not_used_directly;
static void log_reset(void) {
if (g_Log != NULL) {
memset(g_Log, 0, sizeof(em4x70_transmitted_data_log_t));
}
}
static void log_dump_helper(em4x70_sublog_t * part, bool is_transmit) {
static void log_dump_helper(em4x70_sublog_t *part, bool is_transmit) {
if (g_dbglevel >= DBG_INFO || FORCE_ENABLE_LOGGING) {
char const * const direction = is_transmit ? "sent >>>" : "recv <<<";
char const *const direction = is_transmit ? "sent >>>" : "recv <<<";
if (part->bits_used == 0) {
DPRINTF_EXTENDED(("%s: no data", direction));
} else {
@ -390,7 +390,7 @@ static void log_dump(void) {
if (g_dbglevel >= DBG_INFO || FORCE_ENABLE_LOGGING) {
bool hasContent = false;
if (g_Log != NULL) {
uint8_t * check_for_data = (uint8_t *)g_Log;
uint8_t *check_for_data = (uint8_t *)g_Log;
for (size_t i = 0; i < sizeof(em4x70_transmitted_data_log_t); ++i) {
if (check_for_data[i] != 0) {
hasContent = true;
@ -516,12 +516,12 @@ typedef struct _em4x70_command_bitstream {
uint8_t received_data_converted_to_bytes[(EM4X70_MAX_BITSTREAM_BITS / 8) + (EM4X70_MAX_BITSTREAM_BITS % 8 ? 1 : 0)];
} em4x70_command_bitstream_t;
typedef bool (*bitstream_command_generator_id_t)(em4x70_command_bitstream_t * out_cmd_bitstream, bool with_command_parity);
typedef bool (*bitstream_command_generator_um1_t)(em4x70_command_bitstream_t * out_cmd_bitstream, bool with_command_parity);
typedef bool (*bitstream_command_generator_um2_t)(em4x70_command_bitstream_t * out_cmd_bitstream, bool with_command_parity);
typedef bool (*bitstream_command_generator_auth_t)(em4x70_command_bitstream_t * out_cmd_bitstream, bool with_command_parity, const uint8_t * rnd, const uint8_t * frnd);
typedef bool (*bitstream_command_generator_pin_t)(em4x70_command_bitstream_t * out_cmd_bitstream, bool with_command_parity, const uint8_t * tag_id, const uint32_t pin_little_endian);
typedef bool (*bitstream_command_generator_write_t)(em4x70_command_bitstream_t * out_cmd_bitstream, bool with_command_parity, uint16_t data_little_endian, uint8_t address);
typedef bool (*bitstream_command_generator_id_t)(em4x70_command_bitstream_t *out_cmd_bitstream, bool with_command_parity);
typedef bool (*bitstream_command_generator_um1_t)(em4x70_command_bitstream_t *out_cmd_bitstream, bool with_command_parity);
typedef bool (*bitstream_command_generator_um2_t)(em4x70_command_bitstream_t *out_cmd_bitstream, bool with_command_parity);
typedef bool (*bitstream_command_generator_auth_t)(em4x70_command_bitstream_t *out_cmd_bitstream, bool with_command_parity, const uint8_t *rnd, const uint8_t *frnd);
typedef bool (*bitstream_command_generator_pin_t)(em4x70_command_bitstream_t *out_cmd_bitstream, bool with_command_parity, const uint8_t *tag_id, const uint32_t pin_little_endian);
typedef bool (*bitstream_command_generator_write_t)(em4x70_command_bitstream_t *out_cmd_bitstream, bool with_command_parity, uint16_t data_little_endian, uint8_t address);
typedef struct _em4x70_command_generators_t {
bitstream_command_generator_id_t id;
@ -534,9 +534,9 @@ typedef struct _em4x70_command_generators_t {
#endif // #pragma endregion // Bitstream structures / enumerations
#if 1 // #pragma region // Functions to dump bitstreams to debug output
static void bitstream_dump_helper(const em4x70_bitstream_t * bitstream, bool is_transmit) {
static void bitstream_dump_helper(const em4x70_bitstream_t *bitstream, bool is_transmit) {
// mimic the log's output format to make comparisons easier
char const * const direction = is_transmit ? "sent >>>" : "recv <<<";
char const *const direction = is_transmit ? "sent >>>" : "recv <<<";
if (bitstream->bitcount == 0) {
if (g_dbglevel >= DBG_INFO || true) {
DPRINTF_EXTENDED(("%s: no data", direction));
@ -559,8 +559,8 @@ static void bitstream_dump_helper(const em4x70_bitstream_t * bitstream, bool is_
));
}
}
static void bitstream_dump(const em4x70_command_bitstream_t * cmd_bitstream) {
bitstream_dump_helper(&cmd_bitstream->to_send, true );
static void bitstream_dump(const em4x70_command_bitstream_t *cmd_bitstream) {
bitstream_dump_helper(&cmd_bitstream->to_send, true);
bitstream_dump_helper(&cmd_bitstream->to_receive, false);
}
#endif // #pragma region // Functions to dump bitstreams to debug output
@ -570,13 +570,13 @@ static void bitstream_dump(const em4x70_command_bitstream_t * cmd_bitstream) {
/// @details This function presumes a validated structure, and sends the bitstream without delays, to support timing-sensitive operations.
/// @param send The details on the bitstream to send to the tag.
/// @return
static bool send_bitstream_internal(const em4x70_bitstream_t * send) {
static bool send_bitstream_internal(const em4x70_bitstream_t *send) {
// similar to original send_command_and_read, but using provided bitstream
int retries = EM4X70_COMMAND_RETRIES;
// TIMING SENSITIVE FUNCTION ... Minimize delays after finding the listen window
while (retries) {
const uint8_t * s = send->one_bit_per_byte;
const uint8_t *s = send->one_bit_per_byte;
uint8_t sent = 0;
retries--;
if (find_listen_window(true)) { // `true` will automatically send the two `RM` zero bits
@ -597,9 +597,9 @@ static bool send_bitstream_internal(const em4x70_bitstream_t * send) {
/// @param recv Buffer to store received data from the tag.
/// `recv->expected_bitcount` must be initialized to indicate expected bits to receive from the tag.
/// @return true only if the bitstream was sent and the expected count of bits were received from the tag.
static bool send_bitstream_and_read(em4x70_command_bitstream_t * command_bitstream) {
const em4x70_bitstream_t * send = &command_bitstream->to_send;
em4x70_bitstream_t * recv = &command_bitstream->to_receive;
static bool send_bitstream_and_read(em4x70_command_bitstream_t *command_bitstream) {
const em4x70_bitstream_t *send = &command_bitstream->to_send;
em4x70_bitstream_t *recv = &command_bitstream->to_receive;
// Validate the parameters before proceeding
bool parameters_valid = true;
@ -694,9 +694,9 @@ static bool send_bitstream_and_read(em4x70_command_bitstream_t * command_bitstre
// finally return the result of the operation
return result;
}
static bool send_bitstream_wait_ack_wait_read(em4x70_command_bitstream_t * command_bitstream) {
const em4x70_bitstream_t * send = &command_bitstream->to_send;
em4x70_bitstream_t * recv = &command_bitstream->to_receive;
static bool send_bitstream_wait_ack_wait_read(em4x70_command_bitstream_t *command_bitstream) {
const em4x70_bitstream_t *send = &command_bitstream->to_send;
em4x70_bitstream_t *recv = &command_bitstream->to_receive;
// Validate the parameters before proceeding
bool parameters_valid = true;
@ -769,10 +769,10 @@ static bool send_bitstream_wait_ack_wait_read(em4x70_command_bitstream_t * comma
return result;
}
static bool send_bitstream_wait_ack_wait_ack(em4x70_command_bitstream_t * command_bitstream) {
static bool send_bitstream_wait_ack_wait_ack(em4x70_command_bitstream_t *command_bitstream) {
const em4x70_bitstream_t * send = &command_bitstream->to_send;
em4x70_bitstream_t * recv = &command_bitstream->to_receive;
const em4x70_bitstream_t *send = &command_bitstream->to_send;
em4x70_bitstream_t *recv = &command_bitstream->to_receive;
// Validate the parameters before proceeding
bool parameters_valid = true;
@ -835,7 +835,7 @@ static bool send_bitstream_wait_ack_wait_ack(em4x70_command_bitstream_t * comman
#endif // #pragma region // Functions to send bitstreams, with options to receive data
#if 1 // #pragma region // Create bitstreams for each type of EM4x70 command
static bool add_bit_to_bitstream(em4x70_bitstream_t * s, bool b) {
static bool add_bit_to_bitstream(em4x70_bitstream_t *s, bool b) {
uint8_t i = s->bitcount;
uint8_t bits_to_add = 1u;
@ -848,7 +848,7 @@ static bool add_bit_to_bitstream(em4x70_bitstream_t * s, bool b) {
s->bitcount++;
return true;
}
static bool add_nibble_to_bitstream(em4x70_bitstream_t * s, uint8_t nibble, bool add_fifth_parity_bit) {
static bool add_nibble_to_bitstream(em4x70_bitstream_t *s, uint8_t nibble, bool add_fifth_parity_bit) {
uint8_t i = s->bitcount;
uint8_t bits_to_add = add_fifth_parity_bit ? 5u : 4u;
@ -875,7 +875,7 @@ static bool add_nibble_to_bitstream(em4x70_bitstream_t * s, uint8_t nibble, bool
s->bitcount += bits_to_add;
return true;
}
static bool add_byte_to_bitstream(em4x70_bitstream_t * s, uint8_t b) {
static bool add_byte_to_bitstream(em4x70_bitstream_t *s, uint8_t b) {
uint8_t i = s->bitcount;
uint8_t bits_to_add = 8u;
@ -897,7 +897,7 @@ static bool add_byte_to_bitstream(em4x70_bitstream_t * s, uint8_t b) {
}
static bool create_legacy_em4x70_bitstream_for_cmd_id(em4x70_command_bitstream_t * out_cmd_bitstream, bool with_command_parity) {
static bool create_legacy_em4x70_bitstream_for_cmd_id(em4x70_command_bitstream_t *out_cmd_bitstream, bool with_command_parity) {
const uint8_t expected_bits_to_send = 4u;
bool result = true;
memset(out_cmd_bitstream, 0, sizeof(em4x70_command_bitstream_t));
@ -911,7 +911,7 @@ static bool create_legacy_em4x70_bitstream_for_cmd_id(em4x70_command_bitstream_t
}
return result;
}
static bool create_legacy_em4x70_bitstream_for_cmd_um1(em4x70_command_bitstream_t * out_cmd_bitstream, bool with_command_parity) {
static bool create_legacy_em4x70_bitstream_for_cmd_um1(em4x70_command_bitstream_t *out_cmd_bitstream, bool with_command_parity) {
const uint8_t expected_bits_to_send = 4u;
bool result = true;
memset(out_cmd_bitstream, 0, sizeof(em4x70_command_bitstream_t));
@ -925,7 +925,7 @@ static bool create_legacy_em4x70_bitstream_for_cmd_um1(em4x70_command_bitstream_
}
return result;
}
static bool create_legacy_em4x70_bitstream_for_cmd_um2(em4x70_command_bitstream_t * out_cmd_bitstream, bool with_command_parity) {
static bool create_legacy_em4x70_bitstream_for_cmd_um2(em4x70_command_bitstream_t *out_cmd_bitstream, bool with_command_parity) {
const uint8_t expected_bits_to_send = 4u;
bool result = true;
memset(out_cmd_bitstream, 0, sizeof(em4x70_command_bitstream_t));
@ -939,14 +939,14 @@ static bool create_legacy_em4x70_bitstream_for_cmd_um2(em4x70_command_bitstream_
}
return true;
}
static bool create_legacy_em4x70_bitstream_for_cmd_auth(em4x70_command_bitstream_t * out_cmd_bitstream, bool with_command_parity, const uint8_t *rnd, const uint8_t *frnd) {
static bool create_legacy_em4x70_bitstream_for_cmd_auth(em4x70_command_bitstream_t *out_cmd_bitstream, bool with_command_parity, const uint8_t *rnd, const uint8_t *frnd) {
const uint8_t expected_bits_to_send = 96u;
bool result = true;
memset(out_cmd_bitstream, 0, sizeof(em4x70_command_bitstream_t));
out_cmd_bitstream->command = EM4X70_COMMAND_AUTH;
em4x70_bitstream_t * s = &out_cmd_bitstream->to_send;
em4x70_bitstream_t *s = &out_cmd_bitstream->to_send;
// *********************************************************************************
// HACK -- Insert an extra zero bit to match legacy behavior
@ -994,12 +994,12 @@ static bool create_legacy_em4x70_bitstream_for_cmd_auth(em4x70_command_bitstream
return result;
}
static bool create_legacy_em4x70_bitstream_for_cmd_pin(em4x70_command_bitstream_t * out_cmd_bitstream, bool with_command_parity, const uint8_t *tag_id, const uint32_t pin) {
static bool create_legacy_em4x70_bitstream_for_cmd_pin(em4x70_command_bitstream_t *out_cmd_bitstream, bool with_command_parity, const uint8_t *tag_id, const uint32_t pin) {
const uint8_t expected_bits_to_send = 69; // normally 68 bits, but legacy hack inserts an extra RM bit, and always adds a command parity bit
bool result = true;
memset(out_cmd_bitstream, 0, sizeof(em4x70_command_bitstream_t));
em4x70_bitstream_t * s = &out_cmd_bitstream->to_send;
em4x70_bitstream_t *s = &out_cmd_bitstream->to_send;
out_cmd_bitstream->command = EM4X70_COMMAND_PIN;
@ -1015,7 +1015,7 @@ static bool create_legacy_em4x70_bitstream_for_cmd_pin(em4x70_command_bitstream_
// Send tag's ID ... indexes 4 .. 35
// e.g., tag_id points to &tag.data[4] ... &tag.data[7]
for (uint_fast8_t i = 0; i < 4; i++) {
uint8_t b = tag_id[3-i];
uint8_t b = tag_id[3 - i];
result = result && add_byte_to_bitstream(s, b);
}
@ -1033,13 +1033,13 @@ static bool create_legacy_em4x70_bitstream_for_cmd_pin(em4x70_command_bitstream_
}
return result;
}
static bool create_legacy_em4x70_bitstream_for_cmd_write(em4x70_command_bitstream_t * out_cmd_bitstream, bool with_command_parity, uint16_t new_data, uint8_t address) {
static bool create_legacy_em4x70_bitstream_for_cmd_write(em4x70_command_bitstream_t *out_cmd_bitstream, bool with_command_parity, uint16_t new_data, uint8_t address) {
const uint8_t expected_bits_to_send = 35u; // normally 34 bits, but legacy hack inserts an extra RM bit, and always adds a command parity bit
bool result = true;
memset(out_cmd_bitstream, 0, sizeof(em4x70_command_bitstream_t));
out_cmd_bitstream->command = EM4X70_COMMAND_WRITE;
em4x70_bitstream_t * s = &out_cmd_bitstream->to_send;
em4x70_bitstream_t *s = &out_cmd_bitstream->to_send;
// *********************************************************************************
// HACK -- Insert an extra zero bit to match legacy behavior
@ -1105,7 +1105,7 @@ const em4x70_command_generators_t legacy_em4x70_command_generators = {
static int authenticate(const uint8_t *rnd, const uint8_t *frnd, uint8_t *response) {
em4x70_command_bitstream_t auth_cmd;
const em4x70_command_generators_t * generator = &legacy_em4x70_command_generators;
const em4x70_command_generators_t *generator = &legacy_em4x70_command_generators;
generator->auth(&auth_cmd, command_parity, rnd, frnd);
bool result = send_bitstream_and_read(&auth_cmd);
@ -1193,7 +1193,7 @@ static int bruteforce(const uint8_t address, const uint8_t *rnd, const uint8_t *
// log entry/exit point
static int send_pin(const uint32_t pin) {
em4x70_command_bitstream_t send_pin_cmd;
const em4x70_command_generators_t * generator = &legacy_em4x70_command_generators;
const em4x70_command_generators_t *generator = &legacy_em4x70_command_generators;
generator->pin(&send_pin_cmd, command_parity, &tag.data[4], pin);
bool result = send_bitstream_wait_ack_wait_read(&send_pin_cmd);
@ -1204,7 +1204,7 @@ static int send_pin(const uint32_t pin) {
static int write(const uint16_t word, const uint8_t address) {
em4x70_command_bitstream_t write_cmd;
const em4x70_command_generators_t * generator = &legacy_em4x70_command_generators;
const em4x70_command_generators_t *generator = &legacy_em4x70_command_generators;
generator->write(&write_cmd, command_parity, word, address);
bool result = send_bitstream_wait_ack_wait_ack(&write_cmd);
@ -1291,7 +1291,7 @@ static uint8_t encoded_bit_array_to_byte(const uint8_t *bits, int count_of_bits)
*/
static bool em4x70_read_id(void) {
em4x70_command_bitstream_t read_id_cmd;
const em4x70_command_generators_t * generator = &legacy_em4x70_command_generators;
const em4x70_command_generators_t *generator = &legacy_em4x70_command_generators;
generator->id(&read_id_cmd, command_parity);
bool result = send_bitstream_and_read(&read_id_cmd);
@ -1308,7 +1308,7 @@ static bool em4x70_read_id(void) {
*/
static bool em4x70_read_um1(void) {
em4x70_command_bitstream_t read_um1_cmd;
const em4x70_command_generators_t * generator = &legacy_em4x70_command_generators;
const em4x70_command_generators_t *generator = &legacy_em4x70_command_generators;
generator->um1(&read_um1_cmd, command_parity);
bool result = send_bitstream_and_read(&read_um1_cmd);
@ -1327,7 +1327,7 @@ static bool em4x70_read_um1(void) {
*/
static bool em4x70_read_um2(void) {
em4x70_command_bitstream_t read_um2_cmd;
const em4x70_command_generators_t * generator = &legacy_em4x70_command_generators;
const em4x70_command_generators_t *generator = &legacy_em4x70_command_generators;
generator->um2(&read_um2_cmd, command_parity);
bool result = send_bitstream_and_read(&read_um2_cmd);

View file

@ -87,15 +87,15 @@ size_t DemodPCF7931(uint8_t **outBlocks, bool ledcontrol) {
samplePosLastEdge = 0;
block_done = 0;
bitPos = 0;
lastClockDuration=0;
lastClockDuration = 0;
for (sample = 1 ; sample < g_GraphTraceLen-4; sample++) {
for (sample = 1 ; sample < g_GraphTraceLen - 4; sample++) {
// condition is searching for the next edge, in the expected diretion.
//todo: without flouz
dest[sample] = (uint8_t)(dest[sample-1] * IIR_CONST1 + dest[sample] * IIR_CONST2); // apply IIR filter
dest[sample] = (uint8_t)(dest[sample - 1] * IIR_CONST1 + dest[sample] * IIR_CONST2); // apply IIR filter
if ( ((dest[sample] + THRESHOLD) < dest[sample-1] && expectedNextEdge == FALLING ) ||
((dest[sample] - THRESHOLD) > dest[sample-1] && expectedNextEdge == RISING )) {
if (((dest[sample] + THRESHOLD) < dest[sample - 1] && expectedNextEdge == FALLING) ||
((dest[sample] - THRESHOLD) > dest[sample - 1] && expectedNextEdge == RISING)) {
//okay, next falling/rising edge found
expectedNextEdge = (expectedNextEdge == FALLING) ? RISING : FALLING; //toggle the next expected edge
@ -193,7 +193,7 @@ size_t DemodPCF7931(uint8_t **outBlocks, bool ledcontrol) {
half_switch = 0;
}
}else {
} else {
// Dbprintf("%d, %d", sample, dest[sample]);
}
@ -403,7 +403,7 @@ void ReadPCF7931(bool ledcontrol) {
end:
/*
/*
Dbprintf("-----------------------------------------");
Dbprintf("Memory content:");
Dbprintf("-----------------------------------------");
@ -424,7 +424,7 @@ end:
Dbprintf("-----------------------------------------");
}
*/
*/
reply_mix(CMD_ACK, 0, 0, 0, 0, 0);
}
@ -434,7 +434,7 @@ static void RealWritePCF7931(
uint16_t init_delay,
int8_t offsetPulseWidth, int8_t offsetPulsePosition,
uint8_t address, uint8_t byte, uint8_t data,
bool ledcontrol){
bool ledcontrol) {
uint32_t tab[1024] = {0}; // data times frame
uint32_t u = 0;

View file

@ -19,7 +19,7 @@
#include "common.h"
typedef enum{
typedef enum {
FALLING,
RISING
} EdgeType;

View file

@ -186,6 +186,7 @@ static void fill_grabber(const char *string) {
g_grabbed_output.ptr = tmp;
g_grabbed_output.size += MAX_PRINT_BUFFER;
}
int len = snprintf(g_grabbed_output.ptr + g_grabbed_output.idx, MAX_PRINT_BUFFER, "%s", string);
if (len < 0 || len > MAX_PRINT_BUFFER) {
// 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) {
char buff[2000] = "Options:\n";
char format[2000] = "";
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])) {
counts[j] = strlen(str[i][j]);
}
}
}
for (size_t i = 0; i < size; i++) {
for (size_t j = 0; j < 2; j++) {
if (j == 0)
if (j == 0) {
snprintf(format, sizeof(format), "%%%zus%%%zus", space, counts[j]);
else
} else {
snprintf(format, sizeof(format), "%%%zus%%-%zus", space, counts[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);
}
}
PrintAndLogEx(NORMAL, "%s", buff);
}
@ -223,12 +234,14 @@ static uint8_t PrintAndLogEx_spinidx = 0;
void PrintAndLogEx(logLevel_t level, const char *fmt, ...) {
// 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;
}
// 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;
}
char prefix[40] = {0};
char buffer[MAX_PRINT_BUFFER] = {0};
@ -242,17 +255,19 @@ void PrintAndLogEx(logLevel_t level, const char *fmt, ...) {
};
switch (level) {
case ERR:
if (g_session.emoji_mode == EMO_EMOJI)
if (g_session.emoji_mode == EMO_EMOJI) {
strncpy(prefix, "[" _RED_("!!") "] :rotating_light: ", sizeof(prefix) - 1);
else
} else {
strncpy(prefix, "[" _RED_("!!") "] ", sizeof(prefix) - 1);
}
stream = stderr;
break;
case FAILED:
if (g_session.emoji_mode == EMO_EMOJI)
if (g_session.emoji_mode == EMO_EMOJI) {
strncpy(prefix, "[" _RED_("-") "] :no_entry: ", sizeof(prefix) - 1);
else
} else {
strncpy(prefix, "[" _RED_("-") "] ", sizeof(prefix) - 1);
}
break;
case DEBUG:
strncpy(prefix, "[" _BLUE_("#") "] ", sizeof(prefix) - 1);
@ -264,10 +279,11 @@ void PrintAndLogEx(logLevel_t level, const char *fmt, ...) {
strncpy(prefix, "[" _GREEN_("+") "] ", sizeof(prefix) - 1);
break;
case WARNING:
if (g_session.emoji_mode == EMO_EMOJI)
if (g_session.emoji_mode == EMO_EMOJI) {
strncpy(prefix, "[" _CYAN_("!") "] :warning: ", sizeof(prefix) - 1);
else
} else {
strncpy(prefix, "[" _CYAN_("!") "] ", sizeof(prefix) - 1);
}
break;
case INFO:
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) {
strncpy(prefix, spinner_emoji[PrintAndLogEx_spinidx], sizeof(prefix) - 1);
PrintAndLogEx_spinidx++;
if (PrintAndLogEx_spinidx >= ARRAYLEN(spinner_emoji))
if (PrintAndLogEx_spinidx >= ARRAYLEN(spinner_emoji)) {
PrintAndLogEx_spinidx = 0;
}
} else {
strncpy(prefix, spinner[PrintAndLogEx_spinidx], sizeof(prefix) - 1);
PrintAndLogEx_spinidx++;
if (PrintAndLogEx_spinidx >= ARRAYLEN(spinner))
if (PrintAndLogEx_spinidx >= ARRAYLEN(spinner)) {
PrintAndLogEx_spinidx = 0;
}
}
break;
case NORMAL:
// no prefixes for normal
@ -306,8 +324,9 @@ void PrintAndLogEx(logLevel_t level, const char *fmt, ...) {
const char delim[2] = "\n";
// line starts with newline
if (buffer[0] == '\n')
if (buffer[0] == '\n') {
fPrintAndLog(stream, "");
}
token = strtok_r(buffer, delim, &tmp_ptr);
@ -315,16 +334,21 @@ void PrintAndLogEx(logLevel_t level, const char *fmt, ...) {
size_t size = strlen(buffer2);
if (strlen(token))
if (strlen(token)) {
snprintf(buffer2 + size, sizeof(buffer2) - size, "%s%s\n", prefix, token);
else
} else {
snprintf(buffer2 + size, sizeof(buffer2) - size, "\n");
}
token = strtok_r(NULL, delim, &tmp_ptr);
}
fPrintAndLog(stream, "%s", buffer2);
} else {
snprintf(buffer2, sizeof(buffer2), "%s%s", prefix, buffer);
if (level == INPLACE) {
// ignore INPLACE if rest of output is grabbed
if (!(g_printAndLog & PRINTANDLOG_GRAB)) {
@ -354,6 +378,7 @@ static void fPrintAndLog(FILE *stream, const char *fmt, ...) {
if (logging && g_session.incognito) {
logging = 0;
}
if ((g_printAndLog & PRINTANDLOG_LOG) && logging && !logfile) {
char *my_logfile_path = NULL;
char filename[40];
@ -361,11 +386,15 @@ static void fPrintAndLog(FILE *stream, const char *fmt, ...) {
time_t now = time(NULL);
timenow = gmtime(&now);
strftime(filename, sizeof(filename), PROXLOG, timenow);
if (searchHomeFilePath(&my_logfile_path, LOGS_SUBDIR, filename, true) != PM3_SUCCESS) {
printf(_YELLOW_("[-]") " Logging disabled!\n");
my_logfile_path = NULL;
logging = 0;
} else {
logfile = fopen(my_logfile_path, "a");
if (logfile == NULL) {
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;
buffer[strlen(buffer) - 1] = 0;
}
bool filter_ansi = !g_session.supports_colors;
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);
fprintf(stream, "%s", buffer3);
if (linefeed)
if (linefeed) {
fprintf(stream, "\n");
}
}
#ifdef RL_STATE_READCMD
// 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) ||
(g_printAndLog & PRINTANDLOG_GRAB)) {
memcpy_filter_emoji(buffer3, buffer2, sizeof(buffer2), EMO_ALTTEXT);
if (filter_ansi == false) {
memcpy_filter_ansi(buffer, buffer3, sizeof(buffer3), true);
}
}
if ((g_printAndLog & PRINTANDLOG_LOG) && logging && logfile) {
if (filter_ansi) {
fprintf(logfile, "%s", buffer3);
} else {
fprintf(logfile, "%s", buffer);
}
if (linefeed)
if (linefeed) {
fprintf(logfile, "\n");
}
fflush(logfile);
}
if (g_printAndLog & PRINTANDLOG_GRAB) {
if (filter_ansi) {
fill_grabber(buffer3);
} else {
fill_grabber(buffer);
}
if (linefeed)
if (linefeed) {
fill_grabber("\n");
}
}
if (flushAfterWrite)
if (flushAfterWrite) {
fflush(stdout);
}
//release 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;
uint16_t si = 0;
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
continue;
}
rdest[si++] = rsrc[i];
}
}

View file

@ -5047,7 +5047,7 @@
"-v, --verbose verbose output",
"-f, --file <fn> Specify a filename for dump file",
"--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)"
],
"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",
"-p, --pwd <hex> Password, 7bytes, LSB-order",
"-d, --delay <dec> Tag initialization delay (in us)",
"--lw <dec> offset, low pulses width (in us)",
"--lp <dec> offset, low pulses position (in us)"
"--lw <dec> offset, low pulses width (in us), optional!",
"--lp <dec> offset, low pulses position (in us), optional!"
],
"usage": "lf pcf7931 config [-hr] [-p <hex>] [-d <dec>] [--lw <dec>] [--lp <dec>]"
},
@ -13232,6 +13232,6 @@
"metadata": {
"commands_extracted": 760,
"extracted_by": "PM3Help2JSON v1.00",
"extracted_on": "2025-03-12T15:46:33"
"extracted_on": "2025-03-18T06:54:58"
}
}