This commit is contained in:
iceman1001 2019-04-28 11:09:46 +02:00
parent ab6870c573
commit 9779868753
9 changed files with 86 additions and 59 deletions

View file

@ -414,6 +414,17 @@ static int CmdrevengSearch(const char *Cmd) {
// can't test a model that has more crc digits than our data // can't test a model that has more crc digits than our data
if (crcChars >= dataLen) if (crcChars >= dataLen)
continue; continue;
PrintAndLogEx(DEBUG
, "DEBUG: dataLen %d, crcChars %u, width[i] %u"
, dataLen
, crcChars
, width[i]
);
if (crcChars == 0)
continue;
memset(result, 0, 30); memset(result, 0, 30);
char *inCRC = calloc(crcChars + 1, sizeof(char)); char *inCRC = calloc(crcChars + 1, sizeof(char));
memcpy(inCRC, inHexStr + (dataLen - crcChars), crcChars); memcpy(inCRC, inHexStr + (dataLen - crcChars), crcChars);
@ -421,7 +432,6 @@ static int CmdrevengSearch(const char *Cmd) {
char *outHex = calloc(dataLen - crcChars + 1, sizeof(char)); char *outHex = calloc(dataLen - crcChars + 1, sizeof(char));
memcpy(outHex, inHexStr, dataLen - crcChars); memcpy(outHex, inHexStr, dataLen - crcChars);
PrintAndLogEx(DEBUG, "DEBUG: dataLen: %d, crcChars: %d, Model: %s, CRC: %s, width: %d, outHex: %s", dataLen, crcChars, Models[i], inCRC, width[i], outHex);
ans = RunModel(Models[i], outHex, false, 0, result); ans = RunModel(Models[i], outHex, false, 0, result);
if (ans) { if (ans) {
// test for match // test for match

View file

@ -2219,8 +2219,8 @@ static int CmdHF14AMfSim(const char *Cmd) {
, csize , csize
, uidsize , uidsize
, (uidlen == 0) ? "N/A" : sprint_hex(uid, uidlen >> 1) , (uidlen == 0) ? "N/A" : sprint_hex(uid, uidlen >> 1)
); );
PrintAndLogEx(INFO, "Options [ numreads: %d, flags: %d (0x%02x) ]" PrintAndLogEx(INFO, "Options [ numreads: %d, flags: %d (0x%02x) ]"
, exitAfterNReads , exitAfterNReads
, flags , flags

View file

@ -309,22 +309,22 @@ static void lookupChipID(uint32_t iChipID, uint32_t mem_used) {
static int CmdDetectReader(const char *Cmd) { static int CmdDetectReader(const char *Cmd) {
uint16_t arg = 0; uint16_t arg = 0;
char c = tolower(Cmd[0]); char c = tolower(Cmd[0]);
switch ( c ) { switch (c) {
case 'l': case 'l':
arg = 1; arg = 1;
break; break;
case 'h': case 'h':
arg = 2; arg = 2;
break; break;
default: { default: {
PrintAndLogEx(NORMAL, "use 'detectreader'"); PrintAndLogEx(NORMAL, "use 'detectreader'");
PrintAndLogEx(NORMAL, " 'detectreader l' -- 125/134 kHz"); PrintAndLogEx(NORMAL, " 'detectreader l' -- 125/134 kHz");
PrintAndLogEx(NORMAL, " 'detectreader h' -- 13.56 mHz"); PrintAndLogEx(NORMAL, " 'detectreader h' -- 13.56 mHz");
return PM3_EINVARG; return PM3_EINVARG;
}
} }
}
clearCommandBuffer(); clearCommandBuffer();
SendCommandOLD(CMD_LISTEN_READER_FIELD, arg, 0, 0, NULL, 0); SendCommandOLD(CMD_LISTEN_READER_FIELD, arg, 0, 0, NULL, 0);
return PM3_SUCCESS; return PM3_SUCCESS;

View file

@ -241,23 +241,23 @@ static void memcpy_filtered(void *dest, const void *src, size_t n, bool filter)
uint8_t *rsrc = (uint8_t *)src; uint8_t *rsrc = (uint8_t *)src;
uint16_t si = 0; uint16_t si = 0;
for (uint16_t i = 0; i < n; i++) { for (uint16_t i = 0; i < n; i++) {
if ( (rsrc[i] == '\x1b') if ((rsrc[i] == '\x1b')
&& (i < n - 1) && (i < n - 1)
&& (rsrc[i + 1] >= 0x40) && (rsrc[i + 1] >= 0x40)
&& (rsrc[i + 1] <= 0x5F) ) { // entering ANSI sequence && (rsrc[i + 1] <= 0x5F)) { // entering ANSI sequence
i++; i++;
if ((rsrc[i] == '[') && (i < n - 1)) { // entering CSI sequence if ((rsrc[i] == '[') && (i < n - 1)) { // entering CSI sequence
i++; i++;
while ((i < n - 1) && (rsrc[i] >= 0x30) && (rsrc[i] <= 0x3F)) { // parameter bytes while ((i < n - 1) && (rsrc[i] >= 0x30) && (rsrc[i] <= 0x3F)) { // parameter bytes
i++; i++;
} }
while ((i < n - 1) && (rsrc[i] >= 0x20) && (rsrc[i] <= 0x2F)) { // intermediate bytes while ((i < n - 1) && (rsrc[i] >= 0x20) && (rsrc[i] <= 0x2F)) { // intermediate bytes
i++; i++;
} }
if ((rsrc[i] >= 0x40) && (rsrc[i] <= 0x7F)) { // final byte if ((rsrc[i] >= 0x40) && (rsrc[i] <= 0x7F)) { // final byte
continue; continue;
} }

View file

@ -207,7 +207,7 @@ int TinyCborPrintFIDOPackage(uint8_t cmdCode, bool isResponse, uint8_t *data, si
"CBOR parsing failure at offset %" PRId32 " : %s\n", "CBOR parsing failure at offset %" PRId32 " : %s\n",
(uint32_t)(cb.ptr - data), (uint32_t)(cb.ptr - data),
cbor_error_string(err) cbor_error_string(err)
); );
return 1; return 1;
} }

View file

@ -596,11 +596,15 @@ plast(const poly_t poly) {
unsigned long idx, size = SIZE(poly.length); unsigned long idx, size = SIZE(poly.length);
bmp_t accu; bmp_t accu;
unsigned int probe = BMP_SUB, ofs = 0; unsigned int probe = BMP_SUB, ofs = 0;
if (!poly.length) return (0UL); if (!poly.length) return (0UL);
idx = size - 1UL; idx = size - 1UL;
while (idx && !(accu = poly.bitmap[idx])) --idx; while (idx && !(accu = poly.bitmap[idx])) --idx;
if (poly.length == 24)
printf("ICE plast B - poly.length %lu vs size %lu idx %lu bitmap %ld\n", poly.length, size, idx, poly.bitmap[idx]);
if (!idx && !(accu = poly.bitmap[idx])) return (0UL); if (!idx && !(accu = poly.bitmap[idx])) return (0UL);
/* now accu == poly.bitmap[idx] and contains last significant term */ /* now accu == poly.bitmap[idx] and contains last significant term */
while (probe) { while (probe) {
#ifndef BMP_POF2 #ifndef BMP_POF2
@ -609,7 +613,6 @@ plast(const poly_t poly) {
if (accu << (ofs | probe)) ofs |= probe; if (accu << (ofs | probe)) ofs |= probe;
probe >>= 1; probe >>= 1;
} }
return (idx * BMP_BIT + ofs + 1UL); return (idx * BMP_BIT + ofs + 1UL);
} }
@ -1074,20 +1077,34 @@ praloc(poly_t *poly, unsigned long length) {
if (oldsize != size) if (oldsize != size)
/* reallocate if array pointer is null or array resized */ /* reallocate if array pointer is null or array resized */
poly->bitmap = (bmp_t *) realloc((void *)poly->bitmap, size * sizeof(bmp_t)); poly->bitmap = (bmp_t *) realloc((void *)poly->bitmap, size * sizeof(bmp_t));
if (poly->bitmap) { if (poly->bitmap) {
if (poly->length == 24)
printf("ICE praloc - poly->length %lu\n", poly->length);
if (poly->length < length) { if (poly->length < length) {
/* poly->length >= 0, length > 0, size > 0. /* poly->length >= 0, length > 0, size > 0.
* poly expanded. clear old last word and all new words * poly expanded. clear old last word and all new words
*/ */
if (LOFS(poly->length)) if (LOFS(poly->length))
poly->bitmap[oldsize - 1UL] &= ~(~BMP_C(0) >> LOFS(poly->length)); poly->bitmap[oldsize - 1UL] &= ~(~BMP_C(0) >> LOFS(poly->length));
while (oldsize < size) while (oldsize < size)
poly->bitmap[oldsize++] = BMP_C(0); poly->bitmap[oldsize++] = BMP_C(0);
} else if (LOFS(length))
if (poly->length == 24) printf("ICE praloc MISS A\n");
} else if (LOFS(length)) {
/* poly->length >= length > 0. /* poly->length >= length > 0.
* poly shrunk. clear new last word * poly shrunk. clear new last word
*/ */
poly->bitmap[size - 1UL] &= ~(~BMP_C(0) >> LOFS(length)); poly->bitmap[size - 1UL] &= ~(~BMP_C(0) >> LOFS(length));
if (poly->length == 24) printf("ICE praloc B size %lu, bm %lu \n", size, poly->bitmap[size - 1UL]);
}
poly->length = length; poly->length = length;
} else } else
uerror("cannot reallocate memory for poly"); uerror("cannot reallocate memory for poly");

View file

@ -63,7 +63,7 @@ static int l_SendCommandOLD(lua_State *L) {
// (uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, void *data, size_t len) // (uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, void *data, size_t len)
uint64_t cmd, arg0, arg1, arg2; uint64_t cmd, arg0, arg1, arg2;
uint8_t data[USB_CMD_DATA_SIZE] = {0}; uint8_t data[USB_CMD_DATA_SIZE] = {0};
size_t len = 0, size; size_t len = 0, size;
//Check number of arguments //Check number of arguments
@ -78,13 +78,13 @@ static int l_SendCommandOLD(lua_State *L) {
if (size != 4) if (size != 4)
return returnToLuaWithError(L, "Wrong size of cmd, got %d bytes, expected 2", (int) size); return returnToLuaWithError(L, "Wrong size of cmd, got %d bytes, expected 2", (int) size);
sscanf(p_cmd, " %" SCNx64, &cmd); sscanf(p_cmd, " %" SCNx64, &cmd);
// arg0 // arg0
const char *p_arg0 = luaL_checklstring(L, 2, &size); const char *p_arg0 = luaL_checklstring(L, 2, &size);
if (size != 16) if (size != 16)
return returnToLuaWithError(L, "Wrong size of arg0, got %d bytes, expected 16", (int) size); return returnToLuaWithError(L, "Wrong size of arg0, got %d bytes, expected 16", (int) size);
sscanf(p_arg0, " %" SCNx64, &arg0); sscanf(p_arg0, " %" SCNx64, &arg0);
// arg1 // arg1
const char *p_arg1 = luaL_checklstring(L, 3, &size); const char *p_arg1 = luaL_checklstring(L, 3, &size);
if (size != 16) if (size != 16)
@ -96,14 +96,14 @@ static int l_SendCommandOLD(lua_State *L) {
if (size != 16) if (size != 16)
return returnToLuaWithError(L, "Wrong size of arg2, got %d bytes, expected 16", (int) size); return returnToLuaWithError(L, "Wrong size of arg2, got %d bytes, expected 16", (int) size);
sscanf(p_arg2, " %" SCNx64, &arg2); sscanf(p_arg2, " %" SCNx64, &arg2);
// data // data
const char *p_data = luaL_checklstring(L, 5, &size); const char *p_data = luaL_checklstring(L, 5, &size);
if ( size ) { if (size) {
if ( size > 1024 ) if (size > 1024)
size = 1024; size = 1024;
uint32_t tmp; uint32_t tmp;
for (int i = 0; i < size; i += 2) { for (int i = 0; i < size; i += 2) {
sscanf(&p_data[i], "%02x", &tmp); sscanf(&p_data[i], "%02x", &tmp);
@ -118,7 +118,7 @@ static int l_SendCommandOLD(lua_State *L) {
/** /**
* The following params expected: * The following params expected:
* @brief l_SendCommandMIX * @brief l_SendCommandMIX
* @param L - a lua string with the following five params. * @param L - a lua string with the following five params.
* @param cmd must be hexstring, max u64 * @param cmd must be hexstring, max u64
* @param arg0 must be hexstring, max u64 * @param arg0 must be hexstring, max u64
* @param arg1 must be hexstring, max u64 * @param arg1 must be hexstring, max u64
@ -136,20 +136,20 @@ static int l_SendCommandMIX(lua_State *L) {
int n = lua_gettop(L); int n = lua_gettop(L);
if (n != 5) if (n != 5)
return returnToLuaWithError(L, "You need to supply five parameters"); return returnToLuaWithError(L, "You need to supply five parameters");
// parse input // parse input
// cmd // cmd
const char *p_cmd = luaL_checklstring(L, 1, &size); const char *p_cmd = luaL_checklstring(L, 1, &size);
if (size != 4) if (size != 4)
return returnToLuaWithError(L, "Wrong size of cmd, got %d bytes, expected 2", (int) size); return returnToLuaWithError(L, "Wrong size of cmd, got %d bytes, expected 2", (int) size);
sscanf(p_cmd, " %" SCNx64, &cmd); sscanf(p_cmd, " %" SCNx64, &cmd);
// arg0 // arg0
const char *p_arg0 = luaL_checklstring(L, 2, &size); const char *p_arg0 = luaL_checklstring(L, 2, &size);
if (size != 16) if (size != 16)
return returnToLuaWithError(L, "Wrong size of arg0, got %d bytes, expected 16", (int) size); return returnToLuaWithError(L, "Wrong size of arg0, got %d bytes, expected 16", (int) size);
sscanf(p_arg0, " %" SCNx64, &arg0); sscanf(p_arg0, " %" SCNx64, &arg0);
// arg1 // arg1
const char *p_arg1 = luaL_checklstring(L, 3, &size); const char *p_arg1 = luaL_checklstring(L, 3, &size);
if (size != 16) if (size != 16)
@ -161,13 +161,13 @@ static int l_SendCommandMIX(lua_State *L) {
if (size != 16) if (size != 16)
return returnToLuaWithError(L, "Wrong size of arg2, got %d bytes, expected 16", (int) size); return returnToLuaWithError(L, "Wrong size of arg2, got %d bytes, expected 16", (int) size);
sscanf(p_arg2, " %" SCNx64, &arg2); sscanf(p_arg2, " %" SCNx64, &arg2);
// data // data
const char *p_data = luaL_checklstring(L, 5, &size); const char *p_data = luaL_checklstring(L, 5, &size);
if ( size ) { if (size) {
if ( size > 1024 ) if (size > 1024)
size = 1024; size = 1024;
uint32_t tmp; uint32_t tmp;
for (int i = 0; i < size; i += 2) { for (int i = 0; i < size; i += 2) {
sscanf(&p_data[i], "%02x", &tmp); sscanf(&p_data[i], "%02x", &tmp);
@ -196,7 +196,7 @@ static int l_GetFromBigBuf(lua_State *L) {
if (n == 0) { if (n == 0) {
return returnToLuaWithError(L, "You need to supply number of bytes and startindex"); return returnToLuaWithError(L, "You need to supply number of bytes and startindex");
} }
if (n >= 2) { if (n >= 2) {
startindex = luaL_checknumber(L, 1); startindex = luaL_checknumber(L, 1);
len = luaL_checknumber(L, 2); len = luaL_checknumber(L, 2);
@ -240,7 +240,7 @@ static int l_GetFromFlashMem(lua_State *L) {
int n = lua_gettop(L); int n = lua_gettop(L);
if (n == 0) if (n == 0)
return returnToLuaWithError(L, "You need to supply number of bytes and startindex"); return returnToLuaWithError(L, "You need to supply number of bytes and startindex");
if (n >= 2) { if (n >= 2) {
startindex = luaL_checknumber(L, 1); startindex = luaL_checknumber(L, 1);
len = luaL_checknumber(L, 2); len = luaL_checknumber(L, 2);
@ -824,19 +824,19 @@ static int l_T55xx_readblock(lua_State *L) {
const char *p_blockno = luaL_checklstring(L, 1, &size); const char *p_blockno = luaL_checklstring(L, 1, &size);
if (size < 1 || size > 2) if (size < 1 || size > 2)
return returnToLuaWithError(L, "Wrong size of blockNo, got %d, expected 1 or 2", (int) size); return returnToLuaWithError(L, "Wrong size of blockNo, got %d, expected 1 or 2", (int) size);
sscanf(p_blockno, "%x", &block); sscanf(p_blockno, "%x", &block);
const char *p_usepage1 = luaL_checklstring(L, 2, &size); const char *p_usepage1 = luaL_checklstring(L, 2, &size);
if (size != 1) if (size != 1)
return returnToLuaWithError(L, "Wrong size of usePage1, got %d, expected 1", (int) size); return returnToLuaWithError(L, "Wrong size of usePage1, got %d, expected 1", (int) size);
sscanf(p_usepage1, "%x", &usepage1); sscanf(p_usepage1, "%x", &usepage1);
const char *p_override = luaL_checklstring(L, 3, &size); const char *p_override = luaL_checklstring(L, 3, &size);
if (size != 1) if (size != 1)
return returnToLuaWithError(L, "Wrong size of override, got %d, expected 1", (int) size); return returnToLuaWithError(L, "Wrong size of override, got %d, expected 1", (int) size);
sscanf(p_override, "%x", &override); sscanf(p_override, "%x", &override);
const char *p_pwd = luaL_checklstring(L, 4, &size); const char *p_pwd = luaL_checklstring(L, 4, &size);
@ -846,7 +846,7 @@ static int l_T55xx_readblock(lua_State *L) {
if (size != 8) if (size != 8)
return returnToLuaWithError(L, "Wrong size of pwd, got %d , expected 8", (int) size); return returnToLuaWithError(L, "Wrong size of pwd, got %d , expected 8", (int) size);
sscanf(p_pwd, "%08x", &password); sscanf(p_pwd, "%08x", &password);
usepwd = true; usepwd = true;
} }
@ -905,7 +905,7 @@ static int l_T55xx_detect(lua_State *L) {
const char *p_gb = luaL_checklstring(L, 2, &size); const char *p_gb = luaL_checklstring(L, 2, &size);
if (size != 1) if (size != 1)
return returnToLuaWithError(L, "Wrong size of useGB, got %d , expected 1", (int) size); return returnToLuaWithError(L, "Wrong size of useGB, got %d , expected 1", (int) size);
sscanf(p_gb, "%u", &gb); sscanf(p_gb, "%u", &gb);
useGB = (gb) ? true : false; useGB = (gb) ? true : false;
printf("p_gb size %zu | %c \n", size, useGB ? 'Y' : 'N'); printf("p_gb size %zu | %c \n", size, useGB ? 'Y' : 'N');
@ -918,7 +918,7 @@ static int l_T55xx_detect(lua_State *L) {
if (size != 8) if (size != 8)
return returnToLuaWithError(L, "Wrong size of pwd, got %d , expected 8", (int) size); return returnToLuaWithError(L, "Wrong size of pwd, got %d , expected 8", (int) size);
sscanf(p_pwd, "%08x", &password); sscanf(p_pwd, "%08x", &password);
usepwd = true; usepwd = true;
} }

View file

@ -800,19 +800,19 @@ int num_CPUs(void) {
#elif defined(__linux__) && defined(_SC_NPROCESSORS_ONLN) #elif defined(__linux__) && defined(_SC_NPROCESSORS_ONLN)
#include <unistd.h> #include <unistd.h>
int count = sysconf(_SC_NPROCESSORS_ONLN); int count = sysconf(_SC_NPROCESSORS_ONLN);
if (count <= 0) if (count <= 0)
count = 1; count = 1;
return count; return count;
#elif defined(__APPLE__) #elif defined(__APPLE__)
/* /*
TODO ICEMAN 2019, its commented out until someone finds a better solution TODO ICEMAN 2019, its commented out until someone finds a better solution
#include "sys/sysctl.h" #include "sys/sysctl.h"
uint32_t logicalcores = 0; uint32_t logicalcores = 0;
size_t size = sizeof( logicalcores ); size_t size = sizeof( logicalcores );
sysctlbyname( "hw.logicalcpu", &logicalcores, &size, NULL, 0 ); sysctlbyname( "hw.logicalcpu", &logicalcores, &size, NULL, 0 );
return logicalcores; return logicalcores;
*/ */
return 1; return 1;
#else #else
return 1; return 1;
#endif #endif

View file

@ -593,7 +593,7 @@ bool I2C_WriteFW(uint8_t *data, uint8_t len, uint8_t msb, uint8_t lsb, uint8_t d
} }
void I2C_print_status(void) { void I2C_print_status(void) {
DbpStringEx(FLAG_LOG|FLAG_ANSI, _BLUE_("Smart card module (ISO 7816)")); DbpStringEx(FLAG_LOG | FLAG_ANSI, _BLUE_("Smart card module (ISO 7816)"));
uint8_t resp[] = {0, 0, 0, 0}; uint8_t resp[] = {0, 0, 0, 0};
I2C_Reset_EnterMainProgram(); I2C_Reset_EnterMainProgram();
uint8_t len = I2C_BufferRead(resp, sizeof(resp), I2C_DEVICE_CMD_GETVERSION, I2C_DEVICE_ADDRESS_MAIN); uint8_t len = I2C_BufferRead(resp, sizeof(resp), I2C_DEVICE_CMD_GETVERSION, I2C_DEVICE_ADDRESS_MAIN);