From 9779868753c47e757f1168189eb391a434e9fd3a Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Sun, 28 Apr 2019 11:09:46 +0200 Subject: [PATCH] style --- client/cmdcrc.c | 12 +++++++++- client/cmdhfmf.c | 4 ++-- client/cmdhw.c | 16 ++++++------- client/comms.c | 16 ++++++------- client/fido/cbortools.c | 2 +- client/reveng/poly.c | 23 ++++++++++++++++--- client/scripting.c | 50 ++++++++++++++++++++--------------------- client/util.c | 20 ++++++++--------- common/i2c.c | 2 +- 9 files changed, 86 insertions(+), 59 deletions(-) diff --git a/client/cmdcrc.c b/client/cmdcrc.c index 8e3d9bba1..e5d62d46e 100644 --- a/client/cmdcrc.c +++ b/client/cmdcrc.c @@ -414,6 +414,17 @@ static int CmdrevengSearch(const char *Cmd) { // can't test a model that has more crc digits than our data if (crcChars >= dataLen) continue; + + PrintAndLogEx(DEBUG + , "DEBUG: dataLen %d, crcChars %u, width[i] %u" + , dataLen + , crcChars + , width[i] + ); + + if (crcChars == 0) + continue; + memset(result, 0, 30); char *inCRC = calloc(crcChars + 1, sizeof(char)); memcpy(inCRC, inHexStr + (dataLen - crcChars), crcChars); @@ -421,7 +432,6 @@ static int CmdrevengSearch(const char *Cmd) { char *outHex = calloc(dataLen - crcChars + 1, sizeof(char)); 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); if (ans) { // test for match diff --git a/client/cmdhfmf.c b/client/cmdhfmf.c index a0a300c6c..052bcd191 100644 --- a/client/cmdhfmf.c +++ b/client/cmdhfmf.c @@ -2219,8 +2219,8 @@ static int CmdHF14AMfSim(const char *Cmd) { , csize , uidsize , (uidlen == 0) ? "N/A" : sprint_hex(uid, uidlen >> 1) - ); - + ); + PrintAndLogEx(INFO, "Options [ numreads: %d, flags: %d (0x%02x) ]" , exitAfterNReads , flags diff --git a/client/cmdhw.c b/client/cmdhw.c index 72f0b4b2f..461e48f0b 100644 --- a/client/cmdhw.c +++ b/client/cmdhw.c @@ -309,22 +309,22 @@ static void lookupChipID(uint32_t iChipID, uint32_t mem_used) { static int CmdDetectReader(const char *Cmd) { uint16_t arg = 0; - char c = tolower(Cmd[0]); - switch ( c ) { - case 'l': - arg = 1; + char c = tolower(Cmd[0]); + switch (c) { + case 'l': + arg = 1; break; case 'h': - arg = 2; + arg = 2; break; default: { PrintAndLogEx(NORMAL, "use 'detectreader'"); PrintAndLogEx(NORMAL, " 'detectreader l' -- 125/134 kHz"); PrintAndLogEx(NORMAL, " 'detectreader h' -- 13.56 mHz"); - return PM3_EINVARG; + return PM3_EINVARG; + } } - } - + clearCommandBuffer(); SendCommandOLD(CMD_LISTEN_READER_FIELD, arg, 0, 0, NULL, 0); return PM3_SUCCESS; diff --git a/client/comms.c b/client/comms.c index 095bcc115..d79f12c30 100644 --- a/client/comms.c +++ b/client/comms.c @@ -241,23 +241,23 @@ static void memcpy_filtered(void *dest, const void *src, size_t n, bool filter) uint8_t *rsrc = (uint8_t *)src; uint16_t si = 0; for (uint16_t i = 0; i < n; i++) { - if ( (rsrc[i] == '\x1b') - && (i < n - 1) - && (rsrc[i + 1] >= 0x40) - && (rsrc[i + 1] <= 0x5F) ) { // entering ANSI sequence - + if ((rsrc[i] == '\x1b') + && (i < n - 1) + && (rsrc[i + 1] >= 0x40) + && (rsrc[i + 1] <= 0x5F)) { // entering ANSI sequence + i++; if ((rsrc[i] == '[') && (i < n - 1)) { // entering CSI sequence i++; - + while ((i < n - 1) && (rsrc[i] >= 0x30) && (rsrc[i] <= 0x3F)) { // parameter bytes i++; } - + while ((i < n - 1) && (rsrc[i] >= 0x20) && (rsrc[i] <= 0x2F)) { // intermediate bytes i++; } - + if ((rsrc[i] >= 0x40) && (rsrc[i] <= 0x7F)) { // final byte continue; } diff --git a/client/fido/cbortools.c b/client/fido/cbortools.c index d7a138779..7cb7fc456 100644 --- a/client/fido/cbortools.c +++ b/client/fido/cbortools.c @@ -207,7 +207,7 @@ int TinyCborPrintFIDOPackage(uint8_t cmdCode, bool isResponse, uint8_t *data, si "CBOR parsing failure at offset %" PRId32 " : %s\n", (uint32_t)(cb.ptr - data), cbor_error_string(err) - ); + ); return 1; } diff --git a/client/reveng/poly.c b/client/reveng/poly.c index 0ce60aac2..0fc6555d9 100644 --- a/client/reveng/poly.c +++ b/client/reveng/poly.c @@ -596,11 +596,15 @@ plast(const poly_t poly) { unsigned long idx, size = SIZE(poly.length); bmp_t accu; unsigned int probe = BMP_SUB, ofs = 0; - if (!poly.length) return (0UL); idx = size - 1UL; 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); + /* now accu == poly.bitmap[idx] and contains last significant term */ while (probe) { #ifndef BMP_POF2 @@ -609,7 +613,6 @@ plast(const poly_t poly) { if (accu << (ofs | probe)) ofs |= probe; probe >>= 1; } - return (idx * BMP_BIT + ofs + 1UL); } @@ -1074,20 +1077,34 @@ praloc(poly_t *poly, unsigned long length) { if (oldsize != size) /* reallocate if array pointer is null or array resized */ poly->bitmap = (bmp_t *) realloc((void *)poly->bitmap, size * sizeof(bmp_t)); + if (poly->bitmap) { + + if (poly->length == 24) + printf("ICE praloc - poly->length %lu\n", poly->length); + + if (poly->length < length) { /* poly->length >= 0, length > 0, size > 0. * poly expanded. clear old last word and all new words */ if (LOFS(poly->length)) poly->bitmap[oldsize - 1UL] &= ~(~BMP_C(0) >> LOFS(poly->length)); + while (oldsize < size) 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 shrunk. clear new last word */ 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; } else uerror("cannot reallocate memory for poly"); diff --git a/client/scripting.c b/client/scripting.c index 333067e8a..fb5bf4f1d 100644 --- a/client/scripting.c +++ b/client/scripting.c @@ -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, arg0, arg1, arg2; - uint8_t data[USB_CMD_DATA_SIZE] = {0}; + uint8_t data[USB_CMD_DATA_SIZE] = {0}; size_t len = 0, size; //Check number of arguments @@ -78,13 +78,13 @@ static int l_SendCommandOLD(lua_State *L) { if (size != 4) return returnToLuaWithError(L, "Wrong size of cmd, got %d bytes, expected 2", (int) size); sscanf(p_cmd, " %" SCNx64, &cmd); - + // arg0 const char *p_arg0 = luaL_checklstring(L, 2, &size); if (size != 16) return returnToLuaWithError(L, "Wrong size of arg0, got %d bytes, expected 16", (int) size); sscanf(p_arg0, " %" SCNx64, &arg0); - + // arg1 const char *p_arg1 = luaL_checklstring(L, 3, &size); if (size != 16) @@ -96,14 +96,14 @@ static int l_SendCommandOLD(lua_State *L) { if (size != 16) return returnToLuaWithError(L, "Wrong size of arg2, got %d bytes, expected 16", (int) size); sscanf(p_arg2, " %" SCNx64, &arg2); - + // data const char *p_data = luaL_checklstring(L, 5, &size); - - if ( size ) { - if ( size > 1024 ) + + if (size) { + if (size > 1024) size = 1024; - + uint32_t tmp; for (int i = 0; i < size; i += 2) { sscanf(&p_data[i], "%02x", &tmp); @@ -118,7 +118,7 @@ static int l_SendCommandOLD(lua_State *L) { /** * The following params expected: * @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 arg0 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); if (n != 5) return returnToLuaWithError(L, "You need to supply five parameters"); - + // parse input // cmd const char *p_cmd = luaL_checklstring(L, 1, &size); if (size != 4) return returnToLuaWithError(L, "Wrong size of cmd, got %d bytes, expected 2", (int) size); sscanf(p_cmd, " %" SCNx64, &cmd); - + // arg0 const char *p_arg0 = luaL_checklstring(L, 2, &size); if (size != 16) return returnToLuaWithError(L, "Wrong size of arg0, got %d bytes, expected 16", (int) size); sscanf(p_arg0, " %" SCNx64, &arg0); - + // arg1 const char *p_arg1 = luaL_checklstring(L, 3, &size); if (size != 16) @@ -161,13 +161,13 @@ static int l_SendCommandMIX(lua_State *L) { if (size != 16) return returnToLuaWithError(L, "Wrong size of arg2, got %d bytes, expected 16", (int) size); sscanf(p_arg2, " %" SCNx64, &arg2); - + // data - const char *p_data = luaL_checklstring(L, 5, &size); - if ( size ) { - if ( size > 1024 ) + const char *p_data = luaL_checklstring(L, 5, &size); + if (size) { + if (size > 1024) size = 1024; - + uint32_t tmp; for (int i = 0; i < size; i += 2) { sscanf(&p_data[i], "%02x", &tmp); @@ -196,7 +196,7 @@ static int l_GetFromBigBuf(lua_State *L) { if (n == 0) { return returnToLuaWithError(L, "You need to supply number of bytes and startindex"); } - + if (n >= 2) { startindex = luaL_checknumber(L, 1); len = luaL_checknumber(L, 2); @@ -240,7 +240,7 @@ static int l_GetFromFlashMem(lua_State *L) { int n = lua_gettop(L); if (n == 0) return returnToLuaWithError(L, "You need to supply number of bytes and startindex"); - + if (n >= 2) { startindex = luaL_checknumber(L, 1); 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); if (size < 1 || size > 2) return returnToLuaWithError(L, "Wrong size of blockNo, got %d, expected 1 or 2", (int) size); - + sscanf(p_blockno, "%x", &block); const char *p_usepage1 = luaL_checklstring(L, 2, &size); if (size != 1) return returnToLuaWithError(L, "Wrong size of usePage1, got %d, expected 1", (int) size); - + sscanf(p_usepage1, "%x", &usepage1); const char *p_override = luaL_checklstring(L, 3, &size); if (size != 1) return returnToLuaWithError(L, "Wrong size of override, got %d, expected 1", (int) size); - + sscanf(p_override, "%x", &override); const char *p_pwd = luaL_checklstring(L, 4, &size); @@ -846,7 +846,7 @@ static int l_T55xx_readblock(lua_State *L) { if (size != 8) return returnToLuaWithError(L, "Wrong size of pwd, got %d , expected 8", (int) size); - + sscanf(p_pwd, "%08x", &password); usepwd = true; } @@ -905,7 +905,7 @@ static int l_T55xx_detect(lua_State *L) { const char *p_gb = luaL_checklstring(L, 2, &size); if (size != 1) return returnToLuaWithError(L, "Wrong size of useGB, got %d , expected 1", (int) size); - + sscanf(p_gb, "%u", &gb); useGB = (gb) ? true : false; 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) return returnToLuaWithError(L, "Wrong size of pwd, got %d , expected 8", (int) size); - + sscanf(p_pwd, "%08x", &password); usepwd = true; } diff --git a/client/util.c b/client/util.c index a99eeaaaf..ce21ffbee 100644 --- a/client/util.c +++ b/client/util.c @@ -800,19 +800,19 @@ int num_CPUs(void) { #elif defined(__linux__) && defined(_SC_NPROCESSORS_ONLN) #include int count = sysconf(_SC_NPROCESSORS_ONLN); - if (count <= 0) + if (count <= 0) count = 1; - return count; + return count; #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" - uint32_t logicalcores = 0; - size_t size = sizeof( logicalcores ); - sysctlbyname( "hw.logicalcpu", &logicalcores, &size, NULL, 0 ); - return logicalcores; - */ - return 1; + uint32_t logicalcores = 0; + size_t size = sizeof( logicalcores ); + sysctlbyname( "hw.logicalcpu", &logicalcores, &size, NULL, 0 ); + return logicalcores; + */ + return 1; #else return 1; #endif diff --git a/common/i2c.c b/common/i2c.c index b2a9056d4..1a2f2d5d0 100644 --- a/common/i2c.c +++ b/common/i2c.c @@ -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) { - 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}; I2C_Reset_EnterMainProgram(); uint8_t len = I2C_BufferRead(resp, sizeof(resp), I2C_DEVICE_CMD_GETVERSION, I2C_DEVICE_ADDRESS_MAIN);