Reduce some var scopes
This commit is contained in:
@@ -223,7 +223,6 @@ void RunMod() {
|
||||
*/
|
||||
bool printKeys = false; // Prints keys
|
||||
bool transferToEml = true; // Transfer keys to emulator memory
|
||||
bool ecfill = true; // Fill emulator memory with cards content.
|
||||
bool simulation = true; // Simulates an exact copy of the target tag
|
||||
bool fillFromEmulator = false; // Dump emulator memory.
|
||||
|
||||
@@ -236,7 +235,6 @@ void RunMod() {
|
||||
uint64_t key64; // Defines current key
|
||||
uint8_t *keyBlock; // Where the keys will be held in memory.
|
||||
uint8_t stKeyBlock = 20; // Set the quantity of keys in the block.
|
||||
int filled; // Used to check if the memory was filled with success.
|
||||
bool keyFound = false;
|
||||
|
||||
/*
|
||||
@@ -368,7 +366,7 @@ void RunMod() {
|
||||
}
|
||||
Dbprintf("\t✓ Found keys have been transferred to the emulator memory.");
|
||||
if (ecfill) {
|
||||
|
||||
int filled;
|
||||
Dbprintf("\tFilling in with key A.");
|
||||
filled = MifareECardLoad(sectorsCnt, 0);
|
||||
if (filled != PM3_SUCCESS) {
|
||||
|
||||
@@ -160,13 +160,14 @@ void RunMod() {
|
||||
Bytes 5-7 are reserved SAK and ATQA for mifare classic
|
||||
-Use mfCSetBlock(0, block0, oldUID, wantWipe, MAGIC_SINGLE) to write it
|
||||
*/
|
||||
uint8_t oldBlock0[16] = {0}, newBlock0[16] = {0}, testBlock0[16] = {0};
|
||||
uint8_t oldBlock0[16] = {0}, newBlock0[16] = {0};
|
||||
// arg0 = Flags, arg1=blockNo
|
||||
MifareCGetBlock(params, 0, oldBlock0);
|
||||
if (oldBlock0[0] == 0 && oldBlock0[0] == oldBlock0[1] && oldBlock0[1] == oldBlock0[2] && oldBlock0[2] == oldBlock0[3]) {
|
||||
Dbprintf("No changeable tag detected. Returning to replay mode for bank[%d]", selected);
|
||||
playing = 1;
|
||||
} else {
|
||||
uint8_t testBlock0[16] = {0};
|
||||
Dbprintf("UID from target tag: %02X%02X%02X%02X", oldBlock0[0], oldBlock0[1], oldBlock0[2], oldBlock0[3]);
|
||||
memcpy(newBlock0 + 5, oldBlock0 + 5, 11);
|
||||
|
||||
|
||||
@@ -1465,7 +1465,6 @@ static void PacketReceived(PacketCommandNG *packet) {
|
||||
case CMD_DOWNLOAD_EML_BIGBUF: {
|
||||
LED_B_ON();
|
||||
uint8_t *mem = BigBuf_get_EM_addr();
|
||||
size_t len = 0;
|
||||
uint32_t startidx = packet->oldarg[0];
|
||||
uint32_t numofbytes = packet->oldarg[1];
|
||||
|
||||
@@ -1474,7 +1473,7 @@ static void PacketReceived(PacketCommandNG *packet) {
|
||||
// arg2 = RFU
|
||||
|
||||
for (size_t i = 0; i < numofbytes; i += PM3_CMD_DATA_SIZE) {
|
||||
len = MIN((numofbytes - i), PM3_CMD_DATA_SIZE);
|
||||
size_t len = MIN((numofbytes - i), PM3_CMD_DATA_SIZE);
|
||||
int result = reply_old(CMD_DOWNLOADED_EML_BIGBUF, i, len, 0, mem + startidx + i, len);
|
||||
if (result != PM3_SUCCESS)
|
||||
Dbprintf("transfer to client failed :: | bytes between %d - %d (%d) | result: %d", i, i + len, len, result);
|
||||
|
||||
@@ -208,9 +208,9 @@ void permute(const uint8_t *ptable, const uint8_t *in, uint8_t *out) {
|
||||
ob = ptable[1];
|
||||
ptable = &(ptable[2]);
|
||||
for (byte = 0; byte < ob; ++byte) {
|
||||
uint8_t x, t = 0;
|
||||
uint8_t t = 0;
|
||||
for (bit = 0; bit < 8; ++bit) {
|
||||
x = *ptable++ - 1;
|
||||
uint8_t x = *ptable++ - 1;
|
||||
t <<= 1;
|
||||
if ((in[x / 8]) & (0x80 >> (x % 8))) {
|
||||
t |= 0x01;
|
||||
|
||||
@@ -288,7 +288,6 @@ void *mifare_cryto_preprocess_data(desfiretag_t tag, void *data, size_t *nbytes,
|
||||
|
||||
void *mifare_cryto_postprocess_data(desfiretag_t tag, void *data, size_t *nbytes, int communication_settings) {
|
||||
void *res = data;
|
||||
size_t edl;
|
||||
void *edata = NULL;
|
||||
uint8_t first_cmac_byte = 0x00;
|
||||
|
||||
@@ -322,7 +321,7 @@ void *mifare_cryto_postprocess_data(desfiretag_t tag, void *data, size_t *nbytes
|
||||
break;
|
||||
}
|
||||
|
||||
edl = enciphered_data_length(tag, *nbytes - 1, communication_settings);
|
||||
size_t edl = enciphered_data_length(tag, *nbytes - 1, communication_settings);
|
||||
edata = malloc(edl);
|
||||
|
||||
memcpy(edata, data, *nbytes - 1);
|
||||
|
||||
@@ -496,19 +496,17 @@ void EPA_PACE_Replay(PacketCommandNG *c) {
|
||||
// Returns 0 on success or a non-zero error code on failure
|
||||
//-----------------------------------------------------------------------------
|
||||
int EPA_Setup() {
|
||||
int return_code = 0;
|
||||
uint8_t uid[10];
|
||||
uint8_t pps_response[3];
|
||||
uint8_t pps_response_par[1];
|
||||
iso14a_card_select_t card_a_info;
|
||||
iso14b_card_select_t card_b_info;
|
||||
|
||||
// first, look for type A cards
|
||||
// power up the field
|
||||
iso14443a_setup(FPGA_HF_ISO14443A_READER_MOD);
|
||||
// select the card
|
||||
return_code = iso14443a_select_card(uid, &card_a_info, NULL, true, 0, false);
|
||||
int return_code = iso14443a_select_card(uid, &card_a_info, NULL, true, 0, false);
|
||||
if (return_code == 1) {
|
||||
uint8_t pps_response[3];
|
||||
uint8_t pps_response_par[1];
|
||||
// send the PPS request
|
||||
ReaderTransmit((uint8_t *)pps, sizeof(pps), NULL);
|
||||
return_code = ReaderReceive(pps_response, pps_response_par);
|
||||
@@ -523,6 +521,7 @@ int EPA_Setup() {
|
||||
// if we're here, there is no type A card, so we look for type B
|
||||
// power up the field
|
||||
iso14443b_setup();
|
||||
iso14b_card_select_t card_b_info;
|
||||
// select the card
|
||||
return_code = iso14443b_select_card(&card_b_info);
|
||||
if (return_code == 0) {
|
||||
|
||||
@@ -1366,9 +1366,7 @@ void WriterHitag(hitag_function htf, hitag_data *htd, int page) {
|
||||
uint8_t *tx = txbuf;
|
||||
size_t txlen = 0;
|
||||
int lastbit;
|
||||
bool bSkip;
|
||||
int reset_sof;
|
||||
int tag_sof;
|
||||
int t_wait = HITAG_T_WAIT_MAX;
|
||||
bool bStop;
|
||||
|
||||
@@ -1515,8 +1513,8 @@ void WriterHitag(hitag_function htf, hitag_data *htd, int page) {
|
||||
memset(rx, 0x00, sizeof(rx));
|
||||
rxlen = 0;
|
||||
lastbit = 1;
|
||||
bSkip = true;
|
||||
tag_sof = reset_sof;
|
||||
bool bSkip = true;
|
||||
int tag_sof = reset_sof;
|
||||
response = 0;
|
||||
uint32_t errorCount = 0;
|
||||
|
||||
|
||||
@@ -295,8 +295,6 @@ static int check_select(uint8_t *rx, uint32_t uid) {
|
||||
static void hitagS_handle_reader_command(uint8_t *rx, const size_t rxlen,
|
||||
uint8_t *tx, size_t *txlen) {
|
||||
uint8_t rx_air[HITAG_FRAME_LEN];
|
||||
uint8_t page;
|
||||
int i;
|
||||
uint64_t state;
|
||||
unsigned char crc;
|
||||
|
||||
@@ -330,7 +328,7 @@ static void hitagS_handle_reader_command(uint8_t *rx, const size_t rxlen,
|
||||
}
|
||||
//send uid as a response
|
||||
*txlen = 32;
|
||||
for (i = 0; i < 4; i++)
|
||||
for (int i = 0; i < 4; i++)
|
||||
tx[i] = (tag.uid >> (24 - (i * 8))) & 0xff;
|
||||
}
|
||||
break;
|
||||
@@ -357,13 +355,13 @@ static void hitagS_handle_reader_command(uint8_t *rx, const size_t rxlen,
|
||||
}
|
||||
|
||||
//send configuration
|
||||
for (i = 0; i < 4; i++)
|
||||
for (int i = 0; i < 4; i++)
|
||||
tx[i] = (tag.pages[0][1] >> (i * 8)) & 0xff;
|
||||
tx[3] = 0xff;
|
||||
if (tag.mode != HT_STANDARD) {
|
||||
*txlen = 40;
|
||||
crc = CRC_PRESET;
|
||||
for (i = 0; i < 4; i++)
|
||||
for (int i = 0; i < 4; i++)
|
||||
calc_crc(&crc, tx[i], 8);
|
||||
tx[4] = crc;
|
||||
}
|
||||
@@ -399,7 +397,7 @@ static void hitagS_handle_reader_command(uint8_t *rx, const size_t rxlen,
|
||||
break;
|
||||
}
|
||||
|
||||
for (i = 0; i < 4; i++)
|
||||
for (int i = 0; i < 4; i++)
|
||||
_hitag2_byte(&state);
|
||||
|
||||
//send con2, pwdh0, pwdl0, pwdl1 encrypted as a response
|
||||
@@ -490,7 +488,7 @@ static void hitagS_handle_reader_command(uint8_t *rx, const size_t rxlen,
|
||||
//write page, write block, read page or read block command received
|
||||
if ((rx[0] & 0xf0) == 0xc0) { //read page
|
||||
//send page data
|
||||
page = ((rx[0] & 0x0f) * 16) + ((rx[1] & 0xf0) / 16);
|
||||
uint8_t page = ((rx[0] & 0x0f) * 16) + ((rx[1] & 0xf0) / 16);
|
||||
*txlen = 32;
|
||||
tx[0] = (tag.pages[page / 4][page % 4]) & 0xff;
|
||||
tx[1] = (tag.pages[page / 4][page % 4] >> 8) & 0xff;
|
||||
@@ -520,7 +518,7 @@ static void hitagS_handle_reader_command(uint8_t *rx, const size_t rxlen,
|
||||
//add crc8
|
||||
*txlen = 40;
|
||||
crc = CRC_PRESET;
|
||||
for (i = 0; i < 4; i++)
|
||||
for (int i = 0; i < 4; i++)
|
||||
calc_crc(&crc, tx[i], 8);
|
||||
tx[4] = crc;
|
||||
}
|
||||
@@ -531,10 +529,10 @@ static void hitagS_handle_reader_command(uint8_t *rx, const size_t rxlen,
|
||||
*txlen = 0;
|
||||
}
|
||||
} else if ((rx[0] & 0xf0) == 0xd0) { //read block
|
||||
page = ((rx[0] & 0x0f) * 16) + ((rx[1] & 0xf0) / 16);
|
||||
uint8_t page = ((rx[0] & 0x0f) * 16) + ((rx[1] & 0xf0) / 16);
|
||||
*txlen = 32 * 4;
|
||||
//send page,...,page+3 data
|
||||
for (i = 0; i < 4; i++) {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
tx[0 + i * 4] = (tag.pages[page / 4][page % 4]) & 0xff;
|
||||
tx[1 + i * 4] = (tag.pages[page / 4][page % 4] >> 8) & 0xff;
|
||||
tx[2 + i * 4] = (tag.pages[page / 4][page % 4] >> 16) & 0xff;
|
||||
@@ -563,7 +561,7 @@ static void hitagS_handle_reader_command(uint8_t *rx, const size_t rxlen,
|
||||
//add crc8
|
||||
*txlen = 32 * 4 + 8;
|
||||
crc = CRC_PRESET;
|
||||
for (i = 0; i < 16; i++)
|
||||
for (int i = 0; i < 16; i++)
|
||||
calc_crc(&crc, tx[i], 8);
|
||||
tx[16] = crc;
|
||||
}
|
||||
@@ -573,7 +571,7 @@ static void hitagS_handle_reader_command(uint8_t *rx, const size_t rxlen,
|
||||
*txlen = 0;
|
||||
}
|
||||
} else if ((rx[0] & 0xf0) == 0x80) { //write page
|
||||
page = ((rx[0] & 0x0f) * 16) + ((rx[1] & 0xf0) / 16);
|
||||
uint8_t page = ((rx[0] & 0x0f) * 16) + ((rx[1] & 0xf0) / 16);
|
||||
|
||||
switch (tag.mode) {
|
||||
case HT_STANDARD:
|
||||
@@ -604,7 +602,7 @@ static void hitagS_handle_reader_command(uint8_t *rx, const size_t rxlen,
|
||||
}
|
||||
|
||||
} else if ((rx[0] & 0xf0) == 0x90) { //write block
|
||||
page = ((rx[0] & 0x0f) * 6) + ((rx[1] & 0xf0) / 16);
|
||||
uint8_t page = ((rx[0] & 0x0f) * 6) + ((rx[1] & 0xf0) / 16);
|
||||
switch (tag.mode) {
|
||||
case HT_STANDARD:
|
||||
sof_bits = 1;
|
||||
@@ -647,10 +645,8 @@ static void hitagS_handle_reader_command(uint8_t *rx, const size_t rxlen,
|
||||
static int hitagS_handle_tag_auth(hitag_function htf, uint64_t key, uint64_t NrAr, uint8_t *rx, const size_t rxlen, uint8_t *tx, size_t *txlen) {
|
||||
uint8_t rx_air[HITAG_FRAME_LEN];
|
||||
int response_bit[200];
|
||||
int i, j, z;
|
||||
unsigned char mask = 1;
|
||||
unsigned char uid[32];
|
||||
uint8_t uid1, uid2, uid3, uid4;
|
||||
unsigned char crc;
|
||||
uint64_t state;
|
||||
uint8_t auth_ks[4];
|
||||
@@ -664,9 +660,9 @@ static int hitagS_handle_tag_auth(hitag_function htf, uint64_t key, uint64_t NrA
|
||||
Dbprintf("authentication failed!");
|
||||
return -1;
|
||||
}
|
||||
z = 0;
|
||||
for (i = 0; i < 10; i++) {
|
||||
for (j = 0; j < 8; j++) {
|
||||
int z = 0;
|
||||
for (int i = 0; i < 10; i++) {
|
||||
for (int j = 0; j < 8; j++) {
|
||||
response_bit[z] = 0;
|
||||
if ((rx[i] & ((mask << 7) >> j)) != 0)
|
||||
response_bit[z] = 1;
|
||||
@@ -674,13 +670,13 @@ static int hitagS_handle_tag_auth(hitag_function htf, uint64_t key, uint64_t NrA
|
||||
}
|
||||
}
|
||||
uint16_t k = 0;
|
||||
for (i = 5; i < z; i += 2) {
|
||||
for (int i = 5; i < z; i += 2) {
|
||||
uid[k] = response_bit[i];
|
||||
k++;
|
||||
if (k > 31)
|
||||
break;
|
||||
}
|
||||
uid1 = (uid[0] << 7)
|
||||
uint8_t uid1 = (uid[0] << 7)
|
||||
| (uid[1] << 6)
|
||||
| (uid[2] << 5)
|
||||
| (uid[3] << 4)
|
||||
@@ -689,7 +685,7 @@ static int hitagS_handle_tag_auth(hitag_function htf, uint64_t key, uint64_t NrA
|
||||
| (uid[6] << 1)
|
||||
| uid[7];
|
||||
|
||||
uid2 = (uid[8] << 7)
|
||||
uint8_t uid2 = (uid[8] << 7)
|
||||
| (uid[9] << 6)
|
||||
| (uid[10] << 5)
|
||||
| (uid[11] << 4)
|
||||
@@ -698,7 +694,7 @@ static int hitagS_handle_tag_auth(hitag_function htf, uint64_t key, uint64_t NrA
|
||||
| (uid[14] << 1)
|
||||
| uid[15];
|
||||
|
||||
uid3 = (uid[16] << 7)
|
||||
uint8_t uid3 = (uid[16] << 7)
|
||||
| (uid[17] << 6)
|
||||
| (uid[18] << 5)
|
||||
| (uid[19] << 4)
|
||||
@@ -707,7 +703,7 @@ static int hitagS_handle_tag_auth(hitag_function htf, uint64_t key, uint64_t NrA
|
||||
| (uid[22] << 1)
|
||||
| uid[23];
|
||||
|
||||
uid4 = (uid[24] << 7)
|
||||
uint8_t uid4 = (uid[24] << 7)
|
||||
| (uid[25] << 6)
|
||||
| (uid[26] << 5)
|
||||
| (uid[27] << 4)
|
||||
@@ -730,19 +726,19 @@ static int hitagS_handle_tag_auth(hitag_function htf, uint64_t key, uint64_t NrA
|
||||
calc_crc(&crc, uid3, 8);
|
||||
calc_crc(&crc, uid4, 8);
|
||||
|
||||
for (i = 0; i < 100; i++) {
|
||||
for (int i = 0; i < 100; i++) {
|
||||
response_bit[i] = 0;
|
||||
}
|
||||
|
||||
for (i = 0; i < 5; i++) {
|
||||
for (int i = 0; i < 5; i++) {
|
||||
response_bit[i] = 0;
|
||||
}
|
||||
|
||||
for (i = 5; i < 37; i++) {
|
||||
int i = 5;
|
||||
for (; i < 37; i++) {
|
||||
response_bit[i] = uid[i - 5];
|
||||
}
|
||||
|
||||
for (j = 0; j < 8; j++) {
|
||||
for (int j = 0; j < 8; j++) {
|
||||
response_bit[i] = 0;
|
||||
if ((crc & ((mask << 7) >> j)) != 0)
|
||||
response_bit[i] = 1;
|
||||
@@ -750,7 +746,7 @@ static int hitagS_handle_tag_auth(hitag_function htf, uint64_t key, uint64_t NrA
|
||||
}
|
||||
|
||||
k = 0;
|
||||
for (i = 0; i < 6; i++) {
|
||||
for (int i = 0; i < 6; i++) {
|
||||
tx[i] = (response_bit[k] << 7)
|
||||
| (response_bit[k + 1] << 6)
|
||||
| (response_bit[k + 2] << 5)
|
||||
@@ -766,9 +762,9 @@ static int hitagS_handle_tag_auth(hitag_function htf, uint64_t key, uint64_t NrA
|
||||
tag.pstate = HT_INIT;
|
||||
} else if (tag.pstate == HT_INIT && rxlen == 44) {
|
||||
// received configuration after select command
|
||||
z = 0;
|
||||
for (i = 0; i < 6; i++) {
|
||||
for (j = 0; j < 8; j++) {
|
||||
int z = 0;
|
||||
for (int i = 0; i < 6; i++) {
|
||||
for (int j = 0; j < 8; j++) {
|
||||
response_bit[z] = 0;
|
||||
if ((rx[i] & ((mask << 7) >> j)) != 0)
|
||||
response_bit[z] = 1;
|
||||
@@ -819,7 +815,7 @@ static int hitagS_handle_tag_auth(hitag_function htf, uint64_t key, uint64_t NrA
|
||||
if (htf == 02 || htf == 04) { //RHTS_KEY //WHTS_KEY
|
||||
state = _hitag2_init(REV64(key), REV32(tag.uid), REV32(rnd));
|
||||
|
||||
for (i = 0; i < 4; i++) {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
auth_ks[i] = _hitag2_byte(&state) ^ 0xff;
|
||||
}
|
||||
*txlen = 64;
|
||||
@@ -836,7 +832,7 @@ static int hitagS_handle_tag_auth(hitag_function htf, uint64_t key, uint64_t NrA
|
||||
Dbprintf("%02X %02X %02X %02X %02X %02X %02X %02X", tx[0],
|
||||
tx[1], tx[2], tx[3], tx[4], tx[5], tx[6], tx[7]);
|
||||
} else if (htf == 01 || htf == 03) { //RHTS_CHALLENGE //WHTS_CHALLENGE
|
||||
for (i = 0; i < 8; i++)
|
||||
for (int i = 0; i < 8; i++)
|
||||
tx[i] = ((NrAr >> (56 - (i * 8))) & 0xff);
|
||||
}
|
||||
end = true;
|
||||
@@ -869,7 +865,7 @@ static int hitagS_handle_tag_auth(hitag_function htf, uint64_t key, uint64_t NrA
|
||||
if (htf == 02 || htf == 04) { //RHTS_KEY //WHTS_KEY
|
||||
{
|
||||
state = _hitag2_init(REV64(key), REV32(tag.uid), REV32(rnd));
|
||||
for (i = 0; i < 5; i++)
|
||||
for (int i = 0; i < 5; i++)
|
||||
_hitag2_byte(&state);
|
||||
|
||||
pwdh0 = ((rx[1] & 0x0f) * 16 + ((rx[2] & 0xf0) / 16)) ^ _hitag2_byte(&state);
|
||||
@@ -1133,9 +1129,7 @@ void ReadHitagS(hitag_function htf, hitag_data *htd) {
|
||||
uint8_t *tx = txbuf;
|
||||
size_t txlen = 0;
|
||||
int lastbit = 1;
|
||||
bool bSkip;
|
||||
int reset_sof = 1;
|
||||
int tag_sof;
|
||||
int t_wait = HITAG_T_WAIT_MAX;
|
||||
bool bStop = false;
|
||||
int sendNum = 0;
|
||||
@@ -1369,8 +1363,8 @@ void ReadHitagS(hitag_function htf, hitag_data *htd) {
|
||||
memset(rx, 0x00, sizeof(rx));
|
||||
rxlen = 0;
|
||||
lastbit = 1;
|
||||
bSkip = true;
|
||||
tag_sof = reset_sof;
|
||||
bool bSkip = true;
|
||||
int tag_sof = reset_sof;
|
||||
response = 0;
|
||||
|
||||
// Receive frame, watch for at most T0*EOF periods
|
||||
@@ -1462,9 +1456,7 @@ void WritePageHitagS(hitag_function htf, hitag_data *htd, int page) {
|
||||
uint8_t *tx = txbuf;
|
||||
size_t txlen = 0;
|
||||
int lastbit;
|
||||
bool bSkip;
|
||||
int reset_sof;
|
||||
int tag_sof;
|
||||
int t_wait = HITAG_T_WAIT_MAX;
|
||||
bool bStop;
|
||||
unsigned char crc;
|
||||
@@ -1659,8 +1651,8 @@ void WritePageHitagS(hitag_function htf, hitag_data *htd, int page) {
|
||||
memset(rx, 0x00, sizeof(rx));
|
||||
rxlen = 0;
|
||||
lastbit = 1;
|
||||
bSkip = true;
|
||||
tag_sof = reset_sof;
|
||||
bool bSkip = true;
|
||||
int tag_sof = reset_sof;
|
||||
response = 0;
|
||||
uint32_t errorCount = 0;
|
||||
|
||||
@@ -1754,12 +1746,11 @@ void check_challenges(bool file_given, uint8_t *data) {
|
||||
uint8_t rx[HITAG_FRAME_LEN];
|
||||
uint8_t unlocker[60][8];
|
||||
int u1 = 0;
|
||||
size_t rxlen = 0, txlen = 0;
|
||||
size_t rxlen = 0;
|
||||
uint8_t txbuf[HITAG_FRAME_LEN];
|
||||
uint8_t *tx;
|
||||
int t_wait = HITAG_T_WAIT_MAX;
|
||||
int lastbit, reset_sof, tag_sof, STATE = 0;;
|
||||
bool bSkip, bStop;
|
||||
int lastbit, reset_sof, STATE = 0;;
|
||||
bool bStop;
|
||||
int response_bit[200];
|
||||
unsigned char mask = 1;
|
||||
unsigned char uid[32];
|
||||
@@ -1837,8 +1828,8 @@ void check_challenges(bool file_given, uint8_t *data) {
|
||||
LogTrace(rx, nbytes(rxlen), response, 0, NULL, false);
|
||||
}
|
||||
|
||||
tx = txbuf;
|
||||
txlen = 0;
|
||||
uint8_t *tx = txbuf;
|
||||
size_t txlen = 0;
|
||||
if (rxlen == 0) {
|
||||
if (STATE == 2)
|
||||
// challenge failed
|
||||
@@ -1968,8 +1959,8 @@ void check_challenges(bool file_given, uint8_t *data) {
|
||||
memset(rx, 0x00, sizeof(rx));
|
||||
rxlen = 0;
|
||||
lastbit = 1;
|
||||
bSkip = true;
|
||||
tag_sof = reset_sof;
|
||||
bool bSkip = true;
|
||||
int tag_sof = reset_sof;
|
||||
response = 0;
|
||||
|
||||
// Receive frame, watch for at most T0*EOF periods
|
||||
|
||||
@@ -1093,7 +1093,6 @@ void SimulateIso14443aTag(uint8_t tagType, uint8_t flags, uint8_t *data) {
|
||||
#define ORDER_EV1_COMP_WRITE 40
|
||||
#define ORDER_RATS 70
|
||||
int order = ORDER_NONE;
|
||||
int lastorder;
|
||||
|
||||
int retval = PM3_SUCCESS;
|
||||
|
||||
@@ -1101,7 +1100,6 @@ void SimulateIso14443aTag(uint8_t tagType, uint8_t flags, uint8_t *data) {
|
||||
int happened = 0;
|
||||
int happened2 = 0;
|
||||
int cmdsRecvd = 0;
|
||||
tag_response_info_t *p_response;
|
||||
|
||||
// compatible write block number
|
||||
uint8_t wrblock = 0;
|
||||
@@ -1118,10 +1116,10 @@ void SimulateIso14443aTag(uint8_t tagType, uint8_t flags, uint8_t *data) {
|
||||
retval = PM3_EOPABORTED;
|
||||
break;
|
||||
}
|
||||
p_response = NULL;
|
||||
tag_response_info_t *p_response = NULL;
|
||||
|
||||
// Okay, look at the command now.
|
||||
lastorder = order;
|
||||
int lastorder = order;
|
||||
|
||||
//
|
||||
// we need to check "ordered" states before, because received data may be same to any command - is wrong!!!
|
||||
@@ -1527,17 +1525,16 @@ void PrepareDelayedTransfer(uint16_t delay) {
|
||||
delay &= 0x07;
|
||||
if (!delay) return;
|
||||
|
||||
uint8_t bitmask = 0, bits_to_shift;
|
||||
uint8_t bitmask = 0;
|
||||
uint8_t bits_shifted = 0;
|
||||
uint16_t i = 0;
|
||||
|
||||
for (i = 0; i < delay; i++)
|
||||
for (uint16_t i = 0; i < delay; i++)
|
||||
bitmask |= (0x01 << i);
|
||||
|
||||
ToSend[ToSendMax++] = 0x00;
|
||||
|
||||
for (i = 0; i < ToSendMax; i++) {
|
||||
bits_to_shift = ToSend[i] & bitmask;
|
||||
for (uint16_t i = 0; i < ToSendMax; i++) {
|
||||
uint8_t bits_to_shift = ToSend[i] & bitmask;
|
||||
ToSend[i] = ToSend[i] >> delay;
|
||||
ToSend[i] = ToSend[i] | (bits_shifted << (8 - delay));
|
||||
bits_shifted = bits_to_shift;
|
||||
@@ -1600,9 +1597,7 @@ static void TransmitFor14443a(const uint8_t *cmd, uint16_t len, uint32_t *timing
|
||||
// Prepare reader command (in bits, support short frames) to send to FPGA
|
||||
//-----------------------------------------------------------------------------
|
||||
void CodeIso14443aBitsAsReaderPar(const uint8_t *cmd, uint16_t bits, const uint8_t *par) {
|
||||
int i, j;
|
||||
int last = 0;
|
||||
uint8_t b;
|
||||
|
||||
ToSendReset();
|
||||
|
||||
@@ -1612,11 +1607,11 @@ void CodeIso14443aBitsAsReaderPar(const uint8_t *cmd, uint16_t bits, const uint8
|
||||
|
||||
size_t bytecount = nbytes(bits);
|
||||
// Generate send structure for the data bits
|
||||
for (i = 0; i < bytecount; i++) {
|
||||
for (int i = 0; i < bytecount; i++) {
|
||||
// Get the current byte to send
|
||||
b = cmd[i];
|
||||
uint8_t b = cmd[i];
|
||||
size_t bitsleft = MIN((bits - (i * 8)), 8);
|
||||
|
||||
int j;
|
||||
for (j = 0; j < bitsleft; j++) {
|
||||
if (b & 1) {
|
||||
// Sequence X
|
||||
@@ -2078,25 +2073,22 @@ void iso14443a_antifuzz(uint32_t flags) {
|
||||
|
||||
static void iso14a_set_ATS_times(uint8_t *ats) {
|
||||
|
||||
uint8_t tb1;
|
||||
uint8_t fwi, sfgi;
|
||||
uint32_t fwt, sfgt;
|
||||
|
||||
if (ats[0] > 1) { // there is a format byte T0
|
||||
if ((ats[1] & 0x20) == 0x20) { // there is an interface byte TB(1)
|
||||
uint8_t tb1;
|
||||
if ((ats[1] & 0x10) == 0x10) { // there is an interface byte TA(1) preceding TB(1)
|
||||
tb1 = ats[3];
|
||||
} else {
|
||||
tb1 = ats[2];
|
||||
}
|
||||
fwi = (tb1 & 0xf0) >> 4; // frame waiting time integer (FWI)
|
||||
uint8_t fwi = (tb1 & 0xf0) >> 4; // frame waiting time integer (FWI)
|
||||
if (fwi != 15) {
|
||||
fwt = 256 * 16 * (1 << fwi); // frame waiting time (FWT) in 1/fc
|
||||
uint32_t fwt = 256 * 16 * (1 << fwi); // frame waiting time (FWT) in 1/fc
|
||||
iso14a_set_timeout(fwt / (8 * 16));
|
||||
}
|
||||
sfgi = tb1 & 0x0f; // startup frame guard time integer (SFGI)
|
||||
uint8_t sfgi = tb1 & 0x0f; // startup frame guard time integer (SFGI)
|
||||
if (sfgi != 0 && sfgi != 15) {
|
||||
sfgt = 256 * 16 * (1 << sfgi); // startup frame guard time (SFGT) in 1/fc
|
||||
uint32_t sfgt = 256 * 16 * (1 << sfgi); // startup frame guard time (SFGT) in 1/fc
|
||||
NextTransferTime = MAX(NextTransferTime, Demod.endTime + (sfgt - DELAY_AIR2ARM_AS_READER - DELAY_ARM2AIR_AS_READER) / 16);
|
||||
}
|
||||
}
|
||||
@@ -2144,7 +2136,6 @@ int iso14443a_select_card(uint8_t *uid_ptr, iso14a_card_select_t *p_card, uint32
|
||||
|
||||
uint8_t sak = 0x04; // cascade uid
|
||||
int cascade_level = 0;
|
||||
int len;
|
||||
|
||||
if (p_card) {
|
||||
p_card->uidlen = 0;
|
||||
@@ -2271,7 +2262,7 @@ int iso14443a_select_card(uint8_t *uid_ptr, iso14a_card_select_t *p_card, uint32
|
||||
|
||||
AddCrc14A(rats, 2);
|
||||
ReaderTransmit(rats, sizeof(rats), NULL);
|
||||
len = ReaderReceive(resp, resp_par);
|
||||
int len = ReaderReceive(resp, resp_par);
|
||||
|
||||
if (!len) return 0;
|
||||
|
||||
@@ -2639,7 +2630,6 @@ void ReaderMifare(bool first_try, uint8_t block, uint8_t keytype) {
|
||||
uint16_t sync_tries = 0;
|
||||
|
||||
bool have_uid = false;
|
||||
bool received_nack;
|
||||
uint8_t cascade_levels = 0;
|
||||
|
||||
// static variables here, is re-used in the next call
|
||||
@@ -2667,7 +2657,7 @@ void ReaderMifare(bool first_try, uint8_t block, uint8_t keytype) {
|
||||
uint16_t i;
|
||||
for (i = 0; true; ++i) {
|
||||
|
||||
received_nack = false;
|
||||
bool received_nack = false;
|
||||
|
||||
WDT_HIT();
|
||||
|
||||
@@ -2893,7 +2883,6 @@ void DetectNACKbug() {
|
||||
uint16_t sync_tries = 0;
|
||||
uint32_t sync_time = 0;
|
||||
bool have_uid = false;
|
||||
bool received_nack;
|
||||
|
||||
int32_t status = PM3_SUCCESS;
|
||||
|
||||
@@ -2912,7 +2901,7 @@ void DetectNACKbug() {
|
||||
uint16_t i;
|
||||
for (i = 1; true; ++i) {
|
||||
|
||||
received_nack = false;
|
||||
bool received_nack = false;
|
||||
|
||||
// Cards always leaks a NACK, no matter the parity
|
||||
if ((i == 10) && (num_nacks == i - 1)) {
|
||||
|
||||
@@ -237,9 +237,6 @@ static void CodeIso14443bAsTag(const uint8_t *cmd, int len) {
|
||||
*
|
||||
*/
|
||||
|
||||
int i, j;
|
||||
uint8_t b;
|
||||
|
||||
ToSendReset();
|
||||
|
||||
// Transmit a burst of ones, as the initial thing that lets the
|
||||
@@ -252,23 +249,23 @@ static void CodeIso14443bAsTag(const uint8_t *cmd, int len) {
|
||||
|
||||
// Send SOF.
|
||||
// 10-11 ETU * 4times samples ZEROS
|
||||
for (i = 0; i < 10; i++) { SEND4STUFFBIT(0); }
|
||||
for (int i = 0; i < 10; i++) { SEND4STUFFBIT(0); }
|
||||
//for(i = 0; i < 10; i++) { ToSendStuffBit(0); }
|
||||
|
||||
// 2-3 ETU * 4times samples ONES
|
||||
for (i = 0; i < 3; i++) { SEND4STUFFBIT(1); }
|
||||
for (int i = 0; i < 3; i++) { SEND4STUFFBIT(1); }
|
||||
//for(i = 0; i < 3; i++) { ToSendStuffBit(1); }
|
||||
|
||||
// data
|
||||
for (i = 0; i < len; ++i) {
|
||||
for (int i = 0; i < len; ++i) {
|
||||
|
||||
// Start bit
|
||||
SEND4STUFFBIT(0);
|
||||
//ToSendStuffBit(0);
|
||||
|
||||
// Data bits
|
||||
b = cmd[i];
|
||||
for (j = 0; j < 8; ++j) {
|
||||
uint8_t b = cmd[i];
|
||||
for (int j = 0; j < 8; ++j) {
|
||||
// if(b & 1) {
|
||||
// SEND4STUFFBIT(1);
|
||||
// //ToSendStuffBit(1);
|
||||
@@ -292,11 +289,11 @@ static void CodeIso14443bAsTag(const uint8_t *cmd, int len) {
|
||||
|
||||
// Send EOF.
|
||||
// 10-11 ETU * 4 sample rate = ZEROS
|
||||
for (i = 0; i < 10; i++) { SEND4STUFFBIT(0); }
|
||||
for (int i = 0; i < 10; i++) { SEND4STUFFBIT(0); }
|
||||
//for(i = 0; i < 10; i++) { ToSendStuffBit(0); }
|
||||
|
||||
// why this?
|
||||
for (i = 0; i < 40; i++) { SEND4STUFFBIT(1); }
|
||||
for (int i = 0; i < 40; i++) { SEND4STUFFBIT(1); }
|
||||
//for(i = 0; i < 40; i++) { ToSendStuffBit(1); }
|
||||
|
||||
// Convert from last byte pos to length
|
||||
@@ -945,7 +942,7 @@ static RAMFUNC int Handle14443bTagSamplesDemod(int ci, int cq) {
|
||||
* quiet: set to 'TRUE' to disable debug output
|
||||
*/
|
||||
static void GetTagSamplesFor14443bDemod() {
|
||||
bool gotFrame, finished = false;
|
||||
bool finished = false;
|
||||
// int lastRxCounter = ISO14443B_DMA_BUFFER_SIZE;
|
||||
uint32_t time_0 = 0, time_stop = 0;
|
||||
|
||||
@@ -991,7 +988,7 @@ static void GetTagSamplesFor14443bDemod() {
|
||||
}
|
||||
|
||||
// https://github.com/Proxmark/proxmark3/issues/103
|
||||
gotFrame = Handle14443bTagSamplesDemod(ci, cq);
|
||||
bool gotFrame = Handle14443bTagSamplesDemod(ci, cq);
|
||||
time_stop = GetCountSspClk() - time_0;
|
||||
|
||||
finished = (time_stop > iso14b_timeout || gotFrame);
|
||||
@@ -1058,14 +1055,12 @@ static void CodeIso14443bAsReader(const uint8_t *cmd, int len) {
|
||||
* QUESTION: how long is a 1 or 0 in pulses in the xcorr_848 mode?
|
||||
* 1 "stuffbit" = 1ETU (9us)
|
||||
*/
|
||||
int i;
|
||||
uint8_t b;
|
||||
|
||||
ToSendReset();
|
||||
|
||||
// Send SOF
|
||||
// 10-11 ETUs of ZERO
|
||||
for (i = 0; i < 10; ++i) ToSendStuffBit(0);
|
||||
for (int i = 0; i < 10; ++i) ToSendStuffBit(0);
|
||||
|
||||
// 2-3 ETUs of ONE
|
||||
ToSendStuffBit(1);
|
||||
@@ -1074,11 +1069,11 @@ static void CodeIso14443bAsReader(const uint8_t *cmd, int len) {
|
||||
|
||||
// Sending cmd, LSB
|
||||
// from here we add BITS
|
||||
for (i = 0; i < len; ++i) {
|
||||
for (int i = 0; i < len; ++i) {
|
||||
// Start bit
|
||||
ToSendStuffBit(0);
|
||||
// Data bits
|
||||
b = cmd[i];
|
||||
uint8_t b = cmd[i];
|
||||
// if ( b & 1 ) ToSendStuffBit(1); else ToSendStuffBit(0);
|
||||
// if ( (b>>1) & 1) ToSendStuffBit(1); else ToSendStuffBit(0);
|
||||
// if ( (b>>2) & 1) ToSendStuffBit(1); else ToSendStuffBit(0);
|
||||
@@ -1108,13 +1103,13 @@ static void CodeIso14443bAsReader(const uint8_t *cmd, int len) {
|
||||
|
||||
// Send EOF
|
||||
// 10-11 ETUs of ZERO
|
||||
for (i = 0; i < 10; ++i) ToSendStuffBit(0);
|
||||
for (int i = 0; i < 10; ++i) ToSendStuffBit(0);
|
||||
|
||||
// Transition time. TR0 - guard time
|
||||
// 8ETUS minum?
|
||||
// Per specification, Subcarrier must be stopped no later than 2 ETUs after EOF.
|
||||
// I'm guessing this is for the FPGA to be able to send all bits before we switch to listening mode
|
||||
for (i = 0; i < 24 ; ++i) ToSendStuffBit(1);
|
||||
for (int i = 0; i < 24 ; ++i) ToSendStuffBit(1);
|
||||
|
||||
// TR1 - Synchronization time
|
||||
// Convert from last character reference to length
|
||||
@@ -1462,7 +1457,6 @@ static void iso1444b_setup_sniff(void) {
|
||||
void RAMFUNC SniffIso14443b(void) {
|
||||
|
||||
uint32_t time_0 = 0, time_start = 0, time_stop;
|
||||
int ci, cq;
|
||||
|
||||
// We won't start recording the frames that we acquire until we trigger;
|
||||
// a good trigger condition to get started is probably when we see a
|
||||
@@ -1490,8 +1484,8 @@ void RAMFUNC SniffIso14443b(void) {
|
||||
while (!BUTTON_PRESS()) {
|
||||
WDT_HIT();
|
||||
|
||||
ci = data[0];
|
||||
cq = data[1];
|
||||
int ci = data[0];
|
||||
int cq = data[1];
|
||||
data += 2;
|
||||
|
||||
if (data >= dmaBuf + ISO14443B_DMA_BUFFER_SIZE) {
|
||||
|
||||
@@ -736,9 +736,9 @@ int SendDataTag(uint8_t *send, int sendlen, bool init, int speed, uint8_t *outda
|
||||
// Decodes a message from a tag and displays its metadata and content
|
||||
#define DBD15STATLEN 48
|
||||
void DbdecodeIso15693Answer(int len, uint8_t *d) {
|
||||
char status[DBD15STATLEN + 1] = {0};
|
||||
|
||||
if (len > 3) {
|
||||
char status[DBD15STATLEN + 1] = {0};
|
||||
if (d[0] & (1 << 3))
|
||||
strncat(status, "ProtExt ", DBD15STATLEN - strlen(status));
|
||||
if (d[0] & 1) {
|
||||
@@ -802,9 +802,6 @@ void DbdecodeIso15693Answer(int len, uint8_t *d) {
|
||||
void ReaderIso15693(uint32_t parameter) {
|
||||
int answerLen1 = 0;
|
||||
int tsamples = 0, wait = 0, elapsed = 0;
|
||||
|
||||
uint8_t uid[8] = {0, 0, 0, 0, 0, 0, 0, 0};
|
||||
|
||||
// set up device/fpga
|
||||
Iso15693InitReader();
|
||||
|
||||
@@ -829,6 +826,7 @@ void ReaderIso15693(uint32_t parameter) {
|
||||
|
||||
// we should do a better check than this
|
||||
if (answerLen1 >= 12) {
|
||||
uint8_t uid[8];
|
||||
uid[0] = answer1[9]; // always E0
|
||||
uid[1] = answer1[8]; // IC Manufacturer code
|
||||
uid[2] = answer1[7];
|
||||
|
||||
@@ -1151,24 +1151,20 @@ void CmdAWIDdemodFSK(int findone, uint32_t *high, uint32_t *low, int ledcontrol)
|
||||
// w = wiegand parity
|
||||
// (26 bit format shown)
|
||||
|
||||
uint32_t fac = 0;
|
||||
uint32_t cardnum = 0;
|
||||
uint32_t code1 = 0;
|
||||
uint32_t code2 = 0;
|
||||
uint8_t fmtLen = bytebits_to_byte(dest, 8);
|
||||
if (fmtLen == 26) {
|
||||
fac = bytebits_to_byte(dest + 9, 8);
|
||||
cardnum = bytebits_to_byte(dest + 17, 16);
|
||||
code1 = bytebits_to_byte(dest + 8, fmtLen);
|
||||
uint32_t fac = bytebits_to_byte(dest + 9, 8);
|
||||
uint32_t cardnum = bytebits_to_byte(dest + 17, 16);
|
||||
uint32_t code1 = bytebits_to_byte(dest + 8, fmtLen);
|
||||
Dbprintf("AWID Found - BitLength: %d, FC: %d, Card: %d - Wiegand: %x, Raw: %08x%08x%08x", fmtLen, fac, cardnum, code1, rawHi2, rawHi, rawLo);
|
||||
} else {
|
||||
cardnum = bytebits_to_byte(dest + 8 + (fmtLen - 17), 16);
|
||||
uint32_t cardnum = bytebits_to_byte(dest + 8 + (fmtLen - 17), 16);
|
||||
if (fmtLen > 32) {
|
||||
code1 = bytebits_to_byte(dest + 8, fmtLen - 32);
|
||||
code2 = bytebits_to_byte(dest + 8 + (fmtLen - 32), 32);
|
||||
uint32_t code1 = bytebits_to_byte(dest + 8, fmtLen - 32);
|
||||
uint32_t code2 = bytebits_to_byte(dest + 8 + (fmtLen - 32), 32);
|
||||
Dbprintf("AWID Found - BitLength: %d -unknown BitLength- (%d) - Wiegand: %x%08x, Raw: %08x%08x%08x", fmtLen, cardnum, code1, code2, rawHi2, rawHi, rawLo);
|
||||
} else {
|
||||
code1 = bytebits_to_byte(dest + 8, fmtLen);
|
||||
uint32_t code1 = bytebits_to_byte(dest + 8, fmtLen);
|
||||
Dbprintf("AWID Found - BitLength: %d -unknown BitLength- (%d) - Wiegand: %x, Raw: %08x%08x%08x", fmtLen, cardnum, code1, rawHi2, rawHi, rawLo);
|
||||
}
|
||||
}
|
||||
@@ -1189,7 +1185,7 @@ void CmdEM410xdemod(int findone, uint32_t *high, uint64_t *low, int ledcontrol)
|
||||
uint8_t *dest = BigBuf_get_addr();
|
||||
|
||||
size_t size, idx = 0;
|
||||
int clk = 0, invert = 0, errCnt, maxErr = 20;
|
||||
int clk = 0, invert = 0, maxErr = 20;
|
||||
uint32_t hi = 0;
|
||||
uint64_t lo = 0;
|
||||
|
||||
@@ -1207,7 +1203,7 @@ void CmdEM410xdemod(int findone, uint32_t *high, uint64_t *low, int ledcontrol)
|
||||
size = BigBuf_max_traceLen();
|
||||
//askdemod and manchester decode
|
||||
if (size > 16385) size = 16385; //big enough to catch 2 sequences of largest format
|
||||
errCnt = askdemod(dest, &size, &clk, &invert, maxErr, 0, 1);
|
||||
int errCnt = askdemod(dest, &size, &clk, &invert, maxErr, 0, 1);
|
||||
WDT_HIT();
|
||||
|
||||
if (errCnt > 50) continue;
|
||||
|
||||
@@ -861,11 +861,10 @@ void MifareNested(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain)
|
||||
ui64Key = bytes_to_num(datain, 6);
|
||||
|
||||
// variables
|
||||
uint16_t rtr, i, j, len;
|
||||
uint16_t davg = 0;
|
||||
uint16_t i, j, len;
|
||||
static uint16_t dmin, dmax;
|
||||
uint8_t uid[10] = {0x00};
|
||||
uint32_t cuid = 0, nt1, nt2, nttmp, nttest, ks1;
|
||||
uint32_t cuid = 0, nt1, nt2, nttest, ks1;
|
||||
uint8_t par[1] = {0x00};
|
||||
uint32_t target_nt[2] = {0x00}, target_ks[2] = {0x00};
|
||||
|
||||
@@ -893,15 +892,16 @@ void MifareNested(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain)
|
||||
// statistics on nonce distance
|
||||
int16_t isOK = 0;
|
||||
#define NESTED_MAX_TRIES 12
|
||||
uint16_t unsuccessfull_tries = 0;
|
||||
if (arg2) { // calibrate: for first call only. Otherwise reuse previous calibration
|
||||
LED_B_ON();
|
||||
WDT_HIT();
|
||||
|
||||
davg = dmax = 0;
|
||||
uint16_t unsuccessfull_tries = 0;
|
||||
uint16_t davg = 0;
|
||||
dmax = 0;
|
||||
dmin = 2000;
|
||||
delta_time = 0;
|
||||
|
||||
uint16_t rtr;
|
||||
for (rtr = 0; rtr < 17; rtr++) {
|
||||
|
||||
// Test if the action was cancelled
|
||||
@@ -937,7 +937,7 @@ void MifareNested(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain)
|
||||
continue;
|
||||
};
|
||||
|
||||
nttmp = prng_successor(nt1, 100); //NXP Mifare is typical around 840,but for some unlicensed/compatible mifare card this can be 160
|
||||
uint32_t nttmp = prng_successor(nt1, 100); //NXP Mifare is typical around 840,but for some unlicensed/compatible mifare card this can be 160
|
||||
for (i = 101; i < 1200; i++) {
|
||||
nttmp = prng_successor(nttmp, 1);
|
||||
if (nttmp == nt2) break;
|
||||
@@ -1653,7 +1653,6 @@ void MifareEMemGet(uint8_t blockno, uint8_t blockcnt) {
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
int MifareECardLoad(uint32_t arg0, uint32_t arg1) {
|
||||
uint64_t ui64Key;
|
||||
uint32_t cuid = 0;
|
||||
uint8_t numSectors = arg0;
|
||||
uint8_t keyType = arg1;
|
||||
@@ -1682,7 +1681,7 @@ int MifareECardLoad(uint32_t arg0, uint32_t arg1) {
|
||||
}
|
||||
|
||||
for (uint8_t sectorNo = 0; isOK && sectorNo < numSectors; sectorNo++) {
|
||||
ui64Key = emlGetKey(sectorNo, keyType);
|
||||
uint64_t ui64Key = emlGetKey(sectorNo, keyType);
|
||||
if (sectorNo == 0) {
|
||||
if (isOK && mifare_classic_auth(pcs, cuid, FirstBlockOfSector(sectorNo), keyType, ui64Key, AUTH_FIRST)) {
|
||||
if (DBGLEVEL >= 1) Dbprintf("Sector[%2d]. Auth error", sectorNo);
|
||||
@@ -2016,7 +2015,6 @@ void MifareSetMod(uint8_t *datain) {
|
||||
uint32_t cuid = 0;
|
||||
struct Crypto1State mpcs = {0, 0};
|
||||
struct Crypto1State *pcs = &mpcs;
|
||||
int respLen;
|
||||
uint8_t receivedAnswer[MAX_MIFARE_FRAME_SIZE] = {0};
|
||||
uint8_t receivedAnswerPar[MAX_MIFARE_PARITY_SIZE] = {0};
|
||||
|
||||
@@ -2040,6 +2038,7 @@ void MifareSetMod(uint8_t *datain) {
|
||||
break;
|
||||
}
|
||||
|
||||
int respLen;
|
||||
if (((respLen = mifare_sendcmd_short(pcs, 1, 0x43, mod, receivedAnswer, receivedAnswerPar, NULL)) != 1) || (receivedAnswer[0] != 0x0a)) {
|
||||
if (DBGLEVEL >= 1) Dbprintf("SetMod error; response[0]: %hhX, len: %d", receivedAnswer[0], respLen);
|
||||
break;
|
||||
|
||||
@@ -174,22 +174,18 @@ void MifareDES_Auth1(uint8_t arg0, uint8_t arg1, uint8_t arg2, uint8_t *datain)
|
||||
int len = 0;
|
||||
//uint8_t PICC_MASTER_KEY8[8] = { 0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47};
|
||||
uint8_t PICC_MASTER_KEY16[16] = { 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f };
|
||||
uint8_t null_key_data8[8] = {0x00};
|
||||
//uint8_t null_key_data16[16] = {0x00};
|
||||
//uint8_t new_key_data8[8] = { 0x00,0x11,0x22,0x33,0x44,0x55,0x66,0x77};
|
||||
//uint8_t new_key_data16[16] = { 0x00,0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x88,0x99,0xAA,0xBB,0xCC,0xDD,0xEE,0xFF};
|
||||
|
||||
uint8_t resp[256] = {0x00};
|
||||
uint8_t IV[16] = {0x00};
|
||||
|
||||
size_t datalen = datain[0];
|
||||
|
||||
uint8_t cmd[40] = {0x00};
|
||||
uint8_t encRndB[16] = {0x00};
|
||||
uint8_t decRndB[16] = {0x00};
|
||||
uint8_t nonce[16] = {0x00};
|
||||
uint8_t both[32] = {0x00};
|
||||
uint8_t encBoth[32] = {0x00};
|
||||
|
||||
InitDesfireCard();
|
||||
|
||||
@@ -217,6 +213,7 @@ void MifareDES_Auth1(uint8_t arg0, uint8_t arg1, uint8_t arg2, uint8_t *datain)
|
||||
} else {
|
||||
if (arg1 == 1) {
|
||||
if (datain[1] == 0xff) {
|
||||
uint8_t null_key_data8[8] = {0x00};
|
||||
memcpy(keybytes, null_key_data8, 8);
|
||||
} else {
|
||||
memcpy(keybytes, datain + 1, datalen);
|
||||
@@ -437,6 +434,7 @@ void MifareDES_Auth1(uint8_t arg0, uint8_t arg1, uint8_t arg2, uint8_t *datain)
|
||||
Desfire_aes_key_new(keybytes, key);
|
||||
|
||||
AesCtx ctx;
|
||||
uint8_t IV[16] = {0x00};
|
||||
if (AesCtxIni(&ctx, IV, key->data, KEY128, CBC) < 0) {
|
||||
if (DBGLEVEL >= 4) {
|
||||
DbpString("AES context failed to init");
|
||||
@@ -461,8 +459,10 @@ void MifareDES_Auth1(uint8_t arg0, uint8_t arg1, uint8_t arg2, uint8_t *datain)
|
||||
// dekryptera tagnonce.
|
||||
AesDecrypt(&ctx, encRndB, decRndB, 16);
|
||||
rol(decRndB, 16);
|
||||
uint8_t nonce[16] = {0x00};
|
||||
memcpy(both, nonce, 16);
|
||||
memcpy(both + 16, decRndB, 16);
|
||||
uint8_t encBoth[32] = {0x00};
|
||||
AesEncrypt(&ctx, both, encBoth, 32);
|
||||
|
||||
cmd[0] = ADDITIONAL_FRAME;
|
||||
|
||||
@@ -309,13 +309,13 @@ bool RAMFUNC MfSniffLogic(const uint8_t *data, uint16_t len, uint8_t *parity, ui
|
||||
*/
|
||||
|
||||
void RAMFUNC MfSniffSend() {
|
||||
uint16_t chunksize, tracelen = BigBuf_get_traceLen();
|
||||
uint16_t tracelen = BigBuf_get_traceLen();
|
||||
int packlen = tracelen; // total number of bytes to send
|
||||
uint8_t *data = BigBuf_get_addr();
|
||||
|
||||
while (packlen > 0) {
|
||||
LED_B_ON();
|
||||
chunksize = MIN(PM3_CMD_DATA_SIZE, packlen); // chunk size 512
|
||||
uint16_t chunksize = MIN(PM3_CMD_DATA_SIZE, packlen); // chunk size 512
|
||||
reply_old(CMD_ACK, 1, tracelen, chunksize, data + tracelen - packlen, chunksize);
|
||||
packlen -= chunksize;
|
||||
LED_B_OFF();
|
||||
|
||||
@@ -111,9 +111,8 @@ void opt_successor(const uint8_t *k, State *s, bool y, State *successor) {
|
||||
|
||||
void opt_suc(const uint8_t *k, State *s, uint8_t *in, uint8_t length, bool add32Zeroes) {
|
||||
State x2;
|
||||
int i;
|
||||
uint8_t head;
|
||||
for (i = 0; i < length; i++) {
|
||||
for (int i = 0; i < length; i++) {
|
||||
uint8_t head;
|
||||
head = 1 & (in[i] >> 7);
|
||||
opt_successor(k, s, head, &x2);
|
||||
|
||||
@@ -141,7 +140,7 @@ void opt_suc(const uint8_t *k, State *s, uint8_t *in, uint8_t length, bool add32
|
||||
|
||||
//For tag MAC, an additional 32 zeroes
|
||||
if (add32Zeroes) {
|
||||
for (i = 0; i < 16; i++) {
|
||||
for (int i = 0; i < 16; i++) {
|
||||
opt_successor(k, s, 0, &x2);
|
||||
opt_successor(k, &x2, 0, s);
|
||||
}
|
||||
@@ -149,10 +148,9 @@ void opt_suc(const uint8_t *k, State *s, uint8_t *in, uint8_t length, bool add32
|
||||
}
|
||||
|
||||
void opt_output(const uint8_t *k, State *s, uint8_t *buffer) {
|
||||
uint8_t bout, times = 0;
|
||||
State temp = {0, 0, 0, 0};
|
||||
for (; times < 4; times++) {
|
||||
bout = 0;
|
||||
for (uint8_t times = 0; times < 4; times++) {
|
||||
uint8_t bout = 0;
|
||||
bout |= (s->r & 0x4) << 5;
|
||||
opt_successor(k, s, 0, &temp);
|
||||
bout |= (temp.r & 0x4) << 4;
|
||||
|
||||
@@ -60,12 +60,10 @@ char const hex2ascii_data[] = "0123456789abcdefghijklmnopqrstuvwxyz";
|
||||
*/
|
||||
static char *
|
||||
ksprintn(char *nbuf, uintmax_t num, int base, int *lenp, int upper) {
|
||||
char *p, c;
|
||||
|
||||
p = nbuf;
|
||||
char *p = nbuf;
|
||||
*p = '\0';
|
||||
do {
|
||||
c = hex2ascii(num % base);
|
||||
char c = hex2ascii(num % base);
|
||||
*++p = upper ? toupper(c) : c;
|
||||
} while (num /= base);
|
||||
if (lenp)
|
||||
|
||||
@@ -80,10 +80,10 @@ char *strcat(char *dest, const char *src) {
|
||||
|
||||
/* reverse: reverse string s in place */
|
||||
void strreverse(char s[]) {
|
||||
int c, i, j;
|
||||
int j = strlen(s) - 1;
|
||||
|
||||
for (i = 0, j = strlen(s) - 1; i < j; i++, j--) {
|
||||
c = s[i];
|
||||
for (int i = 0; i < j; i++, j--) {
|
||||
int c = s[i];
|
||||
s[i] = s[j];
|
||||
s[j] = c;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user