mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-03-22 05:00:29 +08:00
chg: 'lf t55xx chk' - refactored to use loadDictionary
This commit is contained in:
parent
52be3f4fe5
commit
9133a9164f
2 changed files with 21 additions and 65 deletions
|
@ -1625,17 +1625,14 @@ bool IsCancelled(void) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// load a default pwd file.
|
||||||
int CmdT55xxChkPwds(const char *Cmd) {
|
int CmdT55xxChkPwds(const char *Cmd) {
|
||||||
// load a default pwd file.
|
|
||||||
char line[9];
|
|
||||||
char filename[FILE_PATH_SIZE] = {0};
|
char filename[FILE_PATH_SIZE] = {0};
|
||||||
int keycnt = 0;
|
|
||||||
uint8_t stKeyBlock = 20;
|
|
||||||
uint8_t *keyBlock = NULL, *p = NULL;
|
|
||||||
bool found = false;
|
bool found = false;
|
||||||
uint8_t timeout = 0;
|
uint8_t timeout = 0;
|
||||||
|
uint8_t *keyBlock = NULL;
|
||||||
memset(line, 0, sizeof(line));
|
|
||||||
|
|
||||||
char cmdp = tolower(param_getchar(Cmd, 0));
|
char cmdp = tolower(param_getchar(Cmd, 0));
|
||||||
if (strlen(Cmd) == 0 || cmdp == 'h') return usage_t55xx_chk();
|
if (strlen(Cmd) == 0 || cmdp == 'h') return usage_t55xx_chk();
|
||||||
|
@ -1688,78 +1685,37 @@ int CmdT55xxChkPwds(const char *Cmd) {
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
keyBlock = calloc(stKeyBlock, 4);
|
|
||||||
if (keyBlock == NULL) return 1;
|
|
||||||
|
|
||||||
if (cmdp == 'i') {
|
if (cmdp == 'i') {
|
||||||
|
|
||||||
int len = strlen(Cmd + 2);
|
int len = strlen(Cmd + 2);
|
||||||
if (len > FILE_PATH_SIZE) len = FILE_PATH_SIZE;
|
if (len > FILE_PATH_SIZE) len = FILE_PATH_SIZE;
|
||||||
memcpy(filename, Cmd + 2, len);
|
memcpy(filename, Cmd + 2, len);
|
||||||
|
|
||||||
FILE *f = fopen(filename, "r");
|
uint16_t keycount = 0;
|
||||||
if (!f) {
|
size_t datalen = 0;
|
||||||
PrintAndLogEx(FAILED, "File: " _YELLOW_("%s") ": not found or locked.", filename);
|
|
||||||
free(keyBlock);
|
// TODO, a way of reallocating memory if file was larger
|
||||||
|
keyBlock = calloc(4*200, sizeof(uint8_t));
|
||||||
|
if ( keyBlock == NULL ) {
|
||||||
|
PrintAndLogDevice(WARNING, "error, cannot allocate memory ");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (fgets(line, sizeof(line), f)) {
|
int res = loadFileDICTIONARY(filename, "dic", keyBlock, &datalen, 4, &keycount );
|
||||||
if (strlen(line) < 8 || line[7] == '\n') continue;
|
if (res || keycount == 0) {
|
||||||
|
|
||||||
//goto next line
|
|
||||||
while (fgetc(f) != '\n' && !feof(f)) ;
|
|
||||||
|
|
||||||
//The line start with # is comment, skip
|
|
||||||
if (line[0] == '#') continue;
|
|
||||||
|
|
||||||
if (!isxdigit(line[0])) {
|
|
||||||
PrintAndLogEx(WARNING, "File content error. '%s' must include 8 HEX symbols", line);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
line[8] = 0;
|
|
||||||
|
|
||||||
// realloc keyblock array size.
|
|
||||||
if (stKeyBlock - keycnt < 2) {
|
|
||||||
p = realloc(keyBlock, 4 * (stKeyBlock += 10));
|
|
||||||
if (!p) {
|
|
||||||
PrintAndLogEx(WARNING, "Cannot allocate memory for defaultKeys");
|
|
||||||
free(keyBlock);
|
|
||||||
if (f)
|
|
||||||
fclose(f);
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
keyBlock = p;
|
|
||||||
}
|
|
||||||
// clear mem
|
|
||||||
memset(keyBlock + 4 * keycnt, 0, 4);
|
|
||||||
|
|
||||||
num_to_bytes(strtoll(line, NULL, 16), 4, keyBlock + 4 * keycnt);
|
|
||||||
|
|
||||||
// PrintAndLogEx(NORMAL, "chk custom pwd[%2d] %08X", keycnt, bytes_to_num(keyBlock + 4 * keycnt, 4) );
|
|
||||||
keycnt++;
|
|
||||||
memset(line, 0, sizeof(line));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (f)
|
|
||||||
fclose(f);
|
|
||||||
|
|
||||||
if (keycnt == 0) {
|
|
||||||
PrintAndLogEx(WARNING, "No keys found in file");
|
PrintAndLogEx(WARNING, "No keys found in file");
|
||||||
free(keyBlock);
|
free(keyBlock);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
PrintAndLogEx(SUCCESS, "Loaded %d keys", keycnt);
|
|
||||||
|
|
||||||
// loop
|
// loop
|
||||||
uint64_t testpwd = 0x00;
|
uint64_t testpwd = 0x00;
|
||||||
for (uint16_t c = 0; c < keycnt; ++c) {
|
for (uint16_t c = 0; c < keycount; ++c) {
|
||||||
|
|
||||||
if (IsOffline()) {
|
if (IsOffline()) {
|
||||||
PrintAndLogEx(WARNING, "Device offline\n");
|
PrintAndLogEx(WARNING, "Device offline\n");
|
||||||
free(keyBlock);
|
free(keyBlock);
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IsCancelled()) {
|
if (IsCancelled()) {
|
||||||
|
@ -1780,7 +1736,6 @@ int CmdT55xxChkPwds(const char *Cmd) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
found = tryDetectModulation();
|
found = tryDetectModulation();
|
||||||
if (found)
|
if (found)
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -24,7 +24,9 @@
|
||||||
#include "cmdlf.h"
|
#include "cmdlf.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "lfdemod.h"
|
#include "lfdemod.h"
|
||||||
#include "cmdhf14a.h" //for getTagInfo
|
#include "cmdhf14a.h" // for getTagInfo
|
||||||
|
#include "loclass/fileutils.h" // loadDictionary
|
||||||
|
|
||||||
|
|
||||||
#define T55x7_CONFIGURATION_BLOCK 0x00
|
#define T55x7_CONFIGURATION_BLOCK 0x00
|
||||||
#define T55x7_PAGE0 0x00
|
#define T55x7_PAGE0 0x00
|
||||||
|
@ -162,7 +164,6 @@ extern bool tryDetectP1(bool getData);
|
||||||
bool test(uint8_t mode, uint8_t *offset, int *fndBitRate, uint8_t clk, bool *Q5);
|
bool test(uint8_t mode, uint8_t *offset, int *fndBitRate, uint8_t clk, bool *Q5);
|
||||||
int special(const char *Cmd);
|
int special(const char *Cmd);
|
||||||
bool AquireData(uint8_t page, uint8_t block, bool pwdmode, uint32_t password);
|
bool AquireData(uint8_t page, uint8_t block, bool pwdmode, uint32_t password);
|
||||||
//bool AquireDataEx(uint8_t page, uint8_t block, bool pwdmode, uint32_t password, uint32_t timing) ;
|
|
||||||
|
|
||||||
bool detectPassword(int password);
|
bool detectPassword(int password);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue