added dictionary

This commit is contained in:
merlokk 2019-12-01 10:45:02 +02:00
commit 1daf155b9c
3 changed files with 73 additions and 39 deletions

View file

@ -723,6 +723,7 @@ void Fill2bPattern(uint8_t keyList[MAX_KEYS_LIST_LEN][AES_KEY_LEN], size_t *keyL
static int CmdHFMFPChk(const char *cmd) {
int res;
FILE *dictionary_file = NULL;
uint8_t keyList[MAX_KEYS_LIST_LEN][AES_KEY_LEN] = {0};
size_t keyListLen = 0;
uint8_t foundKeys[2][64][AES_KEY_LEN + 1] = {0};
@ -775,23 +776,20 @@ static int CmdHFMFPChk(const char *cmd) {
return PM3_EINVARG;
}
/* char *dict_path;
int res = searchFile(&dict_path, DICTIONARIES_SUBDIR, filename, ".dic", false);
char *dict_path;
res = searchFile(&dict_path, DICTIONARIES_SUBDIR, (char *)dict_filename, ".dic", false);
if (res != PM3_SUCCESS) {
CLIParserFree();
return PM3_EFILE;
}
f = fopen(dict_path, "r");
if (!f) {
dictionary_file = fopen(dict_path, "r");
if (!dictionary_file) {
PrintAndLogEx(FAILED, "File: " _YELLOW_("%s") ": not found or locked.", dict_path);
free(dict_path);
CLIParserFree();
return PM3_EFILE;
}
free(dict_path);
*/
free(dict_path);
bool pattern1b = arg_get_lit(7);
bool pattern2b = arg_get_lit(8);
@ -801,6 +799,12 @@ static int CmdHFMFPChk(const char *cmd) {
CLIParserFree();
return PM3_EINVARG;
}
if (dictionary_file && (pattern1b || pattern2b)) {
PrintAndLogEx(ERROR, "Pattern search mode and dictionary mode can't be used in one command.");
CLIParserFree();
return PM3_EINVARG;
}
uint32_t startPattern = 0x0000;
uint8_t vpattern[2];
@ -839,6 +843,7 @@ static int CmdHFMFPChk(const char *cmd) {
if (endSector < startSector)
endSector = startSector;
// 1-byte pattern search mode
if (pattern1b) {
for (int i = 0; i < 0x100; i++)
memset(keyList[i], i, 16);
@ -846,8 +851,16 @@ static int CmdHFMFPChk(const char *cmd) {
keyListLen = 0x100;
}
// 2-byte pattern search mode
if (pattern2b)
Fill2bPattern(keyList, &keyListLen, &startPattern);
// dictionary mode
if (dictionary_file) {
size_t endFilePosition = 0;
res = loadFileDICTIONARYEx((char *)dict_filename, keyList, sizeof(keyList), &keyListLen, 16, NULL, 0, &endFilePosition);
printf("---endFilePosition %d", endFilePosition);
}
if (keyListLen == 0) {
for (int i = 0; i < g_mifare_plus_default_keys_len; i++) {