make style

This commit is contained in:
Philippe Teuwen 2020-06-19 18:34:47 +02:00
parent 5787f07617
commit f69739da79
16 changed files with 62 additions and 63 deletions

View file

@ -19,7 +19,7 @@ extern uint8_t _stack_start, __bss_end__;
// BigBuf is the large multi-purpose buffer, typically used to hold A/D samples or traces. // BigBuf is the large multi-purpose buffer, typically used to hold A/D samples or traces.
// Also used to hold various smaller buffers and the Mifare Emulator Memory. // Also used to hold various smaller buffers and the Mifare Emulator Memory.
// We know that bss is aligned to 4 bytes. // We know that bss is aligned to 4 bytes.
static uint8_t* BigBuf = &__bss_end__; static uint8_t *BigBuf = &__bss_end__;
/* BigBuf memory layout: /* BigBuf memory layout:
Pointer to highest available memory: BigBuf_hi Pointer to highest available memory: BigBuf_hi

View file

@ -2080,10 +2080,10 @@ void __attribute__((noreturn)) AppMain(void) {
SpinDelay(100); SpinDelay(100);
BigBuf_initialize(); BigBuf_initialize();
for (uint32_t * p = &_stack_start; p < (uint32_t *)((uintptr_t)&_stack_end - 0x200); ++p) { for (uint32_t *p = &_stack_start; p < (uint32_t *)((uintptr_t)&_stack_end - 0x200); ++p) {
*p = 0xdeadbeef; *p = 0xdeadbeef;
} }
if (common_area.magic != COMMON_AREA_MAGIC || common_area.version != 1) { if (common_area.magic != COMMON_AREA_MAGIC || common_area.version != 1) {
/* Initialize common area */ /* Initialize common area */
memset(&common_area, 0, sizeof(common_area)); memset(&common_area, 0, sizeof(common_area));

View file

@ -19,7 +19,7 @@
#include "cmd.h" #include "cmd.h"
static void RAMFUNC optimizedSniff(uint16_t *dest, uint16_t dsize) { static void RAMFUNC optimizedSniff(uint16_t *dest, uint16_t dsize) {
for (;dsize > 0; dsize -= sizeof(dsize)) { for (; dsize > 0; dsize -= sizeof(dsize)) {
if (AT91C_BASE_SSC->SSC_SR & AT91C_SSC_RXRDY) { if (AT91C_BASE_SSC->SSC_SR & AT91C_SSC_RXRDY) {
*dest = (uint16_t)(AT91C_BASE_SSC->SSC_RHR); *dest = (uint16_t)(AT91C_BASE_SSC->SSC_RHR);
dest++; dest++;
@ -30,7 +30,7 @@ static void RAMFUNC optimizedSniff(uint16_t *dest, uint16_t dsize) {
int HfSniff(uint32_t samplesToSkip, uint32_t triggersToSkip, uint16_t *len) { int HfSniff(uint32_t samplesToSkip, uint32_t triggersToSkip, uint16_t *len) {
BigBuf_free(); BigBuf_free();
BigBuf_Clear_ext(false); BigBuf_Clear_ext(false);
Dbprintf("Skipping first %d sample pairs, Skipping %d triggers", samplesToSkip, triggersToSkip); Dbprintf("Skipping first %d sample pairs, Skipping %d triggers", samplesToSkip, triggersToSkip);
@ -52,10 +52,10 @@ int HfSniff(uint32_t samplesToSkip, uint32_t triggersToSkip, uint16_t *len) {
*len = (BigBuf_max_traceLen() & 0xFFFE); *len = (BigBuf_max_traceLen() & 0xFFFE);
uint8_t *mem = BigBuf_malloc(*len); uint8_t *mem = BigBuf_malloc(*len);
int trigger_cnt = 0; int trigger_cnt = 0;
uint16_t r = 0, interval = 0; uint16_t r = 0, interval = 0;
bool pressed = false; bool pressed = false;
while (pressed == false) { while (pressed == false) {
WDT_HIT(); WDT_HIT();
@ -95,7 +95,7 @@ int HfSniff(uint32_t samplesToSkip, uint32_t triggersToSkip, uint16_t *len) {
waitcount--; waitcount--;
} }
optimizedSniff((uint16_t*)mem, (*len) >> 2); optimizedSniff((uint16_t *)mem, (*len) >> 2);
Dbprintf("Trigger kicked in (%d >= 180)", r); Dbprintf("Trigger kicked in (%d >= 180)", r);
} }

View file

@ -47,7 +47,7 @@ static void __attribute__((optimize("O0"))) I2CSpinDelayClk(uint16_t delay) {
#define I2C_DELAY_2CLK I2CSpinDelayClk(2) #define I2C_DELAY_2CLK I2CSpinDelayClk(2)
#define I2C_DELAY_XCLK(x) I2CSpinDelayClk((x)) #define I2C_DELAY_XCLK(x) I2CSpinDelayClk((x))
#define I2C_DELAY_100us I2CSpinDelayClk( 100 / 3) #define I2C_DELAY_100us I2CSpinDelayClk( 100 / 3)
#define I2C_DELAY_600us I2CSpinDelayClk( 600 / 3) #define I2C_DELAY_600us I2CSpinDelayClk( 600 / 3)
#define I2C_DELAY_10ms I2CSpinDelayClk( 10 * 1000 / 3 ) #define I2C_DELAY_10ms I2CSpinDelayClk( 10 * 1000 / 3 )
#define I2C_DELAY_30ms I2CSpinDelayClk( 30 * 1000 / 3 ) #define I2C_DELAY_30ms I2CSpinDelayClk( 30 * 1000 / 3 )
@ -440,7 +440,7 @@ int16_t I2C_BufferRead(uint8_t *data, uint8_t len, uint8_t device_cmd, uint8_t d
// extra wait 500us (514us measured) // extra wait 500us (514us measured)
// 200us (xx measured) // 200us (xx measured)
// WaitUS(600); // WaitUS(600);
I2C_DELAY_600us; I2C_DELAY_600us;
bool bBreak = true; bool bBreak = true;

View file

@ -988,7 +988,7 @@ bool SimulateIso14443aInit(int tagType, int flags, uint8_t *data, tag_response_i
counters[i] = le24toh(mfu_header->counter_tearing[i]); counters[i] = le24toh(mfu_header->counter_tearing[i]);
if (mfu_header->counter_tearing[i][3] != 0x00) { if (mfu_header->counter_tearing[i][3] != 0x00) {
tearings[i] = mfu_header->counter_tearing[i][3]; tearings[i] = mfu_header->counter_tearing[i][3];
} }
} }

View file

@ -241,7 +241,7 @@ int CmdHFTune(const char *Cmd) {
return PM3_SUCCESS; return PM3_SUCCESS;
} }
// Collects pars of u8, // Collects pars of u8,
// uses 16bit transfers from FPGA for speed // uses 16bit transfers from FPGA for speed
// Takes all available bigbuff memory // Takes all available bigbuff memory
// data sample to download? Not sure what we can do with the data. // data sample to download? Not sure what we can do with the data.
@ -258,7 +258,7 @@ int CmdHFSniff(const char *Cmd) {
params.triggersToSkip = param_get32ex(Cmd, 1, 0, 10); params.triggersToSkip = param_get32ex(Cmd, 1, 0, 10);
clearCommandBuffer(); clearCommandBuffer();
SendCommandNG(CMD_HF_SNIFF, (uint8_t*)&params, sizeof(params)); SendCommandNG(CMD_HF_SNIFF, (uint8_t *)&params, sizeof(params));
for (;;) { for (;;) {
@ -279,10 +279,10 @@ int CmdHFSniff(const char *Cmd) {
PrintAndLogEx(INFO, "HF sniff len %u bytes", len); PrintAndLogEx(INFO, "HF sniff len %u bytes", len);
PrintAndLogEx(HINT, "Use `" _YELLOW_("data plot") "` to view"); PrintAndLogEx(HINT, "Use `" _YELLOW_("data plot") "` to view");
PrintAndLogEx(HINT, "Use `" _YELLOW_("data save") "` to save"); PrintAndLogEx(HINT, "Use `" _YELLOW_("data save") "` to save");
// download bigbuf_malloced.. // download bigbuf_malloced..
// it reservs mem from the higher range. ie we can't start from beginning idx 0. // it reservs mem from the higher range. ie we can't start from beginning idx 0.
// but from // but from
uint32_t start = pm3_capabilities.bigbuf_size - len; uint32_t start = pm3_capabilities.bigbuf_size - len;
int res = getSamplesEx(start, start + len, false); int res = getSamplesEx(start, start + len, false);
if (res != PM3_SUCCESS) { if (res != PM3_SUCCESS) {

View file

@ -4545,7 +4545,7 @@ static int CmdHF14AMfMAD(const char *Cmd) {
// copy default NDEF key // copy default NDEF key
uint8_t akey[6] = {0}; uint8_t akey[6] = {0};
memcpy(akey, g_mifare_ndef_key, 6); memcpy(akey, g_mifare_ndef_key, 6);
// user specified key // user specified key
if (keylen == 6) { if (keylen == 6) {
memcpy(akey, key, 6); memcpy(akey, key, 6);
@ -4584,7 +4584,7 @@ static int CmdHF14AMfMAD(const char *Cmd) {
for (int i = 0; i < madlen; i++) { for (int i = 0; i < madlen; i++) {
if (aaid == mad[i]) { if (aaid == mad[i]) {
uint8_t vsector[16 * 4] = {0}; uint8_t vsector[16 * 4] = {0};
if (mfReadSector(i + 1, keyB ? MF_KEY_B : MF_KEY_A, akey, vsector)) { if (mfReadSector(i + 1, keyB ? MF_KEY_B : MF_KEY_A, akey, vsector)) {
PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "");
@ -4611,7 +4611,7 @@ static int CmdHF14AMfMAD(const char *Cmd) {
for (int i = 0; i < 4; i ++) for (int i = 0; i < 4; i ++)
PrintAndLogEx(INFO, "[%d] %s", i, sprint_hex(&sector0[i * 16], 16)); PrintAndLogEx(INFO, "[%d] %s", i, sprint_hex(&sector0[i * 16], 16));
} }
return PM3_SUCCESS; return PM3_SUCCESS;
} }
@ -4669,7 +4669,7 @@ static int CmdHFMFNDEF(const char *Cmd) {
PrintAndLogEx(HINT, "Try " _YELLOW_("`hf mf ndef -k `") " with your custom key"); PrintAndLogEx(HINT, "Try " _YELLOW_("`hf mf ndef -k `") " with your custom key");
return PM3_ESOFT; return PM3_ESOFT;
} }
bool haveMAD2 = false; bool haveMAD2 = false;
int res = MADCheck(sector0, NULL, verbose, &haveMAD2); int res = MADCheck(sector0, NULL, verbose, &haveMAD2);
if (res != PM3_SUCCESS) { if (res != PM3_SUCCESS) {

View file

@ -1400,7 +1400,7 @@ static int CmdHFMFPMAD(const char *Cmd) {
for (int i = 0; i < madlen; i++) { for (int i = 0; i < madlen; i++) {
if (aaid == mad[i]) { if (aaid == mad[i]) {
uint8_t vsector[16 * 4] = {0}; uint8_t vsector[16 * 4] = {0};
if (mfReadSector(i + 1, keyB ? MF_KEY_B : MF_KEY_A, akey, vsector)) { if (mfReadSector(i + 1, keyB ? MF_KEY_B : MF_KEY_A, akey, vsector)) {
PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "");
@ -1472,7 +1472,7 @@ static int CmdHFMFPNDEF(const char *Cmd) {
if (verbose) if (verbose)
PrintAndLogEx(INFO, "reading MAD v1 sector"); PrintAndLogEx(INFO, "reading MAD v1 sector");
if (mfpReadSector(MF_MAD1_SECTOR, MF_KEY_A, (uint8_t *)g_mifarep_mad_key, sector0, verbose)) { if (mfpReadSector(MF_MAD1_SECTOR, MF_KEY_A, (uint8_t *)g_mifarep_mad_key, sector0, verbose)) {
PrintAndLogEx(ERR, "error, read sector 0. card don't have MAD or don't have MAD on default keys"); PrintAndLogEx(ERR, "error, read sector 0. card don't have MAD or don't have MAD on default keys");
PrintAndLogEx(HINT, "Try " _YELLOW_("`hf mfp ndef -k `") " with your custom key"); PrintAndLogEx(HINT, "Try " _YELLOW_("`hf mfp ndef -k `") " with your custom key");
@ -1487,7 +1487,7 @@ static int CmdHFMFPNDEF(const char *Cmd) {
} }
if (haveMAD2) { if (haveMAD2) {
if (verbose) if (verbose)
PrintAndLogEx(INFO, "reading MAD v2 sector"); PrintAndLogEx(INFO, "reading MAD v2 sector");

View file

@ -1014,7 +1014,7 @@ int EM4x50Read(const char *Cmd, bool verbose) {
PrintAndLogEx(INFO, "%03d | %08x", block, Code[block]); PrintAndLogEx(INFO, "%03d | %08x", block, Code[block]);
} }
PrintAndLogEx(INFO, "----+--------------"); PrintAndLogEx(INFO, "----+--------------");
PrintAndLogEx( (AllPTest) ? SUCCESS : WARNING, "Parities checks | %s", (AllPTest) ? _GREEN_("Passed") : _RED_("Fail")); PrintAndLogEx((AllPTest) ? SUCCESS : WARNING, "Parities checks | %s", (AllPTest) ? _GREEN_("Passed") : _RED_("Fail"));
if (AllPTest == false) { if (AllPTest == false) {
PrintAndLogEx(HINT, "Try cleaning the read samples with " _YELLOW_("'data askedge'")); PrintAndLogEx(HINT, "Try cleaning the read samples with " _YELLOW_("'data askedge'"));

View file

@ -36,8 +36,7 @@
// Partly ripped from PyRun_SimpleFileExFlags // Partly ripped from PyRun_SimpleFileExFlags
// but does not terminate client on sys.exit // but does not terminate client on sys.exit
// and print exit code only if != 0 // and print exit code only if != 0
static int Pm3PyRun_SimpleFileNoExit(FILE *fp, const char *filename) static int Pm3PyRun_SimpleFileNoExit(FILE *fp, const char *filename) {
{
PyObject *m, *d, *v; PyObject *m, *d, *v;
int set_file_name = 0, ret = -1; int set_file_name = 0, ret = -1;
m = PyImport_AddModule("__main__"); m = PyImport_AddModule("__main__");
@ -86,7 +85,7 @@ static int Pm3PyRun_SimpleFileNoExit(FILE *fp, const char *filename)
} }
Py_DECREF(v); Py_DECREF(v);
ret = 0; ret = 0;
done: done:
if (set_file_name && PyDict_DelItemString(d, "__file__")) if (set_file_name && PyDict_DelItemString(d, "__file__"))
PyErr_Clear(); PyErr_Clear();
Py_XDECREF(m); Py_XDECREF(m);

View file

@ -1455,7 +1455,7 @@ static int CmdEMVScan(const char *Cmd) {
// current path + file name // current path + file name
if (MergeJSON) { if (MergeJSON) {
root = json_load_file( (char*)filename, 0, &error); root = json_load_file((char *)filename, 0, &error);
if (!root) { if (!root) {
PrintAndLogEx(ERR, "Json error on line %d: %s", error.line, error.text); PrintAndLogEx(ERR, "Json error on line %d: %s", error.line, error.text);
return PM3_EFILE; return PM3_EFILE;
@ -1750,15 +1750,15 @@ static int CmdEMVScan(const char *Cmd) {
if (MergeJSON == false) { if (MergeJSON == false) {
// create unique new name // create unique new name
char *fname = newfilenamemcopy((char*)filename, ".json"); char *fname = newfilenamemcopy((char *)filename, ".json");
if (fname == NULL) { if (fname == NULL) {
return PM3_EMALLOC; return PM3_EMALLOC;
} }
strcpy((char*)filename, fname); strcpy((char *)filename, fname);
free(fname); free(fname);
} }
res = json_dump_file(root, (char*)filename, JSON_INDENT(2)); res = json_dump_file(root, (char *)filename, JSON_INDENT(2));
if (res) { if (res) {
PrintAndLogEx(ERR, "Can't save the file: %s", filename); PrintAndLogEx(ERR, "Can't save the file: %s", filename);
return PM3_EFILE; return PM3_EFILE;

View file

@ -504,19 +504,19 @@ struct emv_pk *emv_pk_get_ca_pk(const unsigned char *rid, unsigned char idx) {
bool isok = emv_pk_verify(pk); bool isok = emv_pk_verify(pk);
PrintAndLogEx(INFO, "Verifying CA PK for %02hhx:%02hhx:%02hhx:%02hhx:%02hhx IDX %02hhx %zu bits. ( %s )", PrintAndLogEx(INFO, "Verifying CA PK for %02hhx:%02hhx:%02hhx:%02hhx:%02hhx IDX %02hhx %zu bits. ( %s )",
pk->rid[0], pk->rid[0],
pk->rid[1], pk->rid[1],
pk->rid[2], pk->rid[2],
pk->rid[3], pk->rid[3],
pk->rid[4], pk->rid[4],
pk->index, pk->index,
pk->mlen * 8, pk->mlen * 8,
(isok) ? _GREEN_("ok") : _RED_("failed") (isok) ? _GREEN_("ok") : _RED_("failed")
); );
if (isok) { if (isok) {
return pk; return pk;
} }
emv_pk_free(pk); emv_pk_free(pk);
return NULL; return NULL;

View file

@ -1369,17 +1369,17 @@ static int convert_plain_mfu_dump(uint8_t **dump, size_t *dumplen, bool verbose)
} }
static int convert_old_mfu_dump(uint8_t **dump, size_t *dumplen, bool verbose) { static int convert_old_mfu_dump(uint8_t **dump, size_t *dumplen, bool verbose) {
/* For reference /* For reference
typedef struct { typedef struct {
uint8_t version[8]; uint8_t version[8];
uint8_t tbo[2]; uint8_t tbo[2];
uint8_t tearing[3]; uint8_t tearing[3];
uint8_t pack[2]; uint8_t pack[2];
uint8_t tbo1[1]; uint8_t tbo1[1];
uint8_t signature[32]; uint8_t signature[32];
uint8_t data[1024]; uint8_t data[1024];
} PACKED old_mfu_dump_t; } PACKED old_mfu_dump_t;
*/ */
// convert old format // convert old format
old_mfu_dump_t *old_mfu_dump = (old_mfu_dump_t *)*dump; old_mfu_dump_t *old_mfu_dump = (old_mfu_dump_t *)*dump;
@ -1404,8 +1404,8 @@ typedef struct {
memcpy(mfu_dump->data, old_mfu_dump->data, sizeof(mfu_dump->data)); memcpy(mfu_dump->data, old_mfu_dump->data, sizeof(mfu_dump->data));
mfu_dump->pages = old_data_len / 4 - 1; mfu_dump->pages = old_data_len / 4 - 1;
// Add PACK to last block of memory. // Add PACK to last block of memory.
memcpy(mfu_dump->data + (mfu_dump->pages * 4 + MFU_DUMP_PREFIX_LENGTH), old_mfu_dump->pack, 2); memcpy(mfu_dump->data + (mfu_dump->pages * 4 + MFU_DUMP_PREFIX_LENGTH), old_mfu_dump->pack, 2);
if (verbose) { if (verbose) {

View file

@ -882,7 +882,7 @@ void mifare_cypher_blocks_chained(desfiretag_t tag, desfirekey_t key, uint8_t *i
} }
void desfire_crc32(const uint8_t *data, const size_t len, uint8_t *crc) { void desfire_crc32(const uint8_t *data, const size_t len, uint8_t *crc) {
crc32_ex(data,len,crc); crc32_ex(data, len, crc);
} }
void desfire_crc32_append(uint8_t *data, const size_t len) { void desfire_crc32_append(uint8_t *data, const size_t len) {

View file

@ -173,7 +173,7 @@ int MADCheck(uint8_t *sector0, uint8_t *sector10, bool verbose, bool *haveMAD2)
if (sector0 == NULL) if (sector0 == NULL)
return PM3_EINVARG; return PM3_EINVARG;
uint8_t GPB = sector0[3 * 16 + 9]; uint8_t GPB = sector0[3 * 16 + 9];
if (verbose) if (verbose)
PrintAndLogEx(SUCCESS, "%14s " _GREEN_("0x%02x"), "GPB", GPB); PrintAndLogEx(SUCCESS, "%14s " _GREEN_("0x%02x"), "GPB", GPB);
@ -304,7 +304,7 @@ int MAD1DecodeAndPrint(uint8_t *sector, bool swapmad, bool verbose, bool *haveMA
PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "");
PrintAndLogEx(INFO, "---------------- " _CYAN_("Listing") " ----------------"); PrintAndLogEx(INFO, "---------------- " _CYAN_("Listing") " ----------------");
PrintAndLogEx(INFO, " 00 MAD v1"); PrintAndLogEx(INFO, " 00 MAD v1");
uint32_t prev_aid = 0xFFFFFFFF; uint32_t prev_aid = 0xFFFFFFFF;
for (int i = 1; i < 16; i++) { for (int i = 1; i < 16; i++) {
@ -326,10 +326,10 @@ int MAD1DecodeAndPrint(uint8_t *sector, bool swapmad, bool verbose, bool *haveMA
int MAD2DecodeAndPrint(uint8_t *sector, bool swapmad, bool verbose) { int MAD2DecodeAndPrint(uint8_t *sector, bool swapmad, bool verbose) {
open_mad_file(&mad_known_aids, verbose); open_mad_file(&mad_known_aids, verbose);
PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "");
PrintAndLogEx(INFO, "------------ " _CYAN_("MAD v2 details") " -------------"); PrintAndLogEx(INFO, "------------ " _CYAN_("MAD v2 details") " -------------");
int res = madCRCCheck(sector, true, 2); int res = madCRCCheck(sector, true, 2);
if (verbose) { if (verbose) {
if (res == PM3_SUCCESS) if (res == PM3_SUCCESS)
@ -347,7 +347,7 @@ int MAD2DecodeAndPrint(uint8_t *sector, bool swapmad, bool verbose) {
PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "");
PrintAndLogEx(INFO, "---------------- " _CYAN_("Listing") " ----------------"); PrintAndLogEx(INFO, "---------------- " _CYAN_("Listing") " ----------------");
PrintAndLogEx(INFO, " 16 MAD v2"); PrintAndLogEx(INFO, " 16 MAD v2");
uint32_t prev_aid = 0xFFFFFFFF; uint32_t prev_aid = 0xFFFFFFFF;

View file

@ -1541,7 +1541,7 @@ static uint16_t cleanAskRawDemod(uint8_t *bits, size_t *size, int clk, int inver
if ((pos > cl_2 - cl_4 - 1) && (pos <= clk + cl_4 + 1)) { if ((pos > cl_2 - cl_4 - 1) && (pos <= clk + cl_4 + 1)) {
bits[bitCnt++] = invert ^ 1; bits[bitCnt++] = invert ^ 1;
} }
// sample counts, like clock = 32.. it tries to find 32/4 = 8, 32/2 = 16 // sample counts, like clock = 32.. it tries to find 32/4 = 8, 32/2 = 16
for (size_t i = pos; i < *size; i++) { for (size_t i = pos; i < *size; i++) {
if (bits[i] >= high && waveHigh) { if (bits[i] >= high && waveHigh) {