make style
This commit is contained in:
parent
3ec9ecf800
commit
024fca9cb7
3 changed files with 48 additions and 52 deletions
|
@ -370,16 +370,16 @@ main(int argc, char *argv[])
|
||||||
printf("Warning: Unlock command [1/2]: failed / not acknowledged.\n");
|
printf("Warning: Unlock command [1/2]: failed / not acknowledged.\n");
|
||||||
} else {
|
} else {
|
||||||
if (format) {
|
if (format) {
|
||||||
transmit_bytes(abtWipe, 1);
|
transmit_bytes(abtWipe, 1);
|
||||||
transmit_bytes(abtHalt, 4);
|
transmit_bytes(abtHalt, 4);
|
||||||
transmit_bits(abtUnlock1, 7);
|
transmit_bits(abtUnlock1, 7);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (transmit_bytes(abtUnlock2, 1)) {
|
||||||
|
printf("Card unlocked\n");
|
||||||
|
} else {
|
||||||
|
printf("Warning: Unlock command [2/2]: failed / not acknowledged.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (transmit_bytes(abtUnlock2, 1)) {
|
|
||||||
printf("Card unlocked\n");
|
|
||||||
} else {
|
|
||||||
printf("Warning: Unlock command [2/2]: failed / not acknowledged.\n");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
transmit_bytes(abtWrite, 4);
|
transmit_bytes(abtWrite, 4);
|
||||||
|
|
|
@ -251,12 +251,12 @@ unlock_card(void)
|
||||||
if (!transmit_bits(abtUnlock1, 7)) {
|
if (!transmit_bits(abtUnlock1, 7)) {
|
||||||
printf("Warning: Unlock command [1/2]: failed / not acknowledged.\n");
|
printf("Warning: Unlock command [1/2]: failed / not acknowledged.\n");
|
||||||
} else {
|
} else {
|
||||||
if (transmit_bytes(abtUnlock2, 1)) {
|
if (transmit_bytes(abtUnlock2, 1)) {
|
||||||
printf("Card unlocked\n");
|
printf("Card unlocked\n");
|
||||||
unlocked = true;
|
unlocked = true;
|
||||||
} else {
|
} else {
|
||||||
printf("Warning: Unlock command [2/2]: failed / not acknowledged.\n");
|
printf("Warning: Unlock command [2/2]: failed / not acknowledged.\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// reset reader
|
// reset reader
|
||||||
|
|
|
@ -73,7 +73,7 @@ static uint32_t uiBlocks = 0x10;
|
||||||
static uint32_t uiReadPages = 0;
|
static uint32_t uiReadPages = 0;
|
||||||
static uint8_t iPWD[4] = { 0x0 };
|
static uint8_t iPWD[4] = { 0x0 };
|
||||||
static uint8_t iPACK[2] = { 0x0 };
|
static uint8_t iPACK[2] = { 0x0 };
|
||||||
static uint8_t iEV1Type= EV1_NONE;
|
static uint8_t iEV1Type = EV1_NONE;
|
||||||
|
|
||||||
// special unlock command
|
// special unlock command
|
||||||
uint8_t abtUnlock1[1] = { 0x40 };
|
uint8_t abtUnlock1[1] = { 0x40 };
|
||||||
|
@ -123,7 +123,7 @@ read_card(void)
|
||||||
} else {
|
} else {
|
||||||
bFailure = true;
|
bFailure = true;
|
||||||
}
|
}
|
||||||
for (uint8_t i=0; i < (uiBlocks - page < 4 ? uiBlocks - page : 4); i++) {
|
for (uint8_t i = 0; i < (uiBlocks - page < 4 ? uiBlocks - page : 4); i++) {
|
||||||
print_success_or_failure(bFailure, &uiReadPages, &uiFailedPages);
|
print_success_or_failure(bFailure, &uiReadPages, &uiFailedPages);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -132,7 +132,7 @@ read_card(void)
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
|
||||||
// copy EV1 secrets to dump data
|
// copy EV1 secrets to dump data
|
||||||
switch(iEV1Type) {
|
switch (iEV1Type) {
|
||||||
case EV1_UL11:
|
case EV1_UL11:
|
||||||
memcpy(mtDump.amb[4].mbc11.pwd, iPWD, 4);
|
memcpy(mtDump.amb[4].mbc11.pwd, iPWD, 4);
|
||||||
memcpy(mtDump.amb[4].mbc11.pack, iPACK, 2);
|
memcpy(mtDump.amb[4].mbc11.pack, iPACK, 2);
|
||||||
|
@ -208,21 +208,21 @@ get_ev1_version(void)
|
||||||
if (!raw_mode_start())
|
if (!raw_mode_start())
|
||||||
return false;
|
return false;
|
||||||
iso14443a_crc_append(abtEV1, 1);
|
iso14443a_crc_append(abtEV1, 1);
|
||||||
if(!transmit_bytes(abtEV1, 3)){
|
if (!transmit_bytes(abtEV1, 3)) {
|
||||||
raw_mode_end();
|
raw_mode_end();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!raw_mode_end())
|
if (!raw_mode_end())
|
||||||
return false;
|
return false;
|
||||||
if(!szRx)
|
if (!szRx)
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
ev1_load_pwd(uint8_t target[4], const char *pwd)
|
ev1_load_pwd(uint8_t target[4], const char *pwd)
|
||||||
{
|
{
|
||||||
if(sscanf(pwd, "%2x%2x%2x%2x", (unsigned int *) &target[0], (unsigned int *) &target[1], (unsigned int *) &target[2], (unsigned int *) &target[3]) != 4)
|
if (sscanf(pwd, "%2x%2x%2x%2x", (unsigned int *) &target[0], (unsigned int *) &target[1], (unsigned int *) &target[2], (unsigned int *) &target[3]) != 4)
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -234,7 +234,7 @@ ev1_pwd_auth(uint8_t *pwd)
|
||||||
return false;
|
return false;
|
||||||
memcpy(&abtPWAuth[1], pwd, 4);
|
memcpy(&abtPWAuth[1], pwd, 4);
|
||||||
iso14443a_crc_append(abtPWAuth, 5);
|
iso14443a_crc_append(abtPWAuth, 5);
|
||||||
if(!transmit_bytes(abtPWAuth, 7))
|
if (!transmit_bytes(abtPWAuth, 7))
|
||||||
return false;
|
return false;
|
||||||
if (!raw_mode_end())
|
if (!raw_mode_end())
|
||||||
return false;
|
return false;
|
||||||
|
@ -465,7 +465,7 @@ int
|
||||||
main(int argc, const char *argv[])
|
main(int argc, const char *argv[])
|
||||||
{
|
{
|
||||||
int iAction = 0;
|
int iAction = 0;
|
||||||
uint8_t iDumpSize= sizeof(mifareul_tag);
|
uint8_t iDumpSize = sizeof(mifareul_tag);
|
||||||
uint8_t iUID[MAX_UID_LEN] = { 0x0 };
|
uint8_t iUID[MAX_UID_LEN] = { 0x0 };
|
||||||
size_t szUID = 0;
|
size_t szUID = 0;
|
||||||
bool bOTP = false;
|
bool bOTP = false;
|
||||||
|
@ -490,7 +490,7 @@ main(int argc, const char *argv[])
|
||||||
} else if (0 == strcmp(argv[arg], "w")) {
|
} else if (0 == strcmp(argv[arg], "w")) {
|
||||||
iAction = 2;
|
iAction = 2;
|
||||||
} else if (0 == strcmp(argv[arg], "--with-uid")) {
|
} else if (0 == strcmp(argv[arg], "--with-uid")) {
|
||||||
if (arg+1 == argc) {
|
if (arg + 1 == argc) {
|
||||||
ERR("Please supply a UID of 4, 7 or 10 bytes long. Ex: a1:b2:c3:d4");
|
ERR("Please supply a UID of 4, 7 or 10 bytes long. Ex: a1:b2:c3:d4");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
@ -508,10 +508,10 @@ main(int argc, const char *argv[])
|
||||||
} else if (0 == strcmp(argv[arg], "--check-magic")) {
|
} else if (0 == strcmp(argv[arg], "--check-magic")) {
|
||||||
iAction = 3;
|
iAction = 3;
|
||||||
} else if (0 == strcmp(argv[arg], "--partial")) {
|
} else if (0 == strcmp(argv[arg], "--partial")) {
|
||||||
bPart= true;
|
bPart = true;
|
||||||
} else if (0 == strcmp(argv[arg], "--pw")) {
|
} else if (0 == strcmp(argv[arg], "--pw")) {
|
||||||
bPWD= true;
|
bPWD = true;
|
||||||
if(arg+1 == argc || strlen(argv[++arg]) != 8 || ! ev1_load_pwd(iPWD, argv[arg])) {
|
if (arg + 1 == argc || strlen(argv[++arg]) != 8 || ! ev1_load_pwd(iPWD, argv[arg])) {
|
||||||
ERR("Please supply a PASSWORD of 8 HEX digits");
|
ERR("Please supply a PASSWORD of 8 HEX digits");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
@ -593,27 +593,24 @@ main(int argc, const char *argv[])
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
|
||||||
// test if tag is EV1
|
// test if tag is EV1
|
||||||
if(get_ev1_version()) {
|
if (get_ev1_version()) {
|
||||||
if(!bPWD)
|
if (!bPWD)
|
||||||
printf("Tag is EV1 - PASSWORD may be required\n");
|
printf("Tag is EV1 - PASSWORD may be required\n");
|
||||||
printf("EV1 storage size: ");
|
printf("EV1 storage size: ");
|
||||||
if(abtRx[6] == 0x0b) {
|
if (abtRx[6] == 0x0b) {
|
||||||
printf("48 bytes\n");
|
printf("48 bytes\n");
|
||||||
uiBlocks= 0x14;
|
uiBlocks = 0x14;
|
||||||
iEV1Type= EV1_UL11;
|
iEV1Type = EV1_UL11;
|
||||||
iDumpSize= sizeof(mifareul_ev1_mf0ul11_tag);
|
iDumpSize = sizeof(mifareul_ev1_mf0ul11_tag);
|
||||||
}
|
} else if (abtRx[6] == 0x0e) {
|
||||||
else if(abtRx[6] == 0x0e) {
|
|
||||||
printf("128 bytes\n");
|
printf("128 bytes\n");
|
||||||
uiBlocks= 0x29;
|
uiBlocks = 0x29;
|
||||||
iEV1Type= EV1_UL21;
|
iEV1Type = EV1_UL21;
|
||||||
iDumpSize= sizeof(mifareul_ev1_mf0ul21_tag);
|
iDumpSize = sizeof(mifareul_ev1_mf0ul21_tag);
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
printf("unknown!\n");
|
printf("unknown!\n");
|
||||||
}
|
} else {
|
||||||
else {
|
// re-init non EV1 tag
|
||||||
// re-init non EV1 tag
|
|
||||||
if (nfc_initiator_select_passive_target(pnd, nmMifare, (szUID) ? iUID : NULL, szUID, &nt) <= 0) {
|
if (nfc_initiator_select_passive_target(pnd, nmMifare, (szUID) ? iUID : NULL, szUID, &nt) <= 0) {
|
||||||
ERR("no tag was found\n");
|
ERR("no tag was found\n");
|
||||||
nfc_close(pnd);
|
nfc_close(pnd);
|
||||||
|
@ -623,14 +620,13 @@ main(int argc, const char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
// EV1 login required
|
// EV1 login required
|
||||||
if(bPWD){
|
if (bPWD) {
|
||||||
printf("Authing with PWD: %02x%02x%02x%02x ", iPWD[0], iPWD[1], iPWD[2], iPWD[3]);
|
printf("Authing with PWD: %02x%02x%02x%02x ", iPWD[0], iPWD[1], iPWD[2], iPWD[3]);
|
||||||
if(!ev1_pwd_auth(iPWD)){
|
if (!ev1_pwd_auth(iPWD)) {
|
||||||
printf("\n");
|
printf("\n");
|
||||||
ERR("AUTH failed!\n");
|
ERR("AUTH failed!\n");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
printf("Success - PACK: %02x%02x\n", abtRx[0], abtRx[1]);
|
printf("Success - PACK: %02x%02x\n", abtRx[0], abtRx[1]);
|
||||||
memcpy(iPACK, abtRx, 2);
|
memcpy(iPACK, abtRx, 2);
|
||||||
}
|
}
|
||||||
|
@ -647,12 +643,12 @@ main(int argc, const char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t szDump;
|
size_t szDump;
|
||||||
if (((szDump= fread(&mtDump, 1, sizeof(mtDump), pfDump)) != iDumpSize && !bPart) || szDump <= 0) {
|
if (((szDump = fread(&mtDump, 1, sizeof(mtDump), pfDump)) != iDumpSize && !bPart) || szDump <= 0) {
|
||||||
ERR("Could not read from dump file or size mismatch: %s\n", argv[2]);
|
ERR("Could not read from dump file or size mismatch: %s\n", argv[2]);
|
||||||
fclose(pfDump);
|
fclose(pfDump);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
if(szDump != iDumpSize)
|
if (szDump != iDumpSize)
|
||||||
printf("Performing partial write\n");
|
printf("Performing partial write\n");
|
||||||
fclose(pfDump);
|
fclose(pfDump);
|
||||||
DBG("Successfully opened the dump file\n");
|
DBG("Successfully opened the dump file\n");
|
||||||
|
@ -664,7 +660,7 @@ main(int argc, const char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
if (iAction == 1) {
|
if (iAction == 1) {
|
||||||
bool bRF= read_card();
|
bool bRF = read_card();
|
||||||
printf("Writing data to file: %s ... ", argv[2]);
|
printf("Writing data to file: %s ... ", argv[2]);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
pfDump = fopen(argv[2], "wb");
|
pfDump = fopen(argv[2], "wb");
|
||||||
|
@ -683,7 +679,7 @@ main(int argc, const char *argv[])
|
||||||
}
|
}
|
||||||
fclose(pfDump);
|
fclose(pfDump);
|
||||||
printf("Done.\n");
|
printf("Done.\n");
|
||||||
if(!bRF)
|
if (!bRF)
|
||||||
printf("Warning! Read failed - partial data written to file!\n");
|
printf("Warning! Read failed - partial data written to file!\n");
|
||||||
} else if (iAction == 2) {
|
} else if (iAction == 2) {
|
||||||
write_card(bOTP, bLock, bUID);
|
write_card(bOTP, bLock, bUID);
|
||||||
|
|
Loading…
Reference in a new issue