FIXED: Merged all Holimans code-review issues which should fix a lot of memoryleaks.
This commit is contained in:
@@ -552,7 +552,7 @@ int CmdManchesterDemod(const char *Cmd)
|
||||
|
||||
/* But it does not work if compiling on WIndows: therefore we just allocate a */
|
||||
/* large array */
|
||||
uint8_t BitStream[MAX_GRAPH_TRACE_LEN];
|
||||
uint8_t BitStream[MAX_GRAPH_TRACE_LEN] = {0x00};
|
||||
|
||||
/* Detect high and lows */
|
||||
for (i = 0; i < GraphTraceLen; i++)
|
||||
@@ -564,8 +564,7 @@ int CmdManchesterDemod(const char *Cmd)
|
||||
}
|
||||
|
||||
/* Get our clock */
|
||||
clock = GetClock(Cmd, high, 1);
|
||||
|
||||
clock = GetClock(Cmd, high, 1);
|
||||
int tolerance = clock/4;
|
||||
|
||||
/* Detect first transition */
|
||||
@@ -583,8 +582,6 @@ int CmdManchesterDemod(const char *Cmd)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
PrintAndLog("Clock: %d", clock);
|
||||
|
||||
/* If we're not working with 1/0s, demod based off clock */
|
||||
if (high != 1)
|
||||
@@ -723,21 +720,22 @@ int CmdManchesterDemod(const char *Cmd)
|
||||
int CmdManchesterMod(const char *Cmd)
|
||||
{
|
||||
int i, j;
|
||||
int clock;
|
||||
int bit, lastbit, wave;
|
||||
|
||||
/* Get our clock */
|
||||
clock = GetClock(Cmd, 0, 1);
|
||||
|
||||
int clock = GetClock(Cmd, 0, 1);
|
||||
int clock1 = GetT55x7Clock( GraphBuffer, GraphTraceLen, 0 );
|
||||
PrintAndLog("MAN MOD CLOCKS: %d ice %d", clock,clock1);
|
||||
|
||||
int half = (int)(clock/2);
|
||||
|
||||
wave = 0;
|
||||
lastbit = 1;
|
||||
for (i = 0; i < (int)(GraphTraceLen / clock); i++)
|
||||
{
|
||||
bit = GraphBuffer[i * clock] ^ 1;
|
||||
|
||||
for (j = 0; j < (int)(clock/2); j++)
|
||||
for (j = 0; j < half; ++j)
|
||||
GraphBuffer[(i * clock) + j] = bit ^ lastbit ^ wave;
|
||||
for (j = (int)(clock/2); j < clock; j++)
|
||||
for (j = half; j < clock; ++j)
|
||||
GraphBuffer[(i * clock) + j] = bit ^ lastbit ^ wave ^ 1;
|
||||
|
||||
/* Keep track of how we start our wave and if we changed or not this time */
|
||||
|
||||
@@ -561,8 +561,9 @@ int CmdHF15CmdRaw (const char *cmd) {
|
||||
*/
|
||||
int prepareHF15Cmd(char **cmd, UsbCommand *c, uint8_t iso15cmd[], int iso15cmdlen) {
|
||||
int temp;
|
||||
uint8_t *req=c->d.asBytes, uid[8];
|
||||
uint32_t reqlen=0;
|
||||
uint8_t *req = c->d.asBytes;
|
||||
uint8_t uid[8] = {0x00};
|
||||
uint32_t reqlen = 0;
|
||||
|
||||
// strip
|
||||
while (**cmd==' ' || **cmd=='\t') (*cmd)++;
|
||||
|
||||
@@ -501,7 +501,9 @@ int CmdHFiClassReader_Dump(const char *Cmd)
|
||||
SendCommand(&c);
|
||||
|
||||
UsbCommand resp;
|
||||
|
||||
uint8_t key_sel[8] = {0x00};
|
||||
uint8_t key_sel_p[8] = {0x00};
|
||||
|
||||
if (WaitForResponseTimeout(CMD_ACK,&resp,4500)) {
|
||||
uint8_t isOK = resp.arg[0] & 0xff;
|
||||
uint8_t * data = resp.d.asBytes;
|
||||
@@ -519,8 +521,7 @@ int CmdHFiClassReader_Dump(const char *Cmd)
|
||||
{
|
||||
if(elite)
|
||||
{
|
||||
uint8_t key_sel[8] = {0};
|
||||
uint8_t key_sel_p[8] = { 0 };
|
||||
|
||||
//Get the key index (hash1)
|
||||
uint8_t key_index[8] = {0};
|
||||
|
||||
|
||||
@@ -521,8 +521,6 @@ int CmdHF14AMfDump(const char *Cmd)
|
||||
|
||||
int size = GetCardSize();
|
||||
char cmdp = param_getchar(Cmd, 0);
|
||||
|
||||
|
||||
|
||||
if ( size > -1)
|
||||
cmdp = (char)(48+size);
|
||||
@@ -548,7 +546,7 @@ int CmdHF14AMfDump(const char *Cmd)
|
||||
}
|
||||
|
||||
if ((fin = fopen("dumpkeys.bin","rb")) == NULL) {
|
||||
PrintAndLog("Could not find file dumpkeys.bin");
|
||||
PrintAndLog("Could not find file dumpkeys.bin");
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -556,6 +554,7 @@ int CmdHF14AMfDump(const char *Cmd)
|
||||
for (sectorNo=0; sectorNo<numSectors; sectorNo++) {
|
||||
if (fread( keyA[sectorNo], 1, 6, fin ) == 0) {
|
||||
PrintAndLog("File reading error.");
|
||||
fclose(fin);
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
@@ -564,10 +563,13 @@ int CmdHF14AMfDump(const char *Cmd)
|
||||
for (sectorNo=0; sectorNo<numSectors; sectorNo++) {
|
||||
if (fread( keyB[sectorNo], 1, 6, fin ) == 0) {
|
||||
PrintAndLog("File reading error.");
|
||||
fclose(fin);
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
fclose(fin);
|
||||
|
||||
PrintAndLog("|-----------------------------------------|");
|
||||
PrintAndLog("|------ Reading sector access bits...-----|");
|
||||
PrintAndLog("|-----------------------------------------|");
|
||||
@@ -673,7 +675,6 @@ int CmdHF14AMfDump(const char *Cmd)
|
||||
PrintAndLog("Dumped %d blocks (%d bytes) to file dumpdata.bin", numblocks, 16*numblocks);
|
||||
}
|
||||
|
||||
fclose(fin);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1169,11 +1170,12 @@ int CmdHF14AMfChk(const char *Cmd)
|
||||
keycnt++;
|
||||
memset(buf, 0, sizeof(buf));
|
||||
}
|
||||
fclose(f);
|
||||
} else {
|
||||
PrintAndLog("File: %s: not found or locked.", filename);
|
||||
free(keyBlock);
|
||||
return 1;
|
||||
fclose(f);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1454,6 +1456,7 @@ int CmdHF14AMfELoad(const char *Cmd)
|
||||
break;
|
||||
}
|
||||
PrintAndLog("File reading error.");
|
||||
fclose(f);
|
||||
return 2;
|
||||
}
|
||||
if (strlen(buf) < 32){
|
||||
@@ -1478,6 +1481,7 @@ int CmdHF14AMfELoad(const char *Cmd)
|
||||
|
||||
if ((blockNum != 16*4) && (blockNum != 32*4 + 8*16)) {
|
||||
PrintAndLog("File content error. There must be 64 or 256 blocks.");
|
||||
fclose(f);
|
||||
return 4;
|
||||
}
|
||||
PrintAndLog("Loaded %d blocks from file: %s", blockNum, filename);
|
||||
@@ -1610,8 +1614,8 @@ int CmdHF14AMfEKeyPrn(const char *Cmd)
|
||||
int CmdHF14AMfCSetUID(const char *Cmd)
|
||||
{
|
||||
uint8_t wipeCard = 0;
|
||||
uint8_t uid[8];
|
||||
uint8_t oldUid[8];
|
||||
uint8_t uid[8] = {0x00};
|
||||
uint8_t oldUid[8] = {0x00};
|
||||
int res;
|
||||
|
||||
if (strlen(Cmd) < 1 || param_getchar(Cmd, 0) == 'h') {
|
||||
|
||||
@@ -410,7 +410,7 @@ int CmdLFSim(const char *Cmd)
|
||||
printf(".");
|
||||
}
|
||||
printf("\n");
|
||||
PrintAndLog("Starting simulator...");
|
||||
PrintAndLog("Starting to simulate");
|
||||
UsbCommand c = {CMD_SIMULATE_TAG_125K, {GraphTraceLen, gap, 0}};
|
||||
SendCommand(&c);
|
||||
return 0;
|
||||
|
||||
@@ -57,7 +57,8 @@ int CmdEM410xRead(const char *Cmd)
|
||||
|
||||
/* get clock */
|
||||
clock = GetClock(Cmd, high, 0);
|
||||
|
||||
|
||||
|
||||
/* parity for our 4 columns */
|
||||
parity[0] = parity[1] = parity[2] = parity[3] = 0;
|
||||
header = rows = 0;
|
||||
@@ -220,8 +221,7 @@ int CmdEM410xSim(const char *Cmd)
|
||||
int clock = 64;
|
||||
|
||||
/* clear our graph */
|
||||
ClearGraph(0);
|
||||
GraphTraceLen = 0;
|
||||
ClearGraph(1);
|
||||
|
||||
/* write it out a few times */
|
||||
for (h = 0; h < 4; h++)
|
||||
@@ -266,12 +266,12 @@ int CmdEM410xSim(const char *Cmd)
|
||||
}
|
||||
|
||||
/* modulate that biatch */
|
||||
CmdManchesterMod("");
|
||||
CmdManchesterMod("64");
|
||||
|
||||
/* booyah! */
|
||||
RepaintGraphWindow();
|
||||
|
||||
CmdLFSim("64");
|
||||
CmdLFSim("");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -296,10 +296,10 @@ int CmdEM410xWatch(const char *Cmd)
|
||||
}
|
||||
|
||||
CmdLFRead(read_h ? "h" : "");
|
||||
CmdSamples("12000");
|
||||
CmdSamples("16000");
|
||||
|
||||
} while (
|
||||
!CmdEM410xRead("64")
|
||||
!CmdEM410xRead("")
|
||||
);
|
||||
return 0;
|
||||
}
|
||||
@@ -363,7 +363,7 @@ int CmdEM4x50Read(const char *Cmd)
|
||||
++i;
|
||||
while ((GraphBuffer[i] > low) && (i<GraphTraceLen))
|
||||
++i;
|
||||
if (j>(MAX_GRAPH_TRACE_LEN/64)) {
|
||||
if (j>=(MAX_GRAPH_TRACE_LEN/64)) {
|
||||
break;
|
||||
}
|
||||
tmpbuff[j++]= i - start;
|
||||
@@ -616,7 +616,7 @@ int CmdWriteWord(const char *Cmd)
|
||||
return 1;
|
||||
}
|
||||
|
||||
PrintAndLog("Writting word %d with data %08X", Word, Data);
|
||||
PrintAndLog("Writing word %d with data %08X", Word, Data);
|
||||
|
||||
c.cmd = CMD_EM4X_WRITE_WORD;
|
||||
c.d.asBytes[0] = 0x0; //Normal mode
|
||||
@@ -629,7 +629,7 @@ int CmdWriteWord(const char *Cmd)
|
||||
|
||||
int CmdWriteWordPWD(const char *Cmd)
|
||||
{
|
||||
int Word = 8; //default to invalid word
|
||||
int Word = 16; //default to invalid word
|
||||
int Data = 0xFFFFFFFF; //default to blank data
|
||||
int Password = 0xFFFFFFFF; //default to blank password
|
||||
UsbCommand c;
|
||||
@@ -641,7 +641,7 @@ int CmdWriteWordPWD(const char *Cmd)
|
||||
return 1;
|
||||
}
|
||||
|
||||
PrintAndLog("Writting word %d with data %08X and password %08X", Word, Data, Password);
|
||||
PrintAndLog("Writing word %d with data %08X and password %08X", Word, Data, Password);
|
||||
|
||||
c.cmd = CMD_EM4X_WRITE_WORD;
|
||||
c.d.asBytes[0] = 0x1; //Password mode
|
||||
|
||||
@@ -482,8 +482,8 @@ static command_t CommandTable[] =
|
||||
{"rdpwd", CmdReadBlkPWD, 0, "<block> <password> -- Read T55xx block data with password mode"},
|
||||
{"wr", CmdWriteBlk, 0, "<data> <block> -- Write T55xx block data (page 0)"},
|
||||
{"wrpwd", CmdWriteBlkPWD, 0, "<data> <block> <password> -- Write T55xx block data with password"},
|
||||
{"trace", CmdReadTrace, 0, "[1] Read T55xx traceability data (page 1 / blk 0-1) "},
|
||||
{"info", CmdInfo, 0, "[1] Read T55xx configuration data (page0 /blk 0)"},
|
||||
{"trace", CmdReadTrace, 0, "[1] Read T55xx traceability data (page 1/ blk 0-1)"},
|
||||
{"info", CmdInfo, 0, "[1] Read T55xx configuration data (page 0/ blk 0)"},
|
||||
{"dump", CmdDump, 0, "[password] Dump T55xx card block 0-7. optional with password"},
|
||||
{"fsk", CmdIceFsk, 0, "FSK demod"},
|
||||
{"man", CmdIceManchester, 0, "Manchester demod (with SST)"},
|
||||
|
||||
@@ -137,9 +137,11 @@ int getCommand(UsbCommand* response)
|
||||
* @return true if command was returned, otherwise false
|
||||
*/
|
||||
bool WaitForResponseTimeout(uint32_t cmd, UsbCommand* response, size_t ms_timeout) {
|
||||
|
||||
|
||||
UsbCommand resp;
|
||||
|
||||
if (response == NULL) {
|
||||
UsbCommand resp;
|
||||
|
||||
response = &resp;
|
||||
}
|
||||
|
||||
|
||||
@@ -21,11 +21,13 @@ int GraphTraceLen;
|
||||
void AppendGraph(int redraw, int clock, int bit)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < (int)(clock / 2); ++i)
|
||||
GraphBuffer[GraphTraceLen++] = bit ^ 1;
|
||||
int half = (int)(clock/2);
|
||||
int firstbit = bit ^ 1;
|
||||
|
||||
for (i = 0; i < half; ++i)
|
||||
GraphBuffer[GraphTraceLen++] = firstbit;
|
||||
|
||||
for (i = (int)(clock / 2); i < clock; ++i)
|
||||
for (i = 0; i <= half; ++i)
|
||||
GraphBuffer[GraphTraceLen++] = bit;
|
||||
|
||||
if (redraw)
|
||||
@@ -72,8 +74,23 @@ int DetectClock(int peak)
|
||||
lastpeak = i;
|
||||
}
|
||||
}
|
||||
|
||||
int clockmod = clock%8;
|
||||
if ( clockmod == 0)
|
||||
return clock;
|
||||
|
||||
// When detected clock is 31 or 33 then return 32
|
||||
|
||||
return clock;
|
||||
printf("Found clock at %d ", clock);
|
||||
switch( clockmod )
|
||||
{
|
||||
case 7: clock++; break;
|
||||
case 6: clock += 2 ; break;
|
||||
case 1: clock--; break;
|
||||
case 2: clock -= 2; break;
|
||||
}
|
||||
printf("- adjusted it to %d \n", clock);
|
||||
return clock;
|
||||
}
|
||||
|
||||
/* Get or auto-detect clock rate */
|
||||
|
||||
@@ -737,16 +737,14 @@ int doTestsWithKnownInputs()
|
||||
|
||||
int readKeyFile(uint8_t key[8])
|
||||
{
|
||||
|
||||
FILE *f;
|
||||
|
||||
int retval = 1;
|
||||
f = fopen("iclass_key.bin", "rb");
|
||||
if (f)
|
||||
{
|
||||
if(fread(key, sizeof(key), 1, f) == 1) return 0;
|
||||
}
|
||||
return 1;
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -296,7 +296,7 @@ static uint8_t trailerAccessBytes[4] = {0x08, 0x77, 0x8F, 0x00};
|
||||
// variables
|
||||
char logHexFileName[200] = {0x00};
|
||||
static uint8_t traceCard[4096] = {0x00};
|
||||
static char traceFileName[20];
|
||||
static char traceFileName[200] = {0x00};
|
||||
static int traceState = TRACE_IDLE;
|
||||
static uint8_t traceCurBlock = 0;
|
||||
static uint8_t traceCurKey = 0;
|
||||
@@ -449,7 +449,7 @@ int mfTraceDecode(uint8_t *data_src, int len, uint32_t parity, bool wantSaveToEm
|
||||
}
|
||||
|
||||
// AUTHENTICATION
|
||||
if ((len ==4) && ((data[0] == 0x60) || (data[0] == 0x61))) {
|
||||
if ((len == 4) && ((data[0] == 0x60) || (data[0] == 0x61))) {
|
||||
traceState = TRACE_AUTH1;
|
||||
traceCurBlock = data[1];
|
||||
traceCurKey = data[0] == 60 ? 1:0;
|
||||
@@ -497,7 +497,7 @@ int mfTraceDecode(uint8_t *data_src, int len, uint32_t parity, bool wantSaveToEm
|
||||
break;
|
||||
|
||||
case TRACE_WRITE_OK:
|
||||
if ((len == 1) && (data[0] = 0x0a)) {
|
||||
if ((len == 1) && (data[0] == 0x0a)) {
|
||||
traceState = TRACE_WRITE_DATA;
|
||||
|
||||
return 0;
|
||||
@@ -555,23 +555,14 @@ int mfTraceDecode(uint8_t *data_src, int len, uint32_t parity, bool wantSaveToEm
|
||||
at_par = parity;
|
||||
|
||||
// decode key here)
|
||||
if (!traceCrypto1) {
|
||||
ks2 = ar_enc ^ prng_successor(nt, 64);
|
||||
ks3 = at_enc ^ prng_successor(nt, 96);
|
||||
revstate = lfsr_recovery64(ks2, ks3);
|
||||
lfsr_rollback_word(revstate, 0, 0);
|
||||
lfsr_rollback_word(revstate, 0, 0);
|
||||
lfsr_rollback_word(revstate, nr_enc, 1);
|
||||
lfsr_rollback_word(revstate, uid ^ nt, 0);
|
||||
}else{
|
||||
ks2 = ar_enc ^ prng_successor(nt, 64);
|
||||
ks3 = at_enc ^ prng_successor(nt, 96);
|
||||
revstate = lfsr_recovery64(ks2, ks3);
|
||||
lfsr_rollback_word(revstate, 0, 0);
|
||||
lfsr_rollback_word(revstate, 0, 0);
|
||||
lfsr_rollback_word(revstate, nr_enc, 1);
|
||||
lfsr_rollback_word(revstate, uid ^ nt, 0);
|
||||
}
|
||||
ks2 = ar_enc ^ prng_successor(nt, 64);
|
||||
ks3 = at_enc ^ prng_successor(nt, 96);
|
||||
revstate = lfsr_recovery64(ks2, ks3);
|
||||
lfsr_rollback_word(revstate, 0, 0);
|
||||
lfsr_rollback_word(revstate, 0, 0);
|
||||
lfsr_rollback_word(revstate, nr_enc, 1);
|
||||
lfsr_rollback_word(revstate, uid ^ nt, 0);
|
||||
|
||||
crypto1_get_lfsr(revstate, &lfsr);
|
||||
printf("key> %x%x\n", (unsigned int)((lfsr & 0xFFFFFFFF00000000) >> 32), (unsigned int)(lfsr & 0xFFFFFFFF));
|
||||
AddLogUint64(logHexFileName, "key> ", lfsr);
|
||||
|
||||
@@ -544,7 +544,12 @@ lfsr_common_prefix(uint32_t pfx, uint32_t rr, uint8_t ks[8], uint8_t par[8][8],
|
||||
|
||||
statelist = malloc((sizeof *statelist) << 21); //how large should be?
|
||||
if(!statelist || !odd || !even)
|
||||
return 0;
|
||||
{
|
||||
free(statelist);
|
||||
free(odd);
|
||||
free(even);
|
||||
return 0;
|
||||
}
|
||||
|
||||
s = statelist;
|
||||
for(o = odd; *o != -1; ++o)
|
||||
|
||||
25
client/ui.c
25
client/ui.c
@@ -152,30 +152,13 @@ int manchester_decode( int * data, const size_t len, uint8_t * dataout, size_t
|
||||
lastpeak = i;
|
||||
}
|
||||
}
|
||||
//return clock;
|
||||
//defaults clock to precise values.
|
||||
switch(clock){
|
||||
case 8:
|
||||
case 16:
|
||||
case 32:
|
||||
case 40:
|
||||
case 50:
|
||||
case 64:
|
||||
case 100:
|
||||
case 128:
|
||||
return clock;
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
//PrintAndLog(" Found Clock : %d - trying to adjust", clock);
|
||||
|
||||
// When detected clock is 31 or 33 then then return
|
||||
int clockmod = clock%8;
|
||||
if ( clockmod == 7 )
|
||||
clock += 1;
|
||||
else if ( clockmod == 1 )
|
||||
clock -= 1;
|
||||
if ( clockmod == 0) return clock;
|
||||
|
||||
if ( clockmod == 7 ) clock += 1;
|
||||
else if ( clockmod == 1 ) clock -= 1;
|
||||
|
||||
return clock;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user