mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2024-09-20 15:26:13 +08:00
fix the too long filename bug when using a smaller width param. also added some extra text for output length of binary strings in decode. One tend to not see if its 25 or 26 bits sometimes :)
This commit is contained in:
parent
00dfd6e5f1
commit
a79b2bb725
|
@ -3192,7 +3192,7 @@ static int CmdDiff(const char *Cmd) {
|
||||||
// dump magic card memory
|
// dump magic card memory
|
||||||
/*
|
/*
|
||||||
if (use_c) {
|
if (use_c) {
|
||||||
PrintAndLogEx(WARNING, "not implemented yet, feel free to contribute!");
|
PrintAndLogEx(INFO, " To be implemented, feel free to contribute!");
|
||||||
return PM3_ENOTIMPL;
|
return PM3_ENOTIMPL;
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
@ -3200,21 +3200,41 @@ static int CmdDiff(const char *Cmd) {
|
||||||
size_t biggest = (datalenA > datalenB) ? datalenA : datalenB;
|
size_t biggest = (datalenA > datalenB) ? datalenA : datalenB;
|
||||||
PrintAndLogEx(DEBUG, "data len: %zu A %zu B %zu", biggest, datalenA, datalenB);
|
PrintAndLogEx(DEBUG, "data len: %zu A %zu B %zu", biggest, datalenA, datalenB);
|
||||||
|
|
||||||
if (inA == NULL)
|
if (inA == NULL) {
|
||||||
PrintAndLogEx(INFO, "inA null");
|
PrintAndLogEx(INFO, "inA null");
|
||||||
|
}
|
||||||
|
|
||||||
if (inB == NULL)
|
if (inB == NULL) {
|
||||||
PrintAndLogEx(INFO, "inB null");
|
PrintAndLogEx(INFO, "inB null");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
char hdr0[400] = {0};
|
||||||
|
|
||||||
int hdr_sln = (width * 4) + 2;
|
int hdr_sln = (width * 4) + 2;
|
||||||
char hdr0[300] = {0};
|
int max_fn_space = (width * 4);
|
||||||
|
|
||||||
int max_fn_space = (width * 5);
|
if (max_fn_space < fnlenA) {
|
||||||
|
truncate_filename(filenameA, max_fn_space);
|
||||||
|
fnlenA = strlen(filenameA);
|
||||||
|
}
|
||||||
|
|
||||||
if (fnlenA && fnlenB && (max_fn_space > fnlenA) && (max_fn_space > fnlenB)) {
|
if (max_fn_space < fnlenB) {
|
||||||
|
truncate_filename(filenameB, max_fn_space);
|
||||||
|
fnlenB = strlen(filenameB);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fnlenA && fnlenB ) {
|
||||||
|
|
||||||
snprintf(hdr0, sizeof(hdr0) - 1, " # | " _CYAN_("%.*s"), max_fn_space, filenameA);
|
snprintf(hdr0, sizeof(hdr0) - 1, " # | " _CYAN_("%.*s"), max_fn_space, filenameA);
|
||||||
memset(hdr0 + strlen(hdr0), ' ', hdr_sln - strlen(filenameA) - 1);
|
|
||||||
|
// add space if needed
|
||||||
|
int padding_len = (hdr_sln - fnlenA - 1);
|
||||||
|
if ( padding_len > 0 ) {
|
||||||
|
memset(hdr0 + strlen(hdr0), ' ', padding_len);
|
||||||
|
}
|
||||||
snprintf(hdr0 + strlen(hdr0), sizeof(hdr0) - 1 - strlen(hdr0), "| " _CYAN_("%.*s"), max_fn_space, filenameB);
|
snprintf(hdr0 + strlen(hdr0), sizeof(hdr0) - 1 - strlen(hdr0), "| " _CYAN_("%.*s"), max_fn_space, filenameB);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
strcat(hdr0, " # | " _CYAN_("a"));
|
strcat(hdr0, " # | " _CYAN_("a"));
|
||||||
memset(hdr0 + strlen(hdr0), ' ', hdr_sln - 2);
|
memset(hdr0 + strlen(hdr0), ' ', hdr_sln - 2);
|
||||||
|
@ -3334,7 +3354,6 @@ static int CmdNumCon(const char *Cmd) {
|
||||||
memset(dec, 0, sizeof(dec));
|
memset(dec, 0, sizeof(dec));
|
||||||
int res = CLIParamStrToBuf(arg_get_str(ctx, 1), (uint8_t *)dec, sizeof(dec), &dlen);
|
int res = CLIParamStrToBuf(arg_get_str(ctx, 1), (uint8_t *)dec, sizeof(dec), &dlen);
|
||||||
|
|
||||||
|
|
||||||
int hlen = 256;
|
int hlen = 256;
|
||||||
char hex[256];
|
char hex[256];
|
||||||
memset(hex, 0, sizeof(hex));
|
memset(hex, 0, sizeof(hex));
|
||||||
|
@ -3363,13 +3382,13 @@ static int CmdNumCon(const char *Cmd) {
|
||||||
mbedtls_mpi N;
|
mbedtls_mpi N;
|
||||||
mbedtls_mpi_init(&N);
|
mbedtls_mpi_init(&N);
|
||||||
|
|
||||||
|
|
||||||
// hex
|
// hex
|
||||||
if (hlen > 0) {
|
if (hlen > 0) {
|
||||||
if (data_verify_hex((uint8_t *)hex, hlen) == false) {
|
if (data_verify_hex((uint8_t *)hex, hlen) == false) {
|
||||||
return PM3_EINVARG;
|
return PM3_EINVARG;
|
||||||
}
|
}
|
||||||
MBEDTLS_MPI_CHK(mbedtls_mpi_read_string(&N, 16, hex));
|
MBEDTLS_MPI_CHK(mbedtls_mpi_read_string(&N, 16, hex));
|
||||||
|
PrintAndLogEx(INFO, "Input hex len... %d", hlen);
|
||||||
}
|
}
|
||||||
|
|
||||||
// decimal
|
// decimal
|
||||||
|
@ -3382,6 +3401,7 @@ static int CmdNumCon(const char *Cmd) {
|
||||||
if (blen > 0) {
|
if (blen > 0) {
|
||||||
// should have bianry string check here too
|
// should have bianry string check here too
|
||||||
MBEDTLS_MPI_CHK(mbedtls_mpi_read_string(&N, 2, bin));
|
MBEDTLS_MPI_CHK(mbedtls_mpi_read_string(&N, 2, bin));
|
||||||
|
PrintAndLogEx(INFO, "Input bin len... %d", blen);
|
||||||
}
|
}
|
||||||
|
|
||||||
mbedtls_mpi base;
|
mbedtls_mpi base;
|
||||||
|
|
|
@ -145,7 +145,7 @@ int CmdWiegandDecode(const char *Cmd) {
|
||||||
if (hlen) {
|
if (hlen) {
|
||||||
res = hexstring_to_u96(&top, &mid, &bot, hex);
|
res = hexstring_to_u96(&top, &mid, &bot, hex);
|
||||||
if (res != hlen) {
|
if (res != hlen) {
|
||||||
PrintAndLogEx(ERR, "hex string contains none hex chars");
|
PrintAndLogEx(ERR, "Hex string contains none hex chars");
|
||||||
return PM3_EINVARG;
|
return PM3_EINVARG;
|
||||||
}
|
}
|
||||||
} else if (blen) {
|
} else if (blen) {
|
||||||
|
@ -154,8 +154,9 @@ int CmdWiegandDecode(const char *Cmd) {
|
||||||
PrintAndLogEx(ERR, "Binary string contains none <0|1> chars");
|
PrintAndLogEx(ERR, "Binary string contains none <0|1> chars");
|
||||||
return PM3_EINVARG;
|
return PM3_EINVARG;
|
||||||
}
|
}
|
||||||
|
PrintAndLogEx(INFO, "Input bin len... %d", blen);
|
||||||
} else {
|
} else {
|
||||||
PrintAndLogEx(ERR, "empty input");
|
PrintAndLogEx(ERR, "Empty input");
|
||||||
return PM3_EINVARG;
|
return PM3_EINVARG;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -239,6 +239,22 @@ char *newfilenamemcopyEx(const char *preferredName, const char *suffix, savePath
|
||||||
return fileName;
|
return fileName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// trunacate down a filename to LEN size
|
||||||
|
void truncate_filename(char *fn, uint16_t maxlen) {
|
||||||
|
if (fn == NULL || maxlen < 5) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if the filename is already shorter than or equal to the desired length
|
||||||
|
if (strlen(fn) <= maxlen) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If there's no extension or it's too long, just truncate the filename
|
||||||
|
fn[maxlen - 3] = '\0';
|
||||||
|
strcat(fn, "...");
|
||||||
|
}
|
||||||
|
|
||||||
// --------- SAVE FILES
|
// --------- SAVE FILES
|
||||||
int saveFile(const char *preferredName, const char *suffix, const void *data, size_t datalen) {
|
int saveFile(const char *preferredName, const char *suffix, const void *data, size_t datalen) {
|
||||||
|
|
||||||
|
|
|
@ -107,6 +107,8 @@ bool setDefaultPath(savePaths_t pathIndex, const char *path);
|
||||||
|
|
||||||
char *newfilenamemcopy(const char *preferredName, const char *suffix);
|
char *newfilenamemcopy(const char *preferredName, const char *suffix);
|
||||||
char *newfilenamemcopyEx(const char *preferredName, const char *suffix, savePaths_t save_path);
|
char *newfilenamemcopyEx(const char *preferredName, const char *suffix, savePaths_t save_path);
|
||||||
|
void truncate_filename(char *fn, uint16_t len);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Utility function to save data to a binary file. This method takes a preferred name, but if that
|
* @brief Utility function to save data to a binary file. This method takes a preferred name, but if that
|
||||||
|
|
Loading…
Reference in a new issue