mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2026-05-12 11:18:11 -07:00
cleaning out memory unsafe functions for loading files. Also made the loading of files to honor the preference dump/trace settings. Experimental support, which will need more love. I have been using it for some months now but there are still other save/load file operations scattered in the PM3 client which will not benefit from this yet. They need to be adapted too
This commit is contained in:
@@ -3,6 +3,7 @@ All notable changes to this project will be documented in this file.
|
||||
This project uses the changelog in accordance with [keepchangelog](http://keepachangelog.com/). Please use this to write notable changes, which is not the same as git commit log...
|
||||
|
||||
## [unreleased][unreleased]
|
||||
- Changed the PM3 client to honor the preferences dump/trace paths. experimental support (@iceman1001)
|
||||
- Added the possibility to load `.MCT` dump files (@iceman1001)
|
||||
- Changed `lf t55xx dump --ns` - now supports `no save` of memory (@iceman1001)
|
||||
- Fixed the USB enumeration process (@wh201906)
|
||||
|
||||
+162
-125
File diff suppressed because it is too large
Load Diff
+2
-16
@@ -60,12 +60,12 @@ typedef enum {
|
||||
} DumpFileType_t;
|
||||
|
||||
int fileExists(const char *filename);
|
||||
//bool create_path(const char *dirname);
|
||||
|
||||
// set a path in the path list g_session.defaultPaths
|
||||
bool setDefaultPath(savePaths_t pathIndex, const char *path);
|
||||
|
||||
char *newfilenamemcopy(const char *preferredName, const char *suffix);
|
||||
char *newfilenamemcopyEx(const char *preferredName, const char *suffix, savePaths_t save_path);
|
||||
|
||||
/**
|
||||
* @brief Utility function to save data to a binary file. This method takes a preferred name, but if that
|
||||
@@ -105,7 +105,7 @@ int saveFileEML(const char *preferredName, uint8_t *data, size_t datalen, size_t
|
||||
* @return 0 for ok, 1 for failz
|
||||
*/
|
||||
int saveFileJSON(const char *preferredName, JSONFileType ftype, uint8_t *data, size_t datalen, void (*callback)(json_t *));
|
||||
int saveFileJSONex(const char *preferredName, JSONFileType ftype, uint8_t *data, size_t datalen, bool verbose, void (*callback)(json_t *));
|
||||
int saveFileJSONex(const char *preferredName, JSONFileType ftype, uint8_t *data, size_t datalen, bool verbose, void (*callback)(json_t *), savePaths_t e_save_path);
|
||||
int saveFileJSONroot(const char *preferredName, void *root, size_t flags, bool verbose);
|
||||
int saveFileJSONrootEx(const char *preferredName, void *root, size_t flags, bool verbose, bool overwrite);
|
||||
/** STUB
|
||||
@@ -142,20 +142,6 @@ int saveFilePM3(const char *preferredName, int *data, size_t datalen);
|
||||
*/
|
||||
int createMfcKeyDump(const char *preferredName, uint8_t sectorsCnt, sector_t *e_sector);
|
||||
|
||||
/**
|
||||
* @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. 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
|
||||
* @return PM3_SUCCESS for ok, PM3_E* for failz
|
||||
*/
|
||||
int loadFile(const char *preferredName, const char *suffix, void *data, size_t maxdatalen, size_t *datalen);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Utility function to load data from a binary file. This method takes a preferred name.
|
||||
* E.g. dumpdata-15.bin, tries to search for it, and allocated memory.
|
||||
|
||||
@@ -122,17 +122,18 @@ int preferences_save(void) {
|
||||
PrintAndLogEx(INFO, "Saving preferences...");
|
||||
|
||||
char *fn = prefGetFilename();
|
||||
int fnLen = strlen(fn) + 5; // .bak\0
|
||||
int fn_len = strlen(fn) + 5; // .bak\0
|
||||
|
||||
// [FILENAME_MAX+sizeof(preferencesFilename)+10]
|
||||
char *backupFilename = (char *)calloc(fnLen, sizeof(uint8_t));
|
||||
char *backupFilename = (char *)calloc(fn_len, sizeof(uint8_t));
|
||||
if (backupFilename == NULL) {
|
||||
PrintAndLogEx(ERR, "failed to allocate memory");
|
||||
free(fn);
|
||||
return PM3_EMALLOC;
|
||||
}
|
||||
snprintf(backupFilename, fnLen, "%s.bak", fn);
|
||||
snprintf(backupFilename, fn_len, "%s.bak", fn);
|
||||
|
||||
// remove old backup file
|
||||
if (fileExists(backupFilename)) {
|
||||
if (remove(backupFilename) != 0) {
|
||||
PrintAndLogEx(FAILED, "Error - could not delete old settings backup file \"%s\"", backupFilename);
|
||||
@@ -142,6 +143,7 @@ int preferences_save(void) {
|
||||
}
|
||||
}
|
||||
|
||||
// rename file to backup file
|
||||
if (fileExists(fn)) {
|
||||
if (rename(fn, backupFilename) != 0) {
|
||||
PrintAndLogEx(FAILED, "Error - could not backup settings file \"%s\" to \"%s\"", fn, backupFilename);
|
||||
@@ -154,8 +156,9 @@ int preferences_save(void) {
|
||||
uint8_t dummyData = 0x00;
|
||||
size_t dummyDL = 0x01;
|
||||
|
||||
if (saveFileJSON(fn, jsfCustom, &dummyData, dummyDL, &preferences_save_callback) != PM3_SUCCESS)
|
||||
if (saveFileJSONex(fn, jsfCustom, &dummyData, dummyDL, true, &preferences_save_callback, spItemCount) != PM3_SUCCESS) {
|
||||
PrintAndLogEx(ERR, "Error saving preferences to \"%s\"", fn);
|
||||
}
|
||||
|
||||
free(fn);
|
||||
free(backupFilename);
|
||||
|
||||
Reference in New Issue
Block a user