From 6c4d1560e9936615694259ecf5cf82a67b258b14 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Sun, 23 Jul 2017 10:24:30 +0200 Subject: [PATCH] ADD: 'script list' - now sorts the scripts in alphabetic order. It needs the extra define, in order to scandir and alphasort to work. and this made our own version of le32toh function complain. So this is removed from util.c and where it was used a new define replaced it (LE32TOH) --- client/cmdscript.c | 39 +++++++++++++++++++----------------- client/nonce2key/nonce2key.c | 15 ++++++++------ client/nonce2key/nonce2key.h | 1 - client/util.c | 5 ----- client/util.h | 4 +--- 5 files changed, 31 insertions(+), 33 deletions(-) diff --git a/client/cmdscript.c b/client/cmdscript.c index 31827231..073f4e1c 100644 --- a/client/cmdscript.c +++ b/client/cmdscript.c @@ -8,6 +8,9 @@ // Some lua scripting glue to proxmark core. //----------------------------------------------------------------------------- +// this define is needed for scandir/alphasort to work +#define _GNU_SOURCE + #include #include #include @@ -68,32 +71,32 @@ int CmdHelp(const char * Cmd) } /** -* Generate list of available commands, what it does is +* Generate a sorted list of available commands, what it does is * generate a file listing of the script-directory for files * ending with .lua -* */ -int CmdList(const char *Cmd) -{ - DIR *dp; - struct dirent *ep; +int CmdList(const char *Cmd) { + char script_directory_path[strlen(get_my_executable_directory()) + strlen(LUA_SCRIPTS_DIRECTORY) + 1]; strcpy(script_directory_path, get_my_executable_directory()); strcat(script_directory_path, LUA_SCRIPTS_DIRECTORY); - dp = opendir(script_directory_path); - if (dp != NULL) - { - while ((ep = readdir (dp)) != NULL) - { - if(str_ends_with(ep->d_name, ".lua")) - PrintAndLog("%-21s %s", ep->d_name, "A script file"); + struct dirent **namelist; + int n; + + n = scandir(script_directory_path, &namelist, NULL, alphasort); + if (n == -1) { + PrintAndLog ("Couldn't open the scripts-directory"); + return 1; } - (void) closedir (dp); - } - else - PrintAndLog ("Couldn't open the scripts-directory"); - return 0; + + for (uint16_t i = 0; i < n; i++) { + if(str_ends_with(namelist[i]->d_name, ".lua")) + PrintAndLog("%-21s %s", namelist[i]->d_name, "A script file"); + free(namelist[i]); + } + free(namelist); + return 0; } diff --git a/client/nonce2key/nonce2key.c b/client/nonce2key/nonce2key.c index 3c3d3e19..3417d7f7 100644 --- a/client/nonce2key/nonce2key.c +++ b/client/nonce2key/nonce2key.c @@ -11,6 +11,9 @@ //----------------------------------------------------------------------------- #include "nonce2key.h" +// called with a uint8_t *x array +#define LE32TOH(x) (uint32_t)( ( (x)[3]<<24) | ( (x)[2]<<16) | ( (x)[1]<<8) | (x)[0]); + int nonce2key(uint32_t uid, uint32_t nt, uint32_t nr, uint64_t par_info, uint64_t ks_info, uint64_t * key) { struct Crypto1State *state; uint32_t i, pos, rr = 0, nr_diff; @@ -241,7 +244,7 @@ bool tryMfk32_moebius(nonces_t data, uint64_t *outputkey, bool verbose) { uint32_t nt0 = data.nonce; // first tag challenge (nonce) uint32_t nr0_enc = data.nr; // first encrypted reader challenge uint32_t ar0_enc = data.ar; // first encrypted reader response - //uint32_t uid1 = le32toh(data+16); + //uint32_t uid1 = LE32TOH(data+16); uint32_t nt1 = data.nonce2; // second tag challenge (nonce) uint32_t nr1_enc = data.nr2; // second encrypted reader challenge uint32_t ar1_enc = data.ar2; // second encrypted reader response @@ -294,11 +297,11 @@ bool tryMfk32_moebius(nonces_t data, uint64_t *outputkey, bool verbose) { } int tryMfk64_ex(uint8_t *data, uint64_t *outputkey){ - uint32_t uid = le32toh(data); - uint32_t nt = le32toh(data+4); // tag challenge - uint32_t nr_enc = le32toh(data+8); // encrypted reader challenge - uint32_t ar_enc = le32toh(data+12); // encrypted reader response - uint32_t at_enc = le32toh(data+16); // encrypted tag response + uint32_t uid = LE32TOH(data); + uint32_t nt = LE32TOH(data+4); // tag challenge + uint32_t nr_enc = LE32TOH(data+8); // encrypted reader challenge + uint32_t ar_enc = LE32TOH(data+12); // encrypted reader response + uint32_t at_enc = LE32TOH(data+16); // encrypted tag response return tryMfk64(uid, nt, nr_enc, ar_enc, at_enc, outputkey); } diff --git a/client/nonce2key/nonce2key.h b/client/nonce2key/nonce2key.h index 807c2f2f..026b8cfc 100644 --- a/client/nonce2key/nonce2key.h +++ b/client/nonce2key/nonce2key.h @@ -20,7 +20,6 @@ #include "common.h" #include "mifare.h" // nonces_t struct #include "ui.h" // PrintAndLog -#include "util.h" // FALSE / TRUE #include "proxmark3.h" #include "mifarehost.h" diff --git a/client/util.c b/client/util.c index 53564402..c52dfa28 100644 --- a/client/util.c +++ b/client/util.c @@ -534,11 +534,6 @@ void xor(unsigned char * dst, unsigned char * src, size_t len) { int32_t le24toh (uint8_t data[3]) { return (data[2] << 16) | (data[1] << 8) | data[0]; } -#ifndef ANDROID -uint32_t le32toh (uint8_t *data) { - return (uint32_t)( (data[3]<<24) | (data[2]<<16) | (data[1]<<8) | data[0]); -} -#endif // Pack a bitarray into a uint32_t. uint32_t PackBits(uint8_t start, uint8_t len, uint8_t* bits) { diff --git a/client/util.h b/client/util.h index 580bd85a..797fa118 100644 --- a/client/util.h +++ b/client/util.h @@ -151,9 +151,7 @@ extern void wiegand_add_parity(uint8_t *target, uint8_t *source, uint8_t length) extern void xor(unsigned char * dst, unsigned char * src, size_t len); extern int32_t le24toh (uint8_t data[3]); -#ifndef ANDROID -extern uint32_t le32toh (uint8_t *data); -#endif + extern uint32_t PackBits(uint8_t start, uint8_t len, uint8_t* bits); extern void rol(uint8_t *data, const size_t len); extern uint32_t SwapBits(uint32_t value, int nrbits);