make style (linux)

This commit is contained in:
Philippe Teuwen 2020-11-29 00:28:56 +01:00
commit 59667e5d1b
16 changed files with 4007 additions and 4125 deletions

View file

@ -4,8 +4,8 @@
typedef struct pm3_device pm3; typedef struct pm3_device pm3;
pm3 *pm3_open(char *port); pm3 *pm3_open(char *port);
int pm3_console(pm3* dev, char *cmd); int pm3_console(pm3 *dev, char *cmd);
const char *pm3_name_get(pm3* dev); const char *pm3_name_get(pm3 *dev);
void pm3_close(pm3* dev); void pm3_close(pm3 *dev);
pm3 *pm3_get_current_dev(void); pm3 *pm3_get_current_dev(void);
#endif // LIBPM3_H #endif // LIBPM3_H

View file

@ -3024,7 +3024,7 @@ static int CmdHFiClassLookUp(const char *Cmd) {
typedef struct { typedef struct {
uint8_t thread_idx; uint8_t thread_idx;
uint8_t use_raw; uint8_t use_raw;
uint8_t use_elite; uint8_t use_elite;
uint32_t keycnt; uint32_t keycnt;
uint8_t csn[8]; uint8_t csn[8];
@ -3038,25 +3038,25 @@ typedef struct {
static size_t iclass_tc = 1; static size_t iclass_tc = 1;
static void* bf_generate_mac(void *thread_arg) { static void *bf_generate_mac(void *thread_arg) {
iclass_thread_arg_t *targ = (iclass_thread_arg_t *)thread_arg; iclass_thread_arg_t *targ = (iclass_thread_arg_t *)thread_arg;
const uint8_t idx = targ->thread_idx; const uint8_t idx = targ->thread_idx;
const uint8_t use_raw = targ->use_raw; const uint8_t use_raw = targ->use_raw;
const uint8_t use_elite = targ->use_elite; const uint8_t use_elite = targ->use_elite;
const uint32_t keycnt = targ->keycnt; const uint32_t keycnt = targ->keycnt;
uint8_t *keys = targ->keys; uint8_t *keys = targ->keys;
iclass_premac_t *list = targ->list.premac; iclass_premac_t *list = targ->list.premac;
uint8_t csn[8]; uint8_t csn[8];
uint8_t cc_nr[12]; uint8_t cc_nr[12];
memcpy(csn, targ->csn, sizeof(csn)); memcpy(csn, targ->csn, sizeof(csn));
memcpy(cc_nr, targ->cc_nr, sizeof(cc_nr)); memcpy(cc_nr, targ->cc_nr, sizeof(cc_nr));
uint8_t key[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; uint8_t key[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
uint8_t div_key[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; uint8_t div_key[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
for (uint32_t i = idx; i < keycnt; i += iclass_tc) { for (uint32_t i = idx; i < keycnt; i += iclass_tc) {
memcpy(key, keys + 8 * i, 8); memcpy(key, keys + 8 * i, 8);
@ -3080,14 +3080,14 @@ void GenerateMacFrom(uint8_t *CSN, uint8_t *CCNR, bool use_raw, bool use_elite,
// init thread arguments // init thread arguments
for (uint8_t i = 0; i < iclass_tc; i++) { for (uint8_t i = 0; i < iclass_tc; i++) {
args[i].thread_idx = i; args[i].thread_idx = i;
args[i].use_raw = use_raw; args[i].use_raw = use_raw;
args[i].use_elite = use_elite; args[i].use_elite = use_elite;
args[i].keycnt = keycnt; args[i].keycnt = keycnt;
args[i].keys = keys; args[i].keys = keys;
args[i].list.premac = list; args[i].list.premac = list;
memcpy(args[i].csn, CSN, sizeof(args[i].csn) ); memcpy(args[i].csn, CSN, sizeof(args[i].csn));
memcpy(args[i].cc_nr, CCNR, sizeof(args[i].cc_nr) ); memcpy(args[i].cc_nr, CCNR, sizeof(args[i].cc_nr));
} }
for (int i = 0; i < iclass_tc; i++) { for (int i = 0; i < iclass_tc; i++) {
@ -3103,22 +3103,22 @@ void GenerateMacFrom(uint8_t *CSN, uint8_t *CCNR, bool use_raw, bool use_elite,
pthread_join(threads[i], NULL); pthread_join(threads[i], NULL);
} }
static void* bf_generate_mackey(void *thread_arg) { static void *bf_generate_mackey(void *thread_arg) {
iclass_thread_arg_t *targ = (iclass_thread_arg_t *)thread_arg; iclass_thread_arg_t *targ = (iclass_thread_arg_t *)thread_arg;
const uint8_t idx = targ->thread_idx; const uint8_t idx = targ->thread_idx;
const uint8_t use_raw = targ->use_raw; const uint8_t use_raw = targ->use_raw;
const uint8_t use_elite = targ->use_elite; const uint8_t use_elite = targ->use_elite;
const uint32_t keycnt = targ->keycnt; const uint32_t keycnt = targ->keycnt;
uint8_t *keys = targ->keys; uint8_t *keys = targ->keys;
iclass_prekey_t *list = targ->list.prekey; iclass_prekey_t *list = targ->list.prekey;
uint8_t csn[8]; uint8_t csn[8];
uint8_t cc_nr[12]; uint8_t cc_nr[12];
memcpy(csn, targ->csn, sizeof(csn)); memcpy(csn, targ->csn, sizeof(csn));
memcpy(cc_nr, targ->cc_nr, sizeof(cc_nr)); memcpy(cc_nr, targ->cc_nr, sizeof(cc_nr));
uint8_t div_key[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; uint8_t div_key[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
for (uint32_t i = idx; i < keycnt; i += iclass_tc) { for (uint32_t i = idx; i < keycnt; i += iclass_tc) {
@ -3143,14 +3143,14 @@ void GenerateMacKeyFrom(uint8_t *CSN, uint8_t *CCNR, bool use_raw, bool use_elit
// init thread arguments // init thread arguments
for (uint8_t i = 0; i < iclass_tc; i++) { for (uint8_t i = 0; i < iclass_tc; i++) {
args[i].thread_idx = i; args[i].thread_idx = i;
args[i].use_raw = use_raw; args[i].use_raw = use_raw;
args[i].use_elite = use_elite; args[i].use_elite = use_elite;
args[i].keycnt = keycnt; args[i].keycnt = keycnt;
args[i].keys = keys; args[i].keys = keys;
args[i].list.prekey = list; args[i].list.prekey = list;
memcpy(args[i].csn, CSN, sizeof(args[i].csn) ); memcpy(args[i].csn, CSN, sizeof(args[i].csn));
memcpy(args[i].cc_nr, CCNR, sizeof(args[i].cc_nr) ); memcpy(args[i].cc_nr, CCNR, sizeof(args[i].cc_nr));
} }
for (int i = 0; i < iclass_tc; i++) { for (int i = 0; i < iclass_tc; i++) {
@ -3164,7 +3164,7 @@ void GenerateMacKeyFrom(uint8_t *CSN, uint8_t *CCNR, bool use_raw, bool use_elit
for (int i = 0; i < iclass_tc; i++) for (int i = 0; i < iclass_tc; i++)
pthread_join(threads[i], NULL); pthread_join(threads[i], NULL);
PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "");
} }

View file

@ -218,9 +218,9 @@ static int CmdMotorolaClone(const char *Cmd) {
// config for Motorola 64 format (RF/32;PSK1 with RF/2; Maxblock=2) // config for Motorola 64 format (RF/32;PSK1 with RF/2; Maxblock=2)
PrintAndLogEx(INFO, "Preparing to clone Motorola 64bit to " _YELLOW_("%s") " with raw " _GREEN_("%s") PrintAndLogEx(INFO, "Preparing to clone Motorola 64bit to " _YELLOW_("%s") " with raw " _GREEN_("%s")
, cardtype , cardtype
, sprint_hex_inrow(raw, sizeof(raw)) , sprint_hex_inrow(raw, sizeof(raw))
); );
print_blocks(blocks, ARRAYLEN(blocks)); print_blocks(blocks, ARRAYLEN(blocks));
int res; int res;

View file

@ -385,7 +385,7 @@ static int CmdNexWatchSim(const char *Cmd) {
}; };
CLIExecWithReturn(ctx, Cmd, argtable, false); CLIExecWithReturn(ctx, Cmd, argtable, false);
int raw_len = 0; int raw_len = 0;
// skip first block, 3*4 = 12 bytes left // skip first block, 3*4 = 12 bytes left
uint8_t raw[12] = {0x56, 0}; uint8_t raw[12] = {0x56, 0};
CLIGetHexWithReturn(ctx, 1, raw, &raw_len); CLIGetHexWithReturn(ctx, 1, raw, &raw_len);
@ -438,7 +438,7 @@ static int CmdNexWatchSim(const char *Cmd) {
uint8_t bs[96]; uint8_t bs[96];
memset(bs, 0, sizeof(bs)); memset(bs, 0, sizeof(bs));
// hex to bits. (3 * 32 == 96) // hex to bits. (3 * 32 == 96)
for (size_t i = 0; i < 3; i++) { for (size_t i = 0; i < 3; i++) {
uint32_t tmp = bytes_to_num(raw + (i * sizeof(uint32_t)), sizeof(uint32_t)); uint32_t tmp = bytes_to_num(raw + (i * sizeof(uint32_t)), sizeof(uint32_t));
num_to_bytebits(tmp, sizeof(uint32_t) * 8, bs + (i * sizeof(uint32_t) * 8)); num_to_bytebits(tmp, sizeof(uint32_t) * 8, bs + (i * sizeof(uint32_t) * 8));

View file

@ -69,7 +69,7 @@ static int pac_buf_to_cardid(uint8_t *src, const size_t src_size, uint8_t *dst,
// convert a 16 byte array of raw demod data (FF204990XX...) to 8 bytes of PAC_8byte ID // convert a 16 byte array of raw demod data (FF204990XX...) to 8 bytes of PAC_8byte ID
// performs no parity or checksum validation // performs no parity or checksum validation
static void pac_raw_to_cardid(const uint8_t* src, uint8_t *dst) { static void pac_raw_to_cardid(const uint8_t *src, uint8_t *dst) {
for (int i = 4; i < 12; i++) { for (int i = 4; i < 12; i++) {
uint8_t shift = 7 - (i + 3) % 4 * 2; uint8_t shift = 7 - (i + 3) % 4 * 2;
size_t index = i + (i - 1) / 4; size_t index = i + (i - 1) / 4;
@ -162,7 +162,7 @@ static int CmdPacDemod(const char *Cmd) {
} }
static int CmdPacReader(const char *Cmd) { static int CmdPacReader(const char *Cmd) {
CLIParserContext *ctx; CLIParserContext *ctx;
CLIParserInit(&ctx, "lf pac reader", CLIParserInit(&ctx, "lf pac reader",
"read a pac tag", "read a pac tag",
@ -208,7 +208,7 @@ static int CmdPacClone(const char *Cmd) {
CLIExecWithReturn(ctx, Cmd, argtable, false); CLIExecWithReturn(ctx, Cmd, argtable, false);
uint8_t cnstr[9]; uint8_t cnstr[9];
int cnlen = 9; int cnlen = 9;
memset(cnstr, 0x00, sizeof(cnstr)); memset(cnstr, 0x00, sizeof(cnstr));
CLIGetStrWithReturn(ctx, 1, cnstr, &cnlen); CLIGetStrWithReturn(ctx, 1, cnstr, &cnlen);
@ -236,7 +236,7 @@ static int CmdPacClone(const char *Cmd) {
} }
if (cnlen == 8 || cnlen == 9) { if (cnlen == 8 || cnlen == 9) {
pac_cardid_to_raw((char*)cnstr, raw); pac_cardid_to_raw((char *)cnstr, raw);
} else { } else {
pac_raw_to_cardid(raw, cnstr); pac_raw_to_cardid(raw, cnstr);
} }
@ -262,10 +262,10 @@ static int CmdPacClone(const char *Cmd) {
} }
PrintAndLogEx(INFO, "Preparing to clone PAC/Stanley tag to " _YELLOW_("%s") " with ID " _GREEN_("%s") " raw " _GREEN_("%s") PrintAndLogEx(INFO, "Preparing to clone PAC/Stanley tag to " _YELLOW_("%s") " with ID " _GREEN_("%s") " raw " _GREEN_("%s")
, cardtype , cardtype
, cnstr , cnstr
, sprint_hex_inrow(raw, sizeof(raw)) , sprint_hex_inrow(raw, sizeof(raw))
); );
print_blocks(blocks, ARRAYLEN(blocks)); print_blocks(blocks, ARRAYLEN(blocks));
@ -300,7 +300,7 @@ static int CmdPacSim(const char *Cmd) {
CLIExecWithReturn(ctx, Cmd, argtable, false); CLIExecWithReturn(ctx, Cmd, argtable, false);
uint8_t cnstr[10]; uint8_t cnstr[10];
int cnlen = 9; int cnlen = 9;
memset(cnstr, 0x00, sizeof(cnstr)); memset(cnstr, 0x00, sizeof(cnstr));
CLIGetStrWithReturn(ctx, 1, cnstr, &cnlen); CLIGetStrWithReturn(ctx, 1, cnstr, &cnlen);
@ -321,7 +321,7 @@ static int CmdPacSim(const char *Cmd) {
} }
if (cnlen == 8 || cnlen == 9) { if (cnlen == 8 || cnlen == 9) {
pac_cardid_to_raw((char*)cnstr, raw); pac_cardid_to_raw((char *)cnstr, raw);
} else { } else {
pac_raw_to_cardid(raw, cnstr); pac_raw_to_cardid(raw, cnstr);
} }
@ -333,9 +333,9 @@ static int CmdPacSim(const char *Cmd) {
} }
PrintAndLogEx(SUCCESS, "Simulating PAC/Stanley - ID " _YELLOW_("%s")" raw " _YELLOW_("%s") PrintAndLogEx(SUCCESS, "Simulating PAC/Stanley - ID " _YELLOW_("%s")" raw " _YELLOW_("%s")
, cnstr , cnstr
, sprint_hex_inrow(raw, sizeof(raw)) , sprint_hex_inrow(raw, sizeof(raw))
); );
// NRZ sim. // NRZ sim.
lf_nrzsim_t *payload = calloc(1, sizeof(lf_nrzsim_t) + sizeof(bs)); lf_nrzsim_t *payload = calloc(1, sizeof(lf_nrzsim_t) + sizeof(bs));

View file

@ -240,7 +240,7 @@ static int CmdParadoxClone(const char *Cmd) {
for (uint8_t i = 1; i < ARRAYLEN(blocks); i++) { for (uint8_t i = 1; i < ARRAYLEN(blocks); i++) {
blocks[i] = bytes_to_num(raw + ((i - 1) * 4), sizeof(uint32_t)); blocks[i] = bytes_to_num(raw + ((i - 1) * 4), sizeof(uint32_t));
} }
// Paradox - FSK2a, data rate 50, 3 data blocks // Paradox - FSK2a, data rate 50, 3 data blocks
blocks[0] = T55x7_MODULATION_FSK2a | T55x7_BITRATE_RF_50 | 3 << T55x7_MAXBLOCK_SHIFT; blocks[0] = T55x7_MODULATION_FSK2a | T55x7_BITRATE_RF_50 | 3 << T55x7_MAXBLOCK_SHIFT;
char cardtype[16] = {"T55x7"}; char cardtype[16] = {"T55x7"};
@ -255,7 +255,7 @@ static int CmdParadoxClone(const char *Cmd) {
blocks[0] = EM4305_PARADOX_CONFIG_BLOCK; blocks[0] = EM4305_PARADOX_CONFIG_BLOCK;
snprintf(cardtype, sizeof(cardtype), "EM4305/4469"); snprintf(cardtype, sizeof(cardtype), "EM4305/4469");
} }
PrintAndLogEx(INFO, "Preparing to clone Paradox to " _YELLOW_("%s") " with raw hex", cardtype); PrintAndLogEx(INFO, "Preparing to clone Paradox to " _YELLOW_("%s") " with raw hex", cardtype);
print_blocks(blocks, ARRAYLEN(blocks)); print_blocks(blocks, ARRAYLEN(blocks));
@ -323,7 +323,8 @@ static int CmdParadoxSim(const char *Cmd) {
if (resp.status != PM3_EOPABORTED) if (resp.status != PM3_EOPABORTED)
return resp.status; return resp.status;
return PM3_SUCCESS;} return PM3_SUCCESS;
}
/* /*
if (sscanf(Cmd, "%u %u", &fc, &cn) != 2) return usage_lf_paradox_sim(); if (sscanf(Cmd, "%u %u", &fc, &cn) != 2) return usage_lf_paradox_sim();

View file

@ -40,7 +40,7 @@ static int detectPresco(uint8_t *dest, size_t *size) {
// convert base 12 ID to sitecode & usercode & 8 bit other unknown code // convert base 12 ID to sitecode & usercode & 8 bit other unknown code
static int getWiegandFromPrintedPresco(void *arr, uint32_t *fullcode) { static int getWiegandFromPrintedPresco(void *arr, uint32_t *fullcode) {
char *s = (char*)arr; char *s = (char *)arr;
uint8_t val = 0; uint8_t val = 0;
for (int i = 0; i < strlen(s); ++i) { for (int i = 0; i < strlen(s); ++i) {
// Get value from number string. // Get value from number string.
@ -103,11 +103,11 @@ int demodPresco(bool verbose) {
uint32_t sitecode = (fullcode >> 24) & 0x000000FF; uint32_t sitecode = (fullcode >> 24) & 0x000000FF;
PrintAndLogEx(SUCCESS, "Presco Site code: " _GREEN_("%u") " User code: " _GREEN_("%u") " Full code: " _GREEN_("%08X") " Raw: " _YELLOW_("%08X%08X%08X%08X") PrintAndLogEx(SUCCESS, "Presco Site code: " _GREEN_("%u") " User code: " _GREEN_("%u") " Full code: " _GREEN_("%08X") " Raw: " _YELLOW_("%08X%08X%08X%08X")
, sitecode , sitecode
, usercode , usercode
, fullcode , fullcode
, raw1, raw2, raw3, raw4 , raw1, raw2, raw3, raw4
); );
return PM3_SUCCESS; return PM3_SUCCESS;
} }
@ -120,8 +120,8 @@ static int CmdPrescoDemod(const char *Cmd) {
static int CmdPrescoReader(const char *Cmd) { static int CmdPrescoReader(const char *Cmd) {
CLIParserContext *ctx; CLIParserContext *ctx;
CLIParserInit(&ctx, "lf presco reader", CLIParserInit(&ctx, "lf presco reader",
"read a presco tag", "read a presco tag",
"lf presco reader -@ -> continuous reader mode" "lf presco reader -@ -> continuous reader mode"
); );
void *argtable[] = { void *argtable[] = {
@ -162,11 +162,11 @@ static int CmdPrescoClone(const char *Cmd) {
CLIExecWithReturn(ctx, Cmd, argtable, false); CLIExecWithReturn(ctx, Cmd, argtable, false);
int hex_len = 0; int hex_len = 0;
uint8_t hex[4] = {0,0,0,0}; uint8_t hex[4] = {0, 0, 0, 0};
CLIGetHexWithReturn(ctx, 1, hex, &hex_len); CLIGetHexWithReturn(ctx, 1, hex, &hex_len);
uint8_t idstr[11]; uint8_t idstr[11];
int slen = 9; int slen = 9;
memset(idstr, 0x00, sizeof(idstr)); memset(idstr, 0x00, sizeof(idstr));
CLIGetStrWithReturn(ctx, 2, idstr, &slen); CLIGetStrWithReturn(ctx, 2, idstr, &slen);
@ -227,11 +227,11 @@ static int CmdPrescoClone(const char *Cmd) {
blocks[4] = fullcode; blocks[4] = fullcode;
PrintAndLogEx(INFO, "Preparing to clone Presco to " _GREEN_("%s") " with Site code: " _GREEN_("%u") " User code: " _GREEN_("%u") " Full code: " _GREEN_("%08x") PrintAndLogEx(INFO, "Preparing to clone Presco to " _GREEN_("%s") " with Site code: " _GREEN_("%u") " User code: " _GREEN_("%u") " Full code: " _GREEN_("%08x")
, cardtype , cardtype
, sitecode , sitecode
, usercode , usercode
, fullcode , fullcode
); );
print_blocks(blocks, ARRAYLEN(blocks)); print_blocks(blocks, ARRAYLEN(blocks));
int res; int res;
@ -265,11 +265,11 @@ static int CmdPrescoSim(const char *Cmd) {
CLIExecWithReturn(ctx, Cmd, argtable, false); CLIExecWithReturn(ctx, Cmd, argtable, false);
int hex_len = 0; int hex_len = 0;
uint8_t hex[4] = {0,0,0,0}; uint8_t hex[4] = {0, 0, 0, 0};
CLIGetHexWithReturn(ctx, 1, hex, &hex_len); CLIGetHexWithReturn(ctx, 1, hex, &hex_len);
uint8_t idstr[11]; uint8_t idstr[11];
int slen = 9; int slen = 9;
memset(idstr, 0x00, sizeof(idstr)); memset(idstr, 0x00, sizeof(idstr));
CLIGetStrWithReturn(ctx, 2, idstr, &slen); CLIGetStrWithReturn(ctx, 2, idstr, &slen);
CLIParserFree(ctx); CLIParserFree(ctx);
@ -300,10 +300,10 @@ static int CmdPrescoSim(const char *Cmd) {
} }
PrintAndLogEx(SUCCESS, "Simulating Presco - Site Code: " _GREEN_("%u") " User Code: " _GREEN_("%u") " Full Code: " _GREEN_("%08X") PrintAndLogEx(SUCCESS, "Simulating Presco - Site Code: " _GREEN_("%u") " User Code: " _GREEN_("%u") " Full Code: " _GREEN_("%08X")
, sitecode , sitecode
, usercode , usercode
, fullcode) , fullcode)
; ;
uint8_t bs[128]; uint8_t bs[128];
getPrescoBits(fullcode, bs); getPrescoBits(fullcode, bs);

View file

@ -32,12 +32,12 @@
#include "fileutils.h" #include "fileutils.h"
#ifdef HAVE_LUA_SWIG #ifdef HAVE_LUA_SWIG
extern int luaopen_pm3(lua_State* L); extern int luaopen_pm3(lua_State *L);
#endif #endif
#ifdef HAVE_PYTHON #ifdef HAVE_PYTHON
#ifdef HAVE_PYTHON_SWIG #ifdef HAVE_PYTHON_SWIG
extern PyObject* PyInit__pm3(void); extern PyObject *PyInit__pm3(void);
#endif // HAVE_PYTHON_SWIG #endif // HAVE_PYTHON_SWIG
// Partly ripped from PyRun_SimpleFileExFlags // Partly ripped from PyRun_SimpleFileExFlags

View file

@ -232,7 +232,7 @@ void hash2(uint8_t *key64, uint8_t *outp_keytable) {
if (g_debugMode > 0) { if (g_debugMode > 0) {
PrintAndLogEx(DEBUG, "High security custom key (Kcus):"); PrintAndLogEx(DEBUG, "High security custom key (Kcus):");
PrintAndLogEx(DEBUG, "z0 %s", sprint_hex(z[0],8)); PrintAndLogEx(DEBUG, "z0 %s", sprint_hex(z[0], 8));
} }
uint8_t y[8][8] = {{0}, {0}}; uint8_t y[8][8] = {{0}, {0}};
@ -308,7 +308,7 @@ typedef struct {
static size_t loclass_tc = 1; static size_t loclass_tc = 1;
static int loclass_found = 0; static int loclass_found = 0;
static void* bf_thread(void* thread_arg) { static void *bf_thread(void *thread_arg) {
loclass_thread_arg_t *targ = (loclass_thread_arg_t *)thread_arg; loclass_thread_arg_t *targ = (loclass_thread_arg_t *)thread_arg;
const uint32_t endmask = targ->endmask; const uint32_t endmask = targ->endmask;
@ -332,7 +332,7 @@ static void* bf_thread(void* thread_arg) {
int found; int found;
while (!(brute & endmask)) { while (!(brute & endmask)) {
found = __atomic_load_n (&loclass_found, __ATOMIC_SEQ_CST); found = __atomic_load_n(&loclass_found, __ATOMIC_SEQ_CST);
if (found != 0xFF) return NULL; if (found != 0xFF) return NULL;
@ -370,13 +370,13 @@ static void* bf_thread(void* thread_arg) {
// success // success
if (memcmp(calculated_MAC, mac, 4) == 0) { if (memcmp(calculated_MAC, mac, 4) == 0) {
loclass_thread_ret_t *r = (loclass_thread_ret_t*)malloc(sizeof(loclass_thread_ret_t)); loclass_thread_ret_t *r = (loclass_thread_ret_t *)malloc(sizeof(loclass_thread_ret_t));
for (uint8_t i = 0 ; i < numbytes_to_recover; i++) { for (uint8_t i = 0 ; i < numbytes_to_recover; i++) {
r->values[i] = keytable[bytes_to_recover[i]] & 0xFF; r->values[i] = keytable[bytes_to_recover[i]] & 0xFF;
} }
__atomic_store_n(&loclass_found, targ->thread_idx, __ATOMIC_SEQ_CST); __atomic_store_n(&loclass_found, targ->thread_idx, __ATOMIC_SEQ_CST);
pthread_exit ((void*)r); pthread_exit((void *)r);
} }
brute += loclass_tc; brute += loclass_tc;
@ -385,19 +385,19 @@ static void* bf_thread(void* thread_arg) {
if (numbytes_to_recover == 3) { if (numbytes_to_recover == 3) {
if ((brute > 0) && ((brute & 0xFFFF) == 0)) { if ((brute > 0) && ((brute & 0xFFFF) == 0)) {
PrintAndLogEx(INPLACE, "[ %02x %02x %02x ] %8u / %u", bytes_to_recover[0], bytes_to_recover[1], bytes_to_recover[2] , brute, 0xFFFFFF); PrintAndLogEx(INPLACE, "[ %02x %02x %02x ] %8u / %u", bytes_to_recover[0], bytes_to_recover[1], bytes_to_recover[2], brute, 0xFFFFFF);
} }
} else if (numbytes_to_recover == 2) { } else if (numbytes_to_recover == 2) {
if ((brute > 0) && ((brute & 0x3F) == 0)) if ((brute > 0) && ((brute & 0x3F) == 0))
PrintAndLogEx(INPLACE, "[ %02x %02x ] %5u / %u" _CLR_ , bytes_to_recover[0], bytes_to_recover[1], brute, 0xFFFF); PrintAndLogEx(INPLACE, "[ %02x %02x ] %5u / %u" _CLR_, bytes_to_recover[0], bytes_to_recover[1], brute, 0xFFFF);
} else { } else {
if ((brute > 0) && ((brute & 0x1F) == 0)) if ((brute > 0) && ((brute & 0x1F) == 0))
PrintAndLogEx(INPLACE, "[ %02x ] %3u / %u" _CLR_, bytes_to_recover[0], brute, 0xFF); PrintAndLogEx(INPLACE, "[ %02x ] %3u / %u" _CLR_, bytes_to_recover[0], brute, 0xFF);
} }
} }
pthread_exit(NULL); pthread_exit(NULL);
void* dummyptr = NULL; void *dummyptr = NULL;
return dummyptr; return dummyptr;
} }
@ -455,9 +455,9 @@ int bruteforceItem(loclass_dumpdata_t item, uint16_t keytable[]) {
args[i].numbytes_to_recover = numbytes_to_recover; args[i].numbytes_to_recover = numbytes_to_recover;
args[i].endmask = 1 << 8 * numbytes_to_recover; args[i].endmask = 1 << 8 * numbytes_to_recover;
memcpy((void*)&args[i].item, (void*)&item, sizeof(loclass_dumpdata_t)); memcpy((void *)&args[i].item, (void *)&item, sizeof(loclass_dumpdata_t));
memcpy(args[i].bytes_to_recover, bytes_to_recover, sizeof(args[i].bytes_to_recover) ); memcpy(args[i].bytes_to_recover, bytes_to_recover, sizeof(args[i].bytes_to_recover));
memcpy(args[i].key_index, key_index, sizeof(args[i].key_index) ); memcpy(args[i].key_index, key_index, sizeof(args[i].key_index));
memcpy(args[i].keytable, keytable, sizeof(args[i].keytable)); memcpy(args[i].keytable, keytable, sizeof(args[i].keytable));
} }
@ -472,7 +472,7 @@ int bruteforceItem(loclass_dumpdata_t item, uint16_t keytable[]) {
} }
} }
// wait for threads to terminate: // wait for threads to terminate:
void* ptrs[loclass_tc]; void *ptrs[loclass_tc];
for (int i = 0; i < loclass_tc; i++) for (int i = 0; i < loclass_tc; i++)
pthread_join(threads[i], &ptrs[i]); pthread_join(threads[i], &ptrs[i]);
@ -526,18 +526,18 @@ int bruteforceItem(loclass_dumpdata_t item, uint16_t keytable[]) {
uint8_t key_index[8] = {0}; uint8_t key_index[8] = {0};
hash1(item.csn, key_index); hash1(item.csn, key_index);
*/ */
/* /*
* Determine which bytes to retrieve. A hash is typically * Determine which bytes to retrieve. A hash is typically
* 01010000454501 * 01010000454501
* We go through that hash, and in the corresponding keytable, we put markers * We go through that hash, and in the corresponding keytable, we put markers
* on what state that particular index is: * on what state that particular index is:
* - CRACKED (this has already been cracked) * - CRACKED (this has already been cracked)
* - BEING_CRACKED (this is being bruteforced now) * - BEING_CRACKED (this is being bruteforced now)
* - CRACK_FAILED (self-explaining...) * - CRACK_FAILED (self-explaining...)
* *
* The markers are placed in the high area of the 16 bit key-table. * The markers are placed in the high area of the 16 bit key-table.
* Only the lower eight bits correspond to the (hopefully cracked) key-value. * Only the lower eight bits correspond to the (hopefully cracked) key-value.
**/ **/
/* /*
@ -571,13 +571,13 @@ int bruteforceItem(loclass_dumpdata_t item, uint16_t keytable[]) {
//A uint32 has room for 4 bytes, we'll only need 24 of those bits to bruteforce up to three bytes, //A uint32 has room for 4 bytes, we'll only need 24 of those bits to bruteforce up to three bytes,
uint32_t brute = 0; uint32_t brute = 0;
*/ */
/* /*
Determine where to stop the bruteforce. A 1-byte attack stops after 256 tries, Determine where to stop the bruteforce. A 1-byte attack stops after 256 tries,
(when brute reaches 0x100). And so on... (when brute reaches 0x100). And so on...
bytes_to_recover = 1 --> endmask = 0x000000100 bytes_to_recover = 1 --> endmask = 0x000000100
bytes_to_recover = 2 --> endmask = 0x000010000 bytes_to_recover = 2 --> endmask = 0x000010000
bytes_to_recover = 3 --> endmask = 0x001000000 bytes_to_recover = 3 --> endmask = 0x001000000
*/ */
/* /*
uint32_t endmask = 1 << 8 * numbytes_to_recover; uint32_t endmask = 1 << 8 * numbytes_to_recover;
PrintAndLogEx(NORMAL, "----------------------------"); PrintAndLogEx(NORMAL, "----------------------------");
@ -903,11 +903,11 @@ int testElite(bool slowtests) {
int res = PM3_SUCCESS; int res = PM3_SUCCESS;
PrintAndLogEx(INFO, "Testing hash1..."); PrintAndLogEx(INFO, "Testing hash1...");
res += _testHash1(); res += _testHash1();
PrintAndLogEx((res == PM3_SUCCESS) ? SUCCESS : WARNING, " hash1 (%s)", (res == PM3_SUCCESS) ? _GREEN_("ok") : _RED_("fail") ); PrintAndLogEx((res == PM3_SUCCESS) ? SUCCESS : WARNING, " hash1 (%s)", (res == PM3_SUCCESS) ? _GREEN_("ok") : _RED_("fail"));
PrintAndLogEx(INFO, "Testing key diversification..."); PrintAndLogEx(INFO, "Testing key diversification...");
res += _test_iclass_key_permutation(); res += _test_iclass_key_permutation();
PrintAndLogEx((res == PM3_SUCCESS) ? SUCCESS : WARNING, " key diversification (%s)", (res == PM3_SUCCESS) ? _GREEN_("ok") : _RED_("fail") ); PrintAndLogEx((res == PM3_SUCCESS) ? SUCCESS : WARNING, " key diversification (%s)", (res == PM3_SUCCESS) ? _GREEN_("ok") : _RED_("fail"));
if (slowtests) if (slowtests)
res += _testBruteforce(); res += _testBruteforce();

View file

@ -210,12 +210,12 @@ static void permute(BitstreamIn *p_in, uint64_t z, int l, int r, BitstreamOut *o
return; return;
bool pn = tailBit(p_in); bool pn = tailBit(p_in);
if (pn) { if (pn) {
// pn = 1 // pn = 1
uint8_t zl = getSixBitByte(z, l); uint8_t zl = getSixBitByte(z, l);
push6bits(out, zl + 1); push6bits(out, zl + 1);
permute(p_in, z, l + 1, r, out); permute(p_in, z, l + 1, r, out);
} else { } else {
// otherwise // otherwise
uint8_t zr = getSixBitByte(z, r); uint8_t zr = getSixBitByte(z, r);
push6bits(out, zr); push6bits(out, zr);
@ -256,8 +256,8 @@ void hash0(uint64_t c, uint8_t k[8]) {
c = swapZvalues(c); c = swapZvalues(c);
if (g_debugMode > 0) { if (g_debugMode > 0) {
PrintAndLogEx(DEBUG, " | x| y|z0|z1|z2|z3|z4|z5|z6|z7|"); PrintAndLogEx(DEBUG, " | x| y|z0|z1|z2|z3|z4|z5|z6|z7|");
printState("origin", c); printState("origin", c);
} }
//These 64 bits are divided as c = x, y, z [0] , . . . , z [7] //These 64 bits are divided as c = x, y, z [0] , . . . , z [7]
// x = 8 bits // x = 8 bits
@ -421,7 +421,7 @@ static int testDES(uint8_t *key, testcase_t testcase) {
uint8_t des_encrypted_csn[8] = {0}; uint8_t des_encrypted_csn[8] = {0};
uint8_t decrypted[8] = {0}; uint8_t decrypted[8] = {0};
uint8_t div_key[8] = {0}; uint8_t div_key[8] = {0};
mbedtls_des_context ctx_enc; mbedtls_des_context ctx_enc;
mbedtls_des_context ctx_dec; mbedtls_des_context ctx_dec;
@ -466,12 +466,12 @@ static int testDES(uint8_t *key, testcase_t testcase) {
static bool des_getParityBitFromKey(uint8_t key) { static bool des_getParityBitFromKey(uint8_t key) {
// The top 7 bits is used // The top 7 bits is used
bool parity = ((key & 0x80) >> 7) bool parity = ((key & 0x80) >> 7)
^ ((key & 0x40) >> 6) ^ ((key & 0x40) >> 6)
^ ((key & 0x20) >> 5) ^ ((key & 0x20) >> 5)
^ ((key & 0x10) >> 4) ^ ((key & 0x10) >> 4)
^ ((key & 0x08) >> 3) ^ ((key & 0x08) >> 3)
^ ((key & 0x04) >> 2) ^ ((key & 0x04) >> 2)
^ ((key & 0x02) >> 1); ^ ((key & 0x02) >> 1);
return !parity; return !parity;
} }
@ -613,7 +613,7 @@ static int testDES2(uint8_t *key, uint64_t csn, uint64_t expected) {
uint64_t crypt_csn = x_bytes_to_num(result, 8); uint64_t crypt_csn = x_bytes_to_num(result, 8);
PrintAndLogEx(DEBUG, " {csn} %"PRIx64, crypt_csn); PrintAndLogEx(DEBUG, " {csn} %"PRIx64, crypt_csn);
PrintAndLogEx(DEBUG, " expected %"PRIx64 " (%s)", expected, (expected == crypt_csn) ? _GREEN_("ok") : _RED_("fail") ); PrintAndLogEx(DEBUG, " expected %"PRIx64 " (%s)", expected, (expected == crypt_csn) ? _GREEN_("ok") : _RED_("fail"));
if (expected != crypt_csn) if (expected != crypt_csn)
return PM3_ESOFT; return PM3_ESOFT;

View file

@ -13,7 +13,7 @@
#include "util_posix.h" #include "util_posix.h"
#include "comms.h" #include "comms.h"
pm3_device* pm3_open(char *port) { pm3_device *pm3_open(char *port) {
pm3_init(); pm3_init();
OpenProxmark(&session.current_device, port, false, 20, false, USART_BAUD_RATE); OpenProxmark(&session.current_device, port, false, 20, false, USART_BAUD_RATE);
if (session.pm3_present && (TestProxmark(session.current_device) != PM3_SUCCESS)) { if (session.pm3_present && (TestProxmark(session.current_device) != PM3_SUCCESS)) {
@ -30,7 +30,7 @@ pm3_device* pm3_open(char *port) {
return session.current_device; return session.current_device;
} }
void pm3_close(pm3_device* dev) { void pm3_close(pm3_device *dev) {
// Clean up the port // Clean up the port
if (session.pm3_present) { if (session.pm3_present) {
clearCommandBuffer(); clearCommandBuffer();
@ -40,16 +40,16 @@ void pm3_close(pm3_device* dev) {
} }
} }
int pm3_console(pm3_device* dev, char *Cmd) { int pm3_console(pm3_device *dev, char *Cmd) {
// For now, there is no real device context: // For now, there is no real device context:
(void) dev; (void) dev;
return CommandReceived(Cmd); return CommandReceived(Cmd);
} }
const char *pm3_name_get(pm3_device* dev) { const char *pm3_name_get(pm3_device *dev) {
return dev->conn->serial_port_name; return dev->conn->serial_port_name;
} }
pm3_device* pm3_get_current_dev(void) { pm3_device *pm3_get_current_dev(void) {
return session.current_device; return session.current_device;
} }

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -446,10 +446,10 @@ void num_to_bytebitsLSBF(uint64_t n, size_t len, uint8_t *dest) {
} }
} }
void bytes_to_bytebits(void* src, size_t srclen, void* dest) { void bytes_to_bytebits(void *src, size_t srclen, void *dest) {
uint8_t *s = (uint8_t*)src; uint8_t *s = (uint8_t *)src;
uint8_t *d = (uint8_t*)dest; uint8_t *d = (uint8_t *)dest;
uint32_t i = srclen * 8; uint32_t i = srclen * 8;
while (srclen--) { while (srclen--) {

View file

@ -56,7 +56,7 @@ void print_blocks(uint32_t *data, size_t len);
int hex_to_bytes(const char *hexValue, uint8_t *bytesValue, size_t maxBytesValueLen); int hex_to_bytes(const char *hexValue, uint8_t *bytesValue, size_t maxBytesValueLen);
void num_to_bytebits(uint64_t n, size_t len, uint8_t *dest); void num_to_bytebits(uint64_t n, size_t len, uint8_t *dest);
void num_to_bytebitsLSBF(uint64_t n, size_t len, uint8_t *dest); void num_to_bytebitsLSBF(uint64_t n, size_t len, uint8_t *dest);
void bytes_to_bytebits(void* src, size_t srclen, void* dest); void bytes_to_bytebits(void *src, size_t srclen, void *dest);
// Swap endian on arrays up to 64bytes. // Swap endian on arrays up to 64bytes.
uint8_t *SwapEndian64(const uint8_t *src, const size_t len, const uint8_t blockSize); uint8_t *SwapEndian64(const uint8_t *src, const size_t len, const uint8_t blockSize);

View file

@ -732,7 +732,7 @@ Check column "offline" for their availability.
|------- |------- |----------- |------- |------- |-----------
|`lf keri help `|Y |`This help` |`lf keri help `|Y |`This help`
|`lf keri demod `|Y |`Demodulate an KERI tag from the GraphBuffer` |`lf keri demod `|Y |`Demodulate an KERI tag from the GraphBuffer`
|`lf keri reader `|N |`Attempt to read and extract tag data from the antenna` |`lf keri read `|N |`Attempt to read and extract tag data from the antenna`
|`lf keri clone `|N |`clone KERI tag to T55x7 or Q5/T5555` |`lf keri clone `|N |`clone KERI tag to T55x7 or Q5/T5555`
|`lf keri sim `|N |`simulate KERI tag` |`lf keri sim `|N |`simulate KERI tag`
@ -745,7 +745,7 @@ Check column "offline" for their availability.
|------- |------- |----------- |------- |------- |-----------
|`lf motorola help `|Y |`This help` |`lf motorola help `|Y |`This help`
|`lf motorola demod `|Y |`Demodulate an MOTOROLA tag from the GraphBuffer` |`lf motorola demod `|Y |`Demodulate an MOTOROLA tag from the GraphBuffer`
|`lf motorola reader `|N |`Attempt to read and extract tag data from the antenna` |`lf motorola read `|N |`Attempt to read and extract tag data from the antenna`
|`lf motorola clone `|N |`clone MOTOROLA tag to T55x7` |`lf motorola clone `|N |`clone MOTOROLA tag to T55x7`
|`lf motorola sim `|N |`simulate MOTOROLA tag` |`lf motorola sim `|N |`simulate MOTOROLA tag`
@ -772,7 +772,7 @@ Check column "offline" for their availability.
|------- |------- |----------- |------- |------- |-----------
|`lf nexwatch help `|Y |`This help` |`lf nexwatch help `|Y |`This help`
|`lf nexwatch demod `|Y |`Demodulate a NexWatch tag (nexkey, quadrakey) from the GraphBuffer` |`lf nexwatch demod `|Y |`Demodulate a NexWatch tag (nexkey, quadrakey) from the GraphBuffer`
|`lf nexwatch reader `|N |`Attempt to Read and Extract tag data from the antenna` |`lf nexwatch read `|N |`Attempt to Read and Extract tag data from the antenna`
|`lf nexwatch clone `|N |`clone NexWatch tag to T55x7` |`lf nexwatch clone `|N |`clone NexWatch tag to T55x7`
|`lf nexwatch sim `|N |`simulate NexWatch tag` |`lf nexwatch sim `|N |`simulate NexWatch tag`
@ -785,7 +785,7 @@ Check column "offline" for their availability.
|------- |------- |----------- |------- |------- |-----------
|`lf noralsy help `|Y |`This help` |`lf noralsy help `|Y |`This help`
|`lf noralsy demod `|Y |`Demodulate an Noralsy tag from the GraphBuffer` |`lf noralsy demod `|Y |`Demodulate an Noralsy tag from the GraphBuffer`
|`lf noralsy reader `|N |`Attempt to read and extract tag data from the antenna` |`lf noralsy read `|N |`Attempt to read and extract tag data from the antenna`
|`lf noralsy clone `|N |`clone Noralsy tag to T55x7 or Q5/T5555` |`lf noralsy clone `|N |`clone Noralsy tag to T55x7 or Q5/T5555`
|`lf noralsy sim `|N |`simulate Noralsy tag` |`lf noralsy sim `|N |`simulate Noralsy tag`
@ -798,7 +798,7 @@ Check column "offline" for their availability.
|------- |------- |----------- |------- |------- |-----------
|`lf pac help `|Y |`This help` |`lf pac help `|Y |`This help`
|`lf pac demod `|Y |`Demodulate a PAC tag from the GraphBuffer` |`lf pac demod `|Y |`Demodulate a PAC tag from the GraphBuffer`
|`lf pac reader `|N |`Attempt to read and extract tag data from the antenna` |`lf pac read `|N |`Attempt to read and extract tag data from the antenna`
|`lf pac clone `|N |`clone PAC tag to T55x7` |`lf pac clone `|N |`clone PAC tag to T55x7`
|`lf pac sim `|N |`simulate PAC tag` |`lf pac sim `|N |`simulate PAC tag`