This commit is contained in:
iceman1001 2022-06-12 11:51:50 +02:00
commit 372ab2af98
9 changed files with 53 additions and 58 deletions

View file

@ -1196,7 +1196,7 @@ void MifareNested(uint8_t blockNo, uint8_t keyType, uint8_t targetBlockNo, uint8
set_tracing(false);
}
static void MifareFastStaticNestedImpl(uint8_t blockNo, uint8_t keyType, uint8_t targetBlockNo, uint8_t targetKeyType, uint8_t* key, uint32_t* nt1, uint32_t* nt2, uint32_t* cuid, bool firstGet, int16_t* isOK) {
static void MifareFastStaticNestedImpl(uint8_t blockNo, uint8_t keyType, uint8_t targetBlockNo, uint8_t targetKeyType, uint8_t *key, uint32_t *nt1, uint32_t *nt2, uint32_t *cuid, bool firstGet, int16_t *isOK) {
uint64_t ui64Key = 0;
ui64Key = bytes_to_num(key, 6);
@ -1206,7 +1206,7 @@ static void MifareFastStaticNestedImpl(uint8_t blockNo, uint8_t keyType, uint8_t
uint8_t receivedAnswer[10] = { 0x00 };
struct Crypto1State mpcs = { 0, 0 };
struct Crypto1State* pcs;
struct Crypto1State *pcs;
pcs = &mpcs;
*isOK = 0;
@ -1261,7 +1261,7 @@ static void MifareFastStaticNestedImpl(uint8_t blockNo, uint8_t keyType, uint8_t
crypto1_deinit(pcs);
}
void MifareStaticNested(uint8_t blockNo, uint8_t keyType, uint8_t targetBlockNo, uint8_t targetKeyType, uint8_t* key) {
void MifareStaticNested(uint8_t blockNo, uint8_t keyType, uint8_t targetBlockNo, uint8_t targetKeyType, uint8_t *key) {
int16_t isOK;
uint32_t cuid;
@ -1307,7 +1307,7 @@ void MifareStaticNested(uint8_t blockNo, uint8_t keyType, uint8_t targetBlockNo,
memcpy(payload.nt2_2, &nt2_2, 4);
LED_B_ON();
reply_ng(CMD_HF_MIFARE_STATIC_NESTED, PM3_SUCCESS, (uint8_t*)&payload, sizeof(payload));
reply_ng(CMD_HF_MIFARE_STATIC_NESTED, PM3_SUCCESS, (uint8_t *)&payload, sizeof(payload));
LED_B_OFF();
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);

View file

@ -1379,11 +1379,11 @@ static int waitCmd(bool i_select, uint32_t timeout, bool verbose) {
char s[16];
snprintf(s,
sizeof(s),
(crc) ? _GREEN_("%02X %02X") : _RED_("%02X %02X"),
data[len - 2],
data[len - 1]
);
sizeof(s),
(crc) ? _GREEN_("%02X %02X") : _RED_("%02X %02X"),
data[len - 2],
data[len - 1]
);
PrintAndLogEx(SUCCESS, "%s[ %s ]", sprint_hex(data, len - 2), s);
} else {

View file

@ -1713,7 +1713,7 @@ static bool all_bitflips_match(uint8_t byte, uint32_t state, odd_even_t odd_even
byte2,
num_common);
if (failstr[0] == '\0') {
snprintf(failstr, sizeof(failstr), "Other 1st Byte %s, all_bitflips_match(), no match", odd_even ? "odd" : "even");
snprintf(failstr, sizeof(failstr), "Other 1st Byte %s, all_bitflips_match(), no match", odd_even ? "odd" : "even");
}
}
# endif

View file

@ -480,7 +480,7 @@ static int CmdDbg(const char *Cmd) {
}
uint8_t curr = resp.data.asBytes[0];
const char* dbglvlstr;
const char *dbglvlstr;
switch (curr) {
case DBG_NONE:
dbglvlstr = "none";

View file

@ -1993,7 +1993,7 @@ int CmdEM4x05Sniff(const char *Cmd) {
bool fwd = arg_get_lit(ctx, 2);
CLIParserFree(ctx);
const char* cmdText;
const char *cmdText;
char dataText[100];
char blkAddr[4];
char bits[80];
@ -2120,7 +2120,7 @@ int CmdEM4x05Sniff(const char *Cmd) {
cmdText = "Disable";
strncpy(blkAddr, " ", sizeof(blkAddr));
tmpValue = em4x05_Sniff_GetBlock(&bits[11], fwd);
snprintf(dataText, sizeof(dataText), "%08X", tmpValue);
snprintf(dataText, sizeof(dataText), "%08X", tmpValue);
}
// bits[bitidx] = 0;

View file

@ -50,7 +50,7 @@ static void print_result(const em4x50_word_t *words, int fwr, int lwr) {
for (int i = fwr; i <= lwr; i++) {
const char* s;
const char *s;
switch (i) {
case EM4X50_DEVICE_PASSWORD:
s = _YELLOW_("password, write only");

View file

@ -581,11 +581,11 @@ out:
}
int mfStaticNested(uint8_t blockNo, uint8_t keyType, uint8_t* key, uint8_t trgBlockNo, uint8_t trgKeyType, uint8_t* resultKey) {
int mfStaticNested(uint8_t blockNo, uint8_t keyType, uint8_t *key, uint8_t trgBlockNo, uint8_t trgKeyType, uint8_t *resultKey) {
uint32_t uid;
StateList_t statelists[2];
struct Crypto1State* p1, * p2, * p3, * p4;
struct Crypto1State *p1, * p2, * p3, * p4;
struct {
uint8_t block;
@ -602,7 +602,7 @@ int mfStaticNested(uint8_t blockNo, uint8_t keyType, uint8_t* key, uint8_t trgBl
PacketResponseNG resp;
clearCommandBuffer();
SendCommandNG(CMD_HF_MIFARE_STATIC_NESTED, (uint8_t*)&payload, sizeof(payload));
SendCommandNG(CMD_HF_MIFARE_STATIC_NESTED, (uint8_t *)&payload, sizeof(payload));
if (!WaitForResponseTimeout(CMD_HF_MIFARE_STATIC_NESTED, &resp, 2000))
return PM3_ETIMEOUT;
@ -621,7 +621,7 @@ int mfStaticNested(uint8_t blockNo, uint8_t keyType, uint8_t* key, uint8_t trgBl
uint8_t nt1_2[4];
uint8_t nt2_2[4];
} PACKED;
struct p* package = (struct p*)resp.data.asBytes;
struct p *package = (struct p *)resp.data.asBytes;
// error during collecting static nested information
if (package->isOK == 0) return PM3_EUNDEF;
@ -651,8 +651,7 @@ int mfStaticNested(uint8_t blockNo, uint8_t keyType, uint8_t* key, uint8_t trgBl
dist = 161;
}
}
}
else {
} else {
level = 0;
}
@ -677,7 +676,7 @@ int mfStaticNested(uint8_t blockNo, uint8_t keyType, uint8_t* key, uint8_t trgBl
pthread_create(&t, NULL, nested_worker_thread, &statelists[0]);
// wait for thread to terminate:
pthread_join(t, (void*)&statelists[0].head.slhead);
pthread_join(t, (void *)&statelists[0].head.slhead);
// the first 16 Bits of the cryptostate already contain part of our key.
p1 = p3 = statelists[0].head.slhead;
@ -698,8 +697,7 @@ int mfStaticNested(uint8_t blockNo, uint8_t keyType, uint8_t* key, uint8_t trgBl
p3->even = -1;
statelists[0].len = p3 - statelists[0].head.slhead;
statelists[0].tail.sltail = --p3;
}
else { // fast decrypt static nested
} else { // fast decrypt static nested
PrintAndLogEx(SUCCESS, "Fast staticnested decrypt running...");
@ -729,7 +727,7 @@ int mfStaticNested(uint8_t blockNo, uint8_t keyType, uint8_t* key, uint8_t trgBl
// wait for threads to terminate:
for (uint8_t i = 0; i < 2; i++)
pthread_join(thread_id[i], (void*)&statelists[i].head.slhead);
pthread_join(thread_id[i], (void *)&statelists[i].head.slhead);
// the first 16 Bits of the cryptostate already contain part of our key.
// Create the intersection of the two lists based on these 16 Bits and
@ -755,8 +753,7 @@ int mfStaticNested(uint8_t blockNo, uint8_t keyType, uint8_t* key, uint8_t trgBl
p4++;
p2++;
}
}
else {
} else {
while (Compare16Bits(p1, p2) == -1) p1++;
while (Compare16Bits(p1, p2) == 1) p2++;
}
@ -791,7 +788,7 @@ int mfStaticNested(uint8_t blockNo, uint8_t keyType, uint8_t* key, uint8_t trgBl
uint32_t maxkeysinblock = IfPm3Flash() ? 1000 : KEYS_IN_BLOCK;
uint32_t max_keys_chunk = keycnt > maxkeysinblock ? maxkeysinblock : keycnt;
uint8_t* mem = calloc((maxkeysinblock * 6) + 5, sizeof(uint8_t));
uint8_t *mem = calloc((maxkeysinblock * 6) + 5, sizeof(uint8_t));
if (mem == NULL) {
free(statelists[0].head.slhead);
return PM3_EMALLOC;
@ -803,10 +800,10 @@ int mfStaticNested(uint8_t blockNo, uint8_t keyType, uint8_t* key, uint8_t trgBl
mem[3] = ((max_keys_chunk >> 8) & 0xFF);
mem[4] = (max_keys_chunk & 0xFF);
uint8_t* p_keyblock = mem + 5;
uint8_t *p_keyblock = mem + 5;
uint8_t destfn[32];
strncpy((char*)destfn, "static_nested_000.bin", sizeof(destfn) - 1);
strncpy((char *)destfn, "static_nested_000.bin", sizeof(destfn) - 1);
uint64_t start_time = msclock();
for (uint32_t i = 0; i < keycnt; i += max_keys_chunk) {
@ -836,15 +833,14 @@ int mfStaticNested(uint8_t blockNo, uint8_t keyType, uint8_t* key, uint8_t trgBl
mem[4] = (chunk & 0xFF);
// upload to flash.
res = flashmem_spiffs_load((char*)destfn, mem, 5 + (chunk * 6));
res = flashmem_spiffs_load((char *)destfn, mem, 5 + (chunk * 6));
if (res != PM3_SUCCESS) {
PrintAndLogEx(WARNING, "\nSPIFFS upload failed");
free(mem);
return res;
}
res = mfCheckKeys_file(destfn, &key64);
}
else {
} else {
res = mfCheckKeys(statelists[0].blockNo, statelists[0].keyType, false, chunk, p_keyblock, &key64);
}
@ -857,13 +853,12 @@ int mfStaticNested(uint8_t blockNo, uint8_t keyType, uint8_t* key, uint8_t trgBl
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(SUCCESS, "target block:%3u key type: %c -- found valid key [ " _GREEN_("%s") "]",
package->block,
package->keytype ? 'B' : 'A',
sprint_hex(resultKey, 6)
);
package->block,
package->keytype ? 'B' : 'A',
sprint_hex(resultKey, 6)
);
return PM3_SUCCESS;
}
else if (res == PM3_ETIMEOUT || res == PM3_EOPABORTED) {
} else if (res == PM3_ETIMEOUT || res == PM3_EOPABORTED) {
PrintAndLogEx(NORMAL, "");
free(mem);
return res;
@ -878,9 +873,9 @@ int mfStaticNested(uint8_t blockNo, uint8_t keyType, uint8_t* key, uint8_t trgBl
out:
PrintAndLogEx(SUCCESS, "\ntarget block:%3u key type: %c",
package->block,
package->keytype ? 'B' : 'A'
);
package->block,
package->keytype ? 'B' : 'A'
);
free(statelists[0].head.slhead);

View file

@ -690,7 +690,7 @@ void Plot::PlotGraph(int *buffer, size_t len, QRect plotRect, QRect annotationRe
painter->drawPath(penPath);
char str[200];
snprintf(str, sizeof(str), "max=%d min=%d mean=%" PRId64 " n=%u/%zu CursorAVal=[%d] CursorBVal=[%d]",
vMax, vMin, vMean, g_GraphStop - g_GraphStart, len, buffer[CursorAPos], buffer[CursorBPos]);
vMax, vMin, vMean, g_GraphStop - g_GraphStart, len, buffer[CursorAPos], buffer[CursorBPos]);
painter->drawText(20, annotationRect.bottom() - 23 - 20 * graphNum, str);
//clock_t end = clock();
//double elapsed_secs = double(end - begin) / CLOCKS_PER_SEC;
@ -810,18 +810,18 @@ void Plot::paintEvent(QPaintEvent *event) {
}
}
snprintf(str, sizeof(str), "@%u..%u dt=%i %szoom=%2.2f CursorAPos=%u CursorBPos=%u GridX=%lf GridY=%lf (%s) GridXoffset=%lf",
g_GraphStart,
g_GraphStop,
CursorBPos - CursorAPos,
scalestr,
g_GraphPixelsPerPoint,
CursorAPos,
CursorBPos,
g_PlotGridXdefault,
g_PlotGridYdefault,
g_GridLocked ? "Locked" : "Unlocked",
g_GridOffset
);
g_GraphStart,
g_GraphStop,
CursorBPos - CursorAPos,
scalestr,
g_GraphPixelsPerPoint,
CursorAPos,
CursorBPos,
g_PlotGridXdefault,
g_PlotGridYdefault,
g_GridLocked ? "Locked" : "Unlocked",
g_GridOffset
);
painter.setPen(WHITE);
painter.drawText(20, infoRect.bottom() - 3, str);
}

View file

@ -38,10 +38,10 @@ char *iso15693_sprintUID(char *dest, uint8_t *uid) {
#else
sprintf(dest,
#endif
"%02X %02X %02X %02X %02X %02X %02X %02X",
uid[7], uid[6], uid[5], uid[4],
uid[3], uid[2], uid[1], uid[0]
);
"%02X %02X %02X %02X %02X %02X %02X %02X",
uid[7], uid[6], uid[5], uid[4],
uid[3], uid[2], uid[1], uid[0]
);
}
return dest;
}