Merge branch 'master' of github.com:merlokk/proxmark3i into mf_mad

# Conflicts:
#	client/cmdhfmf.c
#	client/mifare/mifarehost.c
This commit is contained in:
merlokk
2019-03-01 19:37:43 +02:00
63 changed files with 1216 additions and 862 deletions

View File

@@ -538,18 +538,19 @@ int bruteforceFile(const char *filename, uint16_t keytable[]) {
if (fsize < 0) {
PrintAndLogDevice(WARNING, "Error, when getting filesize");
if (f) fclose(f);
fclose(f);
return 1;
}
uint8_t *dump = calloc(fsize, sizeof(uint8_t));
if ( !dump ) {
PrintAndLogDevice(WARNING, "Failed to allocate memory");
fclose(f);
return 2;
}
size_t bytes_read = fread(dump, 1, fsize, f);
if (f) fclose(f);
fclose(f);
if (bytes_read < fsize) {
PrintAndLogDevice(WARNING, "Error, could only read %d bytes (should be %d)", bytes_read, fsize );

View File

@@ -266,8 +266,8 @@ int loadFile(const char *preferredName, const char *suffix, void* data, size_t*
FILE *f = fopen(fileName, "rb");
if ( !f ) {
PrintAndLogDevice(WARNING, "file not found or locked. '" _YELLOW_(%s)"'", fileName);
retval = 1;
goto out;
free(fileName);
return 1;
}
// get filesize in order to malloc memory
@@ -310,7 +310,12 @@ int loadFile(const char *preferredName, const char *suffix, void* data, size_t*
out:
fclose(f);
if (data)
free(data);
free(fileName);
return retval;
}
@@ -318,6 +323,7 @@ int loadFileEML(const char *preferredName, const char *suffix, void* data, size_
if ( preferredName == NULL ) return 1;
if ( suffix == NULL ) return 1;
if ( data == NULL ) return 1;
size_t counter = 0;
int retval = 0, hexlen = 0;
@@ -359,7 +365,9 @@ int loadFileEML(const char *preferredName, const char *suffix, void* data, size_
}
fclose(f);
PrintAndLogDevice(SUCCESS, "loaded %d bytes from text file " _YELLOW_(%s), counter, fileName);
*datalen = counter;
if ( datalen )
*datalen = counter;
out:
free(fileName);
@@ -367,12 +375,14 @@ out:
}
int loadFileJSON(const char *preferredName, const char *suffix, void* data, size_t maxdatalen, size_t* datalen) {
*datalen = 0;
json_t *root;
json_error_t error;
if ( preferredName == NULL ) return 1;
if ( suffix == NULL ) return 1;
if ( data == NULL ) return 1;
*datalen = 0;
json_t *root;
json_error_t error;
int retval = 0;
int size = sizeof(char) * (strlen(preferredName) + strlen(suffix) + 10);
@@ -456,6 +466,7 @@ int loadFileDICTIONARY(const char *preferredName, const char *suffix, void* data
if ( preferredName == NULL ) return 1;
if ( suffix == NULL ) return 1;
if ( data == NULL ) return 1;
// t5577 == 4bytes
// mifare == 6 bytes
@@ -511,8 +522,10 @@ int loadFileDICTIONARY(const char *preferredName, const char *suffix, void* data
counter += (keylen >> 1);
}
fclose(f);
PrintAndLogDevice(SUCCESS, "loaded " _GREEN_(%2d) "keys from dictionary file " _YELLOW_(%s), *keycnt, fileName);
*datalen = counter;
PrintAndLogDevice(SUCCESS, "loaded " _GREEN_(%2d) "keys from dictionary file " _YELLOW_(%s), *keycnt, fileName);
if ( datalen )
*datalen = counter;
out:
free(fileName);
return retval;

View File

@@ -428,8 +428,8 @@ void testPermute()
printarr("permuted", res, 8);
}
//These testcases are
//{ UID , TEMP_KEY, DIV_KEY} using the specific key
// These testcases are
// { UID , TEMP_KEY, DIV_KEY} using the specific key
typedef struct
{
uint8_t uid[8];
@@ -475,7 +475,7 @@ int testDES(Testcase testcase, mbedtls_des_context ctx_enc, mbedtls_des_context
return retval;
}
bool des_getParityBitFromKey(uint8_t key)
{//The top 7 bits is used
{ // The top 7 bits is used
bool parity = ((key & 0x80) >> 7)
^ ((key & 0x40) >> 6) ^ ((key & 0x20) >> 5)
^ ((key & 0x10) >> 4) ^ ((key & 0x08) >> 3)
@@ -676,7 +676,8 @@ static bool readKeyFile(uint8_t key[8]) {
bool retval = false;
//Test a few variants
char filename[30];
char filename[30] = {0};
if (fileExists("iclass_key.bin")){
sprintf(filename, "%s.bin", "iclass_key");
} else if (fileExists("loclass/iclass_key.bin")){
@@ -685,6 +686,9 @@ static bool readKeyFile(uint8_t key[8]) {
sprintf(filename, "%s.bin", "client/loclass/iclass_key");
}
if ( strlen(filename) == 0 )
return retval;
FILE *f = fopen(filename, "rb");
if (!f)
return retval;