Rework Cmd exposed API, use more static and fix [-Wmissing-prototypes], ongoing...

This commit is contained in:
Philippe Teuwen 2019-04-12 00:38:54 +02:00
commit 7d48ad19f9
42 changed files with 865 additions and 872 deletions

View file

@ -220,7 +220,7 @@ static uint16_t calcBSDchecksum4(uint8_t *bytes, uint8_t len, uint32_t mask) {
}
// measuring LFSR maximum length
int CmdAnalyseLfsr(const char *Cmd) {
static int CmdAnalyseLfsr(const char *Cmd) {
uint16_t start_state = 0; /* Any nonzero start state will work. */
uint16_t lfsr = start_state;
@ -242,7 +242,7 @@ int CmdAnalyseLfsr(const char *Cmd) {
}
return 0;
}
int CmdAnalyseLCR(const char *Cmd) {
static int CmdAnalyseLCR(const char *Cmd) {
uint8_t data[50];
char cmdp = tolower(param_getchar(Cmd, 0));
if (strlen(Cmd) == 0 || cmdp == 'h') return usage_analyse_lcr();
@ -263,7 +263,7 @@ int CmdAnalyseLCR(const char *Cmd) {
PrintAndLogEx(NORMAL, "Target [%02X] requires final LRC XOR byte value: 0x%02X", data[len - 1], finalXor);
return 0;
}
int CmdAnalyseCRC(const char *Cmd) {
static int CmdAnalyseCRC(const char *Cmd) {
char cmdp = tolower(param_getchar(Cmd, 0));
if (strlen(Cmd) == 0 || cmdp == 'h') return usage_analyse_crc();
@ -359,7 +359,7 @@ int CmdAnalyseCRC(const char *Cmd) {
free(data);
return 0;
}
int CmdAnalyseCHKSUM(const char *Cmd) {
static int CmdAnalyseCHKSUM(const char *Cmd) {
uint8_t data[50];
uint8_t cmdp = 0;
@ -425,13 +425,13 @@ int CmdAnalyseCHKSUM(const char *Cmd) {
return 0;
}
int CmdAnalyseDates(const char *Cmd) {
static int CmdAnalyseDates(const char *Cmd) {
(void)Cmd; // Cmd is not used so far
// look for datestamps in a given array of bytes
PrintAndLogEx(NORMAL, "To be implemented. Feel free to contribute!");
return 0;
}
int CmdAnalyseTEASelfTest(const char *Cmd) {
static int CmdAnalyseTEASelfTest(const char *Cmd) {
uint8_t v[8], v_le[8];
memset(v, 0x00, sizeof(v));
@ -466,7 +466,7 @@ int CmdAnalyseTEASelfTest(const char *Cmd) {
return 0;
}
char *pb(uint32_t b) {
static char *pb(uint32_t b) {
static char buf1[33] = {0};
static char buf2[33] = {0};
static char *s;
@ -486,7 +486,7 @@ char *pb(uint32_t b) {
return s;
}
int CmdAnalyseA(const char *Cmd) {
static int CmdAnalyseA(const char *Cmd) {
int hexlen = 0;
uint8_t cmdp = 0;
@ -852,7 +852,7 @@ int CmdAnalyseA(const char *Cmd) {
return 0;
}
void generate4bNUID(uint8_t *uid, uint8_t *nuid) {
static void generate4bNUID(uint8_t *uid, uint8_t *nuid) {
uint16_t crc;
uint8_t b1, b2;
@ -866,7 +866,7 @@ void generate4bNUID(uint8_t *uid, uint8_t *nuid) {
nuid[3] = crc & 0xFF;
}
int CmdAnalyseNuid(const char *Cmd) {
static int CmdAnalyseNuid(const char *Cmd) {
uint8_t nuid[4] = {0};
uint8_t uid[7] = {0};
int len = 0;
@ -916,14 +916,14 @@ static command_t CommandTable[] = {
{NULL, NULL, 0, NULL}
};
static int CmdHelp(const char *Cmd) {
(void)Cmd; // Cmd is not used so far
CmdsHelp(CommandTable);
return 0;
}
int CmdAnalyse(const char *Cmd) {
clearCommandBuffer();
CmdsParse(CommandTable, Cmd);
return 0;
}
int CmdHelp(const char *Cmd) {
(void)Cmd; // Cmd is not used so far
CmdsHelp(CommandTable);
return 0;
}

View file

@ -27,12 +27,4 @@
#include "util_posix.h" // msclock
int CmdAnalyse(const char *Cmd);
int CmdAnalyseLCR(const char *Cmd);
int CmdAnalyseCHKSUM(const char *Cmd);
int CmdAnalyseDates(const char *Cmd);
int CmdAnalyseCRC(const char *Cmd);
int CmdAnalyseTEASelfTest(const char *Cmd);
int CmdAnalyseLfsr(const char *Cmd);
int CmdAnalyseHid(const char *Cmd);
int CmdAnalyseNuid(const char *Cmd);
#endif

View file

@ -39,25 +39,6 @@ static int split(char *str, char *arr[MAX_ARGS]) {
return wordCnt;
}
int CmdCrc(const char *Cmd) {
char name[] = {"reveng "};
char Cmd2[100 + 7];
memcpy(Cmd2, name, 7);
memcpy(Cmd2 + 7, Cmd, 100);
char *argv[MAX_ARGS];
int argc = split(Cmd2, argv);
if (argc == 3 && memcmp(argv[1], "-g", 2) == 0) {
CmdrevengSearch(argv[2]);
} else {
reveng_main(argc, argv);
}
for (int i = 0; i < argc; ++i) {
free(argv[i]);
}
return 0;
}
//returns array of model names and the count of models returning
// as well as a width array for the width of each model
int GetModels(char *Models[], int *count, uint8_t *width) {
@ -364,9 +345,9 @@ int RunModel(char *inModel, char *inHexStr, bool reverse, char endian, char *res
pfree(&apoly);
return 1;
}
/*
//test call to RunModel
int CmdrevengTestC(const char *Cmd) {
static int CmdrevengTestC(const char *Cmd) {
int cmdp = 0;
char inModel[30] = {0x00};
char inHexStr[30] = {0x00};
@ -387,7 +368,7 @@ int CmdrevengTestC(const char *Cmd) {
PrintAndLogEx(SUCCESS, "result: %s", result);
return 1;
}
*/
//returns a calloced string (needs to be freed)
static char *SwapEndianStr(const char *inStr, const size_t len, const uint8_t blockSize) {
char *tmp = calloc(len + 1, sizeof(char));
@ -401,7 +382,7 @@ static char *SwapEndianStr(const char *inStr, const size_t len, const uint8_t bl
}
// takes hex string in and searches for a matching result (hex string must include checksum)
int CmdrevengSearch(const char *Cmd) {
static int CmdrevengSearch(const char *Cmd) {
#define NMODELS 106
@ -486,3 +467,23 @@ int CmdrevengSearch(const char *Cmd) {
if (!found) PrintAndLogEx(FAILED, "\nno matches found\n");
return 1;
}
int CmdCrc(const char *Cmd) {
char name[] = {"reveng "};
char Cmd2[100 + 7];
memcpy(Cmd2, name, 7);
memcpy(Cmd2 + 7, Cmd, 100);
char *argv[MAX_ARGS];
int argc = split(Cmd2, argv);
if (argc == 3 && memcmp(argv[1], "-g", 2) == 0) {
CmdrevengSearch(argv[2]);
} else {
reveng_main(argc, argv);
}
for (int i = 0; i < argc; ++i) {
free(argv[i]);
}
return 0;
}

View file

@ -30,7 +30,6 @@
int CmdCrc(const char *Cmd);
int CmdrevengSearch(const char *Cmd);
int GetModels(char *Models[], int *count, uint8_t *width);
int RunModel(char *inModel, char *inHexStr, bool reverse, char endian, char *result);
#endif

View file

@ -107,7 +107,7 @@ static int usage_flashmem_info(void) {
return 0;
}
int CmdFlashMemRead(const char *Cmd) {
static int CmdFlashMemRead(const char *Cmd) {
uint8_t cmdp = 0;
bool errors = false;
@ -146,7 +146,7 @@ int CmdFlashMemRead(const char *Cmd) {
return 0;
}
int CmdFlashmemSpiBaudrate(const char *Cmd) {
static int CmdFlashmemSpiBaudrate(const char *Cmd) {
char ctmp = tolower(param_getchar(Cmd, 0));
if (strlen(Cmd) < 1 || ctmp == 'h') return usage_flashmem_spibaud();
@ -158,7 +158,7 @@ int CmdFlashmemSpiBaudrate(const char *Cmd) {
return 0;
}
int CmdFlashMemLoad(const char *Cmd) {
static int CmdFlashMemLoad(const char *Cmd) {
uint32_t start_index = 0;
char filename[FILE_PATH_SIZE] = {0};
@ -301,7 +301,7 @@ int CmdFlashMemLoad(const char *Cmd) {
PrintAndLogEx(SUCCESS, "Wrote %u bytes to offset %u", datalen, start_index);
return 0;
}
int CmdFlashMemSave(const char *Cmd) {
static int CmdFlashMemSave(const char *Cmd) {
char filename[FILE_PATH_SIZE] = {0};
uint8_t cmdp = 0;
@ -357,7 +357,7 @@ int CmdFlashMemSave(const char *Cmd) {
free(dump);
return 0;
}
int CmdFlashMemWipe(const char *Cmd) {
static int CmdFlashMemWipe(const char *Cmd) {
uint8_t cmdp = 0;
bool errors = false;
@ -406,7 +406,7 @@ int CmdFlashMemWipe(const char *Cmd) {
return 0;
}
int CmdFlashMemInfo(const char *Cmd) {
static int CmdFlashMemInfo(const char *Cmd) {
uint8_t sha_hash[20] = {0};
mbedtls_rsa_context rsa;
@ -606,16 +606,16 @@ static command_t CommandTable[] = {
{NULL, NULL, 0, NULL}
};
static int CmdHelp(const char *Cmd) {
(void)Cmd; // Cmd is not used so far
CmdsHelp(CommandTable);
return 0;
}
int CmdFlashMem(const char *Cmd) {
clearCommandBuffer();
CmdsParse(CommandTable, Cmd);
return 0;
}
int CmdHelp(const char *Cmd) {
(void)Cmd; // Cmd is not used so far
CmdsHelp(CommandTable);
return 0;
}
#endif

View file

@ -35,11 +35,6 @@ typedef enum {
int CmdFlashMem(const char *Cmd);
int CmdFlashMemRead(const char *Cmd);
int CmdFlashMemLoad(const char *Cmd);
int CmdFlashMemSave(const char *Cmd);
int CmdFlashMemWipe(const char *Cmd);
int CmdFlashMemInfo(const char *Cmd);
#endif
#endif

View file

@ -898,7 +898,7 @@ int CmdLFfind(const char *Cmd) {
if (CmdHIDDemod("")) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("HID Prox ID") " found!"); goto out;}
if (CmdAWIDDemod("")) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("AWID ID") " found!"); goto out;}
if (CmdParadoxDemod("")) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("Paradox ID") " found!"); goto out;}
if (demodParadox()) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("Paradox ID") " found!"); goto out;}
if (CmdEM410xDemod("")) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("EM410x ID") " found!"); goto out;}
if (CmdFdxDemod("")) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("FDX-B ID") " found!"); goto out;}
@ -906,21 +906,21 @@ int CmdLFfind(const char *Cmd) {
if (CmdIdteckDemod("")) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("Idteck ID") " found!"); goto out;}
if (CmdIndalaDemod("")) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("Indala ID") " found!"); goto out;}
if (CmdIOProxDemod("")) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("IO Prox ID") " found!"); goto out;}
if (CmdJablotronDemod("")) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("Jablotron ID") " found!"); goto out;}
if (CmdLFNedapDemod("")) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("NEDAP ID") " found!"); goto out;}
if (CmdNexWatchDemod("")) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("NexWatch ID") " found!"); goto out;}
if (CmdNoralsyDemod("")) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("Noralsy ID") " found!"); goto out;}
if (CmdKeriDemod("")) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("KERI ID") " found!"); goto out;}
if (CmdPacDemod("")) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("PAC/Stanley ID") " found!"); goto out;}
if (demodJablotron()) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("Jablotron ID") " found!"); goto out;}
if (demodNedap()) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("NEDAP ID") " found!"); goto out;}
if (demodNexWatch()) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("NexWatch ID") " found!"); goto out;}
if (demodNoralsy()) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("Noralsy ID") " found!"); goto out;}
if (demodKeri()) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("KERI ID") " found!"); goto out;}
if (demodPac()) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("PAC/Stanley ID") " found!"); goto out;}
if (CmdPrescoDemod("")) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("Presco ID") " found!"); goto out;}
if (CmdPyramidDemod("")) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("Pyramid ID") " found!"); goto out;}
if (CmdSecurakeyDemod("")) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("Securakey ID") " found!"); goto out;}
if (CmdVikingDemod("")) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("Viking ID") " found!"); goto out;}
if (CmdVisa2kDemod("")) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("Visa2000 ID") " found!"); goto out;}
if (CmdTIDemod("")) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("Texas Instrument ID") " found!"); goto out;}
//if (CmdFermaxDemod("")) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("Fermax ID") " found!"); goto out;}
//if (CmdFlexDemod("")) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("Flex ID") " found!"); goto out;}
if (demodPresco()) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("Presco ID") " found!"); goto out;}
if (demodPyramid()) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("Pyramid ID") " found!"); goto out;}
if (demodSecurakey()) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("Securakey ID") " found!"); goto out;}
if (demodViking()) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("Viking ID") " found!"); goto out;}
if (demodVisa2k()) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("Visa2000 ID") " found!"); goto out;}
if (demodTI()) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("Texas Instrument ID") " found!"); goto out;}
//if (demodFermax()) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("Fermax ID") " found!"); goto out;}
//if (demodFlex()) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("Flex ID") " found!"); goto out;}
PrintAndLogEx(FAILED, _RED_("No known 125/134 KHz tags found!"));

View file

@ -48,37 +48,6 @@ static uint8_t jablontron_chksum(uint8_t *bits) {
return chksum;
}
int getJablotronBits(uint64_t fullcode, uint8_t *bits) {
//preamp
num_to_bytebits(0xFFFF, 16, bits);
//fullcode
num_to_bytebits(fullcode, 40, bits + 16);
//chksum byte
uint8_t chksum = jablontron_chksum(bits);
num_to_bytebits(chksum, 8, bits + 56);
return 1;
}
// ASK/Diphase fc/64 (inverted Biphase)
// Note: this is not a demod, this is only a detection
// the parameter *bits needs to be demoded before call
// 0xFFFF preamble, 64bits
int detectJablotron(uint8_t *bits, size_t *size) {
if (*size < 64 * 2) return -1; //make sure buffer has enough data
size_t startIdx = 0;
uint8_t preamble[] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0};
if (preambleSearch(bits, preamble, sizeof(preamble), size, &startIdx) == 0)
return -2; //preamble not found
if (*size != 64) return -3; // wrong demoded size
uint8_t checkchksum = jablontron_chksum(bits + startIdx);
uint8_t crc = bytebits_to_byte(bits + startIdx + 56, 8);
if (checkchksum != crc) return -5;
return (int)startIdx;
}
static uint64_t getJablontronCardId(uint64_t rawcode) {
uint64_t id = 0;
uint8_t bytes[] = {0, 0, 0, 0, 0};
@ -250,3 +219,38 @@ int CmdHelp(const char *Cmd) {
CmdsHelp(CommandTable);
return 0;
}
int getJablotronBits(uint64_t fullcode, uint8_t *bits) {
//preamp
num_to_bytebits(0xFFFF, 16, bits);
//fullcode
num_to_bytebits(fullcode, 40, bits + 16);
//chksum byte
uint8_t chksum = jablontron_chksum(bits);
num_to_bytebits(chksum, 8, bits + 56);
return 1;
}
// ASK/Diphase fc/64 (inverted Biphase)
// Note: this is not a demod, this is only a detection
// the parameter *bits needs to be demoded before call
// 0xFFFF preamble, 64bits
int detectJablotron(uint8_t *bits, size_t *size) {
if (*size < 64 * 2) return -1; //make sure buffer has enough data
size_t startIdx = 0;
uint8_t preamble[] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0};
if (preambleSearch(bits, preamble, sizeof(preamble), size, &startIdx) == 0)
return -2; //preamble not found
if (*size != 64) return -3; // wrong demoded size
uint8_t checkchksum = jablontron_chksum(bits + startIdx);
uint8_t crc = bytebits_to_byte(bits + startIdx + 56, 8);
if (checkchksum != crc) return -5;
return (int)startIdx;
}
int demodJablotron(void) {
return CmdJablotronDemod("");
}

View file

@ -24,11 +24,7 @@
int CmdLFJablotron(const char *Cmd);
int CmdJablotronDemod(const char *Cmd);
int CmdJablotronRead(const char *Cmd);
int CmdJablotronClone(const char *Cmd);
int CmdJablotronSim(const char *Cmd);
int demodJablotron(void);
int detectJablotron(uint8_t *bits, size_t *size);
int getJablotronBits(uint64_t fullcode, uint8_t *bits);

View file

@ -38,32 +38,7 @@ static int usage_lf_keri_sim(void) {
return 0;
}
// find KERI preamble in already demoded data
int detectKeri(uint8_t *dest, size_t *size, bool *invert) {
uint8_t preamble[] = {1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1};
uint8_t preamble_i[] = {0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0};
// sanity check.
if (*size < sizeof(preamble) + 100) return -1;
size_t startIdx = 0;
if (!preambleSearch(dest, preamble, sizeof(preamble), size, &startIdx)) {
// if didn't find preamble try again inverting
if (!preambleSearch(DemodBuffer, preamble_i, sizeof(preamble_i), size, &startIdx))
return -2;
*invert ^= 1;
}
if (*size != 64) return -3; //wrong demoded size
return (int)startIdx;
}
int CmdKeriDemod(const char *Cmd) {
static int CmdKeriDemod(const char *Cmd) {
(void)Cmd; // Cmd is not used so far
if (!PSKDemod("", false)) {
@ -242,3 +217,33 @@ int CmdHelp(const char *Cmd) {
CmdsHelp(CommandTable);
return 0;
}
// find KERI preamble in already demoded data
int detectKeri(uint8_t *dest, size_t *size, bool *invert) {
uint8_t preamble[] = {1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1};
uint8_t preamble_i[] = {0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0};
// sanity check.
if (*size < sizeof(preamble) + 100) return -1;
size_t startIdx = 0;
if (!preambleSearch(dest, preamble, sizeof(preamble), size, &startIdx)) {
// if didn't find preamble try again inverting
if (!preambleSearch(DemodBuffer, preamble_i, sizeof(preamble_i), size, &startIdx))
return -2;
*invert ^= 1;
}
if (*size != 64) return -3; //wrong demoded size
return (int)startIdx;
}
int demodKeri(void) {
return CmdKeriDemod("");
}

View file

@ -23,11 +23,8 @@
#include "lfdemod.h" // preamble test
int CmdLFKeri(const char *Cmd);
int CmdKeriRead(const char *Cmd);
int CmdKeriDemod(const char *Cmd);
int CmdKeriClone(const char *Cmd);
int CmdKeriSim(const char *Cmd);
int demodKeri(void);
int detectKeri(uint8_t *dest, size_t *size, bool *invert);
#endif

View file

@ -40,80 +40,8 @@ static int usage_lf_nedap_sim(void) {
return 0;
}
// find nedap preamble in already demoded data
int detectNedap(uint8_t *dest, size_t *size) {
//make sure buffer has data
if (*size < 128) return -3;
size_t startIdx = 0;
//uint8_t preamble[] = {1,1,1,1,1,1,1,1,1,0,0,0,1};
uint8_t preamble[] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 0};
if (!preambleSearch(dest, preamble, sizeof(preamble), size, &startIdx))
return -4; //preamble not found
return (int) startIdx;
}
static int GetNedapBits(uint32_t cn, uint8_t *nedapBits) {
uint8_t pre[128];
memset(pre, 0x00, sizeof(pre));
// preamble 1111 1111 10 = 0xFF8
num_to_bytebits(0xFF8, 12, pre);
// fixed tagtype code? 0010 1101 = 0x2D
num_to_bytebits(0x2D, 8, pre + 10);
// 46 encrypted bits - UNKNOWN ALGO
// -- 16 bits checksum. Should be 4x4 checksum, based on UID and 2 constant values.
// -- 30 bits undocumented?
//num_to_bytebits(cn, 46, pre+18);
//----from this part, the UID in clear text, with a 1bit ZERO as separator between bytes.
pre[64] = 0;
pre[73] = 0;
pre[82] = 0;
pre[91] = 0;
pre[100] = 0;
pre[109] = 0;
pre[118] = 0;
// cardnumber (uid)
num_to_bytebits((cn >> 0) & 0xFF, 8, pre + 65);
num_to_bytebits((cn >> 8) & 0xFF, 8, pre + 74);
num_to_bytebits((cn >> 16) & 0xFF, 8, pre + 83);
// two ?
num_to_bytebits(0, 8, pre + 92);
num_to_bytebits(0, 8, pre + 101);
// chksum
num_to_bytebits((0 >> 0) & 0xFF, 8, pre + 110);
num_to_bytebits((0 >> 8) & 0xFF, 8, pre + 119);
// add paritybits (bitsource, dest, sourcelen, paritylen, parityType (odd, even,)
addParity(pre, pre + 64, 64, 8, 1);
addParity(pre + 64, pre + 64, 64, 8, 1);
pre[63] = GetParity(DemodBuffer, EVEN, 63);
pre[127] = GetParity(DemodBuffer + 64, EVEN, 63);
memcpy(nedapBits, pre, 128);
// 1111111110001011010000010110100011001001000010110101001101011001000110011010010000000000100001110001001000000001000101011100111
return 1;
}
/*
- UID: 001630
- i: 4071
- Checksum2 BE21
*/
//GetParity( uint8_t *bits, uint8_t type, int length)
//NEDAP demod - ASK/Biphase (or Diphase), RF/64 with preamble of 1111111110 (always a 128 bit data stream)
//print NEDAP Prox ID, encoding, encrypted ID,
int CmdLFNedapDemod(const char *Cmd) {
(void)Cmd; // Cmd is not used so far
//raw ask demod no start bit finding just get binary from wave
@ -253,7 +181,7 @@ int CmdLFNedapClone(const char *Cmd) {
cardnumber = (cn & 0x00FFFFFF);
if ( !GetNedapBits(cardnumber, bits)) {
if ( !getNedapBits(cardnumber, bits)) {
PrintAndLogEx(WARNING, "Error with tag bitstream generation.");
return 1;
}
@ -312,7 +240,7 @@ int CmdLFNedapSim(const char *Cmd) {
arg1 = clk << 8 | encoding;
arg2 = invert << 8 | separator;
if (!GetNedapBits(cardnumber, bs)) {
if (!getNedapBits(cardnumber, bs)) {
PrintAndLogEx(WARNING, "Error with tag bitstream generation.");
return 1;
}
@ -395,3 +323,79 @@ int CmdHelp(const char *Cmd) {
CmdsHelp(CommandTable);
return 0;
}
// find nedap preamble in already demoded data
int detectNedap(uint8_t *dest, size_t *size) {
//make sure buffer has data
if (*size < 128) return -3;
size_t startIdx = 0;
//uint8_t preamble[] = {1,1,1,1,1,1,1,1,1,0,0,0,1};
uint8_t preamble[] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 0};
if (!preambleSearch(dest, preamble, sizeof(preamble), size, &startIdx))
return -4; //preamble not found
return (int) startIdx;
}
int getNedapBits(uint32_t cn, uint8_t *nedapBits) {
uint8_t pre[128];
memset(pre, 0x00, sizeof(pre));
// preamble 1111 1111 10 = 0xFF8
num_to_bytebits(0xFF8, 12, pre);
// fixed tagtype code? 0010 1101 = 0x2D
num_to_bytebits(0x2D, 8, pre + 10);
// 46 encrypted bits - UNKNOWN ALGO
// -- 16 bits checksum. Should be 4x4 checksum, based on UID and 2 constant values.
// -- 30 bits undocumented?
//num_to_bytebits(cn, 46, pre+18);
//----from this part, the UID in clear text, with a 1bit ZERO as separator between bytes.
pre[64] = 0;
pre[73] = 0;
pre[82] = 0;
pre[91] = 0;
pre[100] = 0;
pre[109] = 0;
pre[118] = 0;
// cardnumber (uid)
num_to_bytebits((cn >> 0) & 0xFF, 8, pre + 65);
num_to_bytebits((cn >> 8) & 0xFF, 8, pre + 74);
num_to_bytebits((cn >> 16) & 0xFF, 8, pre + 83);
// two ?
num_to_bytebits(0, 8, pre + 92);
num_to_bytebits(0, 8, pre + 101);
// chksum
num_to_bytebits((0 >> 0) & 0xFF, 8, pre + 110);
num_to_bytebits((0 >> 8) & 0xFF, 8, pre + 119);
// add paritybits (bitsource, dest, sourcelen, paritylen, parityType (odd, even,)
addParity(pre, pre + 64, 64, 8, 1);
addParity(pre + 64, pre + 64, 64, 8, 1);
pre[63] = GetParity(DemodBuffer, EVEN, 63);
pre[127] = GetParity(DemodBuffer + 64, EVEN, 63);
memcpy(nedapBits, pre, 128);
// 1111111110001011010000010110100011001001000010110101001101011001000110011010010000000000100001110001001000000001000101011100111
return 1;
}
/*
- UID: 001630
- i: 4071
- Checksum2 BE21
*/
//GetParity( uint8_t *bits, uint8_t type, int length)
int demodNedap(void) {
return CmdLFNedapDemod("");
}

View file

@ -23,13 +23,10 @@
#include "crc.h"
int CmdLFNedap(const char *Cmd);
int CmdLFNedapDemod(const char *Cmd);
int CmdLFNedapRead(const char *Cmd);
//int CmdLFNedapClone(const char *Cmd);
int CmdLFNedapSim(const char *Cmd);
int CmdLFNedapChk(const char *Cmd);
int demodNedap(void);
int detectNedap(uint8_t *dest, size_t *size);
int getNedapBits(uint32_t cn, uint8_t *nedapBits);
#endif

View file

@ -12,25 +12,6 @@
static int CmdHelp(const char *Cmd);
int detectNexWatch(uint8_t *dest, size_t *size, bool *invert) {
uint8_t preamble[28] = {0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
uint8_t preamble_i[28] = {1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
// sanity check.
if (*size < sizeof(preamble) + 100) return -1;
size_t startIdx = 0;
if (!preambleSearch(DemodBuffer, preamble, sizeof(preamble), size, &startIdx)) {
// if didn't find preamble try again inverting
if (!preambleSearch(DemodBuffer, preamble_i, sizeof(preamble_i), size, &startIdx)) return -4;
*invert ^= 1;
}
// size tests?
return (int) startIdx;
}
int CmdNexWatchDemod(const char *Cmd) {
(void)Cmd; // Cmd is not used so far
@ -111,3 +92,27 @@ int CmdHelp(const char *Cmd) {
CmdsHelp(CommandTable);
return 0;
}
int detectNexWatch(uint8_t *dest, size_t *size, bool *invert) {
uint8_t preamble[28] = {0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
uint8_t preamble_i[28] = {1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
// sanity check.
if (*size < sizeof(preamble) + 100) return -1;
size_t startIdx = 0;
if (!preambleSearch(DemodBuffer, preamble, sizeof(preamble), size, &startIdx)) {
// if didn't find preamble try again inverting
if (!preambleSearch(DemodBuffer, preamble_i, sizeof(preamble_i), size, &startIdx)) return -4;
*invert ^= 1;
}
// size tests?
return (int) startIdx;
}
int demodNexWatch(void) {
return CmdNexWatchDemod("");
}

View file

@ -23,8 +23,7 @@
#include "lfdemod.h"
int CmdLFNEXWATCH(const char *Cmd);
int CmdNexWatchDemod(const char *Cmd);
int CmdNexWatchRead(const char *Cmd);
int demodNexWatch(void);
int detectNexWatch(uint8_t *dest, size_t *size, bool *invert);
#endif

View file

@ -46,58 +46,6 @@ static uint8_t noralsy_chksum(uint8_t *bits, uint8_t len) {
sum ^= bytebits_to_byte(bits + i, 4);
return sum & 0x0F ;
}
int getnoralsyBits(uint32_t id, uint16_t year, uint8_t *bits) {
//preamp
num_to_bytebits(0xBB0214FF, 32, bits); // --> Have seen 0xBB0214FF / 0xBB0314FF UNKNOWN
//convert ID into BCD-format
id = DEC2BCD(id);
year = DEC2BCD(year);
year &= 0xFF;
uint16_t sub1 = (id & 0xFFF0000) >> 16;
uint8_t sub2 = (id & 0x000FF00) >> 8;
uint8_t sub3 = (id & 0x00000FF);
num_to_bytebits(sub1, 12, bits + 32);
num_to_bytebits(year, 8, bits + 44);
num_to_bytebits(0, 4, bits + 52); // --> UNKNOWN. Flag?
num_to_bytebits(sub2, 8, bits + 56);
num_to_bytebits(sub3, 8, bits + 64);
//chksum byte
uint8_t chksum = noralsy_chksum(bits + 32, 40);
num_to_bytebits(chksum, 4, bits + 72);
chksum = noralsy_chksum(bits, 76);
num_to_bytebits(chksum, 4, bits + 76);
return 1;
}
// by iceman
// find Noralsy preamble in already demoded data
static int detectNoralsy(uint8_t *dest, size_t *size) {
if (*size < 96) return -1; //make sure buffer has data
size_t startIdx = 0;
uint8_t preamble[] = {1, 0, 1, 1, 1, 0, 1, 1, 0, 0, 0, 0};
if (!preambleSearch(dest, preamble, sizeof(preamble), size, &startIdx))
return -2; //preamble not found
if (*size != 96) return -3; //wrong demoded size
//return start position
return (int)startIdx;
}
/*
*
* 2520116 | BB0214FF2529900116360000 | 10111011 00000011 00010100 11111111 00100101 00101001 10010000 00000001 00010110 00110110 00000000 00000000
* aaa*aaaaiiiYY*iiiicc---- **** iiiiiiii iiiiYYYY YYYY**** iiiiiiii iiiiiiii cccccccc
*
* a = fixed value BB0*14FF
* i = printed id, BCD-format
* Y = year
* c = checksum
* * = unknown
*
**/
//see ASKDemod for what args are accepted
int CmdNoralsyDemod(const char *Cmd) {
@ -277,3 +225,60 @@ int CmdHelp(const char *Cmd) {
CmdsHelp(CommandTable);
return 0;
}
int getnoralsyBits(uint32_t id, uint16_t year, uint8_t *bits) {
//preamp
num_to_bytebits(0xBB0214FF, 32, bits); // --> Have seen 0xBB0214FF / 0xBB0314FF UNKNOWN
//convert ID into BCD-format
id = DEC2BCD(id);
year = DEC2BCD(year);
year &= 0xFF;
uint16_t sub1 = (id & 0xFFF0000) >> 16;
uint8_t sub2 = (id & 0x000FF00) >> 8;
uint8_t sub3 = (id & 0x00000FF);
num_to_bytebits(sub1, 12, bits + 32);
num_to_bytebits(year, 8, bits + 44);
num_to_bytebits(0, 4, bits + 52); // --> UNKNOWN. Flag?
num_to_bytebits(sub2, 8, bits + 56);
num_to_bytebits(sub3, 8, bits + 64);
//chksum byte
uint8_t chksum = noralsy_chksum(bits + 32, 40);
num_to_bytebits(chksum, 4, bits + 72);
chksum = noralsy_chksum(bits, 76);
num_to_bytebits(chksum, 4, bits + 76);
return 1;
}
// by iceman
// find Noralsy preamble in already demoded data
int detectNoralsy(uint8_t *dest, size_t *size) {
if (*size < 96) return -1; //make sure buffer has data
size_t startIdx = 0;
uint8_t preamble[] = {1, 0, 1, 1, 1, 0, 1, 1, 0, 0, 0, 0};
if (!preambleSearch(dest, preamble, sizeof(preamble), size, &startIdx))
return -2; //preamble not found
if (*size != 96) return -3; //wrong demoded size
//return start position
return (int)startIdx;
}
/*
*
* 2520116 | BB0214FF2529900116360000 | 10111011 00000011 00010100 11111111 00100101 00101001 10010000 00000001 00010110 00110110 00000000 00000000
* aaa*aaaaiiiYY*iiiicc---- **** iiiiiiii iiiiYYYY YYYY**** iiiiiiii iiiiiiii cccccccc
*
* a = fixed value BB0*14FF
* i = printed id, BCD-format
* Y = year
* c = checksum
* * = unknown
*
**/
int demodNoralsy(void) {
return CmdNoralsyDemod("");
}

View file

@ -23,11 +23,9 @@
#include "lfdemod.h" // parityTest
int CmdLFNoralsy(const char *Cmd);
int CmdNoralsyDemod(const char *Cmd);
int CmdNoralsyRead(const char *Cmd);
int CmdNoralsyClone(const char *Cmd);
int CmdNoralsySim(const char *Cmd);
int demodNoralsy(void);
int detectNoralsy(uint8_t *dest, size_t *size);
int getnoralsyBits(uint32_t id, uint16_t year, uint8_t *bits);
#endif

View file

@ -11,19 +11,6 @@
static int CmdHelp(const char *Cmd);
// by marshmellow
// find PAC preamble in already demoded data
int detectPac(uint8_t *dest, size_t *size) {
if (*size < 128) return -1; //make sure buffer has data
size_t startIdx = 0;
uint8_t preamble[] = {1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0};
if (!preambleSearch(dest, preamble, sizeof(preamble), size, &startIdx))
return -2; //preamble not found
if (*size != 128) return -3; //wrong demoded size
//return start position
return (int)startIdx;
}
//see NRZDemod for what args are accepted
int CmdPacDemod(const char *Cmd) {
@ -86,3 +73,21 @@ int CmdHelp(const char *Cmd) {
CmdsHelp(CommandTable);
return 0;
}
// by marshmellow
// find PAC preamble in already demoded data
int detectPac(uint8_t *dest, size_t *size) {
if (*size < 128) return -1; //make sure buffer has data
size_t startIdx = 0;
uint8_t preamble[] = {1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0};
if (!preambleSearch(dest, preamble, sizeof(preamble), size, &startIdx))
return -2; //preamble not found
if (*size != 128) return -3; //wrong demoded size
//return start position
return (int)startIdx;
}
int demodPac(void) {
return CmdPacDemod("");
}

View file

@ -22,9 +22,8 @@
#include "lfdemod.h" // preamble test
int CmdLFPac(const char *Cmd);
int CmdPacRead(const char *Cmd);
int CmdPacDemod(const char *Cmd);
int demodPac(void);
int detectPac(uint8_t *dest, size_t *size);
#endif

View file

@ -37,43 +37,6 @@ static int usage_lf_paradox_sim(void) {
return 0;
}
// loop to get raw paradox waveform then FSK demodulate the TAG ID from it
int detectParadox(uint8_t *dest, size_t *size, uint32_t *hi2, uint32_t *hi, uint32_t *lo, int *waveStartIdx) {
//make sure buffer has data
if (*size < 96 * 50) return -1;
if (getSignalProperties()->isnoise) return -2;
// FSK demodulator
*size = fskdemod(dest, *size, 50, 1, 10, 8, waveStartIdx); // paradox fsk2a
//did we get a good demod?
if (*size < 96) return -3;
// 00001111 bit pattern represent start of frame, 01 pattern represents a 0 and 10 represents a 1
size_t startIdx = 0;
uint8_t preamble[] = {0, 0, 0, 0, 1, 1, 1, 1};
if (!preambleSearch(dest, preamble, sizeof(preamble), size, &startIdx))
return -4; //preamble not found
size_t numStart = startIdx + sizeof(preamble);
// final loop, go over previously decoded FSK data and manchester decode into usable tag ID
for (size_t idx = numStart; (idx - numStart) < *size - sizeof(preamble); idx += 2) {
if (dest[idx] == dest[idx + 1])
return -5; //not manchester data
*hi2 = (*hi2 << 1) | (*hi >> 31);
*hi = (*hi << 1) | (*lo >> 31);
//Then, shift in a 0 or one into low
*lo <<= 1;
if (dest[idx] && !dest[idx + 1]) // 1 0
*lo |= 1;
else // 0 1
*lo |= 0;
}
return (int)startIdx;
}
//by marshmellow
//Paradox Prox demod - FSK2a RF/50 with preamble of 00001111 (then manchester encoded)
//print full Paradox Prox ID and some bit format details if found
@ -204,3 +167,45 @@ int CmdHelp(const char *Cmd) {
CmdsHelp(CommandTable);
return 0;
}
// loop to get raw paradox waveform then FSK demodulate the TAG ID from it
int detectParadox(uint8_t *dest, size_t *size, uint32_t *hi2, uint32_t *hi, uint32_t *lo, int *waveStartIdx) {
//make sure buffer has data
if (*size < 96 * 50) return -1;
if (getSignalProperties()->isnoise) return -2;
// FSK demodulator
*size = fskdemod(dest, *size, 50, 1, 10, 8, waveStartIdx); // paradox fsk2a
//did we get a good demod?
if (*size < 96) return -3;
// 00001111 bit pattern represent start of frame, 01 pattern represents a 0 and 10 represents a 1
size_t startIdx = 0;
uint8_t preamble[] = {0, 0, 0, 0, 1, 1, 1, 1};
if (!preambleSearch(dest, preamble, sizeof(preamble), size, &startIdx))
return -4; //preamble not found
size_t numStart = startIdx + sizeof(preamble);
// final loop, go over previously decoded FSK data and manchester decode into usable tag ID
for (size_t idx = numStart; (idx - numStart) < *size - sizeof(preamble); idx += 2) {
if (dest[idx] == dest[idx + 1])
return -5; //not manchester data
*hi2 = (*hi2 << 1) | (*hi >> 31);
*hi = (*hi << 1) | (*lo >> 31);
//Then, shift in a 0 or one into low
*lo <<= 1;
if (dest[idx] && !dest[idx + 1]) // 1 0
*lo |= 1;
else // 0 1
*lo |= 0;
}
return (int)startIdx;
}
int demodParadox(void) {
return CmdParadoxDemod("");
}

View file

@ -9,11 +9,7 @@
#ifndef CMDLFPARADOX_H__
#define CMDLFPARADOX_H__
int CmdLFParadox(const char *Cmd);
int CmdParadoxDemod(const char *Cmd);
int CmdParadoxRead(const char *Cmd);
//int CmdParadoxClone(const char *Cmd);
int CmdParadoxSim(const char *Cmd);
int demodParadox(void);
int detectParadox(uint8_t *dest, size_t *size, uint32_t *hi2, uint32_t *hi, uint32_t *lo, int *waveStartIdx);
#endif

View file

@ -24,8 +24,4 @@ int pcf7931_printConfig(void);
int CmdLFPCF7931(const char *Cmd);
int CmdLFPCF7931Read(const char *Cmd);
int CmdLFPCF7931Write(const char *Cmd);
int CmdLFPCF7931Config(const char *Cmd);
#endif

View file

@ -40,6 +40,145 @@ static int usage_lf_presco_sim(void) {
return 0;
}
//see ASKDemod for what args are accepted
int CmdPrescoDemod(const char *Cmd) {
(void)Cmd; // Cmd is not used so far
bool st = true;
if (!ASKDemod_ext("32 0 0 0 0 a", false, false, 1, &st)) {
PrintAndLogEx(DEBUG, "DEBUG: Error Presco ASKDemod failed");
return 0;
}
size_t size = DemodBufferLen;
int ans = detectPresco(DemodBuffer, &size);
if (ans < 0) {
if (ans == -1)
PrintAndLogEx(DEBUG, "DEBUG: Error - Presco: too few bits found");
else if (ans == -2)
PrintAndLogEx(DEBUG, "DEBUG: Error - Presco: preamble not found");
else if (ans == -3)
PrintAndLogEx(DEBUG, "DEBUG: Error - Presco: Size not correct: %d", size);
else
PrintAndLogEx(DEBUG, "DEBUG: Error - Presco: ans: %d", ans);
return 0;
}
setDemodBuff(DemodBuffer, 128, ans);
setClockGrid(g_DemodClock, g_DemodStartIdx + (ans * g_DemodClock));
//got a good demod
uint32_t raw1 = bytebits_to_byte(DemodBuffer, 32);
uint32_t raw2 = bytebits_to_byte(DemodBuffer + 32, 32);
uint32_t raw3 = bytebits_to_byte(DemodBuffer + 64, 32);
uint32_t raw4 = bytebits_to_byte(DemodBuffer + 96, 32);
uint32_t cardid = raw4;
PrintAndLogEx(SUCCESS, "Presco Tag Found: Card ID %08X, Raw: %08X%08X%08X%08X", cardid, raw1, raw2, raw3, raw4);
uint32_t sitecode = 0, usercode = 0, fullcode = 0;
bool Q5 = false;
char cmd[12] = {0};
sprintf(cmd, "H %08X", cardid);
getWiegandFromPresco(cmd, &sitecode, &usercode, &fullcode, &Q5);
PrintAndLogEx(SUCCESS, "SiteCode %u, UserCode %u, FullCode, %08X", sitecode, usercode, fullcode);
return 1;
}
//see ASKDemod for what args are accepted
int CmdPrescoRead(const char *Cmd) {
// Presco Number: 123456789 --> Sitecode 30 | usercode 8665
lf_read(true, 12000);
return CmdPrescoDemod(Cmd);
}
// takes base 12 ID converts to hex
// Or takes 8 digit hex ID
int CmdPrescoClone(const char *Cmd) {
bool Q5 = false;
uint32_t sitecode = 0, usercode = 0, fullcode = 0;
uint32_t blocks[5] = {T55x7_MODULATION_MANCHESTER | T55x7_BITRATE_RF_32 | 4 << T55x7_MAXBLOCK_SHIFT | T55x7_ST_TERMINATOR, 0, 0, 0, 0};
// get wiegand from printed number.
if (getWiegandFromPresco(Cmd, &sitecode, &usercode, &fullcode, &Q5) == -1) return usage_lf_presco_clone();
if (Q5)
blocks[0] = T5555_MODULATION_MANCHESTER | T5555_SET_BITRATE(32) | 4 << T5555_MAXBLOCK_SHIFT | T5555_ST_TERMINATOR;
if ((sitecode & 0xFF) != sitecode) {
sitecode &= 0xFF;
PrintAndLogEx(INFO, "Facility-Code Truncated to 8-bits (Presco): %u", sitecode);
}
if ((usercode & 0xFFFF) != usercode) {
usercode &= 0xFFFF;
PrintAndLogEx(INFO, "Card Number Truncated to 16-bits (Presco): %u", usercode);
}
blocks[1] = 0x10D00000; //preamble
blocks[2] = 0x00000000;
blocks[3] = 0x00000000;
blocks[4] = fullcode;
PrintAndLogEx(INFO, "Preparing to clone Presco to T55x7 with SiteCode: %u, UserCode: %u, FullCode: %08x", sitecode, usercode, fullcode);
print_blocks(blocks, 5);
UsbCommand resp;
UsbCommand c = {CMD_T55XX_WRITE_BLOCK, {0, 0, 0}, {{0}}};
for (uint8_t i = 0; i < 5; i++) {
c.arg[0] = blocks[i];
c.arg[1] = i;
clearCommandBuffer();
SendCommand(&c);
if (!WaitForResponseTimeout(CMD_ACK, &resp, T55XX_WRITE_TIMEOUT)) {
PrintAndLogEx(WARNING, "Error occurred, device did not respond during write operation.");
return -1;
}
}
return 0;
}
// takes base 12 ID converts to hex
// Or takes 8 digit hex ID
int CmdPrescoSim(const char *Cmd) {
uint32_t sitecode = 0, usercode = 0, fullcode = 0;
bool Q5 = false;
// get wiegand from printed number.
if (getWiegandFromPresco(Cmd, &sitecode, &usercode, &fullcode, &Q5) == -1) return usage_lf_presco_sim();
uint8_t clk = 32, encoding = 1, separator = 1, invert = 0;
uint16_t arg1, arg2;
size_t size = 128;
arg1 = clk << 8 | encoding;
arg2 = invert << 8 | separator;
PrintAndLogEx(SUCCESS, "Simulating Presco - SiteCode: %u, UserCode: %u, FullCode: %08X", sitecode, usercode, fullcode);
UsbCommand c = {CMD_ASK_SIM_TAG, {arg1, arg2, size}, {{0}}};
getPrescoBits(fullcode, c.d.asBytes);
clearCommandBuffer();
SendCommand(&c);
return 0;
}
static command_t CommandTable[] = {
{"help", CmdHelp, 1, "This help"},
{"read", CmdPrescoRead, 0, "Attempt to read and Extract tag data"},
{"clone", CmdPrescoClone, 0, "clone presco tag"},
{"sim", CmdPrescoSim, 0, "simulate presco tag"},
{NULL, NULL, 0, NULL}
};
int CmdLFPresco(const char *Cmd) {
clearCommandBuffer();
CmdsParse(CommandTable, Cmd);
return 0;
}
int CmdHelp(const char *Cmd) {
(void)Cmd; // Cmd is not used so far
CmdsHelp(CommandTable);
return 0;
}
// find presco preamble 0x10D in already demoded data
int detectPresco(uint8_t *dest, size_t *size) {
if (*size < 128 * 2) return -1; //make sure buffer has data
@ -53,7 +192,7 @@ int detectPresco(uint8_t *dest, size_t *size) {
}
// convert base 12 ID to sitecode & usercode & 8 bit other unknown code
int GetWiegandFromPresco(const char *Cmd, uint32_t *sitecode, uint32_t *usercode, uint32_t *fullcode, bool *Q5) {
int getWiegandFromPresco(const char *Cmd, uint32_t *sitecode, uint32_t *usercode, uint32_t *fullcode, bool *Q5) {
uint8_t val = 0;
bool hex = false, errors = false;
@ -116,7 +255,7 @@ int GetWiegandFromPresco(const char *Cmd, uint32_t *sitecode, uint32_t *usercode
}
// calc not certain - intended to get bitstream for programming / sim
int GetPrescoBits(uint32_t fullcode, uint8_t *prescoBits) {
int getPrescoBits(uint32_t fullcode, uint8_t *prescoBits) {
num_to_bytebits(0x10D00000, 32, prescoBits);
num_to_bytebits(0x00000000, 32, prescoBits + 32);
num_to_bytebits(0x00000000, 32, prescoBits + 64);
@ -124,141 +263,7 @@ int GetPrescoBits(uint32_t fullcode, uint8_t *prescoBits) {
return 1;
}
//see ASKDemod for what args are accepted
int CmdPrescoDemod(const char *Cmd) {
(void)Cmd; // Cmd is not used so far
bool st = true;
if (!ASKDemod_ext("32 0 0 0 0 a", false, false, 1, &st)) {
PrintAndLogEx(DEBUG, "DEBUG: Error Presco ASKDemod failed");
return 0;
}
size_t size = DemodBufferLen;
int ans = detectPresco(DemodBuffer, &size);
if (ans < 0) {
if (ans == -1)
PrintAndLogEx(DEBUG, "DEBUG: Error - Presco: too few bits found");
else if (ans == -2)
PrintAndLogEx(DEBUG, "DEBUG: Error - Presco: preamble not found");
else if (ans == -3)
PrintAndLogEx(DEBUG, "DEBUG: Error - Presco: Size not correct: %d", size);
else
PrintAndLogEx(DEBUG, "DEBUG: Error - Presco: ans: %d", ans);
return 0;
}
setDemodBuff(DemodBuffer, 128, ans);
setClockGrid(g_DemodClock, g_DemodStartIdx + (ans * g_DemodClock));
//got a good demod
uint32_t raw1 = bytebits_to_byte(DemodBuffer, 32);
uint32_t raw2 = bytebits_to_byte(DemodBuffer + 32, 32);
uint32_t raw3 = bytebits_to_byte(DemodBuffer + 64, 32);
uint32_t raw4 = bytebits_to_byte(DemodBuffer + 96, 32);
uint32_t cardid = raw4;
PrintAndLogEx(SUCCESS, "Presco Tag Found: Card ID %08X, Raw: %08X%08X%08X%08X", cardid, raw1, raw2, raw3, raw4);
uint32_t sitecode = 0, usercode = 0, fullcode = 0;
bool Q5 = false;
char cmd[12] = {0};
sprintf(cmd, "H %08X", cardid);
GetWiegandFromPresco(cmd, &sitecode, &usercode, &fullcode, &Q5);
PrintAndLogEx(SUCCESS, "SiteCode %u, UserCode %u, FullCode, %08X", sitecode, usercode, fullcode);
return 1;
int demodPresco(void) {
return CmdPrescoDemod("");
}
//see ASKDemod for what args are accepted
int CmdPrescoRead(const char *Cmd) {
// Presco Number: 123456789 --> Sitecode 30 | usercode 8665
lf_read(true, 12000);
return CmdPrescoDemod(Cmd);
}
// takes base 12 ID converts to hex
// Or takes 8 digit hex ID
int CmdPrescoClone(const char *Cmd) {
bool Q5 = false;
uint32_t sitecode = 0, usercode = 0, fullcode = 0;
uint32_t blocks[5] = {T55x7_MODULATION_MANCHESTER | T55x7_BITRATE_RF_32 | 4 << T55x7_MAXBLOCK_SHIFT | T55x7_ST_TERMINATOR, 0, 0, 0, 0};
// get wiegand from printed number.
if (GetWiegandFromPresco(Cmd, &sitecode, &usercode, &fullcode, &Q5) == -1) return usage_lf_presco_clone();
if (Q5)
blocks[0] = T5555_MODULATION_MANCHESTER | T5555_SET_BITRATE(32) | 4 << T5555_MAXBLOCK_SHIFT | T5555_ST_TERMINATOR;
if ((sitecode & 0xFF) != sitecode) {
sitecode &= 0xFF;
PrintAndLogEx(INFO, "Facility-Code Truncated to 8-bits (Presco): %u", sitecode);
}
if ((usercode & 0xFFFF) != usercode) {
usercode &= 0xFFFF;
PrintAndLogEx(INFO, "Card Number Truncated to 16-bits (Presco): %u", usercode);
}
blocks[1] = 0x10D00000; //preamble
blocks[2] = 0x00000000;
blocks[3] = 0x00000000;
blocks[4] = fullcode;
PrintAndLogEx(INFO, "Preparing to clone Presco to T55x7 with SiteCode: %u, UserCode: %u, FullCode: %08x", sitecode, usercode, fullcode);
print_blocks(blocks, 5);
UsbCommand resp;
UsbCommand c = {CMD_T55XX_WRITE_BLOCK, {0, 0, 0}, {{0}}};
for (uint8_t i = 0; i < 5; i++) {
c.arg[0] = blocks[i];
c.arg[1] = i;
clearCommandBuffer();
SendCommand(&c);
if (!WaitForResponseTimeout(CMD_ACK, &resp, T55XX_WRITE_TIMEOUT)) {
PrintAndLogEx(WARNING, "Error occurred, device did not respond during write operation.");
return -1;
}
}
return 0;
}
// takes base 12 ID converts to hex
// Or takes 8 digit hex ID
int CmdPrescoSim(const char *Cmd) {
uint32_t sitecode = 0, usercode = 0, fullcode = 0;
bool Q5 = false;
// get wiegand from printed number.
if (GetWiegandFromPresco(Cmd, &sitecode, &usercode, &fullcode, &Q5) == -1) return usage_lf_presco_sim();
uint8_t clk = 32, encoding = 1, separator = 1, invert = 0;
uint16_t arg1, arg2;
size_t size = 128;
arg1 = clk << 8 | encoding;
arg2 = invert << 8 | separator;
PrintAndLogEx(SUCCESS, "Simulating Presco - SiteCode: %u, UserCode: %u, FullCode: %08X", sitecode, usercode, fullcode);
UsbCommand c = {CMD_ASK_SIM_TAG, {arg1, arg2, size}, {{0}}};
GetPrescoBits(fullcode, c.d.asBytes);
clearCommandBuffer();
SendCommand(&c);
return 0;
}
static command_t CommandTable[] = {
{"help", CmdHelp, 1, "This help"},
{"read", CmdPrescoRead, 0, "Attempt to read and Extract tag data"},
{"clone", CmdPrescoClone, 0, "clone presco tag"},
{"sim", CmdPrescoSim, 0, "simulate presco tag"},
{NULL, NULL, 0, NULL}
};
int CmdLFPresco(const char *Cmd) {
clearCommandBuffer();
CmdsParse(CommandTable, Cmd);
return 0;
}
int CmdHelp(const char *Cmd) {
(void)Cmd; // Cmd is not used so far
CmdsHelp(CommandTable);
return 0;
}

View file

@ -22,13 +22,11 @@
#include "lfdemod.h" // parityTest
int CmdLFPresco(const char *Cmd);
int CmdPrescoRead(const char *Cmd);
int CmdPrescoDemod(const char *Cmd);
int CmdPrescoClone(const char *Cmd);
int CmdPrescoSim(const char *Cmd);
int demodPresco(void);
int detectPresco(uint8_t *dest, size_t *size);
int GetWiegandFromPresco(const char *Cmd, uint32_t *sitecode, uint32_t *usercode, uint32_t *fullcode, bool *Q5);
int getPrescoBits(uint32_t fullcode, uint8_t *prescoBits);
int getWiegandFromPresco(const char *Cmd, uint32_t *sitecode, uint32_t *usercode, uint32_t *fullcode, bool *Q5);
#endif

View file

@ -45,63 +45,6 @@ static int usage_lf_pyramid_sim(void) {
return 0;
}
// by marshmellow
// FSK Demod then try to locate a Farpointe Data (pyramid) ID
int detectPyramid(uint8_t *dest, size_t *size, int *waveStartIdx) {
//make sure buffer has data
if (*size < 128 * 50) return -1;
//test samples are not just noise
if (getSignalProperties()->isnoise) return -2;
// FSK demodulator RF/50 FSK 10,8
*size = fskdemod(dest, *size, 50, 1, 10, 8, waveStartIdx); // pyramid fsk2
//did we get a good demod?
if (*size < 128) return -3;
size_t startIdx = 0;
uint8_t preamble[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1};
if (!preambleSearch(dest, preamble, sizeof(preamble), size, &startIdx))
return -4; //preamble not found
// wrong size? (between to preambles)
if (*size != 128) return -5;
return (int)startIdx;
}
// Works for 26bits.
static int GetPyramidBits(uint32_t fc, uint32_t cn, uint8_t *pyramidBits) {
uint8_t pre[128];
memset(pre, 0x00, sizeof(pre));
// format start bit
pre[79] = 1;
// Get 26 wiegand from FacilityCode, CardNumber
uint8_t wiegand[24];
memset(wiegand, 0x00, sizeof(wiegand));
num_to_bytebits(fc, 8, wiegand);
num_to_bytebits(cn, 16, wiegand + 8);
// add wiegand parity bits (dest, source, len)
wiegand_add_parity(pre + 80, wiegand, 24);
// add paritybits (bitsource, dest, sourcelen, paritylen, parityType (odd, even,)
addParity(pre + 8, pyramidBits + 8, 102, 8, 1);
// add checksum
uint8_t csBuff[13];
for (uint8_t i = 0; i < 13; i++)
csBuff[i] = bytebits_to_byte(pyramidBits + 16 + (i * 8), 8);
uint32_t crc = CRC8Maxim(csBuff, 13);
num_to_bytebits(crc, 8, pyramidBits + 120);
return 1;
}
//by marshmellow
//Pyramid Prox demod - FSK RF/50 with preamble of 0000000000000001 (always a 128 bit data stream)
//print full Farpointe Data/Pyramid Prox ID and some bit format details if found
@ -269,7 +212,7 @@ int CmdPyramidClone(const char *Cmd) {
facilitycode = (fc & 0x000000FF);
cardnumber = (cn & 0x0000FFFF);
if (!GetPyramidBits(facilitycode, cardnumber, bs)) {
if (!getPyramidBits(facilitycode, cardnumber, bs)) {
PrintAndLogEx(WARNING, "Error with tag bitstream generation.");
return 1;
}
@ -327,7 +270,7 @@ int CmdPyramidSim(const char *Cmd) {
facilitycode = (fc & 0x000000FF);
cardnumber = (cn & 0x0000FFFF);
if (!GetPyramidBits(facilitycode, cardnumber, bs)) {
if (!getPyramidBits(facilitycode, cardnumber, bs)) {
PrintAndLogEx(WARNING, "Error with tag bitstream generation.");
return 1;
}
@ -361,3 +304,65 @@ int CmdHelp(const char *Cmd) {
CmdsHelp(CommandTable);
return 0;
}
// Works for 26bits.
int getPyramidBits(uint32_t fc, uint32_t cn, uint8_t *pyramidBits) {
uint8_t pre[128];
memset(pre, 0x00, sizeof(pre));
// format start bit
pre[79] = 1;
// Get 26 wiegand from FacilityCode, CardNumber
uint8_t wiegand[24];
memset(wiegand, 0x00, sizeof(wiegand));
num_to_bytebits(fc, 8, wiegand);
num_to_bytebits(cn, 16, wiegand + 8);
// add wiegand parity bits (dest, source, len)
wiegand_add_parity(pre + 80, wiegand, 24);
// add paritybits (bitsource, dest, sourcelen, paritylen, parityType (odd, even,)
addParity(pre + 8, pyramidBits + 8, 102, 8, 1);
// add checksum
uint8_t csBuff[13];
for (uint8_t i = 0; i < 13; i++)
csBuff[i] = bytebits_to_byte(pyramidBits + 16 + (i * 8), 8);
uint32_t crc = CRC8Maxim(csBuff, 13);
num_to_bytebits(crc, 8, pyramidBits + 120);
return 1;
}
int demodPyramid(void) {
return CmdPyramidDemod("");
}
// by marshmellow
// FSK Demod then try to locate a Farpointe Data (pyramid) ID
int detectPyramid(uint8_t *dest, size_t *size, int *waveStartIdx) {
//make sure buffer has data
if (*size < 128 * 50) return -1;
//test samples are not just noise
if (getSignalProperties()->isnoise) return -2;
// FSK demodulator RF/50 FSK 10,8
*size = fskdemod(dest, *size, 50, 1, 10, 8, waveStartIdx); // pyramid fsk2
//did we get a good demod?
if (*size < 128) return -3;
size_t startIdx = 0;
uint8_t preamble[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1};
if (!preambleSearch(dest, preamble, sizeof(preamble), size, &startIdx))
return -4; //preamble not found
// wrong size? (between to preambles)
if (*size != 128) return -5;
return (int)startIdx;
}

View file

@ -23,11 +23,9 @@
#include "crc.h"
int CmdLFPyramid(const char *Cmd);
int CmdPyramidDemod(const char *Cmd);
int CmdPyramidRead(const char *Cmd);
int CmdPyramidClone(const char *Cmd);
int CmdPyramidSim(const char *Cmd);
int demodPyramid(void);
int detectPyramid(uint8_t *dest, size_t *size, int *waveStartIdx);
int getPyramidBits(uint32_t fc, uint32_t cn, uint8_t *pyramidBits);
#endif

View file

@ -11,19 +11,6 @@
static int CmdHelp(const char *Cmd);
// by marshmellow
// find Securakey preamble in already demoded data
static int detectSecurakey(uint8_t *dest, size_t *size) {
if (*size < 96) return -1; //make sure buffer has data
size_t startIdx = 0;
uint8_t preamble[] = {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1};
if (!preambleSearch(dest, preamble, sizeof(preamble), size, &startIdx))
return -2; //preamble not found
if (*size != 96) return -3; //wrong demoded size
//return start position
return (int)startIdx;
}
//see ASKDemod for what args are accepted
int CmdSecurakeyDemod(const char *Cmd) {
(void)Cmd; // Cmd is not used so far
@ -132,3 +119,21 @@ int CmdHelp(const char *Cmd) {
CmdsHelp(CommandTable);
return 0;
}
// by marshmellow
// find Securakey preamble in already demoded data
int detectSecurakey(uint8_t *dest, size_t *size) {
if (*size < 96) return -1; //make sure buffer has data
size_t startIdx = 0;
uint8_t preamble[] = {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1};
if (!preambleSearch(dest, preamble, sizeof(preamble), size, &startIdx))
return -2; //preamble not found
if (*size != 96) return -3; //wrong demoded size
//return start position
return (int)startIdx;
}
int demodSecurakey(void) {
return CmdSecurakeyDemod("");
}

View file

@ -25,10 +25,9 @@
#include "parity.h" // for wiegand parity test
int CmdLFSecurakey(const char *Cmd);
//int CmdSecurakeyClone(const char *Cmd);
//int CmdSecurakeySim(const char *Cmd);
int CmdSecurakeyRead(const char *Cmd);
int CmdSecurakeyDemod(const char *Cmd);
int demodSecurakey(void);
int detectSecurakey(uint8_t *dest, size_t *size);
#endif

View file

@ -139,17 +139,6 @@ void Set_t55xx_Config(t55xx_conf_block_t conf);
int CmdLFT55XX(const char *Cmd);
int CmdT55xxChk(const char *Cmd);
int CmdT55xxBruteForce(const char *Cmd);
int CmdT55xxSetConfig(const char *Cmd);
int CmdT55xxReadBlock(const char *Cmd);
int CmdT55xxWriteBlock(const char *Cmd);
int CmdT55xxReadTrace(const char *Cmd);
int CmdT55xxInfo(const char *Cmd);
int CmdT55xxDetect(const char *Cmd);
int CmdResetRead(const char *Cmd);
int CmdT55xxWipe(const char *Cmd);
char *GetPskCfStr(uint32_t id, bool q5);
char *GetBitRateStr(uint32_t id, bool xmode);
char *GetSaferStr(uint32_t id);

View file

@ -318,3 +318,8 @@ int CmdHelp(const char *Cmd) {
CmdsHelp(CommandTable);
return 0;
}
int demodTI(void) {
return CmdTIDemod("");
}

View file

@ -13,8 +13,5 @@
int CmdLFTI(const char *Cmd);
int CmdTIDemod(const char *Cmd);
int CmdTIRead(const char *Cmd);
int CmdTIWrite(const char *Cmd);
int demodTI(void);
#endif

View file

@ -37,38 +37,6 @@ static int usage_lf_viking_sim(void) {
return 0;
}
// calc checksum
static uint64_t getVikingBits(uint32_t id) {
uint8_t checksum = ((id >> 24) & 0xFF) ^ ((id >> 16) & 0xFF) ^ ((id >> 8) & 0xFF) ^ (id & 0xFF) ^ 0xF2 ^ 0xA8;
uint64_t ret = (uint64_t)0xF2 << 56;
ret |= (uint64_t)id << 8;
ret |= checksum;
return ret;
}
// by marshmellow
// find viking preamble 0xF200 in already demoded data
int detectViking(uint8_t *dest, size_t *size) {
//make sure buffer has data
if (*size < 64 * 2) return -2;
size_t startIdx = 0;
uint8_t preamble[] = {1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
if (!preambleSearch(dest, preamble, sizeof(preamble), size, &startIdx))
return -4; //preamble not found
uint32_t checkCalc = bytebits_to_byte(dest + startIdx, 8) ^
bytebits_to_byte(dest + startIdx + 8, 8) ^
bytebits_to_byte(dest + startIdx + 16, 8) ^
bytebits_to_byte(dest + startIdx + 24, 8) ^
bytebits_to_byte(dest + startIdx + 32, 8) ^
bytebits_to_byte(dest + startIdx + 40, 8) ^
bytebits_to_byte(dest + startIdx + 48, 8) ^
bytebits_to_byte(dest + startIdx + 56, 8);
if (checkCalc != 0xA8) return -5;
if (*size != 64) return -6;
//return start position
return (int)startIdx;
}
//by marshmellow
//see ASKDemod for what args are accepted
int CmdVikingDemod(const char *Cmd) {
@ -178,3 +146,40 @@ int CmdHelp(const char *Cmd) {
CmdsHelp(CommandTable);
return 0;
}
// calc checksum
uint64_t getVikingBits(uint32_t id) {
uint8_t checksum = ((id >> 24) & 0xFF) ^ ((id >> 16) & 0xFF) ^ ((id >> 8) & 0xFF) ^ (id & 0xFF) ^ 0xF2 ^ 0xA8;
uint64_t ret = (uint64_t)0xF2 << 56;
ret |= (uint64_t)id << 8;
ret |= checksum;
return ret;
}
// by marshmellow
// find viking preamble 0xF200 in already demoded data
int detectViking(uint8_t *dest, size_t *size) {
//make sure buffer has data
if (*size < 64 * 2) return -2;
size_t startIdx = 0;
uint8_t preamble[] = {1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
if (!preambleSearch(dest, preamble, sizeof(preamble), size, &startIdx))
return -4; //preamble not found
uint32_t checkCalc = bytebits_to_byte(dest + startIdx, 8) ^
bytebits_to_byte(dest + startIdx + 8, 8) ^
bytebits_to_byte(dest + startIdx + 16, 8) ^
bytebits_to_byte(dest + startIdx + 24, 8) ^
bytebits_to_byte(dest + startIdx + 32, 8) ^
bytebits_to_byte(dest + startIdx + 40, 8) ^
bytebits_to_byte(dest + startIdx + 48, 8) ^
bytebits_to_byte(dest + startIdx + 56, 8);
if (checkCalc != 0xA8) return -5;
if (*size != 64) return -6;
//return start position
return (int)startIdx;
}
int demodViking(void) {
return CmdVikingDemod("");
}

View file

@ -23,12 +23,9 @@
int CmdLFViking(const char *Cmd);
int CmdVikingDemod(const char *Cmd);
int CmdVikingRead(const char *Cmd);
int CmdVikingClone(const char *Cmd);
int CmdVikingSim(const char *Cmd);
int demodViking(void);
int detectViking(uint8_t *dest, size_t *size);
uint64_t getVikingBits(uint32_t id);
#endif

View file

@ -69,19 +69,6 @@ static uint8_t visa_parity(uint32_t id) {
return par;
}
// by iceman
// find Visa2000 preamble in already demoded data
int detectVisa2k(uint8_t *dest, size_t *size) {
if (*size < 96) return -1; //make sure buffer has data
size_t startIdx = 0;
uint8_t preamble[] = {0, 1, 0, 1, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 0};
if (!preambleSearch(dest, preamble, sizeof(preamble), size, &startIdx))
return -2; //preamble not found
if (*size != 96) return -3; //wrong demoded size
//return start position
return (int)startIdx;
}
/**
*
* 56495332 00096ebd 00000077 > tag id 618173
@ -243,3 +230,21 @@ int CmdHelp(const char *Cmd) {
CmdsHelp(CommandTable);
return 0;
}
// by iceman
// find Visa2000 preamble in already demoded data
int detectVisa2k(uint8_t *dest, size_t *size) {
if (*size < 96) return -1; //make sure buffer has data
size_t startIdx = 0;
uint8_t preamble[] = {0, 1, 0, 1, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 0};
if (!preambleSearch(dest, preamble, sizeof(preamble), size, &startIdx))
return -2; //preamble not found
if (*size != 96) return -3; //wrong demoded size
//return start position
return (int)startIdx;
}
int demodVisa2k(void) {
return CmdVisa2kDemod("");
}

View file

@ -23,12 +23,8 @@
#include "lfdemod.h" // parityTest
int CmdLFVisa2k(const char *Cmd);
int CmdVisa2kDemod(const char *Cmd);
int CmdVisa2kRead(const char *Cmd);
int CmdVisa2kClone(const char *Cmd);
int CmdVisa2kSim(const char *Cmd);
int getvisa2kBits(uint64_t fullcode, uint8_t *bits);
int demodVisa2k(void);
int detectVisa2k(uint8_t *dest, size_t *size);
#endif

View file

@ -11,9 +11,28 @@
#include "cmdmain.h"
static int CmdHelp(const char *Cmd);
static int CmdQuit(const char *Cmd);
static int CmdRev(const char *Cmd);
static int CmdRem(const char *Cmd);
static int CmdRem(const char *Cmd) {
char buf[22];
memset(buf, 0x00, sizeof(buf));
struct tm *curTime;
time_t now = time(0);
curTime = gmtime(&now);
strftime(buf, sizeof(buf), "%Y-%m-%dT%H:%M:%SZ", curTime); // ISO8601
PrintAndLogEx(NORMAL, "%s remark: %s", buf, Cmd);
return 0;
}
static int CmdQuit(const char *Cmd) {
(void)Cmd; // Cmd is not used so far
return 99;
}
static int CmdRev(const char *Cmd) {
CmdCrc(Cmd);
return 0;
}
static command_t CommandTable[] = {
{"help", CmdHelp, 1, "This help. Use '<command> help' for details of a particular command."},
@ -38,38 +57,12 @@ static command_t CommandTable[] = {
{NULL, NULL, 0, NULL}
};
command_t *getTopLevelCommandTable() {
return CommandTable;
}
int CmdRem(const char *Cmd) {
char buf[22];
memset(buf, 0x00, sizeof(buf));
struct tm *curTime;
time_t now = time(0);
curTime = gmtime(&now);
strftime(buf, sizeof(buf), "%Y-%m-%dT%H:%M:%SZ", curTime); // ISO8601
PrintAndLogEx(NORMAL, "%s remark: %s", buf, Cmd);
return 0;
}
int CmdHelp(const char *Cmd) {
static int CmdHelp(const char *Cmd) {
(void)Cmd; // Cmd is not used so far
CmdsHelp(CommandTable);
return 0;
}
int CmdQuit(const char *Cmd) {
(void)Cmd; // Cmd is not used so far
return 99;
}
int CmdRev(const char *Cmd) {
CmdCrc(Cmd);
return 0;
}
//-----------------------------------------------------------------------------
// Entry point into our code: called whenever the user types a command and
// then presses Enter, which the full command line that they typed.
@ -77,3 +70,8 @@ int CmdRev(const char *Cmd) {
int CommandReceived(char *Cmd) {
return CmdsParse(CommandTable, Cmd);
}
command_t *getTopLevelCommandTable() {
return CommandTable;
}

View file

@ -67,7 +67,7 @@ static bool endsWith(const char *base, const char *str) {
* generate a file listing of the script-directory for files
* ending with .lua
*/
int CmdScriptList(const char *Cmd) {
static int CmdScriptList(const char *Cmd) {
(void)Cmd; // Cmd is not used so far
char const *exedir = get_my_executable_directory();
@ -102,7 +102,7 @@ int CmdScriptList(const char *Cmd) {
* @param argv
* @return
*/
int CmdScriptRun(const char *Cmd) {
static int CmdScriptRun(const char *Cmd) {
// create new Lua state
lua_State *lua_state;
lua_state = luaL_newstate();
@ -173,6 +173,18 @@ static command_t CommandTable[] = {
{NULL, NULL, 0, NULL}
};
/**
* Shows some basic help
* @brief CmdHelp
* @param Cmd
* @return
*/
static int CmdHelp(const char *Cmd) {
(void)Cmd; // Cmd is not used so far
PrintAndLogEx(NORMAL, "This is a feature to run Lua-scripts. You can place lua-scripts within the scripts/-folder. ");
return 0;
}
/**
* Finds a matching script-file
* @brief CmdScript
@ -185,14 +197,3 @@ int CmdScript(const char *Cmd) {
return 0;
}
/**
* Shows some basic help
* @brief CmdHelp
* @param Cmd
* @return
*/
int CmdHelp(const char *Cmd) {
(void)Cmd; // Cmd is not used so far
PrintAndLogEx(NORMAL, "This is a feature to run Lua-scripts. You can place lua-scripts within the scripts/-folder. ");
return 0;
}

View file

@ -13,6 +13,4 @@
int CmdScript(const char *Cmd);
int CmdScriptList(const char *Cmd);
int CmdScriptRun(const char *Cmd);
#endif

View file

@ -308,37 +308,6 @@ static int PrintATR(uint8_t *atr, size_t atrlen) {
return 0;
}
bool smart_select(bool silent, smart_card_atr_t *atr) {
if (atr)
memset(atr, 0, sizeof(smart_card_atr_t));
UsbCommand c = {CMD_SMART_ATR, {0, 0, 0}, {{0}}};
clearCommandBuffer();
SendCommand(&c);
UsbCommand resp;
if (!WaitForResponseTimeout(CMD_ACK, &resp, 2500)) {
if (!silent) PrintAndLogEx(WARNING, "smart card select failed");
return false;
}
uint8_t isok = resp.arg[0] & 0xFF;
if (!isok) {
if (!silent) PrintAndLogEx(WARNING, "smart card select failed");
return false;
}
smart_card_atr_t card;
memcpy(&card, (smart_card_atr_t *)resp.d.asBytes, sizeof(smart_card_atr_t));
if (atr)
memcpy(atr, &card, sizeof(smart_card_atr_t));
if (!silent)
PrintAndLogEx(INFO, "ISO7816-3 ATR : %s", sprint_hex(card.atr, card.atr_len));
return true;
}
static int smart_wait(uint8_t *data, bool silent) {
UsbCommand resp;
if (!WaitForResponseTimeout(CMD_ACK, &resp, 2500)) {
@ -420,7 +389,7 @@ static int smart_response(uint8_t *data) {
return smart_responseEx(data, false);
}
int CmdSmartRaw(const char *Cmd) {
static int CmdSmartRaw(const char *Cmd) {
int hexlen = 0;
bool active = false;
@ -536,47 +505,7 @@ int CmdSmartRaw(const char *Cmd) {
return 0;
}
int ExchangeAPDUSC(uint8_t *datain, int datainlen, bool activateCard, bool leaveSignalON, uint8_t *dataout, int maxdataoutlen, int *dataoutlen) {
*dataoutlen = 0;
if (activateCard)
smart_select(false, NULL);
PrintAndLogEx(DEBUG, "APDU SC");
UsbCommand c = {CMD_SMART_RAW, {SC_RAW_T0, datainlen, 0}, {{0}}};
if (activateCard) {
c.arg[0] |= SC_SELECT | SC_CONNECT;
}
memcpy(c.d.asBytes, datain, datainlen);
clearCommandBuffer();
SendCommand(&c);
int len = smart_responseEx(dataout, true);
if (len < 0) {
return 1;
}
// retry
if (len > 1 && dataout[len - 2] == 0x6c && datainlen > 4) {
UsbCommand c2 = {CMD_SMART_RAW, {SC_RAW_T0, datainlen, 0}, {{0}}};
memcpy(c2.d.asBytes, datain, 5);
// transfer length via T=0
c2.d.asBytes[4] = dataout[len - 1];
clearCommandBuffer();
SendCommand(&c2);
len = smart_responseEx(dataout, true);
}
*dataoutlen = len;
return 0;
}
int CmdSmartUpgrade(const char *Cmd) {
static int CmdSmartUpgrade(const char *Cmd) {
PrintAndLogEx(WARNING, "WARNING - Sim module firmware upgrade.");
PrintAndLogEx(WARNING, "A dangerous command, do wrong and you could brick the sim module");
@ -763,7 +692,7 @@ int CmdSmartUpgrade(const char *Cmd) {
return 0;
}
int CmdSmartInfo(const char *Cmd) {
static int CmdSmartInfo(const char *Cmd) {
uint8_t cmdp = 0;
bool errors = false, silent = false;
@ -838,7 +767,7 @@ int CmdSmartInfo(const char *Cmd) {
return 0;
}
int CmdSmartReader(const char *Cmd) {
static int CmdSmartReader(const char *Cmd) {
uint8_t cmdp = 0;
bool errors = false, silent = false;
@ -881,7 +810,7 @@ int CmdSmartReader(const char *Cmd) {
return 0;
}
int CmdSmartSetClock(const char *Cmd) {
static int CmdSmartSetClock(const char *Cmd) {
uint8_t cmdp = 0;
bool errors = false;
uint8_t clock1 = 0;
@ -937,7 +866,7 @@ int CmdSmartSetClock(const char *Cmd) {
return 0;
}
int CmdSmartList(const char *Cmd) {
static int CmdSmartList(const char *Cmd) {
(void)Cmd; // Cmd is not used so far
CmdTraceList("7816");
return 0;
@ -1073,7 +1002,7 @@ static void smart_brute_options(bool decodeTLV) {
free(buf);
}
int CmdSmartBruteforceSFI(const char *Cmd) {
static int CmdSmartBruteforceSFI(const char *Cmd) {
uint8_t cmdp = 0;
bool errors = false, decodeTLV = false; //, useT0 = false;
@ -1229,14 +1158,86 @@ static command_t CommandTable[] = {
{NULL, NULL, 0, NULL}
};
static int CmdHelp(const char *Cmd) {
(void)Cmd; // Cmd is not used so far
CmdsHelp(CommandTable);
return 0;
}
int CmdSmartcard(const char *Cmd) {
clearCommandBuffer();
CmdsParse(CommandTable, Cmd);
return 0;
}
int CmdHelp(const char *Cmd) {
(void)Cmd; // Cmd is not used so far
CmdsHelp(CommandTable);
int ExchangeAPDUSC(uint8_t *datain, int datainlen, bool activateCard, bool leaveSignalON, uint8_t *dataout, int maxdataoutlen, int *dataoutlen) {
*dataoutlen = 0;
if (activateCard)
smart_select(false, NULL);
PrintAndLogEx(DEBUG, "APDU SC");
UsbCommand c = {CMD_SMART_RAW, {SC_RAW_T0, datainlen, 0}, {{0}}};
if (activateCard) {
c.arg[0] |= SC_SELECT | SC_CONNECT;
}
memcpy(c.d.asBytes, datain, datainlen);
clearCommandBuffer();
SendCommand(&c);
int len = smart_responseEx(dataout, true);
if (len < 0) {
return 1;
}
// retry
if (len > 1 && dataout[len - 2] == 0x6c && datainlen > 4) {
UsbCommand c2 = {CMD_SMART_RAW, {SC_RAW_T0, datainlen, 0}, {{0}}};
memcpy(c2.d.asBytes, datain, 5);
// transfer length via T=0
c2.d.asBytes[4] = dataout[len - 1];
clearCommandBuffer();
SendCommand(&c2);
len = smart_responseEx(dataout, true);
}
*dataoutlen = len;
return 0;
}
bool smart_select(bool silent, smart_card_atr_t *atr) {
if (atr)
memset(atr, 0, sizeof(smart_card_atr_t));
UsbCommand c = {CMD_SMART_ATR, {0, 0, 0}, {{0}}};
clearCommandBuffer();
SendCommand(&c);
UsbCommand resp;
if (!WaitForResponseTimeout(CMD_ACK, &resp, 2500)) {
if (!silent) PrintAndLogEx(WARNING, "smart card select failed");
return false;
}
uint8_t isok = resp.arg[0] & 0xFF;
if (!isok) {
if (!silent) PrintAndLogEx(WARNING, "smart card select failed");
return false;
}
smart_card_atr_t card;
memcpy(&card, (smart_card_atr_t *)resp.d.asBytes, sizeof(smart_card_atr_t));
if (atr)
memcpy(atr, &card, sizeof(smart_card_atr_t));
if (!silent)
PrintAndLogEx(INFO, "ISO7816-3 ATR : %s", sprint_hex(card.atr, card.atr_len));
return true;
}

View file

@ -29,11 +29,6 @@
int CmdSmartcard(const char *Cmd);
int CmdSmartRaw(const char *Cmd);
int CmdSmartUpgrade(const char *Cmd);
int CmdSmartInfo(const char *Cmd);
int CmdSmartReader(const char *Cmd);
bool smart_select(bool silent, smart_card_atr_t *atr);
int ExchangeAPDUSC(uint8_t *datain, int datainlen, bool activateCard, bool leaveSignalON, uint8_t *dataout, int maxdataoutlen, int *dataoutlen);

View file

@ -507,6 +507,89 @@ static int SanityOfflineCheck( bool useTraceBuffer ){
}
*/
static int CmdTraceLoad(const char *Cmd) {
FILE *f = NULL;
char filename[FILE_PATH_SIZE];
char cmdp = tolower(param_getchar(Cmd, 0));
if (strlen(Cmd) < 1 || cmdp == 'h') return usage_trace_load();
param_getstr(Cmd, 0, filename, sizeof(filename));
if ((f = fopen(filename, "rb")) == NULL) {
PrintAndLogEx(FAILED, "Could not open file %s", filename);
return 0;
}
// get filesize in order to malloc memory
fseek(f, 0, SEEK_END);
long fsize = ftell(f);
fseek(f, 0, SEEK_SET);
if (fsize < 0) {
PrintAndLogEx(FAILED, "error, when getting filesize");
fclose(f);
return 3;
}
if (fsize < 4) {
PrintAndLogEx(FAILED, "error, file is too small");
fclose(f);
return 4;
}
if (trace)
free(trace);
trace = calloc(fsize, sizeof(uint8_t));
if (!trace) {
PrintAndLogEx(FAILED, "Cannot allocate memory for trace");
fclose(f);
return 2;
}
size_t bytes_read = fread(trace, 1, fsize, f);
traceLen = bytes_read;
fclose(f);
PrintAndLogEx(SUCCESS, "Recorded Activity (TraceLen = %d bytes) loaded from file %s", traceLen, filename);
return 0;
}
static int CmdTraceSave(const char *Cmd) {
if (traceLen == 0) {
PrintAndLogEx(WARNING, "trace is empty, nothing to save");
return 0;
}
char filename[FILE_PATH_SIZE];
char cmdp = tolower(param_getchar(Cmd, 0));
if (strlen(Cmd) < 1 || cmdp == 'h') return usage_trace_save();
param_getstr(Cmd, 0, filename, sizeof(filename));
saveFile(filename, "bin", trace, traceLen);
return 0;
}
static command_t CommandTable[] = {
{"help", CmdHelp, 1, "This help"},
{"list", CmdTraceList, 1, "List protocol data in trace buffer"},
{"load", CmdTraceLoad, 1, "Load trace from file"},
{"save", CmdTraceSave, 1, "Save trace buffer to file"},
{NULL, NULL, 0, NULL}
};
static int CmdHelp(const char *Cmd) {
(void)Cmd; // Cmd is not used so far
CmdsHelp(CommandTable);
return 0;
}
int CmdTrace(const char *Cmd) {
clearCommandBuffer();
CmdsParse(CommandTable, Cmd);
return 0;
}
int CmdTraceList(const char *Cmd) {
clearCommandBuffer();
@ -644,85 +727,3 @@ int CmdTraceList(const char *Cmd) {
return 0;
}
int CmdTraceLoad(const char *Cmd) {
FILE *f = NULL;
char filename[FILE_PATH_SIZE];
char cmdp = tolower(param_getchar(Cmd, 0));
if (strlen(Cmd) < 1 || cmdp == 'h') return usage_trace_load();
param_getstr(Cmd, 0, filename, sizeof(filename));
if ((f = fopen(filename, "rb")) == NULL) {
PrintAndLogEx(FAILED, "Could not open file %s", filename);
return 0;
}
// get filesize in order to malloc memory
fseek(f, 0, SEEK_END);
long fsize = ftell(f);
fseek(f, 0, SEEK_SET);
if (fsize < 0) {
PrintAndLogEx(FAILED, "error, when getting filesize");
fclose(f);
return 3;
}
if (fsize < 4) {
PrintAndLogEx(FAILED, "error, file is too small");
fclose(f);
return 4;
}
if (trace)
free(trace);
trace = calloc(fsize, sizeof(uint8_t));
if (!trace) {
PrintAndLogEx(FAILED, "Cannot allocate memory for trace");
fclose(f);
return 2;
}
size_t bytes_read = fread(trace, 1, fsize, f);
traceLen = bytes_read;
fclose(f);
PrintAndLogEx(SUCCESS, "Recorded Activity (TraceLen = %d bytes) loaded from file %s", traceLen, filename);
return 0;
}
int CmdTraceSave(const char *Cmd) {
if (traceLen == 0) {
PrintAndLogEx(WARNING, "trace is empty, nothing to save");
return 0;
}
char filename[FILE_PATH_SIZE];
char cmdp = tolower(param_getchar(Cmd, 0));
if (strlen(Cmd) < 1 || cmdp == 'h') return usage_trace_save();
param_getstr(Cmd, 0, filename, sizeof(filename));
saveFile(filename, "bin", trace, traceLen);
return 0;
}
static command_t CommandTable[] = {
{"help", CmdHelp, 1, "This help"},
{"list", CmdTraceList, 1, "List protocol data in trace buffer"},
{"load", CmdTraceLoad, 1, "Load trace from file"},
{"save", CmdTraceSave, 1, "Save trace buffer to file"},
{NULL, NULL, 0, NULL}
};
int CmdTrace(const char *Cmd) {
clearCommandBuffer();
CmdsParse(CommandTable, Cmd);
return 0;
}
int CmdHelp(const char *Cmd) {
(void)Cmd; // Cmd is not used so far
CmdsHelp(CommandTable);
return 0;
}

View file

@ -28,9 +28,6 @@
#include "loclass/fileutils.h" // for saveFile
int CmdTrace(const char *Cmd);
int CmdTraceList(const char *Cmd);
int CmdTraceLoad(const char *Cmd);
int CmdTraceSave(const char *Cmd);
#endif