revert temporarily hf iclass chk/lookup 2a1e6dff

This commit is contained in:
Philippe Teuwen 2019-08-26 13:55:42 +02:00
parent 7076df0e18
commit 1628ac8e62

View file

@ -244,8 +244,8 @@ static int usage_hf_iclass_chk(void) {
PrintAndLogEx(NORMAL, " e elite"); PrintAndLogEx(NORMAL, " e elite");
PrintAndLogEx(NORMAL, " c credit key (if not use, default is debit)"); PrintAndLogEx(NORMAL, " c credit key (if not use, default is debit)");
PrintAndLogEx(NORMAL, "Examples:"); PrintAndLogEx(NORMAL, "Examples:");
PrintAndLogEx(NORMAL, " hf iclass chk f iclass_default_keys"); PrintAndLogEx(NORMAL, " hf iclass chk f dictionaries/iclass_default_keys.dic");
PrintAndLogEx(NORMAL, " hf iclass chk f iclass_default_keys e"); PrintAndLogEx(NORMAL, " hf iclass chk f dictionaries/iclass_default_keys.dic e");
return PM3_SUCCESS;; return PM3_SUCCESS;;
} }
static int usage_hf_iclass_lookup(void) { static int usage_hf_iclass_lookup(void) {
@ -260,8 +260,8 @@ static int usage_hf_iclass_lookup(void) {
PrintAndLogEx(NORMAL, " r raw"); PrintAndLogEx(NORMAL, " r raw");
PrintAndLogEx(NORMAL, " e elite"); PrintAndLogEx(NORMAL, " e elite");
PrintAndLogEx(NORMAL, "Examples:"); PrintAndLogEx(NORMAL, "Examples:");
PrintAndLogEx(NORMAL, " hf iclass lookup u 9655a400f8ff12e0 p f0ffffffffffffff m 0000000089cb984b f iclass_default_keys"); PrintAndLogEx(NORMAL, " hf iclass lookup u 9655a400f8ff12e0 p f0ffffffffffffff m 0000000089cb984b f dictionaries/iclass_default_keys.dic");
PrintAndLogEx(NORMAL, " hf iclass lookup u 9655a400f8ff12e0 p f0ffffffffffffff m 0000000089cb984b f iclass_default_keys e"); PrintAndLogEx(NORMAL, " hf iclass lookup u 9655a400f8ff12e0 p f0ffffffffffffff m 0000000089cb984b f dictionaries/iclass_default_keys.dic e");
return PM3_SUCCESS; return PM3_SUCCESS;
} }
static int usage_hf_iclass_permutekey(void) { static int usage_hf_iclass_permutekey(void) {
@ -2059,9 +2059,9 @@ static int CmdHFiClassCheckKeys(const char *Cmd) {
// load keys into keyblock // load keys into keyblock
int res = LoadDictionaryKeyFile(filename, &keyBlock, &keycnt); int res = LoadDictionaryKeyFile(filename, &keyBlock, &keycnt);
if (res != PM3_SUCCESS) { if (res > 0) {
free(keyBlock); free(keyBlock);
return res; return PM3_EFILE;
} }
pre = calloc(keycnt, sizeof(iclass_premac_t)); pre = calloc(keycnt, sizeof(iclass_premac_t));
@ -2312,33 +2312,33 @@ static int CmdHFiClassLookUp(const char *Cmd) {
PrintAndLogEx(SUCCESS, "MAC_TAG | %s", sprint_hex(MAC_TAG, sizeof(MAC_TAG))); PrintAndLogEx(SUCCESS, "MAC_TAG | %s", sprint_hex(MAC_TAG, sizeof(MAC_TAG)));
int res = LoadDictionaryKeyFile(filename, &keyBlock, &keycnt); int res = LoadDictionaryKeyFile(filename, &keyBlock, &keycnt);
if (res != PM3_SUCCESS) { if (res > 0) {
free(keyBlock); free(keyBlock);
return res; return 1;
} }
//iclass_prekey_t //iclass_prekey_t
prekey = calloc(keycnt, sizeof(iclass_prekey_t)); prekey = calloc(keycnt, sizeof(iclass_prekey_t));
if (!prekey) { if (!prekey) {
free(keyBlock); free(keyBlock);
return PM3_EMALLOC; return 1;
} }
PrintAndLogEx(INFO, "Generating diversified keys and MAC"); PrintAndLogEx(FAILED, "Generating diversified keys and MAC");
res = GenerateFromKeyFile(CSN, CCNR, use_raw, use_elite, keyBlock, keycnt, prekey); res = GenerateFromKeyFile(CSN, CCNR, use_raw, use_elite, keyBlock, keycnt, prekey);
if (res != PM3_SUCCESS) { if (res > 0) {
free(keyBlock); free(keyBlock);
free(prekey); free(prekey);
return PM3_ESOFT; return 1;
} }
PrintAndLogEx(INFO, "Sorting"); PrintAndLogEx(FAILED, "Sorting");
// sort mac list. // sort mac list.
qsort(prekey, keycnt, sizeof(iclass_prekey_t), cmp_uint32); qsort(prekey, keycnt, sizeof(iclass_prekey_t), cmp_uint32);
//PrintPreCalc(prekey, keycnt); //PrintPreCalc(prekey, keycnt);
PrintAndLogEx(INFO, "Searching"); PrintAndLogEx(FAILED, "Searching");
iclass_prekey_t *item; iclass_prekey_t *item;
iclass_prekey_t lookup; iclass_prekey_t lookup;
memcpy(lookup.mac, MAC_TAG, 4); memcpy(lookup.mac, MAC_TAG, 4);
@ -2377,19 +2377,10 @@ int LoadDictionaryKeyFile(char *filename, uint8_t **keys, int *keycnt) {
uint8_t *p; uint8_t *p;
int keyitems = 0; int keyitems = 0;
if (!(f = fopen(filename, "r"))) {
char *dict_path; PrintAndLogEx(FAILED, "File: " _YELLOW_("%s") ": not found or locked.", filename);
int res = searchFile(&dict_path, DICTIONARIES_SUBDIR, filename, ".dic"); return 1;
if (res != PM3_SUCCESS) {
return res;
} }
f = fopen(dict_path, "r");
if (!f) {
PrintAndLogEx(FAILED, "File: " _YELLOW_("%s") ": not found or locked.", dict_path);
free(dict_path);
return PM3_EFILE;
}
free(dict_path);
while (fgets(buf, sizeof(buf), f)) { while (fgets(buf, sizeof(buf), f)) {
if (strlen(buf) < 16 || buf[15] == '\n') if (strlen(buf) < 16 || buf[15] == '\n')
@ -2405,8 +2396,7 @@ int LoadDictionaryKeyFile(char *filename, uint8_t **keys, int *keycnt) {
// doesn't this only test first char only? // doesn't this only test first char only?
if (!isxdigit(buf[0])) { if (!isxdigit(buf[0])) {
PrintAndLogEx(ERR, "file content error. '%s' must include 16 HEX symbols", buf); PrintAndLogEx(ERR, "file content error. '%s' must include 16 HEX symbols", buf);
fclose(f); continue;
return PM3_EFILE;
} }
// null terminator (skip the rest of the line) // null terminator (skip the rest of the line)
@ -2416,7 +2406,7 @@ int LoadDictionaryKeyFile(char *filename, uint8_t **keys, int *keycnt) {
if (!p) { if (!p) {
PrintAndLogEx(ERR, "cannot allocate memory for default keys"); PrintAndLogEx(ERR, "cannot allocate memory for default keys");
fclose(f); fclose(f);
return PM3_EMALLOC; return 2;
} }
*keys = p; *keys = p;