Merge remote-tracking branch 'upstream/master' into hf_mf_sim

This commit is contained in:
vratiskol 2019-03-25 15:51:21 +01:00
commit 04c14d1931
10 changed files with 41 additions and 41 deletions

View file

@ -58,8 +58,6 @@ APP_CFLAGS = $(PLATFORM_DEFS) \
# -DWITH_HF_COLIN
# -DWITH_HF_BOG
SRC_LCD = fonts.c LCD.c
SRC_LF = lfops.c hitag2_crypto.c hitag2.c hitagS.c lfsampling.c pcf7931.c lfdemod.c
SRC_ISO15693 = iso15693.c iso15693tools.c
SRC_ISO14443a = iso14443a.c mifareutil.c mifarecmd.c epa.c mifaresim.c
@ -90,6 +88,12 @@ else
SRC_FPC =
endif
ifneq (,$(findstring WITH_LCD,$(APP_CLAGS)))
SRC_LCD = fonts.c LCD.c
else
SRC_LCD =
endif
# Generic standalone Mode injection of source code
SRC_STANDALONE =
# WITH_LF_ICERUN

View file

@ -375,7 +375,7 @@ void printDemodBuff(void) {
}
if (len > 512) len = 512;
PrintAndLogEx(NORMAL, "%s", sprint_bin_break(DemodBuffer, len, 16));
PrintAndLogEx(NORMAL, "%s", sprint_bin_break(DemodBuffer, len, 32));
}
int CmdPrintDemodBuff(const char *Cmd) {
@ -426,7 +426,7 @@ int CmdPrintDemodBuff(const char *Cmd) {
}
PrintAndLogEx(NORMAL, "DemodBuffer: %s", hex);
} else {
PrintAndLogEx(NORMAL, "DemodBuffer:\n%s", sprint_bin_break(DemodBuffer + offset, length, 16));
PrintAndLogEx(NORMAL, "DemodBuffer:\n%s", sprint_bin_break(DemodBuffer + offset, length, 32));
}
return 1;
}
@ -599,7 +599,7 @@ int Cmdmandecoderaw(const char *Cmd) {
}
PrintAndLogEx(NORMAL, "Manchester Decoded - # errors:%d - data:", errCnt);
PrintAndLogEx(NORMAL, "%s", sprint_bin_break(bits, size, 16));
PrintAndLogEx(NORMAL, "%s", sprint_bin_break(bits, size, 32));
if (errCnt == 0) {
uint64_t id = 0;
@ -650,7 +650,7 @@ int CmdBiphaseDecodeRaw(const char *Cmd) {
PrintAndLogEx(WARNING, "# Errors found during Demod (shown as " _YELLOW_("7")" in bit stream): %d", errCnt);
PrintAndLogEx(NORMAL, "Biphase Decoded using offset: %d - # invert:%d - data:", offset, invert);
PrintAndLogEx(NORMAL, "%s", sprint_bin_break(bits, size, 16));
PrintAndLogEx(NORMAL, "%s", sprint_bin_break(bits, size, 32));
//remove first bit from raw demod
if (offset)
@ -1094,7 +1094,9 @@ int CmdFSKrawdemod(const char *Cmd) {
//attempt to psk1 demod graph buffer
int PSKDemod(const char *Cmd, bool verbose) {
int invert = 0, clk = 0, maxErr = 100;
sscanf(Cmd, "%i %i %i", &clk, &invert, &maxErr);
if (clk == 1) {
invert = 1;
clk = 0;
@ -1107,28 +1109,29 @@ int PSKDemod(const char *Cmd, bool verbose) {
if (getSignalProperties()->isnoise)
return 0;
uint8_t BitStream[MAX_GRAPH_TRACE_LEN] = {0};
size_t BitLen = getFromGraphBuf(BitStream);
if (BitLen == 0) return 0;
int errCnt = 0;
uint8_t bits[MAX_GRAPH_TRACE_LEN] = {0};
size_t bitlen = getFromGraphBuf(bits);
if (bitlen == 0)
return 0;
int startIdx = 0;
errCnt = pskRawDemod_ext(BitStream, &BitLen, &clk, &invert, &startIdx);
int errCnt = pskRawDemod_ext(bits, &bitlen, &clk, &invert, &startIdx);
if (errCnt > maxErr) {
if (g_debugMode || verbose) PrintAndLogEx(DEBUG, "DEBUG: (PSKdemod) Too many errors found, clk: %d, invert: %d, numbits: %d, errCnt: %d", clk, invert, BitLen, errCnt);
if (g_debugMode || verbose) PrintAndLogEx(DEBUG, "DEBUG: (PSKdemod) Too many errors found, clk: %d, invert: %d, numbits: %d, errCnt: %d", clk, invert, bitlen, errCnt);
return 0;
}
if (errCnt < 0 || BitLen < 16) { //throw away static - allow 1 and -1 (in case of threshold command first)
if (g_debugMode || verbose) PrintAndLogEx(DEBUG, "DEBUG: (PSKdemod) no data found, clk: %d, invert: %d, numbits: %d, errCnt: %d", clk, invert, BitLen, errCnt);
if (errCnt < 0 || bitlen < 16) { //throw away static - allow 1 and -1 (in case of threshold command first)
if (g_debugMode || verbose) PrintAndLogEx(DEBUG, "DEBUG: (PSKdemod) no data found, clk: %d, invert: %d, numbits: %d, errCnt: %d", clk, invert, bitlen, errCnt);
return 0;
}
if (verbose || g_debugMode) {
PrintAndLogEx(DEBUG, "DEBUG: (PSKdemod) Using Clock:%d, invert:%d, Bits Found:%d", clk, invert, BitLen);
PrintAndLogEx(DEBUG, "DEBUG: (PSKdemod) Using Clock:%d, invert:%d, Bits Found:%d", clk, invert, bitlen);
if (errCnt > 0) {
PrintAndLogEx(DEBUG, "DEBUG: (PSKdemod) errors during Demoding (shown as 7 in bit stream): %d", errCnt);
}
}
//prime demod buffer for output
setDemodBuf(BitStream, BitLen, 0);
setDemodBuf(bits, bitlen, 0);
setClockGrid(clk, startIdx);
return 1;
}

View file

@ -18,6 +18,8 @@ A5B4C3D2,
1C0B5848,
# paxton bullit?
575F4F4B,
#
50520901,
# Default pwd, simple:
00000000,
11111111,

View file

@ -256,12 +256,12 @@ char *sprint_bin_break(const uint8_t *data, const size_t len, const uint8_t brea
sprintf(tmp++, ".");
else
sprintf(tmp++, "%u", data[in_index]);
// check if a line break is needed and we have room to print it in our array
if ((breaks > 0) && !((in_index + 1) % breaks) && (out_index + 1 != rowlen)) {
// increment and print line break
out_index++;
sprintf(tmp++, "%s", "\n");
}
in_index++;
}

View file

@ -46,10 +46,6 @@ void legic_prng_forward(int count) {
}
}
uint32_t legic_prng_count() {
return lfsr.c;
}
uint8_t legic_prng_get_bit() {
uint8_t idx = 7 - ((lfsr.a & 4) | (lfsr.a >> 2 & 2) | (lfsr.a >> 4 & 1));
return lfsr.b >> idx & 1;

View file

@ -57,7 +57,7 @@ extern void Dbprintf(const char *fmt, ...);
#include "ui.h"
# include "cmdparser.h"
# include "cmddata.h"
# define prnt PrintAndLog
# define prnt(args...) PrintAndLogEx(DEBUG, ## args );
#else
uint8_t g_debugMode = 0;
# define prnt Dbprintf
@ -262,7 +262,8 @@ bool preambleSearch(uint8_t *bits, uint8_t *preamble, size_t pLen, size_t *size,
//(iceman) FINDONE, only finds start index. NOT SIZE!. I see Em410xDecode (lfdemod.c) uses SIZE to determine success
bool preambleSearchEx(uint8_t *bits, uint8_t *preamble, size_t pLen, size_t *size, size_t *startIdx, bool findone) {
// Sanity check. If preamble length is bigger than bits length.
if (*size <= pLen) return false;
if (*size <= pLen)
return false;
uint8_t foundCnt = 0;
for (size_t idx = 0; idx < *size - pLen; idx++) {
@ -967,11 +968,6 @@ int DetectPSKClock(uint8_t *dest, size_t size, int clock, size_t *firstPhaseShif
uint8_t clk[] = {255, 16, 32, 40, 50, 64, 100, 128, 255}; //255 is not a valid clock
uint16_t loopCnt = 4096; //don't need to loop through entire array...
//if we already have a valid clock quit
size_t i = 1;
for (; i < 8; ++i)
if (clk[i] == clock) return clock;
if (size < 160 + 20) return 0;
// size must be larger than 20 here, and 160 later on.
if (size < loopCnt) loopCnt = size - 20;
@ -995,7 +991,7 @@ int DetectPSKClock(uint8_t *dest, size_t size, int clock, size_t *firstPhaseShif
uint16_t peaksdet[] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
//find start of modulating data in trace
i = findModStart(dest, size, *fc);
size_t i = findModStart(dest, size, *fc);
firstFullWave = pskFindFirstPhaseShift(dest, size, curPhase, i, *fc, &fullWaveLen);
if (firstFullWave == 0) {

View file

@ -38,7 +38,7 @@ typedef struct {
} signal_t;
signal_t *getSignalProperties(void);
void computeSignalProperties(uint8_t *bits, uint32_t size);
void computeSignalProperties(uint8_t *samples, uint32_t size);
void removeSignalOffset(uint8_t *samples, uint32_t size);
void getNextLow(uint8_t *samples, size_t size, int low, size_t *i);
void getNextHigh(uint8_t *samples, size_t size, int high, size_t *i);
@ -61,7 +61,7 @@ extern int DetectNRZClock(uint8_t *dest, size_t size, int clock, size_t *cl
extern int DetectPSKClock(uint8_t *dest, size_t size, int clock, size_t *firstPhaseShift, uint8_t *curPhase, uint8_t *fc);
extern int DetectStrongAskClock(uint8_t *dest, size_t size, int high, int low, int *clock);
extern bool DetectST(uint8_t *buffer, size_t *size, int *foundclock, size_t *ststart, size_t *stend);
extern size_t fskdemod(uint8_t *dest, size_t size, uint8_t rfLen, uint8_t invert, uint8_t fchigh, uint8_t fclow, int *startIdx);
extern size_t fskdemod(uint8_t *dest, size_t size, uint8_t rfLen, uint8_t invert, uint8_t fchigh, uint8_t fclow, int *start_idx);
//extern void getHiLo(uint8_t *bits, size_t size, int *high, int *low, uint8_t fuzzHi, uint8_t fuzzLo);
extern void getHiLo(int *high, int *low, uint8_t fuzzHi, uint8_t fuzzLo);
extern uint32_t manchesterEncode2Bytes(uint16_t datain);

View file

@ -36,22 +36,22 @@ uint8_t checkParity(uint32_t bits, uint8_t len, uint8_t type);
// by marshmellow
// takes a array of binary values, start position, length of bits per parity (includes parity bit),
// Parity Type (1 for odd; 0 for even; 2 for Always 1's; 3 for Always 0's), and binary Length (length to run)
size_t removeParity(uint8_t *bitstream, size_t startIdx, uint8_t pLen, uint8_t pType, size_t bLen) {
size_t removeParity(uint8_t *bits, size_t startIdx, uint8_t pLen, uint8_t pType, size_t bLen) {
uint32_t parityWd = 0;
size_t j = 0, bitcount = 0;
for (int word = 0; word < (bLen); word += pLen) {
for (int bit = 0; bit < pLen; ++bit) {
parityWd = (parityWd << 1) | bitstream[startIdx + word + bit];
bitstream[j++] = (bitstream[startIdx + word + bit]);
parityWd = (parityWd << 1) | bits[startIdx + word + bit];
bits[j++] = (bits[startIdx + word + bit]);
}
j--; // overwrite parity with next data
// if parity fails then return 0
switch (pType) {
case 3:
if (bitstream[j] == 1) return 0;
if (bits[j] == 1) return 0;
break; //should be 0 spacer bit
case 2:
if (bitstream[j] == 0) return 0;
if (bits[j] == 0) return 0;
break; //should be 1 spacer bit
default: //test parity
if (parityTest(parityWd, pLen, pType) == 0) return 0;

View file

@ -12,8 +12,8 @@
#include "common.h"
#include "util.h"
uint8_t getParity(uint8_t *bits, uint8_t length, uint8_t type);
uint8_t checkParity(uint32_t bits, uint8_t bitlen, uint8_t type);
uint8_t getParity(uint8_t *bits, uint8_t len, uint8_t type);
uint8_t checkParity(uint32_t bits, uint8_t len, uint8_t type);
void num_to_wiegand_bytes(uint64_t oem, uint64_t fc, uint64_t cn, uint8_t *dest, uint8_t formatlen);
void num_to_wiegand_bits(uint64_t oem, uint64_t fc, uint64_t cn, uint8_t *dest, uint8_t formatlen);

View file

@ -10,9 +10,8 @@
#define __LEGIC_PRNG_H
#include <stdint.h>
extern void legic_prng_init(uint8_t init);
extern void legic_prng_init(uint8_t iv);
extern void legic_prng_forward(int count);
extern uint32_t legic_prng_count();
extern uint8_t legic_prng_get_bit();
extern uint32_t legic_prng_get_bits(uint8_t len);
#endif