CHG: use FillFileNameByUID() for filename generation for 'hf mf dump' and 'hf mf chk * ? d'

This commit is contained in:
Brian Pow 2018-02-05 18:59:24 +08:00
commit d050e473b7
3 changed files with 18 additions and 18 deletions

View file

@ -340,7 +340,7 @@ int usage_hf14_nack(void) {
return 0; return 0;
} }
int GetHFMF14AUID(uint8_t *uid) { int GetHFMF14AUID(uint8_t *uid, int *uidlen) {
UsbCommand c = {CMD_READER_ISO_14443a, {ISO14A_CONNECT | ISO14A_NO_DISCONNECT, 0, 0}}; UsbCommand c = {CMD_READER_ISO_14443a, {ISO14A_CONNECT | ISO14A_NO_DISCONNECT, 0, 0}};
clearCommandBuffer(); clearCommandBuffer();
SendCommand(&c); SendCommand(&c);
@ -355,24 +355,22 @@ int GetHFMF14AUID(uint8_t *uid) {
iso14a_card_select_t card; iso14a_card_select_t card;
memcpy(&card, (iso14a_card_select_t *)resp.d.asBytes, sizeof(iso14a_card_select_t)); memcpy(&card, (iso14a_card_select_t *)resp.d.asBytes, sizeof(iso14a_card_select_t));
memcpy(uid, card.uid, card.uidlen * sizeof(uint8_t)); memcpy(uid, card.uid, card.uidlen * sizeof(uint8_t));
*uidlen=card.uidlen;
return 1; return 1;
} }
char * GenerateFilename(const char *prefix, const char *suffix){ char * GenerateFilename(const char *prefix, const char *suffix){
uint8_t uid[4] = {0,0,0,0}; uint8_t uid[8] = {0,0,0,0,0,0,0,0};
int len=0; int uidlen=0;
char * fptr = malloc (sizeof (char) * (strlen(prefix) + strlen(suffix)) + sizeof(uid)*2 + 1); char * fptr = malloc (sizeof (char) * (strlen(prefix) + strlen(suffix)) + sizeof(uid)*2 + 1);
if (!GetHFMF14AUID(uid)) { if (!GetHFMF14AUID(uid, &uidlen)) {
PrintAndLog("No tag found."); PrintAndLog("No tag found.");
return NULL; return NULL;
} }
strcpy(fptr, prefix); strcpy(fptr, prefix);
len=strlen(fptr); FillFileNameByUID(fptr,uid,suffix,uidlen);
for (int i=0;i<sizeof(uid)/sizeof(uint8_t);i++)
len += sprintf(fptr+len, "%02x", uid[i]);
strcat(fptr, suffix);
return fptr; return fptr;
} }

View file

@ -101,17 +101,19 @@ void AddLogCurrentDT(char *fn) {
// param *uid - pointer to uid byte array // param *uid - pointer to uid byte array
// param *ext - ".log" // param *ext - ".log"
// param uidlen - length of uid array. // param uidlen - length of uid array.
void FillFileNameByUID(char *fn, uint8_t *uid, char *ext, int uidlen) { void FillFileNameByUID(char *filenamePrefix, uint8_t *uid, const char *ext, int uidlen) {
if ( fn == NULL || uid == NULL || ext == NULL ){ if ( filenamePrefix == NULL || uid == NULL || ext == NULL ){
printf("[!] error parameter is NULL\n"); printf("[!] error parameter is NULL\n");
return; return;
} }
char *fnameptr = fn;
memset(fn, 0x00, FILE_PATH_SIZE);
for (int j = 0; j < uidlen; j++, fnameptr += 2) int len=0;
sprintf(fnameptr, "%02X", uid[j]); len=strlen(filenamePrefix);
sprintf(fnameptr, "%s", ext); //memset(fn, 0x00, FILE_PATH_SIZE);
for (int j = 0; j < uidlen; j++)
sprintf(filenamePrefix + len + j * 2, "%02X", uid[j]);
strcat(filenamePrefix, ext);
} }
void hex_to_buffer(const uint8_t *buf, const uint8_t *hex_data, const size_t hex_len, const size_t hex_max_len, void hex_to_buffer(const uint8_t *buf, const uint8_t *hex_data, const size_t hex_len, const size_t hex_max_len,

View file

@ -174,7 +174,7 @@ extern void AddLogLine(char *fileName, char *extData, char *c);
extern void AddLogHex(char *fileName, char *extData, const uint8_t * data, const size_t len); extern void AddLogHex(char *fileName, char *extData, const uint8_t * data, const size_t len);
extern void AddLogUint64(char *fileName, char *extData, const uint64_t data); extern void AddLogUint64(char *fileName, char *extData, const uint64_t data);
extern void AddLogCurrentDT(char *fileName); extern void AddLogCurrentDT(char *fileName);
extern void FillFileNameByUID(char *fileName, uint8_t * uid, char *ext, int byteCount); extern void FillFileNameByUID(char *fileName, uint8_t * uid, const char *ext, int uidlen);
extern void hex_to_buffer(const uint8_t *buf, const uint8_t *hex_data, const size_t hex_len, extern void hex_to_buffer(const uint8_t *buf, const uint8_t *hex_data, const size_t hex_len,
const size_t hex_max_len, const size_t min_str_len, const size_t spaces_between, const size_t hex_max_len, const size_t min_str_len, const size_t spaces_between,