chg: @piwi's code cleanup and some more.

ref: 43534cbad2
This commit is contained in:
iceman1001 2017-02-23 00:03:10 +01:00
commit 9c624f67b3
31 changed files with 176 additions and 183 deletions

View file

@ -1229,6 +1229,26 @@ void UsbPacketReceived(uint8_t *packet, int len)
case CMD_EMV_DUMP_CARD: case CMD_EMV_DUMP_CARD:
EMVdumpcard(); EMVdumpcard();
break; break;
/*
case CMD_EMV_READ_RECORD:
EMVReadRecord(c->arg[0], c->arg[1], NULL);
break;
case CMD_EMV_TRANSACTION:
EMVTransaction();
break;
case CMD_EMV_CLONE:
EMVClone(c->arg[0], c->arg[1]);
break;
case CMD_EMV_SIM:
EMVSim();
break;
case CMD_EMV_TEST:
EMVTest();
break;
case CMD_EMV_FUZZ_RATS:
EMVFuzz_RATS(c->arg[0],c->d.asBytes);
break;
*/
#endif #endif
#ifdef WITH_ICLASS #ifdef WITH_ICLASS
// Makes use of ISO14443a FPGA Firmware // Makes use of ISO14443a FPGA Firmware
@ -1303,7 +1323,7 @@ void UsbPacketReceived(uint8_t *packet, int len)
// arg0 = startindex // arg0 = startindex
// arg1 = length bytes to transfer // arg1 = length bytes to transfer
// arg2 = RFU // arg2 = RFU
//Dbprintf("transfer to client parameters: %llu | %llu | %llu", c->arg[0], c->arg[1], c->arg[2]); //Dbprintf("transfer to client parameters: %" PRIu64 " | %" PRIu64 " | %" PRIu64, c->arg[0], c->arg[1], c->arg[2]);
for(size_t i = 0; i < c->arg[1]; i += USB_CMD_DATA_SIZE) { for(size_t i = 0; i < c->arg[1]; i += USB_CMD_DATA_SIZE) {
len = MIN( (c->arg[1] - i), USB_CMD_DATA_SIZE); len = MIN( (c->arg[1] - i), USB_CMD_DATA_SIZE);

View file

@ -179,7 +179,7 @@ size_t enciphered_data_length (const desfiretag_t tag, const size_t nbytes, int
void cmac_generate_subkeys (desfirekey_t key); void cmac_generate_subkeys (desfirekey_t key);
void cmac (const desfirekey_t key, uint8_t *ivect, const uint8_t *data, size_t len, uint8_t *cmac); void cmac (const desfirekey_t key, uint8_t *ivect, const uint8_t *data, size_t len, uint8_t *cmac);
/// iso15693.h // iso15693.h
void RecordRawAdcSamplesIso15693(void); void RecordRawAdcSamplesIso15693(void);
void AcquireRawAdcSamplesIso15693(void); void AcquireRawAdcSamplesIso15693(void);
void ReaderIso15693(uint32_t parameter); // Simulate an ISO15693 reader - greg void ReaderIso15693(uint32_t parameter); // Simulate an ISO15693 reader - greg
@ -188,7 +188,7 @@ void BruteforceIso15693Afi(uint32_t speed); // find an AFI of a tag - atrox
void DirectTag15693Command(uint32_t datalen,uint32_t speed, uint32_t recv, uint8_t data[]); // send arbitrary commands from CLI - atrox void DirectTag15693Command(uint32_t datalen,uint32_t speed, uint32_t recv, uint8_t data[]); // send arbitrary commands from CLI - atrox
void SetDebugIso15693(uint32_t flag); void SetDebugIso15693(uint32_t flag);
/// iclass.h // iclass.h
void RAMFUNC SnoopIClass(void); void RAMFUNC SnoopIClass(void);
void SimulateIClass(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain); void SimulateIClass(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain);
void ReaderIClass(uint8_t arg0); void ReaderIClass(uint8_t arg0);
@ -226,6 +226,18 @@ void EMVgetUDOL(void);
void EMVloadvalue(uint32_t tag, uint8_t* datain); void EMVloadvalue(uint32_t tag, uint8_t* datain);
void EMVdumpcard(void); void EMVdumpcard(void);
/*
//void EMVSelect(uint8_t arg0, uint8_t arg1, uint8_t arg2, uint8_t *data);
void EMVFuzz_RATS(uint8_t len, uint8_t* RATS);
void EMVReadRecord(uint8_t arg0, uint8_t arg1,emvcard* inputcard);
void EMVSelectPPSE();
void EMVSelectAID(uint8_t *AID, uint8_t AIDlen, emvcard* inputcard);
void EMVTransaction(); //perform an EMV transaction
void EMVClone(uint8_t maxsfi, uint8_t maxrecord); //clone an EMV card.
void EMVSim();
void EMVTest(); //test function for emv stuff.
*/
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View file

@ -39,13 +39,14 @@ int split(char *str, char *arr[MAX_ARGS]){
int wordCnt = 0; int wordCnt = 0;
while(1){ while(1){
while(isspace(str[beginIndex])){ while(isspace(str[beginIndex])) {
++beginIndex; ++beginIndex;
} }
if(str[beginIndex] == '\0') if(str[beginIndex] == '\0') {
break; break;
}
endIndex = beginIndex; endIndex = beginIndex;
while (str[endIndex] && !isspace(str[endIndex])){ while (str[endIndex] && !isspace(str[endIndex])) {
++endIndex; ++endIndex;
} }
int len = endIndex - beginIndex; int len = endIndex - beginIndex;
@ -151,7 +152,7 @@ int GetModels(char *Models[], int *count, uint8_t *width){
* searched. * searched.
*/ */
/* scan against preset models */ /* scan against preset models */
if(~uflags & C_FORCE) { if (~uflags & C_FORCE) {
pass = 0; pass = 0;
Cnt = 0; Cnt = 0;
do { do {
@ -161,34 +162,36 @@ int GetModels(char *Models[], int *count, uint8_t *width){
mbynum(&pset, --psets); mbynum(&pset, --psets);
/* skip if different width, or refin or refout don't match */ /* skip if different width, or refin or refout don't match */
if(plen(pset.spoly) != width[0] || (model.flags ^ pset.flags) & (P_REFIN | P_REFOUT)) if( plen(pset.spoly) != width[0] || (model.flags ^ pset.flags) & (P_REFIN | P_REFOUT))
continue; continue;
/* skip if the preset doesn't match specified parameters */ /* skip if the preset doesn't match specified parameters */
if(rflags & R_HAVEP && pcmp(&model.spoly, &pset.spoly)) if (rflags & R_HAVEP && pcmp(&model.spoly, &pset.spoly))
continue; continue;
if(rflags & R_HAVEI && psncmp(&model.init, &pset.init)) if (rflags & R_HAVEI && psncmp(&model.init, &pset.init))
continue; continue;
if(rflags & R_HAVEX && psncmp(&model.xorout, &pset.xorout)) if (rflags & R_HAVEX && psncmp(&model.xorout, &pset.xorout))
continue; continue;
//for additional args (not used yet, maybe future?) //for additional args (not used yet, maybe future?)
apoly = pclone(pset.xorout); apoly = pclone(pset.xorout);
if(pset.flags & P_REFOUT)
if (pset.flags & P_REFOUT)
prev(&apoly); prev(&apoly);
for(qptr = apolys; qptr < pptr; ++qptr) {
for (qptr = apolys; qptr < pptr; ++qptr) {
crc = pcrc(*qptr, pset.spoly, pset.init, apoly, 0); crc = pcrc(*qptr, pset.spoly, pset.init, apoly, 0);
if(ptst(crc)) { if (ptst(crc)) {
pfree(&crc); pfree(&crc);
break; break;
} else }
pfree(&crc); pfree(&crc);
} }
pfree(&apoly); pfree(&apoly);
if(qptr == pptr) {
if (qptr == pptr) {
/* the selected model solved all arguments */ /* the selected model solved all arguments */
mcanon(&pset); mcanon(&pset);
size_t size = (pset.name && *pset.name) ? strlen(pset.name) : 6; size_t size = (pset.name && *pset.name) ? strlen(pset.name) : 6;
@ -198,7 +201,7 @@ int GetModels(char *Models[], int *count, uint8_t *width){
PrintAndLog("out of memory?"); PrintAndLog("out of memory?");
return 0; return 0;
} }
width[Cnt] = width[0]; width[Cnt] = width[0];
memcpy(tmp, pset.name, size); memcpy(tmp, pset.name, size);
Models[Cnt++] = tmp; Models[Cnt++] = tmp;
*count = Cnt; *count = Cnt;
@ -208,44 +211,50 @@ int GetModels(char *Models[], int *count, uint8_t *width){
mfree(&pset); mfree(&pset);
/* toggle refIn/refOut and reflect arguments */ /* toggle refIn/refOut and reflect arguments */
if(~rflags & R_HAVERI) { if (~rflags & R_HAVERI) {
model.flags ^= P_REFIN | P_REFOUT; model.flags ^= P_REFIN | P_REFOUT;
for(qptr = apolys; qptr < pptr; ++qptr) for (qptr = apolys; qptr < pptr; ++qptr) {
prevch(qptr, ibperhx); prevch(qptr, ibperhx);
}
} }
} while(~rflags & R_HAVERI && ++pass < 2); } while (~rflags & R_HAVERI && ++pass < 2);
} }
//got everything now free the memory... //got everything now free the memory...
if(uflags & C_RESULT) { if (uflags & C_RESULT) {
for(qptr = apolys; qptr < pptr; ++qptr) for (qptr = apolys; qptr < pptr; ++qptr) {
pfree(qptr); pfree(qptr);
}
} }
if(!(model.flags & P_REFIN) != !(model.flags & P_REFOUT)) if (!(model.flags & P_REFIN) != !(model.flags & P_REFOUT))
return uerr("cannot search for crossed-endian models"); return uerr("cannot search for crossed-endian models");
pass = 0; pass = 0;
do { do {
mptr = candmods = reveng(&model, qpoly, rflags, args, apolys); mptr = candmods = reveng(&model, qpoly, rflags, args, apolys);
if(mptr && plen(mptr->spoly)) if (mptr && plen(mptr->spoly)) {
uflags |= C_RESULT; uflags |= C_RESULT;
while(mptr && plen(mptr->spoly)) { }
while (mptr && plen(mptr->spoly)) {
mfree(mptr++); mfree(mptr++);
} }
free(candmods); free(candmods);
if(~rflags & R_HAVERI) { if (~rflags & R_HAVERI) {
model.flags ^= P_REFIN | P_REFOUT; model.flags ^= P_REFIN | P_REFOUT;
for(qptr = apolys; qptr < pptr; ++qptr) for (qptr = apolys; qptr < pptr; ++qptr) {
prevch(qptr, ibperhx); prevch(qptr, ibperhx);
}
} }
} while(~rflags & R_HAVERI && ++pass < 2); } while (~rflags & R_HAVERI && ++pass < 2);
for(qptr = apolys; qptr < pptr; ++qptr)
for (qptr = apolys; qptr < pptr; ++qptr) {
pfree(qptr); pfree(qptr);
}
free(apolys); free(apolys);
if(~uflags & C_RESULT) if (~uflags & C_RESULT)
return uerr("no models found"); return uerr("no models found");
mfree(&model); mfree(&model);
} }
return 1; return 1;
} }
@ -281,11 +290,11 @@ int RunModel(char *inModel, char *inHexStr, bool reverse, char endian, char *res
SETBMP(); SETBMP();
//set model //set model
if(!(c = mbynam(&model, inModel))) { if (!(c = mbynam(&model, inModel))) {
PrintAndLog("error: preset model '%s' not found. Use reveng -D to list presets.", inModel); PrintAndLog("error: preset model '%s' not found. Use reveng -D to list presets.", inModel);
return 0; return 0;
} }
if(c < 0) if (c < 0)
return uerr("no preset models available"); return uerr("no preset models available");
rflags |= R_HAVEP | R_HAVEI | R_HAVERI | R_HAVERO | R_HAVEX; rflags |= R_HAVEP | R_HAVEI | R_HAVERI | R_HAVERO | R_HAVEX;
@ -340,7 +349,7 @@ int RunModel(char *inModel, char *inHexStr, bool reverse, char endian, char *res
* Consequently Init is the mirror image of the * Consequently Init is the mirror image of the
* one resulting from -V, and so we have: * one resulting from -V, and so we have:
*/ */
if(~model.flags & P_REFOUT) { if (~model.flags & P_REFOUT) {
prev(&model.init); prev(&model.init);
prev(&model.xorout); prev(&model.xorout);
} }
@ -355,17 +364,17 @@ int RunModel(char *inModel, char *inHexStr, bool reverse, char endian, char *res
/* in the Williams model, xorout is applied after the refout stage. /* in the Williams model, xorout is applied after the refout stage.
* as refout is part of ptostr(), we reverse xorout here. * as refout is part of ptostr(), we reverse xorout here.
*/ */
if(model.flags & P_REFOUT) if (model.flags & P_REFOUT)
prev(&model.xorout); prev(&model.xorout);
apoly = strtop(inHexStr, model.flags, ibperhx); apoly = strtop(inHexStr, model.flags, ibperhx);
if(reverse) if (reverse)
prev(&apoly); prev(&apoly);
crc = pcrc(apoly, model.spoly, model.init, model.xorout, model.flags); crc = pcrc(apoly, model.spoly, model.init, model.xorout, model.flags);
if(reverse) if (reverse)
prev(&crc); prev(&crc);
string = ptostr(crc, model.flags, obperhx); string = ptostr(crc, model.flags, obperhx);

View file

@ -376,21 +376,21 @@ void printEM410x(uint32_t hi, uint64_t id)
} }
if (hi){ if (hi){
//output 88 bit em id //output 88 bit em id
PrintAndLog("\nEM TAG ID : %06X%016llX", hi, id); PrintAndLog("\nEM TAG ID : %06X%016" PRIX64, hi, id);
} else{ } else{
//output 40 bit em id //output 40 bit em id
PrintAndLog("\nEM TAG ID : %010llX", id); PrintAndLog("\nEM TAG ID : %010" PRIX64, id);
PrintAndLog("Unique TAG ID : %010llX", id2lo); PrintAndLog("Unique TAG ID : %010" PRIX64, id2lo);
PrintAndLog("\nPossible de-scramble patterns"); PrintAndLog("\nPossible de-scramble patterns");
PrintAndLog("HoneyWell IdentKey {"); PrintAndLog("HoneyWell IdentKey {");
PrintAndLog("DEZ 8 : %08lld",id & 0xFFFFFF); PrintAndLog("DEZ 8 : %08" PRIu64, id & 0xFFFFFF);
PrintAndLog("DEZ 10 : %010lld",id & 0xFFFFFFFF); PrintAndLog("DEZ 10 : %010" PRIu64, id & 0xFFFFFFFF);
PrintAndLog("DEZ 5.5 : %05lld.%05lld",(id>>16LL) & 0xFFFF,(id & 0xFFFF)); PrintAndLog("DEZ 5.5 : %05" PRIu64 ".%05" PRIu64, (id>>16LL) & 0xFFFF, (id & 0xFFFF));
PrintAndLog("DEZ 3.5A : %03lld.%05lld",(id>>32ll),(id & 0xFFFF)); PrintAndLog("DEZ 3.5A : %03" PRIu64 ".%05" PRIu64, (id>>32ll), (id & 0xFFFF));
PrintAndLog("DEZ 3.5B : %03lld.%05lld",(id & 0xFF000000) >> 24,(id & 0xFFFF)); PrintAndLog("DEZ 3.5B : %03" PRIu64 ".%05" PRIu64, (id & 0xFF000000) >> 24, (id & 0xFFFF));
PrintAndLog("DEZ 3.5C : %03lld.%05lld",(id & 0xFF0000) >> 16,(id & 0xFFFF)); PrintAndLog("DEZ 3.5C : %03" PRIu64 ".%05" PRIu64, (id & 0xFF0000) >> 16, (id & 0xFFFF));
PrintAndLog("DEZ 14/IK2 : %014lld",id); PrintAndLog("DEZ 14/IK2 : %014" PRIu64, id);
PrintAndLog("DEZ 15/IK3 : %015lld",id2lo); PrintAndLog("DEZ 15/IK3 : %015" PRIu64, id2lo);
PrintAndLog("DEZ 20/ZK : %02lld%02lld%02lld%02lld%02lld%02lld%02lld%02lld%02lld%02lld", PrintAndLog("DEZ 20/ZK : %02lld%02lld%02lld%02lld%02lld%02lld%02lld%02lld%02lld%02lld",
(id2lo & 0xf000000000) >> 36, (id2lo & 0xf000000000) >> 36,
(id2lo & 0x0f00000000) >> 32, (id2lo & 0x0f00000000) >> 32,
@ -404,8 +404,8 @@ void printEM410x(uint32_t hi, uint64_t id)
(id2lo & 0x000000000f) (id2lo & 0x000000000f)
); );
uint64_t paxton = (((id>>32) << 24) | (id & 0xffffff)) + 0x143e00; uint64_t paxton = (((id>>32) << 24) | (id & 0xffffff)) + 0x143e00;
PrintAndLog("}\nOther : %05lld_%03lld_%08lld",(id&0xFFFF),((id>>16LL) & 0xFF),(id & 0xFFFFFF)); PrintAndLog("}\nOther : %05" PRIu64 "_%03" PRIu64 "_%08" PRIu64, (id&0xFFFF), ((id>>16LL) & 0xFF), (id & 0xFFFFFF));
PrintAndLog("Pattern Paxton : %lld [0x%llX]", paxton, paxton); PrintAndLog("Pattern Paxton : %" PRIu64 " [0x%" PRIX64 "]", paxton, paxton);
uint32_t p1id = (id & 0xFFFFFF); uint32_t p1id = (id & 0xFFFFFF);
uint8_t arr[32] = {0x00}; uint8_t arr[32] = {0x00};
@ -1735,8 +1735,8 @@ int CmdFDXBdemodBI(const char *Cmd){
if (g_debugMode) PrintAndLog("Raw ID Hex: %s", sprint_hex(raw,8)); if (g_debugMode) PrintAndLog("Raw ID Hex: %s", sprint_hex(raw,8));
uint16_t calcCrc = crc16_ccitt_kermit(raw, 8); uint16_t calcCrc = crc16_ccitt_kermit(raw, 8);
PrintAndLog("Animal ID: %04u-%012llu", countryCode, NationalCode); PrintAndLog("Animal ID: %04u-%012" PRIu64, countryCode, NationalCode);
PrintAndLog("National Code: %012llu", NationalCode); PrintAndLog("National Code: %012" PRIu64, NationalCode);
PrintAndLog("CountryCode: %04u", countryCode); PrintAndLog("CountryCode: %04u", countryCode);
PrintAndLog("Reserved/RFU: %u", reservedCode); PrintAndLog("Reserved/RFU: %u", reservedCode);

View file

@ -214,7 +214,7 @@ int CmdHfEmvSim(const char *Cmd) {
if(errors) return usage_hf_emv_sim(); if(errors) return usage_hf_emv_sim();
UsbCommand c = {CMD_SIMULATE_TAG_LEGIC_RF, {6,3,0}}; UsbCommand c = {CMD_SIMULATE_TAG_LEGIC_RF, {6,3,0}};
sscanf(Cmd, " %"lli" %"lli" %"lli, &c.arg[0], &c.arg[1], &c.arg[2]); sscanf(Cmd, " %" SCNi64 " %" SCNi64 " %" SCNi64 , &c.arg[0], &c.arg[1], &c.arg[2]);
clearCommandBuffer(); clearCommandBuffer();
SendCommand(&c); SendCommand(&c);
return 0; return 0;

View file

@ -36,7 +36,7 @@ int CmdHFEPACollectPACENonces(const char *Cmd)
m = m > 0 ? m : 1; m = m > 0 ? m : 1;
n = n > 0 ? n : 1; n = n > 0 ? n : 1;
PrintAndLog("Collecting %u %"hhu"-byte nonces", n, m); PrintAndLog("Collecting %u %u byte nonces", n, m);
PrintAndLog("Start: %u", time(NULL)); PrintAndLog("Start: %u", time(NULL));
// repeat n times // repeat n times
for (unsigned int i = 0; i < n; i++) { for (unsigned int i = 0; i < n; i++) {

View file

@ -1388,25 +1388,6 @@ int CmdHFiClassReadTagFile(const char *Cmd) {
return 0; return 0;
} }
/*
uint64_t xorcheck(uint64_t sdiv,uint64_t hdiv) {
uint64_t new_div = 0x00;
new_div ^= sdiv;
new_div ^= hdiv;
return new_div;
}
uint64_t hexarray_to_uint64(uint8_t *key) {
char temp[17];
uint64_t uint_key;
for (int i = 0;i < 8;i++)
sprintf(&temp[(i *2)],"%02X",key[i]);
temp[16] = '\0';
if (sscanf(temp,"%016"llX,&uint_key) < 1)
return 0;
return uint_key;
}
*/
void HFiClassCalcDivKey(uint8_t *CSN, uint8_t *KEY, uint8_t *div_key, bool elite){ void HFiClassCalcDivKey(uint8_t *CSN, uint8_t *KEY, uint8_t *div_key, bool elite){
uint8_t keytable[128] = {0}; uint8_t keytable[128] = {0};
uint8_t key_index[8] = {0}; uint8_t key_index[8] = {0};

View file

@ -527,7 +527,7 @@ int CmdLegicRdmem(const char *Cmd) {
// int phase, int frame, int reqresp // int phase, int frame, int reqresp
int CmdLegicRfSim(const char *Cmd) { int CmdLegicRfSim(const char *Cmd) {
UsbCommand c = {CMD_SIMULATE_TAG_LEGIC_RF, {6,3,0}}; UsbCommand c = {CMD_SIMULATE_TAG_LEGIC_RF, {6,3,0}};
sscanf(Cmd, " %"lli" %"lli" %"lli, &c.arg[0], &c.arg[1], &c.arg[2]); sscanf(Cmd, " %" SCNi64 " %" SCNi64 " %" SCNi64 , &c.arg[0], &c.arg[1], &c.arg[2]);
clearCommandBuffer(); clearCommandBuffer();
SendCommand(&c); SendCommand(&c);
return 0; return 0;

View file

@ -226,7 +226,7 @@ start:
c.arg[0] = false; c.arg[0] = false;
goto start; goto start;
} else { } else {
PrintAndLog("Found valid key: %012"llx" \n", r_key); PrintAndLog("Found valid key: %012" PRIx64 " \n", r_key);
goto END; goto END;
} }
} }
@ -246,10 +246,10 @@ start:
uint64_t key64 = 0; uint64_t key64 = 0;
int res = mfCheckKeys(blockNo, keytype - 0x60 , false, 1, keyblock, &key64); int res = mfCheckKeys(blockNo, keytype - 0x60 , false, 1, keyblock, &key64);
if ( res > 0 ) { if ( res > 0 ) {
PrintAndLog("Candidate Key found (%012"llx") - Test authentication failed. [%d] Restarting darkside attack", r_key, res); PrintAndLog("Candidate Key found (%012" PRIx64 ") - Test authentication failed. [%d] Restarting darkside attack", r_key, res);
goto start; goto start;
} }
PrintAndLog("Found valid key: %012"llx" \n", r_key); PrintAndLog("Found valid key: %012" PRIx64 " \n", r_key);
} }
END: END:
t1 = clock() - t1; t1 = clock() - t1;
@ -313,9 +313,7 @@ int CmdHF14AMfRdBl(const char *Cmd) {
uint8_t blockNo = 0; uint8_t blockNo = 0;
uint8_t keyType = 0; uint8_t keyType = 0;
uint8_t key[6] = {0, 0, 0, 0, 0, 0}; uint8_t key[6] = {0, 0, 0, 0, 0, 0};
char cmdp = 0x00;
char cmdp = 0x00;
if (strlen(Cmd)<3) { if (strlen(Cmd)<3) {
PrintAndLog("Usage: hf mf rdbl <block number> <key A/B> <key (12 hex symbols)>"); PrintAndLog("Usage: hf mf rdbl <block number> <key A/B> <key (12 hex symbols)>");
@ -1207,7 +1205,7 @@ int CmdHF14AMfChk(const char *Cmd) {
} }
memset(keyBlock + 6 * keycnt, 0, 6); memset(keyBlock + 6 * keycnt, 0, 6);
num_to_bytes(strtoll(buf, NULL, 16), 6, keyBlock + 6*keycnt); num_to_bytes(strtoll(buf, NULL, 16), 6, keyBlock + 6*keycnt);
PrintAndLog("check key[%2d] %012"llx, keycnt, bytes_to_num(keyBlock + 6*keycnt, 6)); PrintAndLog("check key[%2d] %012" PRIx64, keycnt, bytes_to_num(keyBlock + 6*keycnt, 6));
keycnt++; keycnt++;
memset(buf, 0, sizeof(buf)); memset(buf, 0, sizeof(buf));
} }
@ -1400,7 +1398,7 @@ void readerAttack(nonces_t data, bool setEmulatorMem, bool verbose) {
uint8_t sector = data.sector; uint8_t sector = data.sector;
uint8_t keytype = data.keytype; uint8_t keytype = data.keytype;
PrintAndLog("Reader is trying authenticate with: Key %s, sector %02d: [%012"llx"]" PrintAndLog("Reader is trying authenticate with: Key %s, sector %02d: [%012" PRIx64 "]"
, keytype ? "B" : "A" , keytype ? "B" : "A"
, sector , sector
, key , key
@ -1707,7 +1705,7 @@ int CmdHF14AMfKeyBrute(const char *Cmd) {
time(&start); time(&start);
if (mfKeyBrute( blockNo, keytype, key, &foundkey)) if (mfKeyBrute( blockNo, keytype, key, &foundkey))
PrintAndLog("Found valid key: %012"llx" \n", foundkey); PrintAndLog("Found valid key: %012" PRIx64 " \n", foundkey);
else else
PrintAndLog("Key not found"); PrintAndLog("Key not found");
@ -1725,7 +1723,7 @@ void printKeyTable( uint8_t sectorscnt, sector *e_sector ){
PrintAndLog("|sec|key A |res|key B |res|"); PrintAndLog("|sec|key A |res|key B |res|");
PrintAndLog("|---|----------------|---|----------------|---|"); PrintAndLog("|---|----------------|---|----------------|---|");
for (uint8_t i = 0; i < sectorscnt; ++i) { for (uint8_t i = 0; i < sectorscnt; ++i) {
PrintAndLog("|%03d| %012"llx" | %d | %012"llx" | %d |", i, PrintAndLog("|%03d| %012" PRIx64 " | %d | %012" PRIx64 " | %d |", i,
e_sector[i].Key[0], e_sector[i].foundKey[0], e_sector[i].Key[0], e_sector[i].foundKey[0],
e_sector[i].Key[1], e_sector[i].foundKey[1] e_sector[i].Key[1], e_sector[i].foundKey[1]
); );
@ -1774,7 +1772,6 @@ int CmdHF14AMfESet(const char *Cmd)
{ {
uint8_t memBlock[16]; uint8_t memBlock[16];
uint8_t blockNo = 0; uint8_t blockNo = 0;
memset(memBlock, 0x00, sizeof(memBlock)); memset(memBlock, 0x00, sizeof(memBlock));
if (strlen(Cmd) < 3 || param_getchar(Cmd, 0) == 'h') { if (strlen(Cmd) < 3 || param_getchar(Cmd, 0) == 'h') {
@ -2056,7 +2053,7 @@ int CmdHF14AMfEKeyPrn(const char *Cmd)
} }
keyA = bytes_to_num(data, 6); keyA = bytes_to_num(data, 6);
keyB = bytes_to_num(data + 10, 6); keyB = bytes_to_num(data + 10, 6);
PrintAndLog("|%03d| %012"llx" | %012"llx" |", i, keyA, keyB); PrintAndLog("|%03d| %012" PRIx64 " | %012" PRIx64 " |", i, keyA, keyB);
} }
PrintAndLog("|---|----------------|----------------|"); PrintAndLog("|---|----------------|----------------|");

View file

@ -723,8 +723,8 @@ static void simulate_acquire_nonces()
cuid = (rand() & 0xff) << 24 | (rand() & 0xff) << 16 | (rand() & 0xff) << 8 | (rand() & 0xff); cuid = (rand() & 0xff) << 24 | (rand() & 0xff) << 16 | (rand() & 0xff) << 8 | (rand() & 0xff);
known_target_key = ((uint64_t)rand() & 0xfff) << 36 | ((uint64_t)rand() & 0xfff) << 24 | ((uint64_t)rand() & 0xfff) << 12 | ((uint64_t)rand() & 0xfff); known_target_key = ((uint64_t)rand() & 0xfff) << 36 | ((uint64_t)rand() & 0xfff) << 24 | ((uint64_t)rand() & 0xfff) << 12 | ((uint64_t)rand() & 0xfff);
printf("Simulating nonce acquisition for target key %012"llx", cuid %08x ...\n", known_target_key, cuid); printf("Simulating nonce acquisition for target key %012" PRIx64 ", cuid %08x ...\n", known_target_key, cuid);
fprintf(fstats, "%012"llx";%08x;", known_target_key, cuid); fprintf(fstats, "%012" PRIx64 ";%08x;", known_target_key, cuid);
do { do {
uint32_t nt_enc = 0; uint32_t nt_enc = 0;
@ -1247,7 +1247,7 @@ static bool TestIfKeyExists(uint64_t key)
uint32_t state_odd = pcs->odd & 0x00ffffff; uint32_t state_odd = pcs->odd & 0x00ffffff;
uint32_t state_even = pcs->even & 0x00ffffff; uint32_t state_even = pcs->even & 0x00ffffff;
//printf("Tests: searching for key %llx after first byte 0x%02x (state_odd = 0x%06x, state_even = 0x%06x) ...\n", key, best_first_bytes[0], state_odd, state_even); //printf("Tests: searching for key %" PRIx64 " after first byte 0x%02x (state_odd = 0x%06x, state_even = 0x%06x) ...\n", key, best_first_bytes[0], state_odd, state_even);
printf("Validating key search space\n"); printf("Validating key search space\n");
uint64_t count = 0; uint64_t count = 0;
for (statelist_t *p = candidates; p != NULL; p = p->next) { for (statelist_t *p = candidates; p != NULL; p = p->next) {
@ -1271,7 +1271,7 @@ static bool TestIfKeyExists(uint64_t key)
count += (p_odd - p->states[ODD_STATE]) * (p_even - p->states[EVEN_STATE]); count += (p_odd - p->states[ODD_STATE]) * (p_even - p->states[EVEN_STATE]);
if (found_odd && found_even) { if (found_odd && found_even) {
if (known_target_key != -1) { if (known_target_key != -1) {
PrintAndLog("Key Found after testing %llu (2^%1.1f) out of %lld (2^%1.1f) keys.", PrintAndLog("Key Found after testing %" PRIu64 " (2^%1.1f) out of %lld (2^%1.1f) keys.",
count, count,
log(count)/log(2), log(count)/log(2),
maximum_states, maximum_states,

View file

@ -147,7 +147,8 @@ int CmdEM410xWatch(const char *Cmd)
} }
CmdLFRead("s"); CmdLFRead("s");
getSamples("8201",true); //capture enough to get 2 complete preambles (4096*2+9) //getSamples("8201",true); //capture enough to get 2 complete preambles (4096*2+9)
getSamples("6144",true);
} while (!CmdEM410xRead("")); } while (!CmdEM410xRead(""));
return 0; return 0;
@ -159,7 +160,7 @@ int CmdEM410xWatchnSpoof(const char *Cmd)
{ {
// loops if the captured ID was in XL-format. // loops if the captured ID was in XL-format.
CmdEM410xWatch(Cmd); CmdEM410xWatch(Cmd);
PrintAndLog("# Replaying captured ID: %llu", g_em410xid); PrintAndLog("# Replaying captured ID: %" PRIu64 , g_em410xid);
CmdLFaskSim(""); CmdLFaskSim("");
return 0; return 0;
} }
@ -593,8 +594,7 @@ int CmdEM4x50Dump(const char *Cmd){
} }
#define EM_PREAMBLE_LEN 6 #define EM_PREAMBLE_LEN 6
// download samples from device // download samples from device and copy to Graphbuffer
// and copy them to Graphbuffer
bool downloadSamplesEM(){ bool downloadSamplesEM(){
// 8 bit preamble + 32 bit word response (max clock (128) * 40bits = 5120 samples) // 8 bit preamble + 32 bit word response (max clock (128) * 40bits = 5120 samples)
@ -607,7 +607,8 @@ bool downloadSamplesEM(){
setGraphBuf(got, sizeof(got)); setGraphBuf(got, sizeof(got));
return TRUE; return TRUE;
} }
//search for given preamble in given BitStream and return success=1 or fail=0 and startIndex
// em_demod
bool doPreambleSearch(size_t *startIdx){ bool doPreambleSearch(size_t *startIdx){
// sanity check // sanity check
@ -615,26 +616,14 @@ bool doPreambleSearch(size_t *startIdx){
if (g_debugMode) PrintAndLog("DEBUG: Error - EM4305 demodbuffer too small"); if (g_debugMode) PrintAndLog("DEBUG: Error - EM4305 demodbuffer too small");
return FALSE; return FALSE;
} }
// skip first two 0 bits as they might have been missed in the demod // set size to 20 to only test first 14 positions for the preamble
size_t size = (20 > DemodBufferLen) ? DemodBufferLen : 20;
*startIdx = 0;
// skip first two 0 bits as they might have been missed in the demod
uint8_t preamble[EM_PREAMBLE_LEN] = {0,0,1,0,1,0}; uint8_t preamble[EM_PREAMBLE_LEN] = {0,0,1,0,1,0};
// set size to 15 to only test first 4 positions for the preamble if ( !preambleSearchEx(DemodBuffer, preamble, EM_PREAMBLE_LEN, &size, startIdx, TRUE)) {
size_t size = (15 > DemodBufferLen) ? DemodBufferLen : 15;
*startIdx = 0;
uint8_t found = 0;
// em only sends preamble once, so look for it once in the first x bits
for (int idx = 0; idx < size - EM_PREAMBLE_LEN; idx++){
if (memcmp(DemodBuffer+idx, preamble, EM_PREAMBLE_LEN) == 0){
//first index found
*startIdx = idx;
found = 1;
break;
}
}
if ( !found) {
if (g_debugMode) PrintAndLog("DEBUG: Error - EM4305 preamble not found :: %d", *startIdx); if (g_debugMode) PrintAndLog("DEBUG: Error - EM4305 preamble not found :: %d", *startIdx);
return FALSE; return FALSE;
} }
@ -714,12 +703,10 @@ bool setDemodBufferEM(uint32_t *word, size_t idx){
return FALSE; return FALSE;
} }
size_t size = removeParity(DemodBuffer, idx + EM_PREAMBLE_LEN, 9, 0, 44); if (!removeParity(DemodBuffer, idx + EM_PREAMBLE_LEN, 9, 0, 44)) {
if (!size) { if (g_debugMode) PrintAndLog("DEBUG: Error - EM, failed removing parity");
if (g_debugMode) PrintAndLog("DEBUG: Error - EM Parity not detected");
return FALSE; return FALSE;
} }
// set & copy to output
setDemodBuf(DemodBuffer, 40, 0); setDemodBuf(DemodBuffer, 40, 0);
*word = bytebits_to_byteLSBF(DemodBuffer, 32); *word = bytebits_to_byteLSBF(DemodBuffer, 32);
return TRUE; return TRUE;
@ -910,8 +897,7 @@ int CmdEM4x05Write(const char *Cmd) {
if (!downloadSamplesEM()) if (!downloadSamplesEM())
return -1; return -1;
//todo: check response for 00001010 then write data for write confirmation!
//attempt demod: //attempt demod:
//need 0 bits demoded (after preamble) to verify write cmd //need 0 bits demoded (after preamble) to verify write cmd
uint32_t dummy = 0; uint32_t dummy = 0;

View file

@ -175,8 +175,8 @@ int CmdFdxDemod(const char *Cmd) {
uint16_t calcCrc = crc16_ccitt_kermit(raw, 8); uint16_t calcCrc = crc16_ccitt_kermit(raw, 8);
PrintAndLog("\nFDX-B / ISO 11784/5 Animal Tag ID Found: Raw : %s", sprint_hex(raw, 8)); PrintAndLog("\nFDX-B / ISO 11784/5 Animal Tag ID Found: Raw : %s", sprint_hex(raw, 8));
PrintAndLog("Animal ID %04u-%012llu", countryCode, NationalCode); PrintAndLog("Animal ID %04u-%012" PRIu64, countryCode, NationalCode);
PrintAndLog("National Code %012llu (0x%llX)", NationalCode, NationalCode); PrintAndLog("National Code %012" PRIu64 " (0x%" PRIx64 ")", NationalCode, NationalCode);
PrintAndLog("Country Code %04u", countryCode); PrintAndLog("Country Code %04u", countryCode);
PrintAndLog("Reserved/RFU %u (0x04%X)", reservedCode, reservedCode); PrintAndLog("Reserved/RFU %u (0x04%X)", reservedCode, reservedCode);
PrintAndLog(""); PrintAndLog("");

View file

@ -341,7 +341,7 @@ int CmdHIDWiegand(const char *Cmd) {
uint8_t shifts = 64-fmtlen[i]; uint8_t shifts = 64-fmtlen[i];
wiegand >>= shifts; wiegand >>= shifts;
PrintAndLog(" %u | %03u | %03u | %llu | %llX | %llX", PrintAndLog(" %u | %03u | %03u | %" PRIu64 " | %" PRIX64 " | %" PRIX64 ,
fmtlen[i], fmtlen[i],
oem, oem,
fc, fc,

View file

@ -280,7 +280,7 @@ int CmdTIWrite(const char *Cmd)
{ {
int res = 0; int res = 0;
UsbCommand c = {CMD_WRITE_TI_TYPE}; UsbCommand c = {CMD_WRITE_TI_TYPE};
res = sscanf(Cmd, "%012"llx" %012"llx" %012"llx"", &c.arg[0], &c.arg[1], &c.arg[2]); res = sscanf(Cmd, "%012" SCNx64 " %012" SCNx64 " %012" SCNx64, &c.arg[0], &c.arg[1], &c.arg[2]);
if (res == 2) c.arg[2]=0; if (res == 2) c.arg[2]=0;
if (res < 2) { if (res < 2) {

View file

@ -209,7 +209,7 @@ void UsbCommandReceived(UsbCommand *UC)
// arg1 = length bytes to transfer // arg1 = length bytes to transfer
// arg2 = bigbuff tracelength (?) // arg2 = bigbuff tracelength (?)
memcpy( sample_buf + (UC->arg[0]), UC->d.asBytes, UC->arg[1]); memcpy( sample_buf + (UC->arg[0]), UC->d.asBytes, UC->arg[1]);
//printf("DBG:: Download from device. chunk %llu | size %llu | tracelen:%llu \n", UC->arg[0], UC->arg[1], UC->arg[2]); //printf("DBG:: Download from device. chunk %" PRIu64 " | size %" PRIu64 " | tracelen:%" PRIu64 " \n", UC->arg[0], UC->arg[1], UC->arg[2]);
break; break;
} }
default: { default: {

View file

@ -302,7 +302,7 @@ static int get_proxmark_state(uint32_t *state)
*state = resp.arg[0]; *state = resp.arg[0];
break; break;
default: default:
fprintf(stderr, "Error: Couldn't get proxmark state, bad response type: 0x%04"llx"\n", resp.cmd); fprintf(stderr, "Error: Couldn't get proxmark state, bad response type: 0x%04" PRIx64 "\n", resp.cmd);
return -1; return -1;
break; break;
} }
@ -360,7 +360,7 @@ static int wait_for_ack(UsbCommand *ack)
{ {
ReceiveCommand(ack); ReceiveCommand(ack);
if (ack->cmd != CMD_ACK) { if (ack->cmd != CMD_ACK) {
printf("Error: Unexpected reply 0x%04"llx" %s (expected ACK)\n", ack->cmd, (ack->cmd==CMD_NACK)?"NACK":""); printf("Error: Unexpected reply 0x%04" PRIx64 " %s (expected ACK)\n", ack->cmd, (ack->cmd==CMD_NACK)?"NACK":"");
return -1; return -1;
} }
return 0; return 0;

View file

@ -25,10 +25,10 @@ static char* serial_port_name;
void cmd_debug(UsbCommand* UC) { void cmd_debug(UsbCommand* UC) {
// Debug // Debug
printf("UsbCommand length[len=%zd]\n",sizeof(UsbCommand)); printf("UsbCommand length[len=%zd]\n",sizeof(UsbCommand));
printf(" cmd[len=%zd]: %016"llx"\n",sizeof(UC->cmd),UC->cmd); printf(" cmd[len=%zd]: %016" PRIx64"\n",sizeof(UC->cmd),UC->cmd);
printf(" arg0[len=%zd]: %016"llx"\n",sizeof(UC->arg[0]),UC->arg[0]); printf(" arg0[len=%zd]: %016" PRIx64"\n",sizeof(UC->arg[0]),UC->arg[0]);
printf(" arg1[len=%zd]: %016"llx"\n",sizeof(UC->arg[1]),UC->arg[1]); printf(" arg1[len=%zd]: %016" PRIx64"\n",sizeof(UC->arg[1]),UC->arg[1]);
printf(" arg2[len=%zd]: %016"llx"\n",sizeof(UC->arg[2]),UC->arg[2]); printf(" arg2[len=%zd]: %016" PRIx64"\n",sizeof(UC->arg[2]),UC->arg[2]);
printf(" data[len=%zd]: ",sizeof(UC->d.asBytes)); printf(" data[len=%zd]: ",sizeof(UC->d.asBytes));
for (size_t i=0; i<16; i++) for (size_t i=0; i<16; i++)

View file

@ -14,6 +14,7 @@
#include <string.h> #include <string.h>
#include <stdint.h> #include <stdint.h>
#include <stdbool.h> #include <stdbool.h>
#include <inttypes.h>
#include "zlib.h" #include "zlib.h"
#define MAX(a,b) ((a)>(b)?(a):(b)) #define MAX(a,b) ((a)>(b)?(a):(b))
@ -140,7 +141,7 @@ int zlib_compress(FILE *infile[], uint8_t num_infiles, FILE *outfile)
ret = deflate(&compressed_fpga_stream, Z_FINISH); ret = deflate(&compressed_fpga_stream, Z_FINISH);
} }
fprintf(stderr, "compressed %u input bytes to %lu output bytes\n", i, compressed_fpga_stream.total_out); fprintf(stderr, "compressed %u input bytes to %" PRIu32 " output bytes\n", i, compressed_fpga_stream.total_out);
if (ret != Z_STREAM_END) { if (ret != Z_STREAM_END) {
fprintf(stderr, "Error in deflate(): %d %s\n", ret, compressed_fpga_stream.msg); fprintf(stderr, "Error in deflate(): %d %s\n", ret, compressed_fpga_stream.msg);

View file

@ -170,7 +170,7 @@ int mfnested(uint8_t blockNo, uint8_t keyType, uint8_t * key, uint8_t trgBlockNo
free(statelists[1].head.slhead); free(statelists[1].head.slhead);
num_to_bytes(key64, 6, resultKey); num_to_bytes(key64, 6, resultKey);
PrintAndLog("UID: %08x target block:%3u key type: %c -- Found key [%012"llx"]", PrintAndLog("UID: %08x target block:%3u key type: %c -- Found key [%012" PRIx64 "]",
uid, uid,
(uint16_t)resp.arg[2] & 0xff, (uint16_t)resp.arg[2] & 0xff,
(resp.arg[2] >> 8) ? 'B' : 'A', (resp.arg[2] >> 8) ? 'B' : 'A',
@ -627,7 +627,7 @@ int mfTraceDecode(uint8_t *data_src, int len, bool wantSaveToEmlFile) {
lfsr_rollback_word(revstate, nr_enc, 1); lfsr_rollback_word(revstate, nr_enc, 1);
lfsr_rollback_word(revstate, cuid ^ nt, 0); lfsr_rollback_word(revstate, cuid ^ nt, 0);
crypto1_get_lfsr(revstate, &key); crypto1_get_lfsr(revstate, &key);
PrintAndLog("Found Key: [%012"llx"]", key); PrintAndLog("Found Key: [%012" PRIx64 "]", key);
//if ( tryMfk64(cuid, nt, nr_enc, ar_enc, at_enc, &key) ) //if ( tryMfk64(cuid, nt, nr_enc, ar_enc, at_enc, &key) )
AddLogUint64(logHexFileName, "Found Key: ", key); AddLogUint64(logHexFileName, "Found Key: ", key);

View file

@ -25,9 +25,6 @@ THE SOFTWARE.
#include "crypto1_bs.h" #include "crypto1_bs.h"
#include <inttypes.h> #include <inttypes.h>
#define __STDC_FORMAT_MACROS #define __STDC_FORMAT_MACROS
#define llx PRIx64
#define lli PRIi64
#define lu PRIu32
// The following functions use this global or thread-local state // The following functions use this global or thread-local state
// It is sized to fit exactly KEYSTREAM_SIZE more states next to the initial state // It is sized to fit exactly KEYSTREAM_SIZE more states next to the initial state
@ -117,7 +114,7 @@ void crypto1_bs_print_states(bitslice_t bitsliced_states[]){
state_t values[MAX_BITSLICES] = {{0x00}}; state_t values[MAX_BITSLICES] = {{0x00}};
crypto1_bs_convert_states(bitsliced_states, values); crypto1_bs_convert_states(bitsliced_states, values);
for(slice_idx = 0; slice_idx < MAX_BITSLICES; slice_idx++){ for(slice_idx = 0; slice_idx < MAX_BITSLICES; slice_idx++){
printf("State %03zu: %012"llx"\n", slice_idx, values[slice_idx].value); printf("State %03zu: %012" PRIx64 "\n", slice_idx, values[slice_idx].value);
} }
} }

View file

@ -19,7 +19,7 @@ int nonce2key(uint32_t uid, uint32_t nt, uint32_t nr, uint64_t par_info, uint64_
// Reset the last three significant bits of the reader nonce // Reset the last three significant bits of the reader nonce
nr &= 0xffffff1f; nr &= 0xffffff1f;
PrintAndLog("uid(%08x) nt(%08x) par(%016"llx") ks(%016"llx") nr(%08x)", uid, nt, par_info, ks_info, nr); PrintAndLog("uid(%08x) nt(%08x) par(%016" PRIx64") ks(%016" PRIx64") nr(%08x)", uid, nt, par_info, ks_info, nr);
for ( pos = 0; pos < 8; pos++ ) { for ( pos = 0; pos < 8; pos++ ) {
ks3x[7-pos] = (ks_info >> (pos*8)) & 0x0f; ks3x[7-pos] = (ks_info >> (pos*8)) & 0x0f;
@ -121,11 +121,11 @@ int nonce2key_ex(uint8_t blockno, uint8_t keytype, uint32_t uid, uint32_t nt, ui
free(last_keylist); free(last_keylist);
last_keylist = state_s; last_keylist = state_s;
PrintAndLog("parity is all zero, testing special attack. First call, this attack needs at least two calls. Hold on..."); PrintAndLog("parity is all zero, testing special attack. First call, this attack needs at least two calls. Hold on...");
PrintAndLog("uid(%08x) nt(%08x) ks(%016"llx") nr(%08x)", uid, nt, ks_info, nr); PrintAndLog("uid(%08x) nt(%08x) ks(%016" PRIx64") nr(%08x)", uid, nt, ks_info, nr);
return 1; return 1;
} }
PrintAndLog("uid(%08x) nt(%08x) ks(%016"llx") nr(%08x)", uid, nt, ks_info, nr); PrintAndLog("uid(%08x) nt(%08x) ks(%016" PRIx64") nr(%08x)", uid, nt, ks_info, nr);
//Create the intersection: //Create the intersection:
int64_t *p1, *p2, *p3; int64_t *p1, *p2, *p3;
@ -134,7 +134,12 @@ int nonce2key_ex(uint8_t blockno, uint8_t keytype, uint32_t uid, uint32_t nt, ui
while ( *p1 != -1 && *p2 != -1 ) { while ( *p1 != -1 && *p2 != -1 ) {
if (compar_intA(p1, p2) == 0) { if (compar_intA(p1, p2) == 0) {
PrintAndLog("p1:%"llx" p2:%"llx" p3:%"llx" key:%012"llx,(uint64_t)(p1-last_keylist),(uint64_t)(p2-state_s),(uint64_t)(p3-last_keylist),*p1); PrintAndLog("p1:%" PRIx64" p2:%" PRIx64" p3:%" PRIx64" key:%012" PRIx64
, (uint64_t)(p1-last_keylist)
, (uint64_t)(p2-state_s)
, (uint64_t)(p3-last_keylist)
, *p1
);
*p3++ = *p1++; *p3++ = *p1++;
p2++; p2++;
} }
@ -316,7 +321,7 @@ int tryMfk64(uint32_t uid, uint32_t nt, uint32_t nr_enc, uint32_t ar_enc, uint32
lfsr_rollback_word(revstate, uid ^ nt, 0); lfsr_rollback_word(revstate, uid ^ nt, 0);
crypto1_get_lfsr(revstate, &key); crypto1_get_lfsr(revstate, &key);
PrintAndLog("Found Key: [%012"llx"]", key); PrintAndLog("Found Key: [%012" PRIx64 "]", key);
t1 = clock() - t1; t1 = clock() - t1;
if ( t1 > 0 ) PrintAndLog("Time in mfkey64: %.0f ticks", (float)t1); if ( t1 > 0 ) PrintAndLog("Time in mfkey64: %.0f ticks", (float)t1);

View file

@ -8,7 +8,6 @@
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Main binary // Main binary
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
#ifndef PROXMARK3_H__ #ifndef PROXMARK3_H__
#define PROXMARK3_H__ #define PROXMARK3_H__
@ -28,14 +27,11 @@
#include <inttypes.h> #include <inttypes.h>
#include "usb_cmd.h" #include "usb_cmd.h"
/*
#define lu PRIu32 #define lu PRIu32
#define lx PRIx32 #define lx PRIx32
#define llx PRIx64 */
#define lli PRIi64
#define llu PRIu64
#define hhu PRIu8
#define PROXPROMPT "pm3 --> " #define PROXPROMPT "pm3 --> "
void SendCommand(UsbCommand *c); void SendCommand(UsbCommand *c);
#endif
#endif

View file

@ -799,15 +799,15 @@ prev(poly_t *poly) {
unsigned long fulllength = poly->length + ofs; unsigned long fulllength = poly->length + ofs;
bmp_t accu; bmp_t accu;
if(ofs) if(ofs) {
/* removable optimisation */ /* removable optimisation */
if(poly->length < (unsigned long) BMP_BIT) { if(poly->length < (unsigned long) BMP_BIT) {
*poly->bitmap = rev(*poly->bitmap >> ofs, (int) poly->length) << ofs; *poly->bitmap = rev(*poly->bitmap >> ofs, (int) poly->length) << ofs;
return; return;
} }
}
/* claim remaining bits of last word (as we use public function pshift()) */ /* claim remaining bits of last word (as we use public function pshift()) */
poly->length = fulllength; poly->length = fulllength;
/* reverse and swap words in the array, leaving it right-justified */ /* reverse and swap words in the array, leaving it right-justified */
while(leftidx < rightidx) { while(leftidx < rightidx) {

View file

@ -145,7 +145,7 @@ static int l_nonce2key(lua_State *L){
uint8_t dest_key[8]; uint8_t dest_key[8];
num_to_bytes(key,sizeof(dest_key),dest_key); num_to_bytes(key,sizeof(dest_key),dest_key);
//printf("Pushing to lua stack: %012"llx"\n",key); //printf("Pushing to lua stack: %012" PRIx64 "\n",key);
lua_pushlstring(L,(const char *) dest_key,sizeof(dest_key)); lua_pushlstring(L,(const char *) dest_key,sizeof(dest_key));
return 2; //Two return values return 2; //Two return values
@ -531,7 +531,7 @@ static int l_hardnested(lua_State *L){
uint8_t dest_key[6]; uint8_t dest_key[6];
num_to_bytes(foundkey, sizeof(dest_key), dest_key); num_to_bytes(foundkey, sizeof(dest_key), dest_key);
//printf("Pushing to lua stack: %012"llx"\n",key); //printf("Pushing to lua stack: %012" PRIx64 "\n",key);
lua_pushlstring(L, (const char *) dest_key, sizeof(dest_key)); lua_pushlstring(L, (const char *) dest_key, sizeof(dest_key));
return 2; //Two return values return 2; //Two return values
} }

View file

@ -75,7 +75,7 @@ void AddLogUint64(char *fileName, char *extData, const uint64_t data) {
char buf[20] = {0}; char buf[20] = {0};
memset(buf, 0x00, sizeof(buf)); memset(buf, 0x00, sizeof(buf));
//sprintf(buf, "%X%X", (unsigned int)((data & 0xFFFFFFFF00000000) >> 32), (unsigned int)(data & 0xFFFFFFFF)); //sprintf(buf, "%X%X", (unsigned int)((data & 0xFFFFFFFF00000000) >> 32), (unsigned int)(data & 0xFFFFFFFF));
sprintf(buf, "%012"llx"", data); sprintf(buf, "%012" PRIx64 "", data);
AddLogLine(fileName, extData, buf); AddLogLine(fileName, extData, buf);
} }

View file

@ -59,15 +59,12 @@ DETECTED_OS=Windows
endif endif
#
# uncomment these two; to enable EMV # uncomment these two; to enable EMV
#
#APP_CFLAGS += -DWITH_EMV #APP_CFLAGS += -DWITH_EMV
#COMMON_FLAGS += -DWITH_EMV #COMMON_FLAGS += -DWITH_EMV
#
# uncomment these two; to fix 256 vs 512kb PM3 devices # uncomment these two; to fix 256 vs 512kb PM3 devices
# flashing bootrom -b is needed # flashing bootrom -b is needed
#
APP_CFLAGS += -DHAS_512_FLASH APP_CFLAGS += -DHAS_512_FLASH
COMMON_FLAGS += -DHAS_512_FLASH COMMON_FLAGS += -DHAS_512_FLASH

View file

@ -5,8 +5,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <time.h> #include <time.h>
#define llx PRIx64
#define lli PRIi64
int main (int argc, char *argv[]) { int main (int argc, char *argv[]) {
struct Crypto1State *s,*t; struct Crypto1State *s,*t;
uint64_t key; // recovered key uint64_t key; // recovered key
@ -64,7 +62,7 @@ int main (int argc, char *argv[]) {
crypto1_word(t, uid ^ nt, 0); crypto1_word(t, uid ^ nt, 0);
crypto1_word(t, nr1_enc, 1); crypto1_word(t, nr1_enc, 1);
if (ar1_enc == (crypto1_word(t, 0, 0) ^ p64)) { if (ar1_enc == (crypto1_word(t, 0, 0) ^ p64)) {
printf("\nFound Key: [%012"llx"]\n\n",key); printf("\nFound Key: [%012" PRIx64 "]\n\n",key);
break;} break;}
} }
free(s); free(s);

View file

@ -4,9 +4,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <time.h> #include <time.h>
#define llx PRIx64
#define lli PRIi64
int main (int argc, char *argv[]) { int main (int argc, char *argv[]) {
struct Crypto1State *s,*t; struct Crypto1State *s,*t;
uint64_t key; // recovered key uint64_t key; // recovered key
@ -71,7 +69,7 @@ int main (int argc, char *argv[]) {
crypto1_word(t, uid ^ nt1, 0); crypto1_word(t, uid ^ nt1, 0);
crypto1_word(t, nr1_enc, 1); crypto1_word(t, nr1_enc, 1);
if (ar1_enc == (crypto1_word(t, 0, 0) ^ p64b)) { if (ar1_enc == (crypto1_word(t, 0, 0) ^ p64b)) {
printf("\nFound Key: [%012"llx"]\n\n",key); printf("\nFound Key: [%012" PRIx64 "]\n\n",key);
break;} break;}
} }
free(s); free(s);

View file

@ -5,9 +5,6 @@
#include <inttypes.h> #include <inttypes.h>
#include "crapto1.h" #include "crapto1.h"
#define llx PRIx64
#define lli PRIi64
int main (int argc, char *argv[]) { int main (int argc, char *argv[]) {
struct Crypto1State *revstate; struct Crypto1State *revstate;
uint64_t key; // recovered key uint64_t key; // recovered key
@ -98,7 +95,7 @@ int main (int argc, char *argv[]) {
lfsr_rollback_word(revstate, nr_enc, 1); lfsr_rollback_word(revstate, nr_enc, 1);
lfsr_rollback_word(revstate, uid ^ nt, 0); lfsr_rollback_word(revstate, uid ^ nt, 0);
crypto1_get_lfsr(revstate, &key); crypto1_get_lfsr(revstate, &key);
printf("\nFound Key: [%012"llx"]\n\n", key); printf("\nFound Key: [%012" PRIx64 "]\n\n", key);
crypto1_destroy(revstate); crypto1_destroy(revstate);
t1 = clock() - t1; t1 = clock() - t1;

View file

@ -1,7 +1,6 @@
#include "crapto1.h" #include "crapto1.h"
#define __STDC_FORMAT_MACROS #define __STDC_FORMAT_MACROS
#include <inttypes.h> #include <inttypes.h>
#define llx PRIx64
#include <stdio.h> #include <stdio.h>
#include <time.h> #include <time.h>
typedef unsigned char byte_t; typedef unsigned char byte_t;
@ -19,15 +18,15 @@ int main(const int argc, const char* argv[]) {
printf("\nsyntax: %s <uid> <nt> <par> <ks>\n\n",argv[0]); printf("\nsyntax: %s <uid> <nt> <par> <ks>\n\n",argv[0]);
return 1; return 1;
} }
sscanf(argv[1],"%08x",&uid); sscanf(argv[1],"%08x", &uid);
sscanf(argv[2],"%08x",&nt); sscanf(argv[2],"%08x", &nt);
sscanf(argv[3],"%016"llx,&par_info); sscanf(argv[3],"%016" SCNx64 ,&par_info);
sscanf(argv[4],"%016"llx,&ks_info); sscanf(argv[4],"%016" SCNx64 ,&ks_info);
// Reset the last three significant bits of the reader nonce // Reset the last three significant bits of the reader nonce
nr &= 0xffffff1f; nr &= 0xffffff1f;
printf("\nuid(%08x) nt(%08x) par(%016"llx") ks(%016"llx")\n\n",uid,nt,par_info,ks_info); printf("\nuid(%08x) nt(%08x) par(%016" PRIx64 ") ks(%016" PRIx64 ")\n\n", uid, nt, par_info, ks_info);
for ( pos = 0; pos < 8; pos++ ) { for ( pos = 0; pos < 8; pos++ ) {
ks3x[7-pos] = (ks_info >> (pos*8)) & 0x0f; ks3x[7-pos] = (ks_info >> (pos*8)) & 0x0f;
@ -56,7 +55,7 @@ int main(const int argc, const char* argv[]) {
state = lfsr_common_prefix(nr,rr,ks3x,par); state = lfsr_common_prefix(nr,rr,ks3x,par);
lfsr_rollback_word(state,uid^nt,0); lfsr_rollback_word(state,uid^nt,0);
crypto1_get_lfsr(state,&key_recovered); crypto1_get_lfsr(state,&key_recovered);
printf("\nkey recovered: %012"llx"\n\n",key_recovered); printf("\nkey recovered: %012" PRIx64 "\n\n", key_recovered);
crypto1_destroy(state); crypto1_destroy(state);
t1 = clock() - t1; t1 = clock() - t1;

View file

@ -951,7 +951,7 @@ void ZLIB_INTERNAL _tr_flush_block(s, buf, stored_len, last)
opt_lenb = (s->opt_len+3+7)>>3; opt_lenb = (s->opt_len+3+7)>>3;
static_lenb = (s->static_len+3+7)>>3; static_lenb = (s->static_len+3+7)>>3;
Tracev((stderr, "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u ", Tracev((stderr, "\nopt %" PRIu32 "(%" PRIu32 ") stat %" PRIu32 "(%" PRIu32 ") stored %" PRIu32 " lit %u ",
opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len, opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len,
s->last_lit)); s->last_lit));