UsbCommand resp;
UsbCommand c = {CMD_READER_ICLASS, {0}};
- c.arg[0] = FLAG_ICLASS_READER_ONLY_ONCE| FLAG_ICLASS_READER_CC;
+ c.arg[0] = FLAG_ICLASS_READER_ONLY_ONCE | FLAG_ICLASS_READER_CC | FLAG_ICLASS_READER_ONE_TRY;
if (use_credit_key)
c.arg[0] |= FLAG_ICLASS_READER_CEDITKEY;
uint8_t blockno = 0;
uint8_t numblks = 0;
uint8_t maxBlk = 31;
+ uint8_t app_areas = 1;
+ uint8_t kb = 2;
uint8_t KEY[8] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
uint8_t CreditKEY[8] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
uint8_t keyNbr = 0;
SendCommand(&c);
if (!WaitForResponseTimeout(CMD_ACK, &resp, 4500)) {
PrintAndLog("Command execute timeout");
+ ul_switch_off_field();
return 0;
}
uint8_t readStatus = resp.arg[0] & 0xff;
if(readStatus == 0){
PrintAndLog("No tag found...");
+ ul_switch_off_field();
return 0;
}
if( readStatus & (FLAG_ICLASS_READER_CSN|FLAG_ICLASS_READER_CONF|FLAG_ICLASS_READER_CC)){
memcpy(tag_data, data, 8*3);
blockno+=2; // 2 to force re-read of block 2 later. (seems to respond differently..)
numblks = data[8];
-
- if (data[13] & 0x80) {
- // large memory - not able to dump pages currently
- maxBlk = 255;
- } else {
- maxBlk = 31;
- }
+ getMemConfig(data[13], data[12], &maxBlk, &app_areas, &kb);
+ // large memory - not able to dump pages currently
if (numblks > maxBlk) numblks = maxBlk;
}
+ ul_switch_off_field();
// authenticate debit key and get div_key - later store in dump block 3
if (!select_and_auth(KEY, MAC, div_key, use_credit_key, elite, false)){
//try twice - for some reason it sometimes fails the first time...
}
// begin dump
- UsbCommand w = {CMD_ICLASS_DUMP, {blockno, numblks-blockno+1, 0x88}};
+ UsbCommand w = {CMD_ICLASS_DUMP, {blockno, numblks-blockno+1}};
clearCommandBuffer();
SendCommand(&w);
if (!WaitForResponseTimeout(CMD_ACK, &resp, 4500)) {
PrintAndLog("Command execute time-out 1");
+ ul_switch_off_field();
return 1;
}
uint32_t blocksRead = resp.arg[1];
uint8_t isOK = resp.arg[0] & 0xff;
if (!isOK && !blocksRead) {
PrintAndLog("Read Block Failed");
+ ul_switch_off_field();
return 0;
}
uint32_t startindex = resp.arg[2];
// setup dump and start
w.arg[0] = blockno + blocksRead;
w.arg[1] = maxBlk - (blockno + blocksRead);
- w.arg[2] = 0x18;
clearCommandBuffer();
SendCommand(&w);
if (!WaitForResponseTimeout(CMD_ACK, &resp, 4500)) {
PrintAndLog("Command execute timeout 2");
+ ul_switch_off_field();
return 0;
}
uint8_t isOK = resp.arg[0] & 0xff;
blocksRead = resp.arg[1];
if (!isOK && !blocksRead) {
PrintAndLog("Read Block Failed 2");
+ ul_switch_off_field();
return 0;
}
static int WriteBlock(uint8_t blockno, uint8_t *bldata, uint8_t *KEY, bool use_credit_key, bool elite, bool verbose) {
uint8_t MAC[4]={0x00,0x00,0x00,0x00};
uint8_t div_key[8]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
- uint8_t keyType = (use_credit_key) ? 0x18 : 0x88;
if (!select_and_auth(KEY, MAC, div_key, use_credit_key, elite, verbose))
return 0;
UsbCommand resp;
Calc_wb_mac(blockno,bldata,div_key,MAC);
- UsbCommand w = {CMD_ICLASS_WRITEBLOCK, {blockno, keyType}};
+ UsbCommand w = {CMD_ICLASS_WRITEBLOCK, {blockno}};
memcpy(w.d.asBytes, bldata, 8);
- memcpy(w.d.asBytes + 8,MAC, 4);
+ memcpy(w.d.asBytes + 8, MAC, 4);
clearCommandBuffer();
SendCommand(&w);
return 0;
}
PrintAndLog("Write Block Successful");
-
return 1;
}
int CmdHFiClass_WriteBlock(const char *Cmd) {
uint8_t blockno=0;
- uint8_t bldata[8]={0};
+ uint8_t bldata[8]={0,0,0,0,0,0,0,0};
uint8_t KEY[8]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
uint8_t keyNbr = 0;
uint8_t dataLen = 0;
}
if (cmdp < 6) return usage_hf_iclass_writeblock();
-
- return WriteBlock(blockno, bldata, KEY, use_credit_key, elite, true);
+ int ans = WriteBlock(blockno, bldata, KEY, use_credit_key, elite, true);
+ ul_switch_off_field();
+ return ans;
}
int usage_hf_iclass_clone(void) {
if (!select_and_auth(KEY, MAC, div_key, use_credit_key, elite, true))
return 0;
- UsbCommand w = {CMD_ICLASS_CLONE,{startblock,endblock,((use_credit_key) ? 0x18 : 0x88)}};
+ UsbCommand w = {CMD_ICLASS_CLONE,{startblock,endblock}};
uint8_t *ptr;
// calculate all mac for every the block we will write
for (i = startblock; i <= endblock; i++){
return 0;
UsbCommand resp;
- UsbCommand w = {CMD_ICLASS_READBLOCK, {blockno, keyType}};
+ UsbCommand w = {CMD_ICLASS_READBLOCK, {blockno}};
clearCommandBuffer();
SendCommand(&w);
if (!WaitForResponseTimeout(CMD_ACK,&resp,4500))