Applied Holiman's fixes for iclass.c and CSNs
Applied PwPiwi's new parity fix. Applied Marshmellw's fixes for FSKdemod (HID, IO) FIX: a potential bigbuffer fault given pwpiwi's change inside lfops.c CmdIOdemodFSK & CmdHIDdemodFSK FIX: change some "int" parameters to uint's. FIX: changed the lfops.c - DoAcquisition125k_internal to respect pwpiwi's definitions of FREE_BUFFER_OFFSET HEADS up: The ultralight functions hasn't been verified since pwpiwi's changes.
This commit is contained in:
@@ -461,7 +461,7 @@ int CmdSamples(const char *Cmd)
|
||||
|
||||
int n = strtol(Cmd, NULL, 0);
|
||||
if (n == 0)
|
||||
n = 512;
|
||||
n = 16000;
|
||||
if (n > sizeof(got))
|
||||
n = sizeof(got);
|
||||
|
||||
|
||||
@@ -44,8 +44,8 @@ int CmdHF14AList(const char *Cmd)
|
||||
ShowWaitCycles = true;
|
||||
}
|
||||
|
||||
uint8_t got[TRACE_BUFFER_SIZE];
|
||||
GetFromBigBuf(got,sizeof(got),0);
|
||||
uint8_t trace[TRACE_BUFFER_SIZE];
|
||||
GetFromBigBuf(trace,TRACE_BUFFER_SIZE,0);
|
||||
WaitForResponse(CMD_ACK,NULL);
|
||||
|
||||
PrintAndLog("Recorded Activity");
|
||||
@@ -56,122 +56,98 @@ int CmdHF14AList(const char *Cmd)
|
||||
PrintAndLog(" Start | End | Src | Data");
|
||||
PrintAndLog("-----------|-----------|-----|--------");
|
||||
|
||||
int i = 0;
|
||||
uint32_t first_timestamp = 0;
|
||||
uint16_t tracepos = 0;
|
||||
uint16_t duration;
|
||||
uint16_t data_len;
|
||||
uint16_t parity_len;
|
||||
bool isResponse;
|
||||
uint32_t timestamp;
|
||||
uint32_t EndOfTransmissionTimestamp = 0;
|
||||
uint32_t first_timestamp;
|
||||
uint32_t EndOfTransmissionTimestamp;
|
||||
|
||||
for (;;) {
|
||||
if(i >= TRACE_BUFFER_SIZE) {
|
||||
break;
|
||||
}
|
||||
|
||||
bool isResponse;
|
||||
timestamp = *((uint32_t *)(got+i));
|
||||
if (timestamp & 0x80000000) {
|
||||
timestamp &= 0x7fffffff;
|
||||
isResponse = true;
|
||||
} else {
|
||||
isResponse = false;
|
||||
}
|
||||
|
||||
if(i==0) {
|
||||
|
||||
if( tracepos >= TRACE_BUFFER_SIZE) break;
|
||||
|
||||
timestamp = *((uint32_t *)(trace + tracepos));
|
||||
if(tracepos == 0) {
|
||||
first_timestamp = timestamp;
|
||||
}
|
||||
|
||||
int parityBits = *((uint32_t *)(got+i+4));
|
||||
tracepos += 4;
|
||||
duration = *((uint16_t *)(trace + tracepos));
|
||||
tracepos += 2;
|
||||
data_len = *((uint16_t *)(trace + tracepos));
|
||||
tracepos += 2;
|
||||
|
||||
int len = got[i+8];
|
||||
|
||||
if (len > 100) {
|
||||
break;
|
||||
}
|
||||
if (i + len >= TRACE_BUFFER_SIZE) {
|
||||
break;
|
||||
if (data_len & 0x8000) {
|
||||
data_len &= 0x7fff;
|
||||
isResponse = true;
|
||||
} else {
|
||||
isResponse = false;
|
||||
}
|
||||
|
||||
uint8_t *frame = (got+i+9);
|
||||
parity_len = (data_len-1)/8 + 1;
|
||||
|
||||
|
||||
if (tracepos + data_len + parity_len >= TRACE_BUFFER_SIZE) { break; }
|
||||
|
||||
uint8_t *frame = trace + tracepos;
|
||||
tracepos += data_len;
|
||||
uint8_t *parityBytes = trace + tracepos;
|
||||
tracepos += parity_len;
|
||||
|
||||
// Break and stick with current result if buffer was not completely full
|
||||
if (frame[0] == 0x44 && frame[1] == 0x44 && frame[2] == 0x44 && frame[3] == 0x44) break;
|
||||
if (timestamp == 0x44444444) break;
|
||||
|
||||
char line[1000] = "";
|
||||
int j;
|
||||
if (len) {
|
||||
for (j = 0; j < len; j++) {
|
||||
int oddparity = 0x01;
|
||||
int k;
|
||||
for (j = 0; j < data_len; j++) {
|
||||
int oddparity = 0x01;
|
||||
int k;
|
||||
|
||||
for (k=0;k<8;k++) {
|
||||
oddparity ^= (((frame[j] & 0xFF) >> k) & 0x01);
|
||||
}
|
||||
|
||||
//if((parityBits >> (len - j - 1)) & 0x01) {
|
||||
if (isResponse && (oddparity != ((parityBits >> (len - j - 1)) & 0x01))) {
|
||||
sprintf(line+(j*4), "%02x! ", frame[j]);
|
||||
} else {
|
||||
sprintf(line+(j*4), "%02x ", frame[j]);
|
||||
}
|
||||
for (k=0;k<8;k++) {
|
||||
oddparity ^= (((frame[j] & 0xFF) >> k) & 0x01);
|
||||
}
|
||||
} else {
|
||||
if (ShowWaitCycles) {
|
||||
uint32_t next_timestamp = (*((uint32_t *)(got+i+9))) & 0x7fffffff;
|
||||
sprintf(line, "fdt (Frame Delay Time): %d", (next_timestamp - timestamp));
|
||||
|
||||
uint8_t parityBits = parityBytes[j>>3];
|
||||
if (isResponse && (oddparity != ((parityBits >> (7-(j&0x0007))) & 0x01))) {
|
||||
sprintf(line+(j*4), "%02x! ", frame[j]);
|
||||
} else {
|
||||
sprintf(line+(j*4), "%02x ", frame[j]);
|
||||
}
|
||||
}
|
||||
|
||||
char *crc;
|
||||
crc = "";
|
||||
if (len > 2) {
|
||||
|
||||
char crc[6] = "";
|
||||
if (data_len > 2) {
|
||||
uint8_t b1, b2;
|
||||
for (j = 0; j < (len - 1); j++) {
|
||||
// gives problems... search for the reason..
|
||||
/*if(frame[j] == 0xAA) {
|
||||
switch(frame[j+1]) {
|
||||
case 0x01:
|
||||
crc = "[1] Two drops close after each other";
|
||||
break;
|
||||
case 0x02:
|
||||
crc = "[2] Potential SOC with a drop in second half of bitperiod";
|
||||
break;
|
||||
case 0x03:
|
||||
crc = "[3] Segment Z after segment X is not possible";
|
||||
break;
|
||||
case 0x04:
|
||||
crc = "[4] Parity bit of a fully received byte was wrong";
|
||||
break;
|
||||
default:
|
||||
crc = "[?] Unknown error";
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}*/
|
||||
ComputeCrc14443(CRC_14443_A, frame, data_len-2, &b1, &b2);
|
||||
if (b1 != frame[data_len-2] || b2 != frame[data_len-1]) {
|
||||
sprintf(crc, (isResponse & (data_len < 6)) ? "" : " !crc");
|
||||
} else {
|
||||
sprintf(crc, "");
|
||||
}
|
||||
|
||||
if (strlen(crc)==0) {
|
||||
ComputeCrc14443(CRC_14443_A, frame, len-2, &b1, &b2);
|
||||
if (b1 != frame[len-2] || b2 != frame[len-1]) {
|
||||
crc = (isResponse & (len < 6)) ? "" : " !crc";
|
||||
} else {
|
||||
crc = "";
|
||||
}
|
||||
}
|
||||
} else {
|
||||
crc = ""; // SHORT
|
||||
}
|
||||
|
||||
i += (len + 9);
|
||||
|
||||
EndOfTransmissionTimestamp = (*((uint32_t *)(got+i))) & 0x7fffffff;
|
||||
|
||||
if (!ShowWaitCycles) i += 9;
|
||||
EndOfTransmissionTimestamp = timestamp + duration;
|
||||
|
||||
PrintAndLog(" %9d | %9d | %s | %s %s",
|
||||
(timestamp - first_timestamp),
|
||||
(EndOfTransmissionTimestamp - first_timestamp),
|
||||
(len?(isResponse ? "Tag" : "Rdr"):" "),
|
||||
line, crc);
|
||||
|
||||
(isResponse ? "Tag" : "Rdr"),
|
||||
line,
|
||||
crc);
|
||||
|
||||
bool next_isResponse = *((uint16_t *)(trace + tracepos + 6)) & 0x8000;
|
||||
if (ShowWaitCycles && !isResponse && next_isResponse) {
|
||||
uint32_t next_timestamp = *((uint32_t *)(trace + tracepos));
|
||||
if (next_timestamp != 0x44444444) {
|
||||
PrintAndLog(" %9d | %9d | %s | fdt (Frame Delay Time): %d",
|
||||
(EndOfTransmissionTimestamp - first_timestamp),
|
||||
(next_timestamp - first_timestamp),
|
||||
" ",
|
||||
(next_timestamp - EndOfTransmissionTimestamp));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -302,7 +302,7 @@ int CmdHFiClassSnoop(const char *Cmd)
|
||||
SendCommand(&c);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define NUM_CSNS 15
|
||||
int CmdHFiClassSim(const char *Cmd)
|
||||
{
|
||||
uint8_t simType = 0;
|
||||
@@ -339,20 +339,27 @@ int CmdHFiClassSim(const char *Cmd)
|
||||
|
||||
if(simType == 2)
|
||||
{
|
||||
UsbCommand c = {CMD_SIMULATE_TAG_ICLASS, {simType,63}};
|
||||
UsbCommand c = {CMD_SIMULATE_TAG_ICLASS, {simType,NUM_CSNS}};
|
||||
UsbCommand resp = {0};
|
||||
|
||||
uint8_t csns[64] = {
|
||||
0x00,0x0B,0x0F,0xFF,0xF7,0xFF,0x12,0xE0 ,
|
||||
0x00,0x13,0x94,0x7e,0x76,0xff,0x12,0xe0 ,
|
||||
0x2a,0x99,0xac,0x79,0xec,0xff,0x12,0xe0 ,
|
||||
0x17,0x12,0x01,0xfd,0xf7,0xff,0x12,0xe0 ,
|
||||
0xcd,0x56,0x01,0x7c,0x6f,0xff,0x12,0xe0 ,
|
||||
0x4b,0x5e,0x0b,0x72,0xef,0xff,0x12,0xe0 ,
|
||||
0x00,0x73,0xd8,0x75,0x58,0xff,0x12,0xe0 ,
|
||||
0x0c,0x90,0x32,0xf3,0x5d,0xff,0x12,0xe0 };
|
||||
|
||||
memcpy(c.d.asBytes, csns, 64);
|
||||
uint8_t csns[8*NUM_CSNS] = {
|
||||
0x00, 0x0B, 0x0F, 0xFF, 0xF7, 0xFF, 0x12, 0xE0,
|
||||
0x00, 0x04, 0x0E, 0x08, 0xF7, 0xFF, 0x12, 0xE0,
|
||||
0x00, 0x09, 0x0D, 0x05, 0xF7, 0xFF, 0x12, 0xE0,
|
||||
0x00, 0x0A, 0x0C, 0x06, 0xF7, 0xFF, 0x12, 0xE0,
|
||||
0x00, 0x0F, 0x0B, 0x03, 0xF7, 0xFF, 0x12, 0xE0,
|
||||
0x00, 0x08, 0x0A, 0x0C, 0xF7, 0xFF, 0x12, 0xE0,
|
||||
0x00, 0x0D, 0x09, 0x09, 0xF7, 0xFF, 0x12, 0xE0,
|
||||
0x00, 0x0E, 0x08, 0x0A, 0xF7, 0xFF, 0x12, 0xE0,
|
||||
0x00, 0x03, 0x07, 0x17, 0xF7, 0xFF, 0x12, 0xE0,
|
||||
0x00, 0x3C, 0x06, 0xE0, 0xF7, 0xFF, 0x12, 0xE0,
|
||||
0x00, 0x01, 0x05, 0x1D, 0xF7, 0xFF, 0x12, 0xE0,
|
||||
0x00, 0x02, 0x04, 0x1E, 0xF7, 0xFF, 0x12, 0xE0,
|
||||
0x00, 0x07, 0x03, 0x1B, 0xF7, 0xFF, 0x12, 0xE0,
|
||||
0x00, 0x00, 0x02, 0x24, 0xF7, 0xFF, 0x12, 0xE0,
|
||||
0x00, 0x05, 0x01, 0x21, 0xF7, 0xFF, 0x12, 0xE0 };
|
||||
|
||||
memcpy(c.d.asBytes, csns, 8*NUM_CSNS);
|
||||
|
||||
SendCommand(&c);
|
||||
if (!WaitForResponseTimeout(CMD_ACK, &resp, -1)) {
|
||||
@@ -361,9 +368,9 @@ int CmdHFiClassSim(const char *Cmd)
|
||||
}
|
||||
|
||||
uint8_t num_mac_responses = resp.arg[1];
|
||||
PrintAndLog("Mac responses: %d MACs obtained (should be 8)", num_mac_responses);
|
||||
PrintAndLog("Mac responses: %d MACs obtained (should be %d)", num_mac_responses, NUM_CSNS);
|
||||
|
||||
size_t datalen = 8*24;
|
||||
size_t datalen = NUM_CSNS*24;
|
||||
/*
|
||||
* Now, time to dump to file. We'll use this format:
|
||||
* <8-byte CSN><8-byte CC><4 byte NR><4 byte MAC>....
|
||||
@@ -377,7 +384,7 @@ int CmdHFiClassSim(const char *Cmd)
|
||||
void* dump = malloc(datalen);
|
||||
memset(dump,0,datalen);//<-- Need zeroes for the CC-field
|
||||
uint8_t i = 0;
|
||||
for(i = 0 ; i < 8 ; i++)
|
||||
for(i = 0 ; i < NUM_CSNS ; i++)
|
||||
{
|
||||
memcpy(dump+i*24, csns+i*8,8); //CSN
|
||||
//8 zero bytes here...
|
||||
|
||||
@@ -2020,7 +2020,6 @@ int CmdHF14AMfSniff(const char *Cmd){
|
||||
uint8_t atqa[2];
|
||||
uint8_t sak;
|
||||
bool isTag;
|
||||
uint32_t parity;
|
||||
uint8_t buf[3000];
|
||||
uint8_t * bufPtr = buf;
|
||||
memset(buf, 0x00, 3000);
|
||||
@@ -2087,14 +2086,19 @@ int CmdHF14AMfSniff(const char *Cmd){
|
||||
printf(">\n");
|
||||
PrintAndLog("received trace len: %d packages: %d", blockLen, pckNum);
|
||||
num = 0;
|
||||
while (bufPtr - buf + 9 < blockLen) {
|
||||
isTag = bufPtr[3] & 0x80 ? true:false;
|
||||
bufPtr += 4;
|
||||
parity = *((uint32_t *)(bufPtr));
|
||||
bufPtr += 4;
|
||||
len = bufPtr[0];
|
||||
bufPtr++;
|
||||
if ((len == 14) && (bufPtr[0] == 0xff) && (bufPtr[1] == 0xff)) {
|
||||
while (bufPtr - buf < blockLen) {
|
||||
bufPtr += 6;
|
||||
len = *((uint16_t *)bufPtr);
|
||||
|
||||
if(len & 0x8000) {
|
||||
isTag = true;
|
||||
len &= 0x7fff;
|
||||
} else {
|
||||
isTag = false;
|
||||
}
|
||||
bufPtr += 2;
|
||||
if ((len == 14) && (bufPtr[0] == 0xff) && (bufPtr[1] == 0xff) && (bufPtr[12] == 0xff) && (bufPtr[13] == 0xff)) {
|
||||
|
||||
memcpy(uid, bufPtr + 2, 7);
|
||||
memcpy(atqa, bufPtr + 2 + 7, 2);
|
||||
uid_len = (atqa[0] & 0xC0) == 0x40 ? 7 : 4;
|
||||
@@ -2116,9 +2120,10 @@ int CmdHF14AMfSniff(const char *Cmd){
|
||||
if (wantLogToFile)
|
||||
AddLogHex(logHexFileName, isTag ? "TAG: ":"RDR: ", bufPtr, len);
|
||||
if (wantDecrypt)
|
||||
mfTraceDecode(bufPtr, len, parity, wantSaveToEmlFile);
|
||||
mfTraceDecode(bufPtr, len, wantSaveToEmlFile);
|
||||
}
|
||||
bufPtr += len;
|
||||
bufPtr += ((len-1)/8+1); // ignore parity
|
||||
num++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -268,7 +268,7 @@ int CmdIndalaDemod(const char *Cmd)
|
||||
PrintAndLog("UID=%s (%x%08x%08x%08x%08x%08x%08x)", showbits, uid1, uid2, uid3, uid4, uid5, uid6, uid7);
|
||||
}
|
||||
|
||||
// Checking UID against next occurences
|
||||
// Checking UID against next occurrences
|
||||
for (; i + uidlen <= rawbit;) {
|
||||
int failed = 0;
|
||||
for (bit = 0; bit < uidlen; bit++) {
|
||||
@@ -282,7 +282,7 @@ int CmdIndalaDemod(const char *Cmd)
|
||||
}
|
||||
times += 1;
|
||||
}
|
||||
PrintAndLog("Occurences: %d (expected %d)", times, (rawbit - start) / uidlen);
|
||||
PrintAndLog("Occurrences: %d (expected %d)", times, (rawbit - start) / uidlen);
|
||||
|
||||
// Remodulating for tag cloning
|
||||
GraphTraceLen = 32*uidlen;
|
||||
@@ -390,7 +390,8 @@ static void ChkBitstream(const char *str)
|
||||
|
||||
int CmdLFSim(const char *Cmd)
|
||||
{
|
||||
int i;
|
||||
int i,j;
|
||||
|
||||
static int gap;
|
||||
|
||||
sscanf(Cmd, "%i", &gap);
|
||||
@@ -398,10 +399,10 @@ int CmdLFSim(const char *Cmd)
|
||||
/* convert to bitstream if necessary */
|
||||
ChkBitstream(Cmd);
|
||||
|
||||
PrintAndLog("Sending [%d bytes]", GraphTraceLen);
|
||||
printf("Sending [%d bytes]", GraphTraceLen);
|
||||
for (i = 0; i < GraphTraceLen; i += USB_CMD_DATA_SIZE) {
|
||||
UsbCommand c={CMD_DOWNLOADED_SIM_SAMPLES_125K, {i, 0, 0}};
|
||||
int j;
|
||||
|
||||
for (j = 0; j < USB_CMD_DATA_SIZE; j++) {
|
||||
c.d.asBytes[j] = GraphBuffer[i+j];
|
||||
}
|
||||
@@ -569,7 +570,7 @@ static command_t CommandTable[] =
|
||||
|
||||
{"flexdemod", CmdFlexdemod, 1, "Demodulate samples for FlexPass"},
|
||||
{"indalademod", CmdIndalaDemod, 1, "['224'] -- Demodulate samples for Indala 64 bit UID (option '224' for 224 bit)"},
|
||||
{"indalaclone", CmdIndalaClone, 1, "<UID> ['l']-- Clone Indala to T55x7 (UID in HEX)(option 'l' for 224 UID"},
|
||||
{"indalaclone", CmdIndalaClone, 0, "<UID> ['l']-- Clone Indala to T55x7 (UID in HEX)(option 'l' for 224 UID"},
|
||||
{"vchdemod", CmdVchDemod, 1, "['clone'] -- Demodulate samples for VeriChip"},
|
||||
|
||||
|
||||
|
||||
@@ -202,9 +202,9 @@ int CmdEM410xSim(const char *Cmd)
|
||||
uint8_t uid[5] = {0x00};
|
||||
|
||||
if (cmdp == 'h' || cmdp == 'H') {
|
||||
PrintAndLog("Usage: lf em4x sim <UID>");
|
||||
PrintAndLog("Usage: lf em4x 410xsim <UID>");
|
||||
PrintAndLog("");
|
||||
PrintAndLog(" sample: lf em4x sim 0F0368568B");
|
||||
PrintAndLog(" sample: lf em4x 410xsim 0F0368568B");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -258,14 +258,9 @@ int CmdEM410xSim(const char *Cmd)
|
||||
AppendGraph(0, clock, parity[3]);
|
||||
|
||||
/* stop bit */
|
||||
AppendGraph(0, clock, 0);
|
||||
AppendGraph(1, clock, 0);
|
||||
|
||||
//CmdManchesterMod("64");
|
||||
|
||||
/* booyah! */
|
||||
RepaintGraphWindow();
|
||||
|
||||
CmdLFSim("");
|
||||
CmdLFSim("240"); //240 start_gap.
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -39,9 +39,12 @@ int CmdHIDDemod(const char *Cmd)
|
||||
|
||||
int CmdHIDDemodFSK(const char *Cmd)
|
||||
{
|
||||
UsbCommand c={CMD_HID_DEMOD_FSK};
|
||||
SendCommand(&c);
|
||||
return 0;
|
||||
int findone = 0;
|
||||
if(Cmd[0]=='1') findone=1;
|
||||
UsbCommand c = {CMD_HID_DEMOD_FSK};
|
||||
c.arg[0]=findone;
|
||||
SendCommand(&c);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CmdHIDSim(const char *Cmd)
|
||||
@@ -103,9 +106,9 @@ static command_t CommandTable[] =
|
||||
{
|
||||
{"help", CmdHelp, 1, "This help"},
|
||||
{"demod", CmdHIDDemod, 1, "Demodulate HID Prox Card II (not optimal)"},
|
||||
{"fskdemod", CmdHIDDemodFSK, 1, "Realtime HID FSK demodulator"},
|
||||
{"sim", CmdHIDSim, 1, "<ID> -- HID tag simulator"},
|
||||
{"clone", CmdHIDClone, 1, "<ID> ['l'] -- Clone HID to T55x7 (tag must be in antenna)(option 'l' for 84bit ID)"},
|
||||
{"fskdemod", CmdHIDDemodFSK, 0, "['1'] Realtime HID FSK demodulator (option '1' for one tag only)"},
|
||||
{"sim", CmdHIDSim, 0, "<ID> -- HID tag simulator"},
|
||||
{"clone", CmdHIDClone, 0, "<ID> ['l'] -- Clone HID to T55x7 (tag must be in antenna)(option 'l' for 84bit ID)"},
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
|
||||
@@ -39,9 +39,21 @@ int CmdLFHitagList(const char *Cmd)
|
||||
|
||||
int i = 0;
|
||||
int prev = -1;
|
||||
int len = strlen(Cmd);
|
||||
|
||||
char filename[256];
|
||||
char filename[FILE_PATH_SIZE] = { 0x00 };
|
||||
FILE* pf = NULL;
|
||||
|
||||
if (len > FILE_PATH_SIZE)
|
||||
len = FILE_PATH_SIZE;
|
||||
memcpy(filename, Cmd, len);
|
||||
|
||||
if (strlen(filename) > 0) {
|
||||
if ((pf = fopen(filename,"wb")) == NULL) {
|
||||
PrintAndLog("Error: Could not open file [%s]",filename);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
|
||||
@@ -116,8 +128,8 @@ int CmdLFHitagList(const char *Cmd)
|
||||
}
|
||||
|
||||
if (pf) {
|
||||
PrintAndLog("Recorded activity succesfully written to file: %s", filename);
|
||||
fclose(pf);
|
||||
PrintAndLog("Recorded activity succesfully written to file: %s", filename);
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -135,9 +147,7 @@ int CmdLFHitagSim(const char *Cmd) {
|
||||
char filename[FILE_PATH_SIZE] = { 0x00 };
|
||||
FILE* pf;
|
||||
bool tag_mem_supplied;
|
||||
int len = 0;
|
||||
|
||||
len = strlen(Cmd);
|
||||
int len = strlen(Cmd);
|
||||
if (len > FILE_PATH_SIZE) len = FILE_PATH_SIZE;
|
||||
memcpy(filename, Cmd, len);
|
||||
|
||||
@@ -148,7 +158,7 @@ int CmdLFHitagSim(const char *Cmd) {
|
||||
}
|
||||
tag_mem_supplied = true;
|
||||
if (fread(c.d.asBytes,48,1,pf) == 0) {
|
||||
PrintAndLog("Error: File reading error");
|
||||
PrintAndLog("Error: File reading error");
|
||||
return 1;
|
||||
}
|
||||
fclose(pf);
|
||||
@@ -234,11 +244,11 @@ int CmdLFHitagReader(const char *Cmd) {
|
||||
static command_t CommandTable[] =
|
||||
{
|
||||
{"help", CmdHelp, 1, "This help"},
|
||||
{"list", CmdLFHitagList, 1, "List Hitag trace history"},
|
||||
{"list", CmdLFHitagList, 1, "<outfile> List Hitag trace history"},
|
||||
{"reader", CmdLFHitagReader, 1, "Act like a Hitag Reader"},
|
||||
{"sim", CmdLFHitagSim, 1, "Simulate Hitag transponder"},
|
||||
{"sim", CmdLFHitagSim, 1, "<infile> Simulate Hitag transponder"},
|
||||
{"snoop", CmdLFHitagSnoop, 1, "Eavesdrop Hitag communication"},
|
||||
{NULL, NULL, 0, NULL}
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
int CmdLFHitag(const char *Cmd)
|
||||
|
||||
@@ -16,9 +16,13 @@ static int CmdHelp(const char *Cmd);
|
||||
|
||||
int CmdIODemodFSK(const char *Cmd)
|
||||
{
|
||||
UsbCommand c={CMD_IO_DEMOD_FSK};
|
||||
SendCommand(&c);
|
||||
return 0;
|
||||
int findone = 0;
|
||||
if (Cmd[0] =='1') findone = 1;
|
||||
|
||||
UsbCommand c={CMD_IO_DEMOD_FSK};
|
||||
c.arg[0] = findone;
|
||||
SendCommand(&c);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CmdIOProxDemod(const char *Cmd){
|
||||
@@ -64,8 +68,8 @@ static command_t CommandTable[] =
|
||||
{
|
||||
{"help", CmdHelp, 1, "This help"},
|
||||
{"demod", CmdIOProxDemod, 1, "Demodulate Stream"},
|
||||
{"fskdemod", CmdIODemodFSK, 1, "Demodulate ioProx Tag"},
|
||||
{"clone", CmdIOClone, 1, "Clone ioProx Tag"},
|
||||
{"fskdemod", CmdIODemodFSK, 0, "['1'] Realtime IO FSK demodulator (option '1' for one tag only)"},
|
||||
{"clone", CmdIOClone, 0, "Clone ioProx Tag"},
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
|
||||
@@ -46,18 +46,17 @@ int CmdReadBlk(const char *Cmd)
|
||||
SendCommand(&c);
|
||||
WaitForResponse(CMD_ACK, NULL);
|
||||
|
||||
// uint8_t data[LF_TRACE_BUFF_SIZE] = {0x00};
|
||||
uint8_t data[LF_TRACE_BUFF_SIZE] = {0x00};
|
||||
|
||||
// GetFromBigBuf(data,LF_TRACE_BUFF_SIZE,3560); //3560 -- should be offset..
|
||||
// WaitForResponseTimeout(CMD_ACK,NULL, 1500);
|
||||
GetFromBigBuf(data,LF_TRACE_BUFF_SIZE,3560); //3560 -- should be offset..
|
||||
WaitForResponseTimeout(CMD_ACK,NULL, 1500);
|
||||
|
||||
// for (int j = 0; j < LF_TRACE_BUFF_SIZE; j++) {
|
||||
// GraphBuffer[j] = (int)data[j];
|
||||
// }
|
||||
// GraphTraceLen = LF_TRACE_BUFF_SIZE;
|
||||
CmdSamples("12000");
|
||||
for (int j = 0; j < LF_TRACE_BUFF_SIZE; j++) {
|
||||
GraphBuffer[j] = (int)data[j];
|
||||
}
|
||||
GraphTraceLen = LF_TRACE_BUFF_SIZE;
|
||||
ManchesterDemod(block);
|
||||
// RepaintGraphWindow();
|
||||
RepaintGraphWindow();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -321,7 +320,7 @@ int CmdDump(const char *Cmd){
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for ( int i = 0; i <8; ++i){
|
||||
memset(s,0,sizeof(s));
|
||||
if ( hasPwd ) {
|
||||
@@ -352,6 +351,7 @@ int ManchesterDemod(int blockNum){
|
||||
if (!HasGraphData()) return 0;
|
||||
|
||||
uint8_t sizebyte = 32;
|
||||
// the value 5 was selected during empirical studies of the decoded data. Some signal noise to skip.
|
||||
uint8_t offset = 5;
|
||||
uint32_t blockData;
|
||||
uint8_t bits[LF_BITSSTREAM_LEN] = {0x00};
|
||||
|
||||
@@ -198,10 +198,9 @@ void UsbCommandReceived(UsbCommand *UC)
|
||||
switch(UC->cmd) {
|
||||
// First check if we are handling a debug message
|
||||
case CMD_DEBUG_PRINT_STRING: {
|
||||
char s[USB_CMD_DATA_SIZE+1];
|
||||
char s[USB_CMD_DATA_SIZE+1] = {0x00};
|
||||
size_t len = MIN(UC->arg[0],USB_CMD_DATA_SIZE);
|
||||
memcpy(s,UC->d.asBytes,len);
|
||||
s[len] = 0x00;
|
||||
PrintAndLog("#db# %s ", s);
|
||||
return;
|
||||
} break;
|
||||
|
||||
@@ -275,8 +275,7 @@ static int get_proxmark_state(uint32_t *state)
|
||||
{
|
||||
UsbCommand c;
|
||||
c.cmd = CMD_DEVICE_INFO;
|
||||
// SendCommand_(&c);
|
||||
SendCommand(&c);
|
||||
SendCommand(&c);
|
||||
UsbCommand resp;
|
||||
ReceiveCommand(&resp);
|
||||
|
||||
@@ -390,7 +389,6 @@ int flash_start_flashing(int enable_bl_writes,char *serial_port_name)
|
||||
c.arg[2] = 0;
|
||||
}
|
||||
SendCommand(&c);
|
||||
// SendCommand_(&c);
|
||||
return wait_for_ack();
|
||||
} else {
|
||||
fprintf(stderr, "Note: Your bootloader does not understand the new START_FLASH command\n");
|
||||
@@ -406,25 +404,11 @@ static int write_block(uint32_t address, uint8_t *data, uint32_t length)
|
||||
|
||||
memset(block_buf, 0xFF, BLOCK_SIZE);
|
||||
memcpy(block_buf, data, length);
|
||||
UsbCommand c;
|
||||
/*
|
||||
c.cmd = {CMD_SETUP_WRITE};
|
||||
for (int i = 0; i < 240; i += 48) {
|
||||
memcpy(c.d.asBytes, block_buf + i, 48);
|
||||
c.arg[0] = i / 4;
|
||||
SendCommand(&c);
|
||||
// SendCommand_(&c);
|
||||
if (wait_for_ack() < 0) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
*/
|
||||
UsbCommand c;
|
||||
c.cmd = CMD_FINISH_WRITE;
|
||||
c.arg[0] = address;
|
||||
// memcpy(c.d.asBytes, block_buf+240, 16);
|
||||
// SendCommand_(&c);
|
||||
memcpy(c.d.asBytes, block_buf, length);
|
||||
SendCommand(&c);
|
||||
SendCommand(&c);
|
||||
return wait_for_ack();
|
||||
}
|
||||
|
||||
@@ -485,8 +469,7 @@ void flash_free(flash_file_t *ctx)
|
||||
// just reset the unit
|
||||
int flash_stop_flashing(void) {
|
||||
UsbCommand c = {CMD_HARDWARE_RESET};
|
||||
// SendCommand_(&c);
|
||||
SendCommand(&c);
|
||||
msleep(100);
|
||||
return 0;
|
||||
SendCommand(&c);
|
||||
msleep(100);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ int fileExists(const char *filename) {
|
||||
|
||||
int saveFile(const char *preferredName, const char *suffix, const void* data, size_t datalen)
|
||||
{
|
||||
int size = sizeof(char) * (strlen(preferredName)+strlen(suffix)+5);
|
||||
int size = sizeof(char) * (strlen(preferredName)+strlen(suffix)+10);
|
||||
char * fileName = malloc(size);
|
||||
|
||||
memset(fileName,0,size);
|
||||
@@ -70,14 +70,14 @@ 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) {
|
||||
prnlog("Failed to write to file '%s'", fileName);
|
||||
FILE *fh=fopen(fileName,"wb");
|
||||
if(!fh) {
|
||||
PrintAndLog("Failed to write to file '%s'", fileName);
|
||||
return 1;
|
||||
}
|
||||
fwrite(data, 1, datalen, fileHandle);
|
||||
fclose(fileHandle);
|
||||
prnlog("Saved data to '%s'", fileName);
|
||||
fwrite(data, 1, datalen, fh);
|
||||
fclose(fh);
|
||||
PrintAndLog("Saved data to '%s'", fileName);
|
||||
free(fileName);
|
||||
|
||||
return 0;
|
||||
@@ -87,7 +87,7 @@ int loadFile(const char *fileName, void* data, size_t datalen)
|
||||
{
|
||||
FILE *filehandle = fopen(fileName, "rb");
|
||||
if(!filehandle) {
|
||||
prnlog("Failed to read from file '%s'", fileName);
|
||||
PrintAndLog("Failed to read from file '%s'", fileName);
|
||||
return 1;
|
||||
}
|
||||
fread(data,datalen,1,filehandle);
|
||||
|
||||
@@ -231,7 +231,7 @@ int mfEmlSetMem(uint8_t *data, int blockNum, int blocksCount) {
|
||||
|
||||
// "MAGIC" CARD
|
||||
|
||||
int mfCSetUID(uint8_t *uid, uint8_t *oldUID, int wantWipe) {
|
||||
int mfCSetUID(uint8_t *uid, uint8_t *oldUID, bool wantWipe) {
|
||||
uint8_t block0[16];
|
||||
memset(block0, 0, 16);
|
||||
memcpy(block0, uid, 4);
|
||||
@@ -244,7 +244,7 @@ int mfCSetUID(uint8_t *uid, uint8_t *oldUID, int wantWipe) {
|
||||
return mfCSetBlock(0, block0, oldUID, wantWipe, CSETBLOCK_SINGLE_OPER);
|
||||
}
|
||||
|
||||
int mfCSetBlock(uint8_t blockNo, uint8_t *data, uint8_t *uid, int wantWipe, uint8_t params) {
|
||||
int mfCSetBlock(uint8_t blockNo, uint8_t *data, uint8_t *uid, bool wantWipe, uint8_t params) {
|
||||
uint8_t isOK = 0;
|
||||
|
||||
UsbCommand c = {CMD_MIFARE_EML_CSETBLOCK, {wantWipe, params & (0xFE | (uid == NULL ? 0:1)), blockNo}};
|
||||
@@ -303,12 +303,9 @@ uint32_t ks3;
|
||||
|
||||
uint32_t uid; // serial number
|
||||
uint32_t nt; // tag challenge
|
||||
uint32_t nt_par;
|
||||
uint32_t nr_enc; // encrypted reader challenge
|
||||
uint32_t ar_enc; // encrypted reader response
|
||||
uint32_t nr_ar_par;
|
||||
uint32_t at_enc; // encrypted tag response
|
||||
uint32_t at_par;
|
||||
|
||||
int isTraceCardEmpty(void) {
|
||||
return ((traceCard[0] == 0) && (traceCard[1] == 0) && (traceCard[2] == 0) && (traceCard[3] == 0));
|
||||
@@ -415,7 +412,7 @@ void mf_crypto1_decrypt(struct Crypto1State *pcs, uint8_t *data, int len, bool i
|
||||
}
|
||||
|
||||
|
||||
int mfTraceDecode(uint8_t *data_src, int len, uint32_t parity, bool wantSaveToEmlFile) {
|
||||
int mfTraceDecode(uint8_t *data_src, int len, bool wantSaveToEmlFile) {
|
||||
uint8_t data[64];
|
||||
|
||||
if (traceState == TRACE_ERROR) return 1;
|
||||
@@ -516,9 +513,7 @@ int mfTraceDecode(uint8_t *data_src, int len, uint32_t parity, bool wantSaveToEm
|
||||
case TRACE_AUTH1:
|
||||
if (len == 4) {
|
||||
traceState = TRACE_AUTH2;
|
||||
|
||||
nt = bytes_to_num(data, 4);
|
||||
nt_par = parity;
|
||||
return 0;
|
||||
} else {
|
||||
traceState = TRACE_ERROR;
|
||||
@@ -532,7 +527,6 @@ int mfTraceDecode(uint8_t *data_src, int len, uint32_t parity, bool wantSaveToEm
|
||||
|
||||
nr_enc = bytes_to_num(data, 4);
|
||||
ar_enc = bytes_to_num(data + 4, 4);
|
||||
nr_ar_par = parity;
|
||||
return 0;
|
||||
} else {
|
||||
traceState = TRACE_ERROR;
|
||||
@@ -545,7 +539,6 @@ int mfTraceDecode(uint8_t *data_src, int len, uint32_t parity, bool wantSaveToEm
|
||||
traceState = TRACE_IDLE;
|
||||
|
||||
at_enc = bytes_to_num(data, 4);
|
||||
at_par = parity;
|
||||
|
||||
// decode key here)
|
||||
ks2 = ar_enc ^ prng_successor(nt, 64);
|
||||
|
||||
@@ -55,12 +55,12 @@ int mfCheckKeys (uint8_t blockNo, uint8_t keyType, uint8_t keycnt, uint8_t * key
|
||||
int mfEmlGetMem(uint8_t *data, int blockNum, int blocksCount);
|
||||
int mfEmlSetMem(uint8_t *data, int blockNum, int blocksCount);
|
||||
|
||||
int mfCSetUID(uint8_t *uid, uint8_t *oldUID, int wantWipe);
|
||||
int mfCSetBlock(uint8_t blockNo, uint8_t *data, uint8_t *uid, int wantWipe, uint8_t params);
|
||||
int mfCSetUID(uint8_t *uid, uint8_t *oldUID, bool wantWipe);
|
||||
int mfCSetBlock(uint8_t blockNo, uint8_t *data, uint8_t *uid, bool wantWipe, uint8_t params);
|
||||
int mfCGetBlock(uint8_t blockNo, uint8_t *data, uint8_t params);
|
||||
|
||||
int mfTraceInit(uint8_t *tuid, uint8_t *atqa, uint8_t sak, bool wantSaveToEmlFile);
|
||||
int mfTraceDecode(uint8_t *data_src, int len, uint32_t parity, bool wantSaveToEmlFile);
|
||||
int mfTraceDecode(uint8_t *data_src, int len, bool wantSaveToEmlFile);
|
||||
|
||||
int isTraceCardEmpty(void);
|
||||
int isBlockEmpty(int blockN);
|
||||
|
||||
Reference in New Issue
Block a user