Merge branch 'master' into experimental_varlen

* master:
  ltrim cmd before display
  hf mf eload: fix absence of filename
  detect wrong numOfBlocks / numOfSectors arguments
  safeFile*: accept when suffix is already provided
  loadFile*: accept when suffix is already provided
  textual,  to reflect which repo.
  LoadEML: don't complain on the last \n
This commit is contained in:
Philippe Teuwen 2019-04-28 22:53:12 +02:00
commit f1deb865db
16 changed files with 170 additions and 121 deletions

View file

@ -222,7 +222,7 @@ static int CmdFlashMemLoad(const char *Cmd) {
switch (d) {
case DICTIONARY_MIFARE:
start_index = DEFAULT_MF_KEYS_OFFSET;
res = loadFileDICTIONARY(filename, "dic", data + 2, &datalen, 6, &keycount);
res = loadFileDICTIONARY(filename, data + 2, &datalen, 6, &keycount);
if (res || !keycount) {
free(data);
return PM3_EFILE;
@ -233,7 +233,7 @@ static int CmdFlashMemLoad(const char *Cmd) {
break;
case DICTIONARY_T55XX:
start_index = DEFAULT_T55XX_KEYS_OFFSET;
res = loadFileDICTIONARY(filename, "dic", data + 2, &datalen, 4, &keycount);
res = loadFileDICTIONARY(filename, data + 2, &datalen, 4, &keycount);
if (res || !keycount) {
free(data);
return PM3_EFILE;
@ -244,7 +244,7 @@ static int CmdFlashMemLoad(const char *Cmd) {
break;
case DICTIONARY_ICLASS:
start_index = DEFAULT_ICLASS_KEYS_OFFSET;
res = loadFileDICTIONARY(filename, "dic", data + 2, &datalen, 8, &keycount);
res = loadFileDICTIONARY(filename, data + 2, &datalen, 8, &keycount);
if (res || !keycount) {
free(data);
return PM3_EFILE;
@ -254,8 +254,8 @@ static int CmdFlashMemLoad(const char *Cmd) {
datalen += 2;
break;
case DICTIONARY_NONE:
res = loadFile(filename, "bin", data, FLASH_MEM_MAX_SIZE, &datalen);
//int res = loadFileEML( filename, "eml", data, &datalen);
res = loadFile(filename, ".bin", data, FLASH_MEM_MAX_SIZE, &datalen);
//int res = loadFileEML( filename, data, &datalen);
if (res) {
free(data);
return PM3_EFILE;
@ -367,8 +367,8 @@ static int CmdFlashMemSave(const char *Cmd) {
return PM3_EFLASH;
}
saveFile(filename, "bin", dump, len);
saveFileEML(filename, "eml", dump, len, 16);
saveFile(filename, ".bin", dump, len);
saveFileEML(filename, dump, len, 16);
free(dump);
return PM3_SUCCESS;
}

View file

@ -961,8 +961,8 @@ static int CmdHF14BDump(const char *Cmd) {
size_t datalen = (blocks + 1) * 4;
saveFileEML(filename, "eml", data, datalen, 4);
saveFile(filename, "bin", data, datalen);
saveFileEML(filename, data, datalen, 4);
saveFile(filename, ".bin", data, datalen);
out:
return switch_off_field_14b();
}

View file

@ -833,8 +833,8 @@ static int CmdHF15Dump(const char *Cmd) {
PrintAndLogEx(NORMAL, "\n");
size_t datalen = blocknum * 4;
saveFileEML(filename, "eml", data, datalen, 4);
saveFile(filename, "bin", data, datalen);
saveFileEML(filename, data, datalen, 4);
saveFile(filename, ".bin", data, datalen);
return 0;
}

View file

@ -422,7 +422,7 @@ static int CmdHFiClassSim(const char *Cmd) {
memcpy(dump + i * 24 + 16, resp.data.asBytes + i * 16 + 8, 8);
}
/** Now, save to dumpfile **/
saveFile("iclass_mac_attack", "bin", dump, datalen);
saveFile("iclass_mac_attack", ".bin", dump, datalen);
free(dump);
break;
}
@ -474,7 +474,7 @@ static int CmdHFiClassSim(const char *Cmd) {
// copy NR_MAC (eight bytes from the response) ( 8b csn + 8b epurse == 16)
memcpy(dump + i * MAC_ITEM_SIZE + 16, resp.data.asBytes + i * 16 + 8, 8);
}
saveFile("iclass_mac_attack_keyroll_A", "bin", dump, datalen);
saveFile("iclass_mac_attack_keyroll_A", ".bin", dump, datalen);
//KEYROLL 2
memset(dump, 0, datalen);
@ -489,7 +489,7 @@ static int CmdHFiClassSim(const char *Cmd) {
memcpy(dump + i * MAC_ITEM_SIZE + 16, resp.data.asBytes + resp_index + 8, 8);
resp_index++;
}
saveFile("iclass_mac_attack_keyroll_B", "bin", dump, datalen);
saveFile("iclass_mac_attack_keyroll_B", ".bin", dump, datalen);
free(dump);
break;
}
@ -707,7 +707,7 @@ static int CmdHFiClassDecrypt(const char *Cmd) {
}
}
saveFile(outfilename, "bin", decrypted, fsize);
saveFile(outfilename, ".bin", decrypted, fsize);
printIclassDumpContents(decrypted, 1, (fsize / 8), fsize);
free(decrypted);
return 0;
@ -1067,7 +1067,7 @@ static int CmdHFiClassReader_Dump(const char *Cmd) {
// save the dump to .bin file
PrintAndLogEx(SUCCESS, "saving dump file - %d blocks read", gotBytes / 8);
saveFile(filename, "bin", tag_data, gotBytes);
saveFile(filename, ".bin", tag_data, gotBytes);
return 1;
}

View file

@ -1199,8 +1199,8 @@ static int CmdLegicESave(const char *Cmd) {
else
sprintf(fnameptr + fileNlen, ".bin");
saveFileEML(filename, "eml", data, numofbytes, 8);
saveFile(filename, "bin", data, numofbytes);
saveFileEML(filename, data, numofbytes, 8);
saveFile(filename, ".bin", data, numofbytes);
return 0;
}

View file

@ -678,7 +678,7 @@ static uint16_t NumOfBlocks(char card) {
case '4' :
return MIFARE_4K_MAXBLOCK;
default :
return MIFARE_1K_MAXBLOCK;
return 0;
}
}
@ -693,7 +693,7 @@ static uint8_t NumOfSectors(char card) {
case '4' :
return MIFARE_4K_MAXSECTOR;
default :
return MIFARE_1K_MAXSECTOR;
return 0;
}
}
@ -748,6 +748,7 @@ static int CmdHF14AMfDump(const char *Cmd) {
default:
if (cmdp == 0) {
numSectors = NumOfSectors(param_getchar(Cmd, cmdp));
if (numSectors == 0) return usage_hf14_dump();
cmdp++;
} else {
PrintAndLogEx(WARNING, "Unknown parameter '%c'\n", param_getchar(Cmd, cmdp));
@ -904,9 +905,9 @@ static int CmdHF14AMfDump(const char *Cmd) {
uint16_t bytes = 16 * (FirstBlockOfSector(numSectors - 1) + NumBlocksPerSector(numSectors - 1));
saveFile(dataFilename, "bin", (uint8_t *)carddata, bytes);
saveFileEML(dataFilename, "eml", (uint8_t *)carddata, bytes, MFBLOCK_SIZE);
saveFileJSON(dataFilename, "json", jsfCardMemory, (uint8_t *)carddata, bytes);
saveFile(dataFilename, ".bin", (uint8_t *)carddata, bytes);
saveFileEML(dataFilename, (uint8_t *)carddata, bytes, MFBLOCK_SIZE);
saveFileJSON(dataFilename, jsfCardMemory, (uint8_t *)carddata, bytes);
return 0;
}
@ -948,6 +949,7 @@ static int CmdHF14AMfRestore(const char *Cmd) {
default:
if (cmdp == 0) {
numSectors = NumOfSectors(param_getchar(Cmd, cmdp));
if (numSectors == 0) return usage_hf14_restore();
cmdp++;
} else {
PrintAndLogEx(WARNING, "Unknown parameter '%c'\n", param_getchar(Cmd, cmdp));
@ -1101,6 +1103,7 @@ static int CmdHF14AMfNested(const char *Cmd) {
}
} else {
SectorsCnt = NumOfSectors(cmdp);
if (SectorsCnt == 0) return usage_hf14_nested();
}
uint8_t j = 4;
@ -1803,6 +1806,7 @@ static int CmdHF14AMfChk(const char *Cmd) {
if (param_getchar(Cmd, 0) == '*') {
blockNo = 3;
SectorsCnt = NumOfSectors(param_getchar(Cmd + 1, 0));
if (SectorsCnt == 0) return usage_hf14_chk();
} else {
blockNo = param_get8(Cmd, 0);
}
@ -2562,12 +2566,13 @@ int CmdHF14AMfELoad(const char *Cmd) {
if (numblk2 > 0)
numBlocks = numblk2;
param_getstr(Cmd, nameParamNo, filename, sizeof(filename));
if (0 == param_getstr(Cmd, nameParamNo, filename, sizeof(filename)))
return usage_hf14_eload();
uint8_t *data = calloc(4096, sizeof(uint8_t));
size_t datalen = 0;
//int res = loadFile(filename, "bin", data, maxdatalen, &datalen);
int res = loadFileEML(filename, "eml", data, &datalen);
//int res = loadFile(filename, ".bin", data, maxdatalen, &datalen);
int res = loadFileEML(filename, data, &datalen);
if (res) {
free(data);
return 1;
@ -2641,7 +2646,12 @@ static int CmdHF14AMfESave(const char *Cmd) {
char c = tolower(param_getchar(Cmd, 0));
if (c == 'h') return usage_hf14_esave();
blocks = NumOfBlocks(c);
if (c != 0) {
blocks = NumOfBlocks(c);
if (blocks == 0) return usage_hf14_esave();
} else {
blocks = MIFARE_1K_MAXBLOCK;
}
bytes = blocks * MFBLOCK_SIZE;
dump = calloc(bytes, sizeof(uint8_t));
@ -2667,9 +2677,9 @@ static int CmdHF14AMfESave(const char *Cmd) {
FillFileNameByUID(fnameptr, dump, "-dump", 4);
}
saveFile(filename, "bin", dump, bytes);
saveFileEML(filename, "eml", dump, bytes, MFBLOCK_SIZE);
saveFileJSON(filename, "json", jsfCardMemory, dump, bytes);
saveFile(filename, ".bin", dump, bytes);
saveFileEML(filename, dump, bytes, MFBLOCK_SIZE);
saveFileJSON(filename, jsfCardMemory, dump, bytes);
free(dump);
return 0;
}
@ -2690,7 +2700,12 @@ static int CmdHF14AMfECFill(const char *Cmd) {
keyType = 1;
c = tolower(param_getchar(Cmd, 1));
numSectors = NumOfSectors(c);
if (c != 0) {
numSectors = NumOfSectors(c);
if (numSectors == 0) return usage_hf14_ecfill();
} else {
numSectors = MIFARE_1K_MAXSECTOR;
}
PrintAndLogEx(NORMAL, "--params: numSectors: %d, keyType: %c\n", numSectors, (keyType == 0) ? 'A' : 'B');
clearCommandBuffer();
@ -2708,7 +2723,12 @@ static int CmdHF14AMfEKeyPrn(const char *Cmd) {
if (c == 'h')
return usage_hf14_ekeyprn();
numSectors = NumOfSectors(c);
if (c != 0) {
numSectors = NumOfSectors(c);
if (numSectors == 0) return usage_hf14_ekeyprn();
} else {
numSectors = MIFARE_1K_MAXSECTOR;
}
PrintAndLogEx(NORMAL, "|---|----------------|----------------|");
PrintAndLogEx(NORMAL, "|sec|key A |key B |");
@ -2861,12 +2881,12 @@ static int CmdHF14AMfCLoad(const char *Cmd) {
size_t datalen = 0;
int res = 0;
if (fillFromBin) {
res = loadFile(fileName, "bin", data, maxdatalen, &datalen);
res = loadFile(fileName, ".bin", data, maxdatalen, &datalen);
} else {
if (fillFromJson) {
res = loadFileJSON(fileName, "json", data, maxdatalen, &datalen);
res = loadFileJSON(fileName, data, maxdatalen, &datalen);
} else {
res = loadFileEML(Cmd, "eml", data, &datalen);
res = loadFileEML(Cmd, data, &datalen);
}
}
@ -3100,9 +3120,9 @@ static int CmdHF14AMfCSave(const char *Cmd) {
PrintAndLogEx(SUCCESS, "uploaded %d bytes to emulator memory", bytes);
}
saveFile(filename, "bin", dump, bytes);
saveFileEML(filename, "eml", dump, bytes, MFBLOCK_SIZE);
saveFileJSON(filename, "json", jsfCardMemory, dump, bytes);
saveFile(filename, ".bin", dump, bytes);
saveFileEML(filename, dump, bytes, MFBLOCK_SIZE);
saveFileJSON(filename, jsfCardMemory, dump, bytes);
free(dump);
return 0;
}

View file

@ -1969,8 +1969,8 @@ static int CmdHF14AMfUDump(const char *Cmd) {
FillFileNameByUID(fptr, card.uid, "-dump", card.uidlen);
}
uint16_t datalen = pages * 4 + MFU_DUMP_PREFIX_LENGTH;
saveFile(filename, "bin", (uint8_t *)&dump_file_data, datalen);
saveFileJSON(filename, "json", jsfMfuMemory, (uint8_t *)&dump_file_data, datalen);
saveFile(filename, ".bin", (uint8_t *)&dump_file_data, datalen);
saveFileJSON(filename, jsfMfuMemory, (uint8_t *)&dump_file_data, datalen);
if (is_partial)
PrintAndLogEx(WARNING, "Partial dump created. (%d of %d blocks)", pages, card_mem_size);

View file

@ -293,7 +293,7 @@ static int CmdLFHitagSim(const char *Cmd) {
break;
case 'e':
param_getstr(Cmd, cmdp + 1, filename, sizeof(filename));
res = loadFileEML(filename, "eml", data, &datalen);
res = loadFileEML(filename, data, &datalen);
if (res > 0 || datalen != maxdatalen) {
PrintAndLogDevice(FAILED, "error, bytes read mismatch file size");
errors = true;
@ -304,7 +304,7 @@ static int CmdLFHitagSim(const char *Cmd) {
break;
case 'j':
param_getstr(Cmd, cmdp + 1, filename, sizeof(filename));
res = loadFileJSON(filename, "json", data, maxdatalen, &datalen);
res = loadFileJSON(filename, data, maxdatalen, &datalen);
if (res > 0) {
errors = true;
break;
@ -314,7 +314,7 @@ static int CmdLFHitagSim(const char *Cmd) {
break;
case 'b':
param_getstr(Cmd, cmdp + 1, filename, sizeof(filename));
res = loadFile(filename, "bin", data, maxdatalen, &datalen);
res = loadFile(filename, ".bin", data, maxdatalen, &datalen);
if (res > 0) {
errors = true;
break;
@ -579,9 +579,9 @@ static int CmdLFHitagReader(const char *Cmd) {
fnameptr += sprintf(fnameptr, "lf-hitag-");
FillFileNameByUID(fnameptr, data, "-dump", 4);
saveFile(filename, "bin", data, 48);
saveFileEML(filename, "eml", data, 48, 4);
saveFileJSON(filename, "json", jsfHitag, data, 48);
saveFile(filename, ".bin", data, 48);
saveFileEML(filename, data, 48, 4);
saveFileJSON(filename, jsfHitag, data, 48);
// block3, 1 byte
printHitagConfiguration(data[4 * 3]);
@ -607,7 +607,7 @@ static int CmdLFHitagCheckChallenges(const char *Cmd) {
case 'f':
//file with all the challenges to try
param_getstr(Cmd, cmdp + 1, filename, sizeof(filename));
res = loadFile(filename, "cc", data, 8 * 60, &datalen);
res = loadFile(filename, ".cc", data, 8 * 60, &datalen);
if (res > 0) {
errors = true;
break;

View file

@ -1903,7 +1903,7 @@ static int CmdT55xxChkPwds(const char *Cmd) {
return 1;
}
int res = loadFileDICTIONARY(filename, "dic", keyBlock, &datalen, 4, &keycount);
int res = loadFileDICTIONARY(filename, keyBlock, &datalen, 4, &keycount);
if (res || keycount == 0) {
PrintAndLogEx(WARNING, "No keys found in file");
free(keyBlock);

View file

@ -563,7 +563,7 @@ static int CmdTraceSave(const char *Cmd) {
if (strlen(Cmd) < 1 || cmdp == 'h') return usage_trace_save();
param_getstr(Cmd, 0, filename, sizeof(filename));
saveFile(filename, "bin", trace, traceLen);
saveFile(filename, ".bin", trace, traceLen);
return 0;
}

View file

@ -57,15 +57,49 @@ int fileExists(const char *filename) {
return result == 0;
}
int saveFile(const char *preferredName, const char *suffix, const void *data, size_t datalen) {
int size = sizeof(char) * (strlen(preferredName) + strlen(suffix) + 10);
char *fileName = calloc(size, sizeof(char));
static char *filenamemcopy(const char *preferredName, const char *suffix) {
if (preferredName == NULL) return NULL;
if (suffix == NULL) return NULL;
char *fileName = (char *) calloc(strlen(preferredName) + strlen(suffix) + 1, sizeof(uint8_t));
if (fileName == NULL)
return NULL;
strcpy(fileName, preferredName);
if (str_endswith(fileName, suffix))
return fileName;
strcat(fileName, suffix);
return fileName;
}
static char *newfilenamemcopy(const char *preferredName, const char *suffix) {
if (preferredName == NULL) return NULL;
if (suffix == NULL) return NULL;
char *preferredNameTmp = (char *) calloc(strlen(preferredName) + 1, sizeof(uint8_t));
if (preferredNameTmp == NULL)
return NULL;
strcpy(preferredNameTmp, preferredName);
if (str_endswith(preferredNameTmp, suffix))
preferredNameTmp[strlen(preferredNameTmp) - strlen(suffix)] = '\0';
char *fileName = (char *) calloc(strlen(preferredNameTmp) + strlen(suffix) + 1 + 10, sizeof(uint8_t)); // 10: room for filenum to ensure new filename
if (fileName == NULL) {
free(preferredNameTmp);
return NULL;
}
int num = 1;
sprintf(fileName, "%s.%s", preferredName, suffix);
sprintf(fileName, "%s%s", preferredNameTmp, suffix);
while (fileExists(fileName)) {
sprintf(fileName, "%s-%d.%s", preferredName, num, suffix);
sprintf(fileName, "%s-%d%s", preferredNameTmp, num, suffix);
num++;
}
free(preferredNameTmp);
return fileName;
}
int saveFile(const char *preferredName, const char *suffix, const void *data, size_t datalen) {
if (data == NULL) return 1;
char *fileName = newfilenamemcopy(preferredName, suffix);
if (fileName == NULL) return 1;
/* We should have a valid filename now, e.g. dumpdata-3.bin */
/*Opening file for writing in binary mode*/
@ -83,23 +117,15 @@ int saveFile(const char *preferredName, const char *suffix, const void *data, si
return 0;
}
int saveFileEML(const char *preferredName, const char *suffix, uint8_t *data, size_t datalen, size_t blocksize) {
int saveFileEML(const char *preferredName, uint8_t *data, size_t datalen, size_t blocksize) {
if (preferredName == NULL) return 1;
if (suffix == NULL) return 1;
if (data == NULL) return 1;
char *fileName = newfilenamemcopy(preferredName, ".eml");
if (fileName == NULL) return 1;
int retval = 0;
int blocks = datalen / blocksize;
uint16_t currblock = 1;
int size = sizeof(char) * (strlen(preferredName) + strlen(suffix) + 10);
char *fileName = calloc(size, sizeof(char));
int num = 1;
sprintf(fileName, "%s.%s", preferredName, suffix);
while (fileExists(fileName)) {
sprintf(fileName, "%s-%d.%s", preferredName, num, suffix);
num++;
}
/* We should have a valid filename now, e.g. dumpdata-3.bin */
@ -136,20 +162,13 @@ out:
return retval;
}
int saveFileJSON(const char *preferredName, const char *suffix, JSONFileType ftype, uint8_t *data, size_t datalen) {
if (preferredName == NULL) return 1;
if (suffix == NULL) return 1;
int saveFileJSON(const char *preferredName, JSONFileType ftype, uint8_t *data, size_t datalen) {
if (data == NULL) return 1;
char *fileName = newfilenamemcopy(preferredName, ".json");
if (fileName == NULL) return 1;
int retval = 0;
int size = sizeof(char) * (strlen(preferredName) + strlen(suffix) + 10);
char *fileName = calloc(size, sizeof(char));
int num = 1;
sprintf(fileName, "%s.%s", preferredName, suffix);
while (fileExists(fileName)) {
sprintf(fileName, "%s-%d.%s", preferredName, num, suffix);
num++;
}
json_t *root = json_object();
JsonSaveStr(root, "Created", "proxmark3");
@ -274,14 +293,11 @@ out:
int loadFile(const char *preferredName, const char *suffix, void *data, size_t maxdatalen, size_t *datalen) {
if (preferredName == NULL) return 1;
if (suffix == NULL) return 1;
if (data == NULL) return 1;
char *fileName = filenamemcopy(preferredName, suffix);
if (fileName == NULL) return 1;
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, "rb");
if (!f) {
@ -336,17 +352,14 @@ out:
return retval;
}
int loadFileEML(const char *preferredName, const char *suffix, void *data, size_t *datalen) {
int loadFileEML(const char *preferredName, void *data, size_t *datalen) {
if (preferredName == NULL) return 1;
if (suffix == NULL) return 1;
if (data == NULL) return 1;
char *fileName = filenamemcopy(preferredName, ".eml");
if (fileName == NULL) return 1;
size_t counter = 0;
int retval = 0, hexlen = 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) {
@ -365,6 +378,8 @@ int loadFileEML(const char *preferredName, const char *suffix, void *data, size_
memset(line, 0, sizeof(line));
if (fgets(line, sizeof(line), f) == NULL) {
if (feof(f))
break;
fclose(f);
PrintAndLogEx(FAILED, "File reading error.");
retval = 2;
@ -391,20 +406,17 @@ out:
return retval;
}
int loadFileJSON(const char *preferredName, const char *suffix, void *data, size_t maxdatalen, size_t *datalen) {
int loadFileJSON(const char *preferredName, void *data, size_t maxdatalen, size_t *datalen) {
if (preferredName == NULL) return 1;
if (suffix == NULL) return 1;
if (data == NULL) return 1;
char *fileName = filenamemcopy(preferredName, ".json");
if (fileName == NULL) return 1;
*datalen = 0;
json_t *root;
json_error_t error;
int retval = 0;
int size = sizeof(char) * (strlen(preferredName) + strlen(suffix) + 10);
char *fileName = calloc(size, sizeof(char));
sprintf(fileName, "%s.%s", preferredName, suffix);
root = json_load_file(fileName, 0, &error);
if (!root) {
@ -500,11 +512,12 @@ out:
return retval;
}
int loadFileDICTIONARY(const char *preferredName, const char *suffix, void *data, size_t *datalen, uint8_t keylen, uint16_t *keycnt) {
int loadFileDICTIONARY(const char *preferredName, void *data, size_t *datalen, uint8_t keylen, uint16_t *keycnt) {
if (preferredName == NULL) return 1;
if (suffix == NULL) return 1;
if (data == NULL) return 1;
char *fileName = filenamemcopy(preferredName, ".dic");
if (fileName == NULL) return 1;
// t5577 == 4bytes
// mifare == 6 bytes
@ -521,9 +534,6 @@ int loadFileDICTIONARY(const char *preferredName, const char *suffix, void *data
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) {

View file

@ -70,7 +70,7 @@ int fileExists(const char *filename);
* E.g. dumpdata-15.txt
*
* @param preferredName
* @param suffix the file suffix. Leave out the ".".
* @param suffix the file suffix. Including the ".".
* @param data The binary data to write to the file
* @param datalen the length of the data
* @return 0 for ok, 1 for failz
@ -83,13 +83,12 @@ int saveFile(const char *preferredName, const char *suffix, const void *data, si
* E.g. dumpdata-15.txt
*
* @param preferredName
* @param suffix the file suffix. Leave out the ".".
* @param data The binary data to write to the file
* @param datalen the length of the data
* @param blocksize the length of one row
* @return 0 for ok, 1 for failz
*/
int saveFileEML(const char *preferredName, const char *suffix, uint8_t *data, size_t datalen, size_t blocksize);
int saveFileEML(const char *preferredName, uint8_t *data, size_t datalen, size_t blocksize);
/** STUB
* @brief Utility function to save JSON data to a file. This method takes a preferred name, but if that
@ -97,20 +96,19 @@ int saveFileEML(const char *preferredName, const char *suffix, uint8_t *data, si
* E.g. dumpdata-15.json
*
* @param preferredName
* @param suffix the file suffix. Leave out the ".".
* @param ftype type of file.
* @param data The binary data to write to the file
* @param datalen the length of the data
* @return 0 for ok, 1 for failz
*/
int saveFileJSON(const char *preferredName, const char *suffix, JSONFileType ftype, uint8_t *data, size_t datalen);
int saveFileJSON(const char *preferredName, JSONFileType ftype, uint8_t *data, size_t datalen);
/** STUB
* @brief Utility function to load data from a binary file. This method takes a preferred name.
* E.g. dumpdata-15.bin
*
* @param preferredName
* @param suffix the file suffix. Leave out the ".".
* @param suffix the file suffix. Including the ".".
* @param data The data array to store the loaded bytes from file
* @param maxdatalen the number of bytes that your data array has
* @param datalen the number of bytes loaded from file
@ -123,25 +121,23 @@ int loadFile(const char *preferredName, const char *suffix, void *data, size_t m
* E.g. dumpdata-15.txt
*
* @param preferredName
* @param suffix the file suffix. Leave out the ".".
* @param data The data array to store the loaded bytes from file
* @param datalen the number of bytes loaded from file
* @return 0 for ok, 1 for failz
*/
int loadFileEML(const char *preferredName, const char *suffix, void *data, size_t *datalen);
int loadFileEML(const char *preferredName, void *data, size_t *datalen);
/**
* @brief Utility function to load data from a JSON textfile. This method takes a preferred name.
* E.g. dumpdata-15.json
*
* @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
* @return 0 for ok, 1 for failz
*/
int loadFileJSON(const char *preferredName, const char *suffix, void *data, size_t maxdatalen, size_t *datalen);
int loadFileJSON(const char *preferredName, void *data, size_t maxdatalen, size_t *datalen);
/**
@ -149,14 +145,13 @@ int loadFileJSON(const char *preferredName, const char *suffix, void *data, size
* 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
*/
int loadFileDICTIONARY(const char *preferredName, const char *suffix, void *data, size_t *datalen, uint8_t keylen, uint16_t *keycnt);
int loadFileDICTIONARY(const char *preferredName, void *data, size_t *datalen, uint8_t keylen, uint16_t *keycnt);
/**
* @brief Utility function to check and convert old mfu dump format to new

View file

@ -97,7 +97,7 @@ main_loop(char *script_cmds_file, char *script_cmd, bool pm3_present) {
// loops every time enter is pressed...
while (1) {
bool printprompt = false;
// this should hook up the PM3 again.
/*
if ( IsOffline() ) {
@ -134,13 +134,13 @@ main_loop(char *script_cmds_file, char *script_cmd, bool pm3_present) {
strcleanrn(script_cmd_buf, sizeof(script_cmd_buf));
if ((cmd = strmcopy(script_cmd_buf)) != NULL)
PrintAndLogEx(NORMAL, PROXPROMPT"%s\n", cmd);
printprompt = true;
}
} else {
// If there is a script command
if (execCommand) {
if ((cmd = strmcopy(script_cmd)) != NULL)
PrintAndLogEx(NORMAL, PROXPROMPT"%s", cmd);
printprompt = true;
uint16_t len = strlen(script_cmd) + 1;
script_cmd += len;
if (script_cmd_len == len - 1)
@ -165,7 +165,7 @@ main_loop(char *script_cmds_file, char *script_cmd, bool pm3_present) {
strcleanrn(script_cmd_buf, sizeof(script_cmd_buf));
if ((cmd = strmcopy(script_cmd_buf)) != NULL)
PrintAndLogEx(NORMAL, PROXPROMPT"%s", cmd);
printprompt = true;
} else {
cmd = readline(PROXPROMPT);
@ -179,10 +179,20 @@ main_loop(char *script_cmds_file, char *script_cmd, bool pm3_present) {
// rtrim
size_t l = strlen(cmd);
if (l > 0 && isspace(cmd[l - 1]))
cmd[l - 1] = 0x00;
while (l > 0 && isspace(cmd[l - 1])) {
cmd[--l] = '\0';
}
// ltrim
size_t off=0;
while ((cmd[off] != '\0') && isspace(cmd[off]))
off++;
for (size_t i=0; i < strlen(cmd) - off; i++)
cmd[i] = cmd[i+off];
cmd[strlen(cmd) - off] = '\0';
if (cmd[0] != 0x00) {
if (cmd[0] != '\0') {
if (printprompt)
PrintAndLogEx(NORMAL, PROXPROMPT"%s", cmd);
int ret = CommandReceived(cmd);
HIST_ENTRY *entry = history_get(history_length);
if ((!entry) || (strcmp(entry->line, cmd) != 0))

View file

@ -822,10 +822,23 @@ void str_lower(char *s) {
for (size_t i = 0; i < strlen(s); i++)
s[i] = tolower(s[i]);
}
// check for prefix in string
bool str_startswith(const char *s, const char *pre) {
return strncmp(pre, s, strlen(pre)) == 0;
}
// check for suffix in string
bool str_endswith(const char *s, const char *suffix) {
size_t ls = strlen(s);
size_t lsuffix = strlen(suffix);
if (ls >= lsuffix)
{
return strncmp(suffix, s + (ls - lsuffix), lsuffix) == 0;
}
return false;
}
// Replace unprintable characters with a dot in char buffer
void clean_ascii(unsigned char *buf, size_t len) {
for (size_t i = 0; i < len; i++) {
@ -848,7 +861,7 @@ void strcreplace(char *buf, size_t len, char from, char to) {
}
}
char *strmcopy(char *buf) {
char *strmcopy(const char *buf) {
char *str = (char *) calloc(strlen(buf) + 1, sizeof(uint8_t));
if (str != NULL) {
memset(str, 0, strlen(buf) + 1);

View file

@ -231,8 +231,9 @@ int num_CPUs(void); // number of logical CPUs
void str_lower(char *s); // converts string to lower case
bool str_startswith(const char *s, const char *pre); // check for prefix in string
bool str_endswith(const char *s, const char *suffix); // check for suffix in string
void clean_ascii(unsigned char *buf, size_t len);
void strcleanrn(char *buf, size_t len);
void strcreplace(char *buf, size_t len, char from, char to);
char *strmcopy(char *buf);
char *strmcopy(const char *buf);
#endif

View file

@ -14,7 +14,7 @@ $ENV{'LC_ALL'} = "C";
$ENV{'LANG'} = "C";
# if you are making your own fork, change this line to reflect your fork-name
my $fullgitinfo = 'RRG';
my $fullgitinfo = 'RRG/Iceman';
my $ctime;
# GIT status 0 = dirty, 1 = clean , 2 = undecided
my $clean = 2;