summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
3c528f5)
CHG: some filehandles = NULL.
15 files changed:
// Set up simulator mode, frequency divisor which will drive the FPGA
// and analog mux selection.
FpgaDownloadAndGo(FPGA_BITSTREAM_LF);
// 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();
FpgaSendCommand(FPGA_CMD_SET_DIVISOR, 95); //125Khz
SetAdcMuxFor(GPIO_MUXSEL_LOPKD);
RELAY_OFF();
GraphBuffer[GraphTraceLen] = atoi(line);
GraphTraceLen++;
}
GraphBuffer[GraphTraceLen] = atoi(line);
GraphTraceLen++;
}
+ if (f) {
+ fclose(f);
+ f = NULL;
+ }
PrintAndLog("loaded %d samples", GraphTraceLen);
RepaintGraphWindow();
return 0;
PrintAndLog("loaded %d samples", GraphTraceLen);
RepaintGraphWindow();
return 0;
for (i = 0; i < GraphTraceLen; i++) {
fprintf(f, "%d\n", GraphBuffer[i]);
}
for (i = 0; i < GraphTraceLen; i++) {
fprintf(f, "%d\n", GraphBuffer[i]);
}
+ if (f) {
+ fclose(f);
+ f = NULL;
+ }
PrintAndLog("saved to '%s'", Cmd);
return 0;
}
PrintAndLog("saved to '%s'", Cmd);
return 0;
}
if ( bytes_read == 0) {\r
PrintAndLog("File reading error.");\r
fclose(fin);\r
if ( bytes_read == 0) {\r
PrintAndLog("File reading error.");\r
fclose(fin);\r
if ( bytes_read == 0) {\r
PrintAndLog("File reading error.");\r
fclose(fin);\r
if ( bytes_read == 0) {\r
PrintAndLog("File reading error.");\r
fclose(fin);\r
return 2;\r
}\r
}\r
\r
fclose(fin);\r
return 2;\r
}\r
}\r
\r
fclose(fin);\r
PrintAndLog("|-----------------------------------------|");\r
PrintAndLog("|------ Reading sector access bits...-----|");\r
PrintAndLog("|-----------------------------------------|");\r
PrintAndLog("|-----------------------------------------|");\r
PrintAndLog("|------ Reading sector access bits...-----|");\r
PrintAndLog("|-----------------------------------------|");\r
uint16_t numblocks = FirstBlockOfSector(numSectors - 1) + NumBlocksPerSector(numSectors - 1);\r
fwrite(carddata, 1, 16*numblocks, fout);\r
fclose(fout);\r
uint16_t numblocks = FirstBlockOfSector(numSectors - 1) + NumBlocksPerSector(numSectors - 1);\r
fwrite(carddata, 1, 16*numblocks, fout);\r
fclose(fout);\r
PrintAndLog("Dumped %d blocks (%d bytes) to file dumpdata.bin", numblocks, 16*numblocks);\r
}\r
\r
PrintAndLog("Dumped %d blocks (%d bytes) to file dumpdata.bin", numblocks, 16*numblocks);\r
}\r
\r
if ( bytes_read == 0) {\r
PrintAndLog("File reading error (dumpkeys.bin).");\r
fclose(fkeys);\r
if ( bytes_read == 0) {\r
PrintAndLog("File reading error (dumpkeys.bin).");\r
fclose(fkeys);\r
if ( bytes_read == 0) {\r
PrintAndLog("File reading error (dumpkeys.bin).");\r
fclose(fkeys);\r
if ( bytes_read == 0) {\r
PrintAndLog("File reading error (dumpkeys.bin).");\r
fclose(fkeys);\r
if ( bytes_read == 0) {\r
PrintAndLog("File reading error (dumpdata.bin).");\r
fclose(fdump);\r
if ( bytes_read == 0) {\r
PrintAndLog("File reading error (dumpdata.bin).");\r
fclose(fdump);\r
// Mifare Classic Cards" in Proceedings of the 22nd ACM SIGSAC Conference on
// Computer and Communications Security, 2015
//-----------------------------------------------------------------------------
// 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
#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
if ( bytes_read == 0) {
PrintAndLog("File reading error.");
fclose(fnonces);
if ( bytes_read == 0) {
PrintAndLog("File reading error.");
fclose(fnonces);
return 1;
}
cuid = bytes_to_num(read_buf, 4);
return 1;
}
cuid = bytes_to_num(read_buf, 4);
total_num_nonces += 2;
}
fclose(fnonces);
total_num_nonces += 2;
}
fclose(fnonces);
PrintAndLog("Read %d nonces from file. cuid=%08x, Block=%d, Keytype=%c", total_num_nonces, cuid, trgBlockNo, trgKeyType==0?'A':'B');
return 0;
}
PrintAndLog("Read %d nonces from file. cuid=%08x, Block=%d, Keytype=%c", total_num_nonces, cuid, trgBlockNo, trgKeyType==0?'A':'B');
return 0;
}
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) {
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) {
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) {
// hf mf hardnested command
//-----------------------------------------------------------------------------
// 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);
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);
return 1;
}
fwrite( dump_file_data, 1, Pages*4 + DUMP_PREFIX_LENGTH, fout );
return 1;
}
fwrite( dump_file_data, 1, Pages*4 + DUMP_PREFIX_LENGTH, 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;
}
PrintAndLog("Dumped %d pages, wrote %d bytes to %s", Pages+(DUMP_PREFIX_LENGTH/4), Pages*4 + DUMP_PREFIX_LENGTH, filename);
return 0;
}
if (!p) {\r
PrintAndLog("Cannot allocate memory for defaultKeys");\r
free(keyBlock);\r
if (!p) {\r
PrintAndLog("Cannot allocate memory for defaultKeys");\r
free(keyBlock);\r
+ if (f) {\r
+ fclose(f);\r
+ f = NULL;\r
+ }\r
return 2;\r
}\r
keyBlock = p;\r
return 2;\r
}\r
keyBlock = p;\r
keycnt++;\r
memset(buf, 0, sizeof(buf));\r
} \r
keycnt++;\r
memset(buf, 0, sizeof(buf));\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
if (keycnt == 0) {\r
PrintAndLog("No keys found in file");\r
free(keyBlock);\r
*/
int bruteforceFile(const char *filename, 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);
FILE *f = fopen(filename, "rb");
if(!f) {
prnlog("Failed to read from file '%s'", filename);
if (fsize < 0) {
prnlog("Error, when getting filesize");
if (fsize < 0) {
prnlog("Error, when getting filesize");
+ if (f) {
+ fclose(f);
+ f = NULL;
+ }
return 1;
}
uint8_t *dump = malloc(fsize);
size_t bytes_read = fread(dump, 1, fsize, f);
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 );
}
prnlog("Error, could only read %d bytes (should be %d)",bytes_read, fsize );
}
uint8_t res = bruteforceDump(dump,fsize,keytable);
free(dump);
return res;
uint8_t res = bruteforceDump(dump,fsize,keytable);
free(dump);
return res;
/* We should have a valid filename now, e.g. dumpdata-3.bin */
/*Opening file for writing in binary mode*/
/* 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;
}
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);
prnlog("Saved data to '%s'", fileName);
free(fileName);
if ( bytes_read == 1) {
retval = 0;
}
if ( bytes_read == 1) {
retval = 0;
}
+ if (f) {
+ fclose(f);
+ f = NULL;
+ }
memset(buf, 0, sizeof(buf));\r
if (fgets(buf, sizeof(buf), f) == NULL) {\r
PrintAndLog("No trace file found or reading error.");\r
memset(buf, 0, sizeof(buf));\r
if (fgets(buf, sizeof(buf), f) == NULL) {\r
PrintAndLog("No trace file found or reading error.");\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
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
+ if (f) {\r
+ fclose(f);\r
+ f = NULL;\r
+ }\r
return 2;\r
}\r
for (i = 0; i < 32; i += 2)\r
return 2;\r
}\r
for (i = 0; i < 32; i += 2)\r
+ if (f) {\r
+ fclose(f);\r
+ f = NULL;\r
+ }\r
fprintf(f,"\n");\r
}\r
fflush(f);\r
fprintf(f,"\n");\r
}\r
fflush(f);\r
+ if (f) {\r
+ fclose(f);\r
+ f = NULL;\r
+ }\r
}
void SetLogFilename(char *fn) {
}
void SetLogFilename(char *fn) {
}
void iceIIR_Butterworth(int *data, const size_t len){
}
void iceIIR_Butterworth(int *data, const size_t len){
fprintf(f, "%s", extData);
fprintf(f, "%s\n", c);
fflush(f);
fprintf(f, "%s", extData);
fprintf(f, "%s\n", c);
fflush(f);
+ if (f) {
+ fclose(f);
+ f = NULL;
+ }
}
void AddLogHex(char *fileName, char *extData, const uint8_t * data, const size_t len){
}
void AddLogHex(char *fileName, char *extData, const uint8_t * data, const size_t len){
#define prnt dummy
#endif
#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;
#include <stdbool.h> // for bool
//generic
#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);
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);