X-Git-Url: http://cvs.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/blobdiff_plain/d3a22c7dfa87bf5e21d228849a602194be4a0895..c0e6c18bf5e0a25d57a14dd04224f4a02fd1c675:/client/cmdhfmf.c

diff --git a/client/cmdhfmf.c b/client/cmdhfmf.c
index 49928c9a..0229c947 100644
--- a/client/cmdhfmf.c
+++ b/client/cmdhfmf.c
@@ -1282,7 +1282,7 @@ int CmdHF14AMfESave(const char *Cmd)
 
 	char ctmp = param_getchar(Cmd, 0);
 	
-	if ( ctmp == 'h') {
+	if ( ctmp == 'h' || ctmp == 'H') {
 		PrintAndLog("It saves emul dump into the file `filename.eml` or `cardID.eml`");		
 		PrintAndLog(" Usage:  hf mf esave [card memory] [file name w/o `.eml`]");
 		PrintAndLog("  [card memory]: 0 = 320 bytes (Mifare Mini), 1 = 1K (default), 2 = 2K, 4 = 4K");
@@ -1327,7 +1327,12 @@ int CmdHF14AMfESave(const char *Cmd)
 	
 	// open file
 	f = fopen(filename, "w+");
-
+	
+	if ( !f ) {
+		PrintAndLog("Can't open file %s ", filename);
+		return 1;
+	}
+	
 	// put hex
 	for (i = 0; i < numBlocks; i++) {
 		if (mfEmlGetMem(buf, i, 1)) {
@@ -1506,15 +1511,15 @@ int CmdHF14AMfCSetBlk(const char *Cmd)
 int CmdHF14AMfCLoad(const char *Cmd)
 {
 	FILE * f;
-	char filename[FILE_PATH_SIZE];
+	char filename[FILE_PATH_SIZE] = {0x00};
 	char * fnameptr = filename;
-	char buf[64];
-	uint8_t buf8[64];
+	char buf[64] = {0x00};
+	uint8_t buf8[64] = {0x00};
 	uint8_t fillFromEmulator = 0;
 	int i, len, blockNum, flags;
 	
-	memset(filename, 0, sizeof(filename));
-	memset(buf, 0, sizeof(buf));
+	// memset(filename, 0, sizeof(filename));
+	// memset(buf, 0, sizeof(buf));
 
 	if (param_getchar(Cmd, 0) == 'h' || param_getchar(Cmd, 0)== 0x00) {
 		PrintAndLog("It loads magic Chinese card (only works with!!!) from the file `filename.eml`");
@@ -1670,14 +1675,14 @@ int CmdHF14AMfCGetSc(const char *Cmd) {
 int CmdHF14AMfCSave(const char *Cmd) {
 
 	FILE * f;
-	char filename[FILE_PATH_SIZE];
+	char filename[FILE_PATH_SIZE] = {0x00};
 	char * fnameptr = filename;
 	uint8_t fillFromEmulator = 0;
-	uint8_t buf[64];
+	uint8_t buf[64] = {0x00};
 	int i, j, len, flags;
 	
-	memset(filename, 0, sizeof(filename));
-	memset(buf, 0, sizeof(buf));
+	// memset(filename, 0, sizeof(filename));
+	// memset(buf, 0, sizeof(buf));
 
 	if (param_getchar(Cmd, 0) == 'h') {
 		PrintAndLog("It saves `magic Chinese` card dump into the file `filename.eml` or `cardID.eml`");
@@ -1731,6 +1736,11 @@ int CmdHF14AMfCSave(const char *Cmd) {
 	
 		// open file
 		f = fopen(filename, "w+");
+		
+		if (f == NULL) {
+			PrintAndLog("File not found or locked.");
+			return 1;
+		}
 
 		// put hex
 		flags = CSETBLOCK_INIT_FIELD + CSETBLOCK_WUPC;
@@ -1946,7 +1956,7 @@ int GetCardSize()
 	if ( ((atqa & 0xffff) == 0x0008) && (sak == 0x38) ) return 4;
 
 	
-	PrintAndLog("BEFOOO  1K %02X",  (atqa & 0xff0f));
+	//PrintAndLog("BEFOOO  1K %02X",  (atqa & 0xff0f));
 	
 	// MIFARE Plus (4 Byte UID or 4 Byte RID)
 	// MIFARE Plus (7 Byte UID)
@@ -1983,9 +1993,6 @@ static command_t CommandTable[] =
   {"help",		CmdHelp,				1, "This help"},
   {"dbg",		CmdHF14AMfDbg,			0, "Set default debug mode"},
   {"rdbl",		CmdHF14AMfRdBl,			0, "Read MIFARE classic block"},
-  //{"urdbl",              CmdHF14AMfURdBl,                 0, "Read MIFARE Ultralight block"},
-  //{"urdcard",           CmdHF14AMfURdCard,               0,"Read MIFARE Ultralight Card"},
-  //{"uwrbl",		CmdHF14AMfUWrBl,		0,"Write MIFARE Ultralight block"},
   {"rdsc",		CmdHF14AMfRdSc,			0, "Read MIFARE classic sector"},
   {"dump",		CmdHF14AMfDump,			0, "Dump MIFARE classic tag to binary file"},
   {"restore",	CmdHF14AMfRestore,		0, "Restore MIFARE classic binary file to BLANK tag"},
@@ -2003,9 +2010,9 @@ static command_t CommandTable[] =
   {"ecfill",	CmdHF14AMfECFill,		0, "Fill simulator memory with help of keys from simulator"},
   {"ekeyprn",	CmdHF14AMfEKeyPrn,		0, "Print keys from simulator memory"},
   {"csetuid",	CmdHF14AMfCSetUID,		0, "Set UID for magic Chinese card"},
-  {"csetblk",	CmdHF14AMfCSetBlk,		0, "Write block into magic Chinese card"},
-  {"cgetblk",	CmdHF14AMfCGetBlk,		0, "Read block from magic Chinese card"},
-  {"cgetsc",	CmdHF14AMfCGetSc,		0, "Read sector from magic Chinese card"},
+  {"csetblk",	CmdHF14AMfCSetBlk,		0, "Write block - Magic Chinese card"},
+  {"cgetblk",	CmdHF14AMfCGetBlk,		0, "Read block - Magic Chinese card"},
+  {"cgetsc",	CmdHF14AMfCGetSc,		0, "Read sector - Magic Chinese card"},
   {"cload",		CmdHF14AMfCLoad,		0, "Load dump into magic Chinese card"},
   {"csave",		CmdHF14AMfCSave,		0, "Save dump from magic Chinese card into file or emulator"},
   {NULL, NULL, 0, NULL}