]> git.zerfleddert.de Git - proxmark3-svn/commitdiff
CHG: "hf mf hardnested" - less printing
authoriceman1001 <iceman@iuse.se>
Fri, 21 Oct 2016 14:06:53 +0000 (16:06 +0200)
committericeman1001 <iceman@iuse.se>
Fri, 21 Oct 2016 14:06:53 +0000 (16:06 +0200)
CHG: some filehandles = NULL.

15 files changed:
armsrc/hitagS.c
client/cmddata.c
client/cmdhfmf.c
client/cmdhfmfhard.c
client/cmdhfmfhard.h
client/cmdhfmfu.c
client/cmdlft55xx.c
client/loclass/elite_crack.c
client/loclass/fileutils.c
client/loclass/ikeys.c
client/mifarehost.c
client/ui.c
client/util.c
common/lfdemod.c
common/lfdemod.h

index 036b5ce67c322b21173c8e54b154906e0d08cf42..45387c4f0093639986bb34d5946de0545e33ed4a 100644 (file)
@@ -1026,8 +1026,7 @@ void SimulateHitagSTag(bool tag_mem_supplied, byte_t* data) {
 // Set up simulator mode, frequency divisor which will drive the FPGA
 // and analog mux selection.
        FpgaDownloadAndGo(FPGA_BITSTREAM_LF);
-       FpgaWriteConfWord(
-       FPGA_MAJOR_MODE_LF_EDGE_DETECT | FPGA_LF_EDGE_DETECT_READER_FIELD);
+       FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_EDGE_DETECT | FPGA_LF_EDGE_DETECT_READER_FIELD);
        FpgaSendCommand(FPGA_CMD_SET_DIVISOR, 95); //125Khz
        SetAdcMuxFor(GPIO_MUXSEL_LOPKD);
        RELAY_OFF();
index f263bbe9ef4a52f1edb650de13b085abb5166c28..169b0acebd7194644a5a7682b115ed4c0ef4d5b0 100644 (file)
@@ -2216,7 +2216,10 @@ int CmdLoad(const char *Cmd)
                GraphBuffer[GraphTraceLen] = atoi(line);
                GraphTraceLen++;
        }
-       fclose(f);
+       if (f) {
+               fclose(f);
+               f = NULL;
+       }
        PrintAndLog("loaded %d samples", GraphTraceLen);
        RepaintGraphWindow();
        return 0;
@@ -2290,7 +2293,10 @@ int CmdSave(const char *Cmd)
        for (i = 0; i < GraphTraceLen; i++) {
                fprintf(f, "%d\n", GraphBuffer[i]);
        }
-       fclose(f);
+       if (f) {
+               fclose(f);
+               f = NULL;
+       }
        PrintAndLog("saved to '%s'", Cmd);
        return 0;
 }
index 6ddf845aa446ab7fbaf00117eb9e7631d694e404..dc8f78982dca416c58f756928932077760d9678a 100644 (file)
@@ -475,6 +475,7 @@ int CmdHF14AMfDump(const char *Cmd) {
                if ( bytes_read == 0) {\r
                        PrintAndLog("File reading error.");\r
                        fclose(fin);\r
+                       fin = NULL;\r
                        return 2;\r
                }\r
        }\r
@@ -485,12 +486,14 @@ int CmdHF14AMfDump(const char *Cmd) {
                if ( bytes_read == 0) {\r
                        PrintAndLog("File reading error.");\r
                        fclose(fin);\r
+                       fin = NULL;\r
                        return 2;\r
                }\r
        }\r
        \r
        fclose(fin);\r
-\r
+       fin = NULL;\r
+                       \r
        PrintAndLog("|-----------------------------------------|");\r
        PrintAndLog("|------ Reading sector access bits...-----|");\r
        PrintAndLog("|-----------------------------------------|");\r
@@ -596,6 +599,7 @@ int CmdHF14AMfDump(const char *Cmd) {
                uint16_t numblocks = FirstBlockOfSector(numSectors - 1) + NumBlocksPerSector(numSectors - 1);\r
                fwrite(carddata, 1, 16*numblocks, fout);\r
                fclose(fout);\r
+               fout = NULL;            \r
                PrintAndLog("Dumped %d blocks (%d bytes) to file dumpdata.bin", numblocks, 16*numblocks);\r
        }\r
                \r
@@ -644,6 +648,7 @@ int CmdHF14AMfRestore(const char *Cmd) {
                if ( bytes_read == 0) {\r
                        PrintAndLog("File reading error (dumpkeys.bin).");\r
                        fclose(fkeys);\r
+                       fkeys = NULL;\r
                        return 2;\r
                }\r
        }\r
@@ -653,6 +658,7 @@ int CmdHF14AMfRestore(const char *Cmd) {
                if ( bytes_read == 0) {\r
                        PrintAndLog("File reading error (dumpkeys.bin).");\r
                        fclose(fkeys);\r
+                       fkeys = NULL;\r
                        return 2;\r
                }\r
        }\r
@@ -673,6 +679,7 @@ int CmdHF14AMfRestore(const char *Cmd) {
                        if ( bytes_read == 0) {\r
                                PrintAndLog("File reading error (dumpdata.bin).");\r
                                fclose(fdump);\r
+                               fdump = NULL;                           \r
                                return 2;\r
                        }\r
                                        \r
@@ -708,6 +715,7 @@ int CmdHF14AMfRestore(const char *Cmd) {
        }\r
        \r
        fclose(fdump);\r
+       fdump = NULL;   \r
        return 0;\r
 }\r
 \r
index 0687e2bb9fefea5c1a057bd608ecf265e9ce888b..cb234e03e89733aa6decefd44c602fa71da86c7f 100644 (file)
 //   Mifare Classic Cards" in Proceedings of the 22nd ACM SIGSAC Conference on 
 //   Computer and Communications Security, 2015
 //-----------------------------------------------------------------------------
-
-#include <stdlib.h> 
-#include <stdio.h>
-#include <string.h>
-#include <pthread.h>
-#include <locale.h>
-#include <math.h>
-#include "proxmark3.h"
-#include "cmdmain.h"
-#include "ui.h"
-#include "util.h"
-#include "nonce2key/crapto1.h"
-#include "nonce2key/crypto1_bs.h"
-#include "parity.h"
-#ifdef __WIN32
-       #include <windows.h>
-#endif
-// don't include for APPLE/mac which has malloc stuff elsewhere.
-#ifndef __APPLE__
-       #include <malloc.h>
-#endif
-#include <assert.h>
+#include "cmdhfmfhard.h"
 
 #define CONFIDENCE_THRESHOLD   0.95            // Collect nonces until we are certain enough that the following brute force is successfull
 #define GOOD_BYTES_REQUIRED    13              // default 28, could be smaller == faster
@@ -639,6 +618,7 @@ static int read_nonce_file(void)
        if ( bytes_read == 0) {
                PrintAndLog("File reading error.");
                fclose(fnonces);
+               fnonces = NULL;
                return 1;
        }
        cuid = bytes_to_num(read_buf, 4);
@@ -656,6 +636,7 @@ static int read_nonce_file(void)
                total_num_nonces += 2;
        }
        fclose(fnonces);
+       fnonces = NULL;
        PrintAndLog("Read %d nonces from file. cuid=%08x, Block=%d, Keytype=%c", total_num_nonces, cuid, trgBlockNo, trgKeyType==0?'A':'B');
        return 0;
 }
@@ -1339,8 +1320,8 @@ static bool generate_candidates(uint16_t sum_a0, uint16_t sum_a8)
        for (uint16_t p = 0; p <= 16; p += 2) {
                for (uint16_t q = 0; q <= 16; q += 2) {
                        if (p*(16-q) + (16-p)*q == sum_a0) {
-                               printf("Reducing Partial Statelists (p,q) = (%d,%d) with lengths %d, %d\n", 
-                                               p, q, partial_statelist[p].len[ODD_STATE], partial_statelist[q].len[EVEN_STATE]);
+                               // printf("Reducing Partial Statelists (p,q) = (%d,%d) with lengths %d, %d\n", 
+                                               // p, q, partial_statelist[p].len[ODD_STATE], partial_statelist[q].len[EVEN_STATE]);
                                for (uint16_t r = 0; r <= 16; r += 2) {
                                        for (uint16_t s = 0; s <= 16; s += 2) {
                                                if (r*(16-s) + (16-r)*s == sum_a8) {
index d339ae3c3a2c222d0c3ff04465d834097929b292..72cc850ad1ad8470d95f3a369591cf6a1638db2e 100644 (file)
@@ -8,4 +8,32 @@
 // hf mf hardnested command
 //-----------------------------------------------------------------------------
 
+#ifndef CMDHFMFHARD_H__
+#define CMDHFMFHARD_H__
+
+#include "sleep.h"
+#include <stdlib.h> 
+#include <stdio.h>
+#include <string.h>
+#include <pthread.h>
+#include <locale.h>
+#include <math.h>
+#include "proxmark3.h"
+#include "cmdmain.h"
+#include "ui.h"
+#include "util.h"
+#include "nonce2key/crapto1.h"
+#include "nonce2key/crypto1_bs.h"
+#include "parity.h"
+#ifdef __WIN32
+       #include <windows.h>
+#endif
+// don't include for APPLE/mac which has malloc stuff elsewhere.
+#ifndef __APPLE__
+       #include <malloc.h>
+#endif
+#include <assert.h>
+
 int mfnestedhard(uint8_t blockNo, uint8_t keyType, uint8_t *key, uint8_t trgBlockNo, uint8_t trgKeyType, uint8_t *trgkey, bool nonce_file_read, bool nonce_file_write, bool slow, int tests);
+
+#endif
index 336fd64afa084d853193505a5bf7f34f21d93f46..1b43898039da18914e3c5211643a36ad5c44f4ec 100644 (file)
@@ -1679,8 +1679,10 @@ int CmdHF14AMfUDump(const char *Cmd){
                return 1;
        }
        fwrite( dump_file_data, 1, Pages*4 + DUMP_PREFIX_LENGTH, fout );
-       fclose(fout);
-       
+       if (fout) {
+               fclose(fout);
+               fout = NULL;
+       }
        PrintAndLog("Dumped %d pages, wrote %d bytes to %s", Pages+(DUMP_PREFIX_LENGTH/4), Pages*4 + DUMP_PREFIX_LENGTH, filename);
        return 0;
 }
index 28149efff6f02268c7c050e20e7ea344b94aac3b..f28f84ceff0475c5206ae27d51a61f9ae5219032 100644 (file)
@@ -1491,7 +1491,10 @@ int CmdT55xxBruteForce(const char *Cmd) {
                                if (!p) {\r
                                        PrintAndLog("Cannot allocate memory for defaultKeys");\r
                                        free(keyBlock);\r
-                                       fclose(f);\r
+                                       if (f) {\r
+                                               fclose(f);\r
+                                               f = NULL;\r
+                                       }\r
                                        return 2;\r
                                }\r
                                keyBlock = p;\r
@@ -1502,8 +1505,10 @@ int CmdT55xxBruteForce(const char *Cmd) {
                        keycnt++;\r
                        memset(buf, 0, sizeof(buf));\r
                }               \r
-               fclose(f);\r
-               \r
+               if (f) {\r
+                       fclose(f);\r
+                       f = NULL;\r
+               }\r
                if (keycnt == 0) {\r
                        PrintAndLog("No keys found in file");\r
                        free(keyBlock);\r
index a282ec5022f07b3b16ddc0173451d55cce7cf9c5..2395a178802554c25cdfddab7c160fb9bf2d58b5 100644 (file)
@@ -552,7 +552,6 @@ int bruteforceDump(uint8_t dump[], size_t dumpsize, uint16_t keytable[])
  */
 int bruteforceFile(const char *filename, uint16_t keytable[])
 {
-
        FILE *f = fopen(filename, "rb");
        if(!f) {
                prnlog("Failed to read from file '%s'", filename);
@@ -565,19 +564,23 @@ int bruteforceFile(const char *filename, uint16_t keytable[])
 
        if (fsize < 0) {
                prnlog("Error, when getting filesize");
-               fclose(f);
+               if (f) {
+                       fclose(f);
+                       f = NULL;
+               }
                return 1;
        }
 
        uint8_t *dump = malloc(fsize);
        size_t bytes_read = fread(dump, 1, fsize, f);
 
-       fclose(f);
-    if (bytes_read < fsize)
-    {
+       if (f) {
+               fclose(f);
+               f = NULL;
+       }
+    if (bytes_read < fsize) {
         prnlog("Error, could only read %d bytes (should be %d)",bytes_read, fsize );
     }
-
        uint8_t res = bruteforceDump(dump,fsize,keytable);
        free(dump);
        return res;
index e5e5c5b0569270c422c53e83078d738a64f9e106..fd18b96421f50b8b43185e9d3d3b1308b735154c 100644 (file)
@@ -77,17 +77,19 @@ int saveFile(const char *preferredName, const char *suffix, const void* data, si
        /* We should have a valid filename now, e.g. dumpdata-3.bin */
 
        /*Opening file for writing in binary mode*/
-       FILE *fileHandle=fopen(fileName,"wb");
-       if(!fileHandle) {
+       FILE *f = fopen(fileName,"wb");
+       if (!f) {
                prnlog("Failed to write to file '%s'", fileName);
                free(fileName);
                return 1;
        }
-       fwrite(data, 1, datalen, fileHandle);
-       fclose(fileHandle);
+       fwrite(data, 1, datalen, f);
+       if (f) {
+               fclose(f);
+               f = NULL;
+       }
        prnlog("Saved data to '%s'", fileName);
        free(fileName);
-
        return 0;
 }
 
index 73da2ce6cd686b7bd0320c090a2531f2f19053a3..0ba788d7de39c0daa6ffb726784c47dbea9c06ce 100644 (file)
@@ -748,7 +748,10 @@ int readKeyFile(uint8_t key[8])
        if ( bytes_read == 1) {
                retval = 0;     
        }
-       fclose(f);
+       if (f) {
+               fclose(f);
+               f = NULL;
+       }
        return retval;
 }
 
index b41c368702e6cbb4c94e82ee519ff9f2b5e7c8f5..b7cd3b590cea356100bfdc8f7be793f91e388f00 100644 (file)
@@ -412,14 +412,20 @@ int loadTraceCard(uint8_t *tuid, uint8_t uidlen) {
                memset(buf, 0, sizeof(buf));\r
                if (fgets(buf, sizeof(buf), f) == NULL) {\r
                        PrintAndLog("No trace file found or reading error.");\r
-                       fclose(f);\r
+                       if (f) {\r
+                               fclose(f);\r
+                               f = NULL;\r
+                       }\r
                        return 2;\r
                }\r
 \r
                if (strlen(buf) < 32){\r
                        if (feof(f)) break;\r
                        PrintAndLog("File content error. Block data must include 32 HEX symbols");\r
-                       fclose(f);\r
+                       if (f) {\r
+                               fclose(f);\r
+                               f = NULL;\r
+                       }\r
                        return 2;\r
                }\r
                for (i = 0; i < 32; i += 2)\r
@@ -429,7 +435,10 @@ int loadTraceCard(uint8_t *tuid, uint8_t uidlen) {
 \r
                blockNum++;\r
        }\r
-       fclose(f);\r
+       if (f) {\r
+               fclose(f);\r
+               f = NULL;\r
+       }\r
        return 0;\r
 }\r
 \r
@@ -447,7 +456,10 @@ int saveTraceCard(void) {
                fprintf(f,"\n");\r
        }\r
        fflush(f);\r
-       fclose(f);\r
+       if (f) {\r
+               fclose(f);\r
+               f = NULL;\r
+       }\r
        return 0;\r
 }\r
 \r
index cfaec6a510dcfaadfe4edc725a41eeddf461097c..6819f649f0b47b3f0ad398f5ae61c0801007b72c 100644 (file)
@@ -77,7 +77,7 @@ void PrintAndLog(char *fmt, ...)
 }
 
 void SetLogFilename(char *fn) {
-  logfilename = fn;
+       logfilename = fn;
 }
  
 void iceIIR_Butterworth(int *data, const size_t len){
index c5c7d7fe2f2fc3d019507426581c84bf43cdea64..a6ba8e81d16622d951f0e15a7684fdfa4f5ac9a9 100644 (file)
@@ -63,7 +63,10 @@ void AddLogLine(char *file, char *extData, char *c) {
        fprintf(f, "%s", extData);
        fprintf(f, "%s\n", c);
        fflush(f);
-       fclose(f);
+       if (f) {
+               fclose(f);
+               f = NULL;
+       }
 }
 
 void AddLogHex(char *fileName, char *extData, const uint8_t * data, const size_t len){
index 8bbe5bebf884a594a18c1c163eae165ba61b7f3e..5fec933f5d18102f11f94a0f1a0b673d44f63860 100644 (file)
@@ -25,15 +25,13 @@ void dummy(char *fmt, ...){}
 #define prnt dummy
 #endif
 
-uint8_t justNoise(uint8_t *BitStream, size_t size)
-{
-       static const uint8_t THRESHOLD = 123;
-       //test samples are not just noise
-       uint8_t justNoise1 = 1;
-       for(size_t idx=0; idx < size && justNoise1 ;idx++){
-               justNoise1 = BitStream[idx] < THRESHOLD;
-       }
-       return justNoise1;
+//test samples are not just noise
+uint8_t justNoise(uint8_t *bits, size_t size) {
+       #define THRESHOLD 123
+       uint8_t val = 1;
+       for(size_t idx=0; idx < size && val ;idx++)
+               val = bits[idx] < THRESHOLD;
+       return val;
 }
 
 //by marshmellow
index d540a2df2e551da393e6ee44664c4c731abb429c..60e34732ecc154737f64cb2e4f0e13d943189f76 100644 (file)
@@ -17,6 +17,7 @@
 #include <stdbool.h> // for bool
 
 //generic
+uint8_t  justNoise(uint8_t *bits, size_t size);
 size_t   addParity(uint8_t *BitSource, uint8_t *dest, uint8_t sourceLen, uint8_t pLen, uint8_t pType);
 int      askdemod(uint8_t *BinStream, size_t *size, int *clk, int *invert, int maxErr, uint8_t amp, uint8_t askType);
 int      BiphaseRawDecode(uint8_t * BitStream, size_t *size, int offset, int invert);
Impressum, Datenschutz