CHG: 'mem load' - the possibility to upload default_iclass_keys.dic, default_keys.dic, default_pwd.dic to predefined flashmemory sections. These will be used in pwd / key checking algorithms on device.
CHG: 'script run read_pwd_mem.lua' - script now can print those uploaded dictionary files. How to upload pm3 --> mem load f default_iclass_keys i pm3 --> mem load f default_keys m pm3 --> mem load f default_pwd t How to validate / view PM3 -->scr run read_pwd_mem -o 237568 -k 8 pm3 -->scr run read_pwd_mem -o 241664 -k 6 pm3 -->scr run read_pwd_mem -o 245760 -k 4
This commit is contained in:
@@ -453,6 +453,72 @@ out:
|
||||
return retval;
|
||||
}
|
||||
|
||||
int loadFileDICTIONARY(const char *preferredName, const char *suffix, void* data, size_t* datalen, uint8_t keylen, uint16_t* keycnt ) {
|
||||
|
||||
if ( preferredName == NULL ) return 1;
|
||||
if ( suffix == NULL ) return 1;
|
||||
|
||||
// t5577 == 4bytes
|
||||
// mifare == 6 bytes
|
||||
// iclass == 8 bytes
|
||||
// default to 6 bytes.
|
||||
if (keylen != 4 && keylen != 6 && keylen != 8) {
|
||||
keylen = 6;
|
||||
}
|
||||
|
||||
// double up since its chars
|
||||
keylen <<= 1;
|
||||
|
||||
char line[255];
|
||||
|
||||
size_t counter = 0;
|
||||
int retval = 0;
|
||||
int size = sizeof(char) * (strlen(preferredName) + strlen(suffix) + 10);
|
||||
char * fileName = calloc(size, sizeof(char));
|
||||
sprintf(fileName,"%s.%s", preferredName, suffix);
|
||||
|
||||
FILE *f = fopen(fileName, "r");
|
||||
if ( !f ) {
|
||||
PrintAndLogDevice(FAILED, "file: %s: not found or locked.", fileName);
|
||||
retval = 1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
// read file
|
||||
while ( fgets(line, sizeof(line), f) ) {
|
||||
|
||||
// add null terminator
|
||||
line[keylen] = 0;
|
||||
|
||||
// smaller keys than expected is skipped
|
||||
if (strlen(line) < keylen)
|
||||
continue;
|
||||
|
||||
|
||||
// The line start with # is comment, skip
|
||||
if( line[0] == '#' )
|
||||
continue;
|
||||
|
||||
if (!isxdigit(line[0])){
|
||||
PrintAndLogEx(FAILED, "file content error. '%s' must include " _BLUE_(%2d) "HEX symbols", line, keylen);
|
||||
continue;
|
||||
}
|
||||
|
||||
uint64_t key = strtoull(line, NULL, 16);
|
||||
|
||||
num_to_bytes(key, keylen >> 1, data + counter);
|
||||
(*keycnt)++;
|
||||
memset(line, 0, sizeof(line));
|
||||
counter += (keylen >> 1);
|
||||
}
|
||||
fclose(f);
|
||||
PrintAndLogDevice(SUCCESS, "loaded " _GREEN_(%2d) "keys from dictionary file %s", *keycnt, fileName);
|
||||
*datalen = counter;
|
||||
out:
|
||||
free(fileName);
|
||||
return retval;
|
||||
}
|
||||
|
||||
#else //if we're on ARM
|
||||
|
||||
#endif
|
||||
|
||||
@@ -124,7 +124,7 @@ extern int loadFile(const char *preferredName, const char *suffix, void* data, s
|
||||
*/
|
||||
extern int loadFileEML(const char *preferredName, const char *suffix, void* data, size_t* datalen);
|
||||
|
||||
/** STUB
|
||||
/**
|
||||
* @brief Utility function to load data from a JSON textfile. This method takes a preferred name.
|
||||
* E.g. dumpdata-15.json
|
||||
*
|
||||
@@ -137,6 +137,21 @@ extern int loadFileEML(const char *preferredName, const char *suffix, void* data
|
||||
*/
|
||||
extern int loadFileJSON(const char *preferredName, const char *suffix, void* data, size_t maxdatalen, size_t* datalen);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Utility function to load data from a DICTIONARY textfile. This method takes a preferred name.
|
||||
* E.g. default_keys.dic
|
||||
*
|
||||
* @param preferredName
|
||||
* @param suffix the file suffix. Leave out the ".".
|
||||
* @param data The data array to store the loaded bytes from file
|
||||
* @param maxdatalen maximum size of data array in bytes
|
||||
* @param datalen the number of bytes loaded from file
|
||||
* @param keylen the number of bytes a key per row is
|
||||
* @return 0 for ok, 1 for failz
|
||||
*/
|
||||
extern int loadFileDICTIONARY(const char *preferredName, const char *suffix, void* data, size_t* datalen, uint8_t keylen, uint16_t* keycnt );
|
||||
|
||||
#define PrintAndLogDevice(level, format, args...) PrintAndLogEx(level, format , ## args)
|
||||
#else
|
||||
|
||||
|
||||
Reference in New Issue
Block a user