rename globals DemodBuffer and DemodBufferLen

This commit is contained in:
Philippe Teuwen
2021-08-21 17:12:50 +02:00
parent 45d4d361e9
commit e4fbfe0f40
34 changed files with 445 additions and 445 deletions
+7 -7
View File
@@ -23,7 +23,7 @@
#include "crc32.h" // crc32_ex
#include "tea.h"
#include "legic_prng.h"
#include "cmddata.h" // demodbuffer
#include "cmddata.h" // g_DemodBuffer
#include "graph.h"
#include "proxgui.h"
#include "cliparser.h"
@@ -936,7 +936,7 @@ static int CmdAnalyseNuid(const char *Cmd) {
static int CmdAnalyseDemodBuffer(const char *Cmd) {
CLIParserContext *ctx;
CLIParserInit(&ctx, "analyse demodbuff",
"loads a binary string into demod buffer",
"loads a binary string into DemodBuffer",
"analyse demodbuff -d 0011101001001011"
);
@@ -959,9 +959,9 @@ static int CmdAnalyseDemodBuffer(const char *Cmd) {
for (size_t i = 0; i <= strlen(s); i++) {
char c = s[i];
if (c == '1')
DemodBuffer[i] = 1;
g_DemodBuffer[i] = 1;
if (c == '0')
DemodBuffer[i] = 0;
g_DemodBuffer[i] = 0;
PrintAndLogEx(NORMAL, "%c" NOLF, c);
}
@@ -969,9 +969,9 @@ static int CmdAnalyseDemodBuffer(const char *Cmd) {
CLIParserFree(ctx);
PrintAndLogEx(NORMAL, "");
DemodBufferLen = len;
g_DemodBufferLen = len;
free(data);
PrintAndLogEx(HINT, "Use `" _YELLOW_("data print") "` to view demod buffer");
PrintAndLogEx(HINT, "Use `" _YELLOW_("data print") "` to view DemodBuffer");
return PM3_SUCCESS;
}
@@ -1164,7 +1164,7 @@ static command_t CommandTable[] = {
{"lfsr", CmdAnalyseLfsr, AlwaysAvailable, "LFSR tests"},
{"a", CmdAnalyseA, AlwaysAvailable, "num bits test"},
{"nuid", CmdAnalyseNuid, AlwaysAvailable, "create NUID from 7byte UID"},
{"demodbuff", CmdAnalyseDemodBuffer, AlwaysAvailable, "Load binary string to demodbuffer"},
{"demodbuff", CmdAnalyseDemodBuffer, AlwaysAvailable, "Load binary string to DemodBuffer"},
{"freq", CmdAnalyseFreq, AlwaysAvailable, "Calc wave lengths"},
{"foo", CmdAnalyseFoo, AlwaysAvailable, "muxer"},
{"units", CmdAnalyseUnits, AlwaysAvailable, "convert ETU <> US <> SSP_CLK (3.39MHz)"},
+43 -43
View File
@@ -29,14 +29,14 @@
#include "cmdlft55xx.h" // print...
#include "crypto/asn1utils.h" // ASN1 decode / print
uint8_t DemodBuffer[MAX_DEMOD_BUF_LEN];
size_t DemodBufferLen = 0;
uint8_t g_DemodBuffer[MAX_DEMOD_BUF_LEN];
size_t g_DemodBufferLen = 0;
int32_t g_DemodStartIdx = 0;
int g_DemodClock = 0;
static int CmdHelp(const char *Cmd);
//set the demod buffer with given array ofq binary (one bit per byte)
//set the g_DemodBuffer with given array ofq binary (one bit per byte)
//by marshmellow
void setDemodBuff(uint8_t *buff, size_t size, size_t start_idx) {
if (buff == NULL) return;
@@ -45,9 +45,9 @@ void setDemodBuff(uint8_t *buff, size_t size, size_t start_idx) {
size = MAX_DEMOD_BUF_LEN - start_idx;
for (size_t i = 0; i < size; i++)
DemodBuffer[i] = buff[start_idx++];
g_DemodBuffer[i] = buff[start_idx++];
DemodBufferLen = size;
g_DemodBufferLen = size;
}
bool getDemodBuff(uint8_t *buff, size_t *size) {
@@ -55,9 +55,9 @@ bool getDemodBuff(uint8_t *buff, size_t *size) {
if (size == NULL) return false;
if (*size == 0) return false;
*size = (*size > DemodBufferLen) ? DemodBufferLen : *size;
*size = (*size > g_DemodBufferLen) ? g_DemodBufferLen : *size;
memcpy(buff, DemodBuffer, *size);
memcpy(buff, g_DemodBuffer, *size);
return true;
}
@@ -139,7 +139,7 @@ static double compute_autoc(const int *data, size_t n, int lag) {
}
*/
// option '1' to save DemodBuffer any other to restore
// option '1' to save g_DemodBuffer any other to restore
void save_restoreDB(uint8_t saveOpt) {
static uint8_t SavedDB[MAX_DEMOD_BUF_LEN];
static size_t SavedDBlen;
@@ -149,15 +149,15 @@ void save_restoreDB(uint8_t saveOpt) {
if (saveOpt == GRAPH_SAVE) { //save
memcpy(SavedDB, DemodBuffer, sizeof(DemodBuffer));
SavedDBlen = DemodBufferLen;
memcpy(SavedDB, g_DemodBuffer, sizeof(g_DemodBuffer));
SavedDBlen = g_DemodBufferLen;
DB_Saved = true;
savedDemodStartIdx = g_DemodStartIdx;
savedDemodClock = g_DemodClock;
} else if (DB_Saved) { //restore
memcpy(DemodBuffer, SavedDB, sizeof(DemodBuffer));
DemodBufferLen = SavedDBlen;
memcpy(g_DemodBuffer, SavedDB, sizeof(g_DemodBuffer));
g_DemodBufferLen = SavedDBlen;
g_DemodClock = savedDemodClock;
g_DemodStartIdx = savedDemodStartIdx;
}
@@ -215,9 +215,9 @@ static int CmdSetDebugMode(const char *Cmd) {
// max output to 512 bits if we have more
// doesn't take inconsideration where the demod offset or bitlen found.
int printDemodBuff(uint8_t offset, bool strip_leading, bool invert, bool print_hex) {
size_t len = DemodBufferLen;
size_t len = g_DemodBufferLen;
if (len == 0) {
PrintAndLogEx(WARNING, "Demodbuffer is empty");
PrintAndLogEx(WARNING, "DemodBuffer is empty");
return PM3_EINVARG;
}
@@ -226,15 +226,15 @@ int printDemodBuff(uint8_t offset, bool strip_leading, bool invert, bool print_h
PrintAndLogEx(WARNING, "dail, cannot allocate memory");
return PM3_EMALLOC;
}
memcpy(buf, DemodBuffer, len);
memcpy(buf, g_DemodBuffer, len);
uint8_t *p = NULL;
if (strip_leading) {
p = (buf + offset);
if (len > (DemodBufferLen - offset))
len = (DemodBufferLen - offset);
if (len > (g_DemodBufferLen - offset))
len = (g_DemodBufferLen - offset);
size_t i;
for (i = 0; i < len; i++) {
@@ -243,8 +243,8 @@ int printDemodBuff(uint8_t offset, bool strip_leading, bool invert, bool print_h
offset += i;
}
if (len > (DemodBufferLen - offset)) {
len = (DemodBufferLen - offset);
if (len > (g_DemodBufferLen - offset)) {
len = (g_DemodBufferLen - offset);
}
if (len > 512) {
@@ -291,7 +291,7 @@ int CmdPrintDemodBuff(const char *Cmd) {
);
void *argtable[] = {
arg_param_begin,
arg_lit0("i", "inv", "invert Demodbuffer before printing"),
arg_lit0("i", "inv", "invert DemodBuffer before printing"),
// arg_int0("l","len", "<dec>", "length to print in # of bits or hex characters respectively"),
arg_int0("o", "offset", "<dec>", "offset in # of bits"),
arg_lit0("s", "strip", "strip leading zeroes, i.e. set offset to first bit equal to one"),
@@ -535,7 +535,7 @@ static int Cmdmandecoderaw(const char *Cmd) {
CLIParserInit(&ctx, "data manrawdecode",
"Manchester decode binary stream in DemodBuffer\n"
"Converts 10 and 01 and converts to 0 and 1 respectively\n"
" - must have binary sequence in demodbuffer (run `data rawdemod --ar` before)",
" - must have binary sequence in DemodBuffer (run `data rawdemod --ar` before)",
"data manrawdecode"
);
void *argtable[] = {
@@ -549,7 +549,7 @@ static int Cmdmandecoderaw(const char *Cmd) {
int max_err = arg_get_int_def(ctx, 2, 20);
CLIParserFree(ctx);
if (DemodBufferLen == 0) {
if (g_DemodBufferLen == 0) {
PrintAndLogEx(WARNING, "DemodBuffer empty, run " _YELLOW_("`data rawdemod --ar`"));
return PM3_ESOFT;
}
@@ -559,12 +559,12 @@ static int Cmdmandecoderaw(const char *Cmd) {
// make sure its just binary data 0|1|7 in buffer
int high = 0, low = 0;
size_t i = 0;
for (; i < DemodBufferLen; ++i) {
if (DemodBuffer[i] > high)
high = DemodBuffer[i];
else if (DemodBuffer[i] < low)
low = DemodBuffer[i];
bits[i] = DemodBuffer[i];
for (; i < g_DemodBufferLen; ++i) {
if (g_DemodBuffer[i] > high)
high = g_DemodBuffer[i];
else if (g_DemodBuffer[i] < low)
low = g_DemodBuffer[i];
bits[i] = g_DemodBuffer[i];
}
if (high > 7 || low < 0) {
@@ -618,10 +618,10 @@ static int CmdBiphaseDecodeRaw(const char *Cmd) {
CLIParserInit(&ctx, "data biphaserawdecode",
"Biphase decode binary stream in DemodBuffer\n"
"Converts 10 or 01 -> 1 and 11 or 00 -> 0\n"
" - must have binary sequence in demodbuffer (run `data rawdemod --ar` before)\n"
" - must have binary sequence in DemodBuffer (run `data rawdemod --ar` before)\n"
" - invert for Conditional Dephase Encoding (CDP) AKA Differential Manchester",
"data biphaserawdecode --> decode biphase bitstream from the demodbuffer\n"
"data biphaserawdecode -oi --> decode biphase bitstream from the demodbuffer, adjust offset, and invert output"
"data biphaserawdecode --> decode biphase bitstream from the DemodBuffer\n"
"data biphaserawdecode -oi --> decode biphase bitstream from the DemodBuffer, adjust offset, and invert output"
);
void *argtable[] = {
arg_param_begin,
@@ -636,7 +636,7 @@ static int CmdBiphaseDecodeRaw(const char *Cmd) {
int max_err = arg_get_int_def(ctx, 3, 20);
CLIParserFree(ctx);
if (DemodBufferLen == 0) {
if (g_DemodBufferLen == 0) {
PrintAndLogEx(WARNING, "DemodBuffer empty, run " _YELLOW_("`data rawdemod --ar`"));
return PM3_ESOFT;
}
@@ -699,7 +699,7 @@ int ASKbiphaseDemod(int offset, int clk, int invert, int maxErr, bool verbose) {
if (offset >= 1) {
offset -= 1;
}
//success set DemodBuffer and return
//success set g_DemodBuffer and return
setDemodBuff(bs, size, 0);
setClockGrid(clk, startIdx + clk * offset / 2);
if (g_debugMode || verbose) {
@@ -853,7 +853,7 @@ int AutoCorrelate(const int *in, int *out, size_t len, size_t window, bool SaveG
CursorCPos = idx_1;
CursorDPos = idx_1 + retval;
DemodBufferLen = 0;
g_DemodBufferLen = 0;
RepaintGraphWindow();
}
free(correl_buf);
@@ -1308,7 +1308,7 @@ int PSKDemod(int clk, int invert, int maxErr, bool verbose) {
PrintAndLogEx(DEBUG, "DEBUG: (PSKdemod) errors during Demoding (shown as 7 in bit stream): %d", errCnt);
}
}
//prime demod buffer for output
//prime g_DemodBuffer for output
setDemodBuff(bits, bitlen, 0);
setClockGrid(clk, startIdx);
free(bits);
@@ -1317,7 +1317,7 @@ int PSKDemod(int clk, int invert, int maxErr, bool verbose) {
// takes 3 arguments - clock, invert, maxErr as integers
// attempts to demodulate nrz only
// prints binary found and saves in demodbuffer for further commands
// prints binary found and saves in g_DemodBuffer for further commands
int NRZrawDemod(int clk, int invert, int maxErr, bool verbose) {
int errCnt = 0, clkStartIdx = 0;
@@ -1355,7 +1355,7 @@ int NRZrawDemod(int clk, int invert, int maxErr, bool verbose) {
}
if (verbose || g_debugMode) PrintAndLogEx(DEBUG, "DEBUG: (NRZrawDemod) Tried NRZ Demod using Clock: %d - invert: %d - Bits Found: %zu", clk, invert, bitlen);
//prime demod buffer for output
//prime g_DemodBuffer for output
setDemodBuff(bits, bitlen, 0);
setClockGrid(clk, clkStartIdx);
@@ -1400,7 +1400,7 @@ static int CmdNRZrawDemod(const char *Cmd) {
// takes 3 arguments - clock, invert, max_err as integers
// attempts to demodulate psk only
// prints binary found and saves in demodbuffer for further commands
// prints binary found and saves in g_DemodBuffer for further commands
int CmdPSK1rawDemod(const char *Cmd) {
CLIParserContext *ctx;
CLIParserInit(&ctx, "data rawdemod --p1",
@@ -1468,7 +1468,7 @@ static int CmdPSK2rawDemod(const char *Cmd) {
if (g_debugMode) PrintAndLogEx(ERR, "Error demoding: %d", ans);
return PM3_ESOFT;
}
psk1TOpsk2(DemodBuffer, DemodBufferLen);
psk1TOpsk2(g_DemodBuffer, g_DemodBufferLen);
PrintAndLogEx(SUCCESS, _YELLOW_("PSK2") " demoded bitstream");
PrintAndLogEx(INFO, "----------------------");
// Now output the bitstream to the scrollback by line of 16 bits
@@ -1794,7 +1794,7 @@ int getSamplesEx(uint32_t start, uint32_t end, bool verbose) {
computeSignalProperties(bits, size);
setClockGrid(0, 0);
DemodBufferLen = 0;
g_DemodBufferLen = 0;
RepaintGraphWindow();
return PM3_SUCCESS;
}
@@ -1845,7 +1845,7 @@ int CmdTuneSamples(const char *Cmd) {
#define ANTENNA_ERROR 1.00 // current algo has 3% error margin.
// hide demod plot line
DemodBufferLen = 0;
g_DemodBufferLen = 0;
setClockGrid(0, 0);
RepaintGraphWindow();
@@ -2071,7 +2071,7 @@ static int CmdLoad(const char *Cmd) {
computeSignalProperties(bits, size);
setClockGrid(0, 0);
DemodBufferLen = 0;
g_DemodBufferLen = 0;
RepaintGraphWindow();
return PM3_SUCCESS;
}
@@ -2663,7 +2663,7 @@ static int CmdFSKToNRZ(const char *Cmd) {
CLIParserFree(ctx);
setClockGrid(0, 0);
DemodBufferLen = 0;
g_DemodBufferLen = 0;
int ans = FSKToNRZ(GraphBuffer, &GraphTraceLen, clk, fc_low, fc_high);
CmdNorm("");
RepaintGraphWindow();
+3 -3
View File
@@ -72,7 +72,7 @@ int printDemodBuff(uint8_t offset, bool strip_leading, bool invert, bool print_h
void setDemodBuff(uint8_t *buff, size_t size, size_t start_idx);
bool getDemodBuff(uint8_t *buff, size_t *size);
void save_restoreDB(uint8_t saveOpt);// option '1' to save DemodBuffer any other to restore
void save_restoreDB(uint8_t saveOpt);// option '1' to save g_DemodBuffer any other to restore
int AutoCorrelate(const int *in, int *out, size_t len, size_t window, bool SaveGrph, bool verbose);
int getSamples(uint32_t n, bool verbose);
@@ -83,8 +83,8 @@ int directionalThreshold(const int *in, int *out, size_t len, int8_t up, int8_t
int AskEdgeDetect(const int *in, int *out, int len, int threshold);
#define MAX_DEMOD_BUF_LEN (1024*128)
extern uint8_t DemodBuffer[MAX_DEMOD_BUF_LEN];
extern size_t DemodBufferLen;
extern uint8_t g_DemodBuffer[MAX_DEMOD_BUF_LEN];
extern size_t g_DemodBufferLen;
extern int g_DemodClock;
extern int32_t g_DemodStartIdx;
+1 -1
View File
@@ -376,7 +376,7 @@ int handle_hf_plot(void) {
CmdHpf("");
setClockGrid(0, 0);
DemodBufferLen = 0;
g_DemodBufferLen = 0;
RepaintGraphWindow();
return PM3_SUCCESS;
}
+32 -32
View File
@@ -417,7 +417,7 @@ int CmdFlexdemod(const char *Cmd) {
}
// iceman, use demod buffer? blue line?
// iceman, use g_DemodBuffer? blue line?
// HACK writing back to graphbuffer.
GraphTraceLen = 32 * 64;
i = 0;
@@ -871,11 +871,11 @@ int CmdLFSim(const char *Cmd) {
}
// sim fsk data given clock, fcHigh, fcLow, invert
// - allow pull data from DemodBuffer
// - allow pull data from g_DemodBuffer
int CmdLFfskSim(const char *Cmd) {
CLIParserContext *ctx;
CLIParserInit(&ctx, "lf simfsk",
"Simulate FSK tag from demodbuffer or input. There are about four FSK modulations to know of.\n"
"Simulate FSK tag from DemodBuffer or input. There are about four FSK modulations to know of.\n"
"FSK1 - where fc/8 = high and fc/5 = low\n"
"FSK1a - is inverted FSK1, ie: fc/5 = high and fc/8 = low\n"
"FSK2 - where fc/10 = high and fc/8 = low\n"
@@ -912,8 +912,8 @@ int CmdLFfskSim(const char *Cmd) {
CLIParserFree(ctx);
// No args
if (raw_len == 0 && DemodBufferLen == 0) {
PrintAndLogEx(ERR, "No user supplied data nor inside Demodbuffer");
if (raw_len == 0 && g_DemodBufferLen == 0) {
PrintAndLogEx(ERR, "No user supplied data nor inside DemodBuffer");
return PM3_EINVARG;
}
@@ -925,10 +925,10 @@ int CmdLFfskSim(const char *Cmd) {
uint8_t bs[256] = {0x00};
int bs_len = hextobinarray((char *)bs, raw);
if (bs_len == 0) {
// Using data from DemodBuffer
// might be able to autodetect FC and clock from Graphbuffer if using demod buffer
// Using data from g_DemodBuffer
// might be able to autodetect FC and clock from Graphbuffer if using g_DemodBuffer
// will need clock, fchigh, fclow and bitstream
PrintAndLogEx(INFO, "No user supplied data, using Demodbuffer...");
PrintAndLogEx(INFO, "No user supplied data, using DemodBuffer...");
if (clk == 0 || fchigh == 0 || fclow == 0) {
int firstClockEdge = 0;
@@ -939,7 +939,7 @@ int CmdLFfskSim(const char *Cmd) {
fclow = 0;
}
}
PrintAndLogEx(DEBUG, "Detected rf/%u, High fc/%u, Low fc/%u, n %zu ", clk, fchigh, fclow, DemodBufferLen);
PrintAndLogEx(DEBUG, "Detected rf/%u, High fc/%u, Low fc/%u, n %zu ", clk, fchigh, fclow, g_DemodBufferLen);
} else {
setDemodBuff(bs, bs_len, 0);
@@ -961,7 +961,7 @@ int CmdLFfskSim(const char *Cmd) {
PrintAndLogEx(DEBUG, "Autodetection of smaller clock failed, falling back to fc/%u", fclow);
}
size_t size = DemodBufferLen;
size_t size = g_DemodBufferLen;
if (size > (PM3_CMD_DATA_SIZE - sizeof(lf_fsksim_t))) {
PrintAndLogEx(WARNING, "DemodBuffer too long for current implementation - length: %zu - max: %zu", size, PM3_CMD_DATA_SIZE - sizeof(lf_fsksim_t));
PrintAndLogEx(INFO, "Continuing with trimmed down data");
@@ -973,7 +973,7 @@ int CmdLFfskSim(const char *Cmd) {
payload->fclow = fclow;
payload->separator = separator;
payload->clock = clk;
memcpy(payload->data, DemodBuffer, size);
memcpy(payload->data, g_DemodBuffer, size);
clearCommandBuffer();
SendCommandNG(CMD_LF_FSK_SIMULATE, (uint8_t *)payload, sizeof(lf_fsksim_t) + size);
@@ -984,11 +984,11 @@ int CmdLFfskSim(const char *Cmd) {
}
// sim ask data given clock, invert, manchester or raw, separator
// - allow pull data from DemodBuffer
// - allow pull data from g_DemodBuffer
int CmdLFaskSim(const char *Cmd) {
CLIParserContext *ctx;
CLIParserInit(&ctx, "lf simask",
"Simulate ASK tag from demodbuffer or input",
"Simulate ASK tag from DemodBuffer or input",
"lf simask --clk 32 --am -d 0102030405 --> simulate ASK/MAN rf/32\n"
"lf simask --clk 32 --bi -d 0102030405 --> simulate ASK/BIPHASE rf/32\n\n"
"lf simask --clk 64 --am -d ffbd8001686f1924 --> simulate a EM410x tag\n"
@@ -1033,18 +1033,18 @@ int CmdLFaskSim(const char *Cmd) {
encoding = 0;
// No args
if (raw_len == 0 && DemodBufferLen == 0) {
PrintAndLogEx(ERR, "No user supplied data nor any inside Demodbuffer");
if (raw_len == 0 && g_DemodBufferLen == 0) {
PrintAndLogEx(ERR, "No user supplied data nor any inside DemodBuffer");
return PM3_EINVARG;
}
uint8_t bs[256] = {0x00};
int bs_len = hextobinarray((char *)bs, raw);
if (bs_len == 0) {
// Using data from DemodBuffer
// might be able to autodetect FC and clock from Graphbuffer if using demod buffer
// Using data from g_DemodBuffer
// might be able to autodetect FC and clock from Graphbuffer if using g_DemodBuffer
// will need carrier, clock, and bitstream
PrintAndLogEx(INFO, "No user supplied data, using Demodbuffer...");
PrintAndLogEx(INFO, "No user supplied data, using DemodBuffer...");
if (clk == 0) {
int res = GetAskClock("0", verbose);
@@ -1055,7 +1055,7 @@ int CmdLFaskSim(const char *Cmd) {
}
}
PrintAndLogEx(DEBUG, "Detected rf/%u, n %zu ", clk, DemodBufferLen);
PrintAndLogEx(DEBUG, "Detected rf/%u, n %zu ", clk, g_DemodBufferLen);
} else {
setDemodBuff(bs, bs_len, 0);
@@ -1072,7 +1072,7 @@ int CmdLFaskSim(const char *Cmd) {
PrintAndLogEx(DEBUG, "ASK/RAW needs half rf. Using rf/%u", clk);
}
size_t size = DemodBufferLen;
size_t size = g_DemodBufferLen;
if (size > (PM3_CMD_DATA_SIZE - sizeof(lf_asksim_t))) {
PrintAndLogEx(WARNING, "DemodBuffer too long for current implementation - length: %zu - max: %zu", size, PM3_CMD_DATA_SIZE - sizeof(lf_asksim_t));
PrintAndLogEx(INFO, "Continuing with trimmed down data");
@@ -1084,7 +1084,7 @@ int CmdLFaskSim(const char *Cmd) {
payload->invert = invert;
payload->separator = separator;
payload->clock = clk;
memcpy(payload->data, DemodBuffer, size);
memcpy(payload->data, g_DemodBuffer, size);
clearCommandBuffer();
SendCommandNG(CMD_LF_ASK_SIMULATE, (uint8_t *)payload, sizeof(lf_asksim_t) + size);
@@ -1095,12 +1095,12 @@ int CmdLFaskSim(const char *Cmd) {
}
// sim psk data given carrier, clock, invert
// - allow pull data from DemodBuffer or parameters
// - allow pull data from g_DemodBuffer or parameters
int CmdLFpskSim(const char *Cmd) {
CLIParserContext *ctx;
CLIParserInit(&ctx, "lf simpsk",
"Simulate PSK tag from demodbuffer or input",
"Simulate PSK tag from DemodBuffer or input",
"lf simpsk -1 --clk 40 --fc 4 -d 01020304 --> simulate PSK1 rf/40 psksub fc/4, data 01020304\n\n"
"lf simpsk -1 --clk 32 --fc 2 -d a0000000bd989a11 --> simulate a indala tag manually"
);
@@ -1147,8 +1147,8 @@ int CmdLFpskSim(const char *Cmd) {
psk_type = 3;
// No args
if (raw_len == 0 && DemodBufferLen == 0) {
PrintAndLogEx(ERR, "No user supplied data nor any inside Demodbuffer");
if (raw_len == 0 && g_DemodBufferLen == 0) {
PrintAndLogEx(ERR, "No user supplied data nor any inside DemodBuffer");
return PM3_EINVARG;
}
@@ -1156,10 +1156,10 @@ int CmdLFpskSim(const char *Cmd) {
int bs_len = hextobinarray((char *)bs, raw);
if (bs_len == 0) {
// Using data from DemodBuffer
// might be able to autodetect FC and clock from Graphbuffer if using demod buffer
// Using data from g_DemodBuffer
// might be able to autodetect FC and clock from Graphbuffer if using g_DemodBuffer
// will need carrier, clock, and bitstream
PrintAndLogEx(INFO, "No user supplied data, using Demodbuffer...");
PrintAndLogEx(INFO, "No user supplied data, using DemodBuffer...");
int res;
if (clk == 0) {
@@ -1180,7 +1180,7 @@ int CmdLFpskSim(const char *Cmd) {
}
}
PrintAndLogEx(DEBUG, "Detected rf/%u, fc/%u, n %zu ", clk, carrier, DemodBufferLen);
PrintAndLogEx(DEBUG, "Detected rf/%u, fc/%u, n %zu ", clk, carrier, g_DemodBufferLen);
} else {
setDemodBuff(bs, bs_len, 0);
@@ -1193,12 +1193,12 @@ int CmdLFpskSim(const char *Cmd) {
if (psk_type == 2) {
//need to convert psk2 to psk1 data before sim
psk2TOpsk1(DemodBuffer, DemodBufferLen);
psk2TOpsk1(g_DemodBuffer, g_DemodBufferLen);
} else if (psk_type == 3) {
PrintAndLogEx(INFO, "PSK3 not yet available. Falling back to PSK1");
}
size_t size = DemodBufferLen;
size_t size = g_DemodBufferLen;
if (size > (PM3_CMD_DATA_SIZE - sizeof(lf_psksim_t))) {
PrintAndLogEx(WARNING, "DemodBuffer too long for current implementation - length: %zu - max: %zu", size, PM3_CMD_DATA_SIZE - sizeof(lf_psksim_t));
PrintAndLogEx(INFO, "Continuing with trimmed down data");
@@ -1209,7 +1209,7 @@ int CmdLFpskSim(const char *Cmd) {
payload->carrier = carrier;
payload->invert = invert;
payload->clock = clk;
memcpy(payload->data, DemodBuffer, size);
memcpy(payload->data, g_DemodBuffer, size);
clearCommandBuffer();
SendCommandNG(CMD_LF_PSK_SIMULATE, (uint8_t *)payload, sizeof(lf_psksim_t) + size);
free(payload);
+1 -1
View File
@@ -268,7 +268,7 @@ int demodAWID(bool verbose) {
}
free(bits);
PrintAndLogEx(DEBUG, "DEBUG: AWID idx: %d, Len: %zu Printing Demod Buffer:", idx, size);
PrintAndLogEx(DEBUG, "DEBUG: AWID idx: %d, Len: %zu Printing DemodBuffer:", idx, size);
if (g_debugMode) {
printDemodBuff(0, false, false, true);
printDemodBuff(0, false, false, false);
+3 -3
View File
@@ -27,7 +27,7 @@ int demodCOTAG(bool verbose) {
uint8_t bits[COTAG_BITS] = {0};
size_t bitlen = COTAG_BITS;
memcpy(bits, DemodBuffer, COTAG_BITS);
memcpy(bits, g_DemodBuffer, COTAG_BITS);
uint8_t alignPos = 0;
uint16_t err = manrawdecode(bits, &bitlen, 1, &alignPos);
@@ -150,8 +150,8 @@ static int CmdCOTAGReader(const char *Cmd) {
break;
}
case 1: {
memcpy(DemodBuffer, resp.data.asBytes, resp.length);
DemodBufferLen = resp.length;
memcpy(g_DemodBuffer, resp.data.asBytes, resp.length);
g_DemodBufferLen = resp.length;
return demodCOTAG(true);
}
}
+4 -4
View File
@@ -37,8 +37,8 @@ int demodDestron(bool verbose) {
return PM3_ESOFT;
}
size_t size = DemodBufferLen;
int ans = detectDestron(DemodBuffer, &size);
size_t size = g_DemodBufferLen;
int ans = detectDestron(g_DemodBuffer, &size);
if (ans < 0) {
if (ans == -1)
PrintAndLogEx(DEBUG, "DEBUG: Error - Destron: too few bits found");
@@ -52,12 +52,12 @@ int demodDestron(bool verbose) {
return PM3_ESOFT;
}
setDemodBuff(DemodBuffer, DESTRON_FRAME_SIZE, ans);
setDemodBuff(g_DemodBuffer, DESTRON_FRAME_SIZE, ans);
setClockGrid(g_DemodClock, g_DemodStartIdx + (ans * g_DemodClock));
uint8_t bits[DESTRON_FRAME_SIZE - DESTRON_PREAMBLE_SIZE] = {0};
size_t bitlen = DESTRON_FRAME_SIZE - DESTRON_PREAMBLE_SIZE;
memcpy(bits, DemodBuffer + DESTRON_PREAMBLE_SIZE, DESTRON_FRAME_SIZE - DESTRON_PREAMBLE_SIZE);
memcpy(bits, g_DemodBuffer + DESTRON_PREAMBLE_SIZE, DESTRON_FRAME_SIZE - DESTRON_PREAMBLE_SIZE);
uint8_t alignPos = 0;
uint16_t errCnt = manrawdecode(bits, &bitlen, 0, &alignPos);
+2 -2
View File
@@ -264,10 +264,10 @@ int AskEm410xDecode(bool verbose, uint32_t *hi, uint64_t *lo) {
}
//set GraphBuffer for clone or sim command
setDemodBuff(DemodBuffer, (size == 40) ? 64 : 128, idx + 1);
setDemodBuff(g_DemodBuffer, (size == 40) ? 64 : 128, idx + 1);
setClockGrid(g_DemodClock, g_DemodStartIdx + ((idx + 1)*g_DemodClock));
PrintAndLogEx(DEBUG, "DEBUG: Em410x idx: %zu, Len: %zu, Printing Demod Buffer:", idx, size);
PrintAndLogEx(DEBUG, "DEBUG: Em410x idx: %zu, Len: %zu, Printing DemodBuffer:", idx, size);
if (g_debugMode) {
printDemodBuff(0, false, false, true);
}
+15 -15
View File
@@ -113,22 +113,22 @@ static bool em4x05_download_samples(void) {
static int doPreambleSearch(size_t *startIdx) {
// sanity check
if (DemodBufferLen < EM_PREAMBLE_LEN) {
PrintAndLogEx(DEBUG, "DEBUG: Error - EM4305 demodbuffer too small");
if (g_DemodBufferLen < EM_PREAMBLE_LEN) {
PrintAndLogEx(DEBUG, "DEBUG: Error - EM4305 DemodBuffer too small");
return PM3_ESOFT;
}
// set size to 11 to only test first 3 positions for the preamble
// do not set it too long else an error preamble followed by 010 could be seen as success.
size_t size = (11 > DemodBufferLen) ? DemodBufferLen : 11;
size_t size = (11 > g_DemodBufferLen) ? g_DemodBufferLen : 11;
*startIdx = 0;
// skip first two 0 bits as they might have been missed in the demod
uint8_t preamble[EM_PREAMBLE_LEN] = {0, 0, 0, 0, 1, 0, 1, 0};
if (!preambleSearchEx(DemodBuffer, preamble, EM_PREAMBLE_LEN, &size, startIdx, true)) {
if (!preambleSearchEx(g_DemodBuffer, preamble, EM_PREAMBLE_LEN, &size, startIdx, true)) {
uint8_t errpreamble[EM_PREAMBLE_LEN] = {0, 0, 0, 0, 0, 0, 0, 1};
if (!preambleSearchEx(DemodBuffer, errpreamble, EM_PREAMBLE_LEN, &size, startIdx, true)) {
if (!preambleSearchEx(g_DemodBuffer, errpreamble, EM_PREAMBLE_LEN, &size, startIdx, true)) {
PrintAndLogEx(DEBUG, "DEBUG: Error - EM4305 preamble not found :: %zu", *startIdx);
return PM3_ESOFT;
}
@@ -168,14 +168,14 @@ static bool detectPSK(void) {
}
// In order to hit the INVERT, we need to demod here
if (DemodBufferLen < 11) {
if (g_DemodBufferLen < 11) {
PrintAndLogEx(INFO, " demod buff len less than PREAMBLE lEN");
}
size_t size = (11 > DemodBufferLen) ? DemodBufferLen : 11;
size_t size = (11 > g_DemodBufferLen) ? g_DemodBufferLen : 11;
size_t startIdx = 0;
uint8_t preamble[EM_PREAMBLE_LEN] = {0, 0, 0, 0, 1, 0, 1, 0};
if (!preambleSearchEx(DemodBuffer, preamble, EM_PREAMBLE_LEN, &size, &startIdx, true)) {
if (!preambleSearchEx(g_DemodBuffer, preamble, EM_PREAMBLE_LEN, &size, &startIdx, true)) {
//try psk1 inverted
ans = PSKDemod(0, 1, 6, false);
@@ -184,7 +184,7 @@ static bool detectPSK(void) {
return false;
}
if (!preambleSearchEx(DemodBuffer, preamble, EM_PREAMBLE_LEN, &size, &startIdx, true)) {
if (!preambleSearchEx(g_DemodBuffer, preamble, EM_PREAMBLE_LEN, &size, &startIdx, true)) {
PrintAndLogEx(DEBUG, "DEBUG: Error - EM: PSK1 inverted Demod failed 2");
return false;
}
@@ -237,19 +237,19 @@ static int em4x05_setdemod_buffer(uint32_t *word, size_t idx) {
//test for even parity bits.
uint8_t parity[45] = {0};
memcpy(parity, DemodBuffer, 45);
if (!em4x05_col_parity_test(DemodBuffer + idx + EM_PREAMBLE_LEN, 45, 5, 9, 0)) {
memcpy(parity, g_DemodBuffer, 45);
if (!em4x05_col_parity_test(g_DemodBuffer + idx + EM_PREAMBLE_LEN, 45, 5, 9, 0)) {
PrintAndLogEx(DEBUG, "DEBUG: Error - End Parity check failed");
return PM3_ESOFT;
}
// test for even parity bits and remove them. (leave out the end row of parities so 36 bits)
if (!removeParity(DemodBuffer, idx + EM_PREAMBLE_LEN, 9, 0, 36)) {
if (!removeParity(g_DemodBuffer, idx + EM_PREAMBLE_LEN, 9, 0, 36)) {
PrintAndLogEx(DEBUG, "DEBUG: Error - EM, failed removing parity");
return PM3_ESOFT;
}
setDemodBuff(DemodBuffer, 32, 0);
*word = bytebits_to_byteLSBF(DemodBuffer, 32);
setDemodBuff(g_DemodBuffer, 32, 0);
*word = bytebits_to_byteLSBF(g_DemodBuffer, 32);
return PM3_SUCCESS;
}
@@ -299,7 +299,7 @@ static int em4x05_demod_resp(uint32_t *word, bool onlyPreamble) {
if (res == PM3_EFAILED)
found_err = true;
psk1TOpsk2(DemodBuffer, DemodBufferLen);
psk1TOpsk2(g_DemodBuffer, g_DemodBufferLen);
res = doPreambleSearch(&idx);
if (res == PM3_SUCCESS)
break;
+17 -17
View File
@@ -485,8 +485,8 @@ int demodFDXB(bool verbose) {
PrintAndLogEx(DEBUG, "DEBUG: Error - FDX-B ASKbiphaseDemod failed");
return PM3_ESOFT;
}
size_t size = DemodBufferLen;
int preambleIndex = detectFDXB(DemodBuffer, &size);
size_t size = g_DemodBufferLen;
int preambleIndex = detectFDXB(g_DemodBuffer, &size);
if (preambleIndex < 0) {
if (preambleIndex == -1)
@@ -500,13 +500,13 @@ int demodFDXB(bool verbose) {
return PM3_ESOFT;
}
// set and leave DemodBuffer intact
setDemodBuff(DemodBuffer, 128, preambleIndex);
// set and leave g_DemodBuffer intact
setDemodBuff(g_DemodBuffer, 128, preambleIndex);
setClockGrid(g_DemodClock, g_DemodStartIdx + (preambleIndex * g_DemodClock));
// remove marker bits (1's every 9th digit after preamble) (pType = 2)
size = removeParity(DemodBuffer, 11, 9, 2, 117);
size = removeParity(g_DemodBuffer, 11, 9, 2, 117);
if (size != 104) {
PrintAndLogEx(DEBUG, "DEBUG: Error - FDX-B error removeParity: %zu", size);
return PM3_ESOFT;
@@ -515,42 +515,42 @@ int demodFDXB(bool verbose) {
//got a good demod
uint8_t offset;
// ISO: bits 27..64
uint64_t NationalCode = ((uint64_t)(bytebits_to_byteLSBF(DemodBuffer + 32, 6)) << 32) | bytebits_to_byteLSBF(DemodBuffer, 32);
uint64_t NationalCode = ((uint64_t)(bytebits_to_byteLSBF(g_DemodBuffer + 32, 6)) << 32) | bytebits_to_byteLSBF(g_DemodBuffer, 32);
offset = 38;
// ISO: bits 17..26
uint16_t countryCode = bytebits_to_byteLSBF(DemodBuffer + offset, 10);
uint16_t countryCode = bytebits_to_byteLSBF(g_DemodBuffer + offset, 10);
offset += 10;
// ISO: bits 16
uint8_t dataBlockBit = DemodBuffer[offset];
uint8_t dataBlockBit = g_DemodBuffer[offset];
offset++;
// ISO: bits 15
uint8_t rudiBit = DemodBuffer[offset];
uint8_t rudiBit = g_DemodBuffer[offset];
offset++;
// ISO: bits 10..14
uint32_t reservedCode = bytebits_to_byteLSBF(DemodBuffer + offset, 5);
uint32_t reservedCode = bytebits_to_byteLSBF(g_DemodBuffer + offset, 5);
offset += 5;
// ISO: bits 5..9
uint32_t userInfo = bytebits_to_byteLSBF(DemodBuffer + offset, 5);
uint32_t userInfo = bytebits_to_byteLSBF(g_DemodBuffer + offset, 5);
offset += 5;
// ISO: bits 2..4
uint32_t replacementNr = bytebits_to_byteLSBF(DemodBuffer + offset, 3);
uint32_t replacementNr = bytebits_to_byteLSBF(g_DemodBuffer + offset, 3);
offset += 3;
uint8_t animalBit = DemodBuffer[offset];
uint8_t animalBit = g_DemodBuffer[offset];
offset++;
uint16_t crc = bytebits_to_byteLSBF(DemodBuffer + offset, 16);
uint16_t crc = bytebits_to_byteLSBF(g_DemodBuffer + offset, 16);
offset += 16;
uint32_t extended = bytebits_to_byteLSBF(DemodBuffer + offset, 24);
uint32_t extended = bytebits_to_byteLSBF(g_DemodBuffer + offset, 24);
uint64_t rawid = (uint64_t)(bytebits_to_byte(DemodBuffer, 32)) << 32 | bytebits_to_byte(DemodBuffer + 32, 32);
uint64_t rawid = (uint64_t)(bytebits_to_byte(g_DemodBuffer, 32)) << 32 | bytebits_to_byte(g_DemodBuffer + 32, 32);
uint8_t raw[8];
num_to_bytes(rawid, 8, raw);
@@ -578,7 +578,7 @@ int demodFDXB(bool verbose) {
if (g_debugMode) {
PrintAndLogEx(DEBUG, "Start marker %d; Size %zu", preambleIndex, size);
char *bin = sprint_bin_break(DemodBuffer, size, 16);
char *bin = sprint_bin_break(g_DemodBuffer, size, 16);
PrintAndLogEx(DEBUG, "DEBUG bin stream:\n%s", bin);
}
+8 -8
View File
@@ -88,8 +88,8 @@ int demodGallagher(bool verbose) {
return PM3_ESOFT;
}
size_t size = DemodBufferLen;
int ans = detectGallagher(DemodBuffer, &size);
size_t size = g_DemodBufferLen;
int ans = detectGallagher(g_DemodBuffer, &size);
if (ans < 0) {
if (ans == -1)
PrintAndLogEx(DEBUG, "DEBUG: Error - GALLAGHER: too few bits found");
@@ -102,23 +102,23 @@ int demodGallagher(bool verbose) {
return PM3_ESOFT;
}
setDemodBuff(DemodBuffer, 96, ans);
setDemodBuff(g_DemodBuffer, 96, 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 raw1 = bytebits_to_byte(g_DemodBuffer, 32);
uint32_t raw2 = bytebits_to_byte(g_DemodBuffer + 32, 32);
uint32_t raw3 = bytebits_to_byte(g_DemodBuffer + 64, 32);
// bytes
uint8_t arr[8] = {0};
for (int i = 0, pos = 0; i < ARRAYLEN(arr); i++) {
pos = 16 + (9 * i);
arr[i] = bytebits_to_byte(DemodBuffer + pos, 8);
arr[i] = bytebits_to_byte(g_DemodBuffer + pos, 8);
}
// crc
uint8_t crc = bytebits_to_byte(DemodBuffer + 16 + (9 * 8), 8);
uint8_t crc = bytebits_to_byte(g_DemodBuffer + 16 + (9 * 8), 8);
uint8_t calc_crc = CRC8Cardx(arr, ARRAYLEN(arr));
descramble(arr, ARRAYLEN(arr));
+10 -10
View File
@@ -28,9 +28,9 @@
static int CmdHelp(const char *Cmd);
// attempts to demodulate and identify a G_Prox_II verex/chubb card
// WARNING: if it fails during some points it will destroy the DemodBuffer data
// WARNING: if it fails during some points it will destroy the g_DemodBuffer data
// but will leave the GraphBuffer intact.
// if successful it will push askraw data back to demod buffer ready for emulation
// if successful it will push askraw data back to g_DemodBuffer ready for emulation
int demodGuard(bool verbose) {
(void) verbose; // unused so far
//Differential Biphase
@@ -40,9 +40,9 @@ int demodGuard(bool verbose) {
return PM3_ESOFT;
}
size_t size = DemodBufferLen;
size_t size = g_DemodBufferLen;
int preambleIndex = detectGProxII(DemodBuffer, &size);
int preambleIndex = detectGProxII(g_DemodBuffer, &size);
if (preambleIndex < 0) {
if (preambleIndex == -1)
@@ -65,8 +65,8 @@ int demodGuard(bool verbose) {
size_t startIdx = preambleIndex + 6; //start after 6 bit preamble
uint8_t bits_no_spacer[90];
// not mess with raw DemodBuffer copy to a new sample array
memcpy(bits_no_spacer, DemodBuffer + startIdx, 90);
// not mess with raw g_DemodBuffer copy to a new sample array
memcpy(bits_no_spacer, g_DemodBuffer + startIdx, 90);
// remove the 18 (90/5=18) parity bits (down to 72 bits (96-6-18=72))
size_t len = removeParity(bits_no_spacer, 0, 5, 3, 90); //source, startloc, paritylen, ptype, length_to_run
@@ -82,7 +82,7 @@ int demodGuard(bool verbose) {
PrintAndLogEx(DEBUG, "DEBUG: gProxII byte %zu after xor: %02x", idx, plain[idx]);
}
setDemodBuff(DemodBuffer, 96, preambleIndex);
setDemodBuff(g_DemodBuffer, 96, preambleIndex);
setClockGrid(g_DemodClock, g_DemodStartIdx + (preambleIndex * g_DemodClock));
//plain contains 8 Bytes (64 bits) of decrypted raw tag data
@@ -90,9 +90,9 @@ int demodGuard(bool verbose) {
uint32_t FC = 0;
uint32_t Card = 0;
//get raw 96 bits to print
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 raw1 = bytebits_to_byte(g_DemodBuffer, 32);
uint32_t raw2 = bytebits_to_byte(g_DemodBuffer + 32, 32);
uint32_t raw3 = bytebits_to_byte(g_DemodBuffer + 64, 32);
bool unknown = false;
switch (fmtLen) {
case 36:
+1 -1
View File
@@ -146,7 +146,7 @@ int demodHID(bool verbose) {
}
PrintAndLogEx(INFO, "raw: " _GREEN_("%08x%08x%08x"), hi2, hi, lo);
PrintAndLogEx(DEBUG, "DEBUG: HID idx: %d, Len: %zu, Printing Demod Buffer: ", idx, size);
PrintAndLogEx(DEBUG, "DEBUG: HID idx: %d, Len: %zu, Printing DemodBuffer: ", idx, size);
if (g_debugMode) {
PrintAndLogEx(DEBUG, "raw: " _GREEN_("%08x%08x%08x"), hi2, hi, lo);
+6 -6
View File
@@ -33,10 +33,10 @@ int demodIdteck(bool verbose) {
PrintAndLogEx(DEBUG, "DEBUG: Error - Idteck PSKDemod failed");
return PM3_ESOFT;
}
size_t size = DemodBufferLen;
size_t size = g_DemodBufferLen;
//get binary from PSK1 wave
int idx = detectIdteck(DemodBuffer, &size);
int idx = detectIdteck(g_DemodBuffer, &size);
if (idx < 0) {
if (idx == -1)
@@ -55,7 +55,7 @@ int demodIdteck(bool verbose) {
PrintAndLogEx(DEBUG, "DEBUG: Error - Idteck PSKDemod failed");
return PM3_ESOFT;
}
idx = detectIdteck(DemodBuffer, &size);
idx = detectIdteck(g_DemodBuffer, &size);
if (idx < 0) {
if (idx == -1)
@@ -72,12 +72,12 @@ int demodIdteck(bool verbose) {
return PM3_ESOFT;
}
}
setDemodBuff(DemodBuffer, 64, idx);
setDemodBuff(g_DemodBuffer, 64, idx);
//got a good demod
uint32_t id = 0;
uint32_t raw1 = bytebits_to_byte(DemodBuffer, 32);
uint32_t raw2 = bytebits_to_byte(DemodBuffer + 32, 32);
uint32_t raw1 = bytebits_to_byte(g_DemodBuffer, 32);
uint32_t raw2 = bytebits_to_byte(g_DemodBuffer + 32, 32);
//parity check (TBD)
//checksum check (TBD)
+55 -55
View File
@@ -124,8 +124,8 @@ int demodIndalaEx(int clk, int invert, int maxErr, bool verbose) {
}
uint8_t inv = 0;
size_t size = DemodBufferLen;
int idx = detectIndala(DemodBuffer, &size, &inv);
size_t size = g_DemodBufferLen;
int idx = detectIndala(g_DemodBuffer, &size, &inv);
if (idx < 0) {
if (idx == -1)
PrintAndLogEx(DEBUG, "DEBUG: Error - Indala: not enough samples");
@@ -139,68 +139,68 @@ int demodIndalaEx(int clk, int invert, int maxErr, bool verbose) {
PrintAndLogEx(DEBUG, "DEBUG: Error - Indala: error demoding psk idx: %d", idx);
return PM3_ESOFT;
}
setDemodBuff(DemodBuffer, size, idx);
setDemodBuff(g_DemodBuffer, size, idx);
setClockGrid(g_DemodClock, g_DemodStartIdx + (idx * g_DemodClock));
//convert UID to HEX
uint32_t uid1 = bytebits_to_byte(DemodBuffer, 32);
uint32_t uid2 = bytebits_to_byte(DemodBuffer + 32, 32);
uint32_t uid1 = bytebits_to_byte(g_DemodBuffer, 32);
uint32_t uid2 = bytebits_to_byte(g_DemodBuffer + 32, 32);
// To be checked, what's this internal ID ?
// foo is only used for 64b ids and in that case uid1 must be only preamble, plus the following code is wrong as x<<32 & 0x1FFFFFFF is always zero
//uint64_t foo = (((uint64_t)uid1 << 32) & 0x1FFFFFFF) | (uid2 & 0x7FFFFFFF);
uint64_t foo = uid2 & 0x7FFFFFFF;
if (DemodBufferLen == 64) {
PrintAndLogEx(SUCCESS, "Indala (len %zu) Raw: " _GREEN_("%x%08x"), DemodBufferLen, uid1, uid2);
if (g_DemodBufferLen == 64) {
PrintAndLogEx(SUCCESS, "Indala (len %zu) Raw: " _GREEN_("%x%08x"), g_DemodBufferLen, uid1, uid2);
uint16_t p1 = 0;
p1 |= DemodBuffer[32 + 3] << 8;
p1 |= DemodBuffer[32 + 6] << 5;
p1 |= DemodBuffer[32 + 8] << 4;
p1 |= DemodBuffer[32 + 9] << 3;
p1 |= DemodBuffer[32 + 11] << 1;
p1 |= DemodBuffer[32 + 16] << 6;
p1 |= DemodBuffer[32 + 19] << 7;
p1 |= DemodBuffer[32 + 20] << 10;
p1 |= DemodBuffer[32 + 21] << 2;
p1 |= DemodBuffer[32 + 22] << 0;
p1 |= DemodBuffer[32 + 24] << 9;
p1 |= g_DemodBuffer[32 + 3] << 8;
p1 |= g_DemodBuffer[32 + 6] << 5;
p1 |= g_DemodBuffer[32 + 8] << 4;
p1 |= g_DemodBuffer[32 + 9] << 3;
p1 |= g_DemodBuffer[32 + 11] << 1;
p1 |= g_DemodBuffer[32 + 16] << 6;
p1 |= g_DemodBuffer[32 + 19] << 7;
p1 |= g_DemodBuffer[32 + 20] << 10;
p1 |= g_DemodBuffer[32 + 21] << 2;
p1 |= g_DemodBuffer[32 + 22] << 0;
p1 |= g_DemodBuffer[32 + 24] << 9;
uint8_t fc = 0;
fc |= DemodBuffer[57] << 7; // b8
fc |= DemodBuffer[49] << 6; // b7
fc |= DemodBuffer[44] << 5; // b6
fc |= DemodBuffer[47] << 4; // b5
fc |= DemodBuffer[48] << 3; // b4
fc |= DemodBuffer[53] << 2; // b3
fc |= DemodBuffer[39] << 1; // b2
fc |= DemodBuffer[58] << 0; // b1
fc |= g_DemodBuffer[57] << 7; // b8
fc |= g_DemodBuffer[49] << 6; // b7
fc |= g_DemodBuffer[44] << 5; // b6
fc |= g_DemodBuffer[47] << 4; // b5
fc |= g_DemodBuffer[48] << 3; // b4
fc |= g_DemodBuffer[53] << 2; // b3
fc |= g_DemodBuffer[39] << 1; // b2
fc |= g_DemodBuffer[58] << 0; // b1
uint16_t csn = 0;
csn |= DemodBuffer[42] << 15; // b16
csn |= DemodBuffer[45] << 14; // b15
csn |= DemodBuffer[43] << 13; // b14
csn |= DemodBuffer[40] << 12; // b13
csn |= DemodBuffer[52] << 11; // b12
csn |= DemodBuffer[36] << 10; // b11
csn |= DemodBuffer[35] << 9; // b10
csn |= DemodBuffer[51] << 8; // b9
csn |= DemodBuffer[46] << 7; // b8
csn |= DemodBuffer[33] << 6; // b7
csn |= DemodBuffer[37] << 5; // b6
csn |= DemodBuffer[54] << 4; // b5
csn |= DemodBuffer[56] << 3; // b4
csn |= DemodBuffer[59] << 2; // b3
csn |= DemodBuffer[50] << 1; // b2
csn |= DemodBuffer[41] << 0; // b1
csn |= g_DemodBuffer[42] << 15; // b16
csn |= g_DemodBuffer[45] << 14; // b15
csn |= g_DemodBuffer[43] << 13; // b14
csn |= g_DemodBuffer[40] << 12; // b13
csn |= g_DemodBuffer[52] << 11; // b12
csn |= g_DemodBuffer[36] << 10; // b11
csn |= g_DemodBuffer[35] << 9; // b10
csn |= g_DemodBuffer[51] << 8; // b9
csn |= g_DemodBuffer[46] << 7; // b8
csn |= g_DemodBuffer[33] << 6; // b7
csn |= g_DemodBuffer[37] << 5; // b6
csn |= g_DemodBuffer[54] << 4; // b5
csn |= g_DemodBuffer[56] << 3; // b4
csn |= g_DemodBuffer[59] << 2; // b3
csn |= g_DemodBuffer[50] << 1; // b2
csn |= g_DemodBuffer[41] << 0; // b1
uint8_t parity = 0;
parity |= DemodBuffer[34] << 1; // b2
parity |= DemodBuffer[38] << 0; // b1
parity |= g_DemodBuffer[34] << 1; // b2
parity |= g_DemodBuffer[38] << 0; // b1
uint8_t checksum = 0;
checksum |= DemodBuffer[62] << 1; // b2
checksum |= DemodBuffer[63] << 0; // b1
checksum |= g_DemodBuffer[62] << 1; // b2
checksum |= g_DemodBuffer[63] << 0; // b1
PrintAndLogEx(SUCCESS, "Fmt " _GREEN_("26") " FC: " _GREEN_("%u") " Card: " _GREEN_("%u") " Parity: " _GREEN_("%1d%1d")
, fc
@@ -214,18 +214,18 @@ int demodIndalaEx(int clk, int invert, int maxErr, bool verbose) {
// This doesn't seem to line up with the hot-stamp numbers on any HID cards I have seen, but, leaving it alone since I do not know how those work. -MS
PrintAndLogEx(SUCCESS, " Printed | __%04d__ [0x%X]", p1, p1);
PrintAndLogEx(SUCCESS, " Internal ID | %" PRIu64, foo);
decodeHeden2L(DemodBuffer);
decodeHeden2L(g_DemodBuffer);
} else {
uint32_t uid3 = bytebits_to_byte(DemodBuffer + 64, 32);
uint32_t uid4 = bytebits_to_byte(DemodBuffer + 96, 32);
uint32_t uid5 = bytebits_to_byte(DemodBuffer + 128, 32);
uint32_t uid6 = bytebits_to_byte(DemodBuffer + 160, 32);
uint32_t uid7 = bytebits_to_byte(DemodBuffer + 192, 32);
uint32_t uid3 = bytebits_to_byte(g_DemodBuffer + 64, 32);
uint32_t uid4 = bytebits_to_byte(g_DemodBuffer + 96, 32);
uint32_t uid5 = bytebits_to_byte(g_DemodBuffer + 128, 32);
uint32_t uid6 = bytebits_to_byte(g_DemodBuffer + 160, 32);
uint32_t uid7 = bytebits_to_byte(g_DemodBuffer + 192, 32);
PrintAndLogEx(
SUCCESS
, "Indala (len %zu) Raw: " _GREEN_("%x%08x%08x%08x%08x%08x%08x")
, DemodBufferLen
, g_DemodBufferLen
, uid1
, uid2
, uid3
@@ -237,7 +237,7 @@ int demodIndalaEx(int clk, int invert, int maxErr, bool verbose) {
}
if (g_debugMode) {
PrintAndLogEx(DEBUG, "DEBUG: Indala - printing demodbuffer");
PrintAndLogEx(DEBUG, "DEBUG: Indala - printing DemodBuffer");
printDemodBuff(0, false, false, false);
}
return PM3_SUCCESS;
@@ -314,7 +314,7 @@ static int CmdIndalaDemodAlt(const char *Cmd) {
//clear clock grid and demod plot
setClockGrid(0, 0);
DemodBufferLen = 0;
g_DemodBufferLen = 0;
// PrintAndLogEx(NORMAL, "Expecting a bit less than %d raw bits", GraphTraceLen / 32);
// loop through raw signal - since we know it is psk1 rf/32 fc/2 skip every other value (+=2)
+1 -1
View File
@@ -144,7 +144,7 @@ int demodIOProx(bool verbose) {
if (crc != calccrc)
PrintAndLogEx(DEBUG, "DEBUG: Error - IO prox crc failed");
PrintAndLogEx(DEBUG, "DEBUG: IO prox idx: %d, Len: %zu, Printing demod buffer:", idx, size);
PrintAndLogEx(DEBUG, "DEBUG: IO prox idx: %d, Len: %zu, Printing DemodBuffer:", idx, size);
printDemodBuff(0, false, false, true);
printDemodBuff(0, false, false, false);
}
+7 -7
View File
@@ -57,8 +57,8 @@ int demodJablotron(bool verbose) {
if (g_debugMode) PrintAndLogEx(DEBUG, "DEBUG: Error - Jablotron ASKbiphaseDemod failed");
return PM3_ESOFT;
}
size_t size = DemodBufferLen;
int ans = detectJablotron(DemodBuffer, &size);
size_t size = g_DemodBufferLen;
int ans = detectJablotron(g_DemodBuffer, &size);
if (ans < 0) {
if (g_debugMode) {
if (ans == -1)
@@ -75,21 +75,21 @@ int demodJablotron(bool verbose) {
return PM3_ESOFT;
}
setDemodBuff(DemodBuffer, JABLOTRON_ARR_LEN, ans);
setDemodBuff(g_DemodBuffer, JABLOTRON_ARR_LEN, 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 raw1 = bytebits_to_byte(g_DemodBuffer, 32);
uint32_t raw2 = bytebits_to_byte(g_DemodBuffer + 32, 32);
// bytebits_to_byte - uint32_t
uint64_t rawid = ((uint64_t)(bytebits_to_byte(DemodBuffer + 16, 8) & 0xff) << 32) | bytebits_to_byte(DemodBuffer + 24, 32);
uint64_t rawid = ((uint64_t)(bytebits_to_byte(g_DemodBuffer + 16, 8) & 0xff) << 32) | bytebits_to_byte(g_DemodBuffer + 24, 32);
uint64_t id = getJablontronCardId(rawid);
PrintAndLogEx(SUCCESS, "Jablotron - Card: " _GREEN_("%"PRIx64) ", Raw: %08X%08X", id, raw1, raw2);
uint8_t chksum = raw2 & 0xFF;
bool isok = (chksum == jablontron_chksum(DemodBuffer));
bool isok = (chksum == jablontron_chksum(g_DemodBuffer));
PrintAndLogEx(DEBUG, "Checksum: %02X (%s)", chksum, isok ? _GREEN_("ok") : _RED_("Fail"));
+10 -10
View File
@@ -105,8 +105,8 @@ int demodKeri(bool verbose) {
}
bool invert = false;
size_t size = DemodBufferLen;
int idx = detectKeri(DemodBuffer, &size, &invert);
size_t size = g_DemodBufferLen;
int idx = detectKeri(g_DemodBuffer, &size, &invert);
if (idx < 0) {
if (idx == -1)
PrintAndLogEx(DEBUG, "DEBUG: Error - KERI: too few bits found");
@@ -119,7 +119,7 @@ int demodKeri(bool verbose) {
return PM3_ESOFT;
}
setDemodBuff(DemodBuffer, size, idx);
setDemodBuff(g_DemodBuffer, size, idx);
setClockGrid(g_DemodClock, g_DemodStartIdx + (idx * g_DemodClock));
/*
@@ -143,22 +143,22 @@ int demodKeri(bool verbose) {
uint32_t fc = 0;
uint32_t cardid = 0;
//got a good demod
uint32_t raw1 = bytebits_to_byte(DemodBuffer, 32);
uint32_t raw2 = bytebits_to_byte(DemodBuffer + 32, 32);
uint32_t raw1 = bytebits_to_byte(g_DemodBuffer, 32);
uint32_t raw2 = bytebits_to_byte(g_DemodBuffer + 32, 32);
if (invert) {
PrintAndLogEx(INFO, "Had to Invert - probably KERI");
for (size_t i = 0; i < size; i++)
DemodBuffer[i] ^= 1;
g_DemodBuffer[i] ^= 1;
raw1 = bytebits_to_byte(DemodBuffer, 32);
raw2 = bytebits_to_byte(DemodBuffer + 32, 32);
raw1 = bytebits_to_byte(g_DemodBuffer, 32);
raw2 = bytebits_to_byte(g_DemodBuffer + 32, 32);
CmdPrintDemodBuff("-x");
}
//get internal id
// uint32_t ID = bytebits_to_byte(DemodBuffer + 29, 32);
// uint32_t ID = bytebits_to_byte(g_DemodBuffer + 29, 32);
// Due to the 3 sync bits being at the start of the capture
// We can take the last 32bits as the internal ID.
uint32_t ID = raw2;
@@ -391,7 +391,7 @@ int detectKeri(uint8_t *dest, size_t *size, bool *invert) {
found_size = *size;
// if didn't find preamble try again inverting
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};
if (!preambleSearch(DemodBuffer, preamble_i, sizeof(preamble_i), &found_size, &startIdx))
if (!preambleSearch(g_DemodBuffer, preamble_i, sizeof(preamble_i), &found_size, &startIdx))
return -2;
*invert ^= 1;
+33 -33
View File
@@ -34,8 +34,8 @@ int demodMotorola(bool verbose) {
return PM3_ESOFT;
}
size_t size = DemodBufferLen;
int ans = detectMotorola(DemodBuffer, &size);
size_t size = g_DemodBufferLen;
int ans = detectMotorola(g_DemodBuffer, &size);
if (ans < 0) {
if (ans == -1)
PrintAndLogEx(DEBUG, "DEBUG: Error - Motorola: too few bits found");
@@ -48,12 +48,12 @@ int demodMotorola(bool verbose) {
return PM3_ESOFT;
}
setDemodBuff(DemodBuffer, 64, ans);
setDemodBuff(g_DemodBuffer, 64, 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 raw1 = bytebits_to_byte(g_DemodBuffer, 32);
uint32_t raw2 = bytebits_to_byte(g_DemodBuffer + 32, 32);
// A0000000E308C0C1
// 10100000000000000000000000000000 1110 0011 0000 1000 1100 0000 1100 0001
@@ -74,42 +74,42 @@ int demodMotorola(bool verbose) {
// FC seems to be guess work. Need more samples
// guessing printed FC is 4 digits. 1024? 10bit?
// fc |= DemodBuffer[38] << 9; // b10
fc |= DemodBuffer[34] << 8; // b9
// fc |= g_DemodBuffer[38] << 9; // b10
fc |= g_DemodBuffer[34] << 8; // b9
fc |= DemodBuffer[44] << 7; // b8
fc |= DemodBuffer[47] << 6; // b7
fc |= DemodBuffer[57] << 5; // b6
fc |= DemodBuffer[49] << 4; // b5
fc |= g_DemodBuffer[44] << 7; // b8
fc |= g_DemodBuffer[47] << 6; // b7
fc |= g_DemodBuffer[57] << 5; // b6
fc |= g_DemodBuffer[49] << 4; // b5
// seems to match
fc |= DemodBuffer[53] << 3; // b4
fc |= DemodBuffer[48] << 2; // b3
fc |= DemodBuffer[58] << 1; // b2
fc |= DemodBuffer[39] << 0; // b1
fc |= g_DemodBuffer[53] << 3; // b4
fc |= g_DemodBuffer[48] << 2; // b3
fc |= g_DemodBuffer[58] << 1; // b2
fc |= g_DemodBuffer[39] << 0; // b1
// CSN was same as Indala CSN descramble.
uint16_t csn = 0;
csn |= DemodBuffer[42] << 15; // b16
csn |= DemodBuffer[45] << 14; // b15
csn |= DemodBuffer[43] << 13; // b14
csn |= DemodBuffer[40] << 12; // b13
csn |= DemodBuffer[52] << 11; // b12
csn |= DemodBuffer[36] << 10; // b11
csn |= DemodBuffer[35] << 9; // b10
csn |= DemodBuffer[51] << 8; // b9
csn |= DemodBuffer[46] << 7; // b8
csn |= DemodBuffer[33] << 6; // b7
csn |= DemodBuffer[37] << 5; // b6
csn |= DemodBuffer[54] << 4; // b5
csn |= DemodBuffer[56] << 3; // b4
csn |= DemodBuffer[59] << 2; // b3
csn |= DemodBuffer[50] << 1; // b2
csn |= DemodBuffer[41] << 0; // b1
csn |= g_DemodBuffer[42] << 15; // b16
csn |= g_DemodBuffer[45] << 14; // b15
csn |= g_DemodBuffer[43] << 13; // b14
csn |= g_DemodBuffer[40] << 12; // b13
csn |= g_DemodBuffer[52] << 11; // b12
csn |= g_DemodBuffer[36] << 10; // b11
csn |= g_DemodBuffer[35] << 9; // b10
csn |= g_DemodBuffer[51] << 8; // b9
csn |= g_DemodBuffer[46] << 7; // b8
csn |= g_DemodBuffer[33] << 6; // b7
csn |= g_DemodBuffer[37] << 5; // b6
csn |= g_DemodBuffer[54] << 4; // b5
csn |= g_DemodBuffer[56] << 3; // b4
csn |= g_DemodBuffer[59] << 2; // b3
csn |= g_DemodBuffer[50] << 1; // b2
csn |= g_DemodBuffer[41] << 0; // b1
uint8_t checksum = 0;
checksum |= DemodBuffer[62] << 1; // b2
checksum |= DemodBuffer[63] << 0; // b1
checksum |= g_DemodBuffer[62] << 1; // b2
checksum |= g_DemodBuffer[63] << 0; // b1
PrintAndLogEx(SUCCESS, "Motorola - fmt: " _GREEN_("26") " FC: " _GREEN_("%u") " Card: " _GREEN_("%u") ", Raw: %08X%08X", fc, csn, raw1, raw2);

Some files were not shown because too many files have changed in this diff Show More