Merge pull request #6 from RfidResearchGroup/master

update
This commit is contained in:
mwalker33 2019-09-13 20:49:30 +10:00 committed by GitHub
commit 9e218dd376
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 47 additions and 39 deletions

View file

@ -78,7 +78,7 @@ void RunMod() {
WAIT_BUTTON_RELEASED();
// record
DbpString("[=] starting recording");
DbpString("[=] start recording");
// findone, high, low, no ledcontrol (A)
uint32_t hi = 0, lo = 0;
@ -86,16 +86,16 @@ void RunMod() {
high[selected] = hi;
low[selected] = lo;
Dbprintf("[=] recorded bank %x | %x%08x", selected, high[selected], low[selected]);
Dbprintf("[=] recorded %x | %x%08x", selected, high[selected], low[selected]);
// got nothing. blink and loop.
if ( hi == 0 && lo == 0 ) {
SpinErr( (selected == 0) ? LED_A : LED_B, 100, 12);
Dbprintf("[=] recorded nothing, looping");
DbpString("[=] only got zeros, retry recording after click");
continue;
}
SpinErr( (select==0) ? LED_A : LED_B, 250, 2);
SpinErr( (selected == 0) ? LED_A : LED_B, 250, 2);
state = STATE_SIM;
continue;
@ -109,7 +109,11 @@ void RunMod() {
// high, low, no led control(A) no time limit
CmdHIDsimTAGEx(high[selected], low[selected], false, -1);
SpinErr( LED_C, 250, 2);
DbpString("[=] simulating done");
uint8_t leds = ((selected == 0) ? LED_A : LED_B) | LED_C;
SpinErr( leds , 250, 2);
state = STATE_CLONE;
continue;
@ -119,17 +123,21 @@ void RunMod() {
LED_D_ON(); // clone
WAIT_BUTTON_RELEASED();
Dbprintf("[=] cloning %x | %x%08x", selected, high[selected], low[selected]);
Dbprintf("[=] cloning %x | %x%08x", selected, high[selected], low[selected]);
// high2, high, low, no longFMT
CopyHIDtoT55x7(0, high[selected], low[selected], 0);
DbpString("[=] cloned done");
state = STATE_READ;
SpinErr( LED_D, 250, 2);
uint8_t leds = ((selected == 0) ? LED_A : LED_B) | LED_D;
SpinErr(leds, 250, 2);
selected = (selected + 1) % OPTS;
LEDsoff();
}
}
DbpString("[=] exiting samyrun");
DbpString("[=] You can take shell back :) ...");
LEDsoff();
}

View file

@ -941,12 +941,10 @@ static void fcSTT(int *n) {
}
// compose fc/X fc/Y waveform (FSKx)
static uint8_t fcAll(uint8_t fc, int *n, uint8_t clock, uint16_t *modCnt) {
static void fcAll(uint8_t fc, int *n, uint8_t clock, int16_t *remainder) {
uint8_t *dest = BigBuf_get_addr();
uint8_t halfFC = fc >> 1;
uint8_t wavesPerClock = clock / fc;
uint8_t mod = clock % fc; //modifier
uint8_t wavesPerClock = (clock + *remainder) / fc;
// loop through clock - step field clock
for (uint8_t idx = 0; idx < wavesPerClock; idx++) {
// put 1/2 FC length 1's and 1/2 0's per field clock wave (to create the wave)
@ -954,27 +952,14 @@ static uint8_t fcAll(uint8_t fc, int *n, uint8_t clock, uint16_t *modCnt) {
memset(dest + (*n) + (fc - halfFC), 1, halfFC);
*n += fc;
}
if (mod > 0) {
uint8_t modAdj = fc / mod; //how often to apply modifier
bool modAdjOk = !(fc % mod); //if (fc % mod==0) modAdjOk = true;
(*modCnt)++;
if (modAdjOk) { //fsk2
if ((*modCnt % modAdj) == 0) { //if 4th 8 length wave in a rf/50 add extra 8 length wave
memset(dest + (*n), 0, fc - halfFC);
memset(dest + (*n) + (fc - halfFC), 1, halfFC);
*n += fc;
}
}
/* This code interfers with FSK2 and I don't see any example of FSK1 simulation in the code...
if (!modAdjOk) { //fsk1
memset(dest + (*n), 0, mod - (mod >> 1));
memset(dest + (*n) + (mod - (mod >> 1)), 1, mod >> 1);
*n += mod;
}
*/
*remainder = (clock + *remainder) % fc;
// if we've room for more than a half wave, add a full wave and use negative remainder
if (*remainder > halfFC) {
memset(dest + (*n), 0, fc - halfFC); //in case of odd number use extra here
memset(dest + (*n) + (fc - halfFC), 1, halfFC);
*n += fc;
*remainder -= fc;
}
return mod;
}
// prepare a waveform pattern in the buffer based on the ID given then
@ -1061,8 +1046,7 @@ void CmdFSKsimTAG(uint8_t fchigh, uint8_t fclow, uint8_t separator, uint8_t clk,
set_tracing(false);
int n = 0, i = 0;
uint16_t modCnt = 0;
uint8_t mod = 0;
int16_t remainder = 0;
if (separator) {
//int fsktype = ( fchigh == 8 && fclow == 5) ? 1 : 2;
@ -1070,9 +1054,9 @@ void CmdFSKsimTAG(uint8_t fchigh, uint8_t fclow, uint8_t separator, uint8_t clk,
}
for (i = 0; i < bitslen; i++) {
if (bits[i])
mod = fcAll(fchigh, &n, clk+mod, &modCnt);
fcAll(fchigh, &n, clk, &remainder);
else
mod = fcAll(fclow, &n, clk+mod, &modCnt);
fcAll(fclow, &n, clk, &remainder);
}
WDT_HIT();

View file

@ -36,6 +36,7 @@ static int usage_data_printdemodbuf(void) {
PrintAndLogEx(NORMAL, "Usage: data printdemodbuffer x o <offset> l <length>");
PrintAndLogEx(NORMAL, "Options:");
PrintAndLogEx(NORMAL, " h This help");
PrintAndLogEx(NORMAL, " i invert Demodbuffer before printing");
PrintAndLogEx(NORMAL, " x output in hex (omit for binary output)");
PrintAndLogEx(NORMAL, " o <offset> enter offset in # of bits");
PrintAndLogEx(NORMAL, " l <length> enter length to print in # of bits or hex characters respectively");
@ -251,7 +252,6 @@ static int usage_data_fsktonrz() {
return PM3_SUCCESS;
}
//set the demod buffer with given array of binary (one bit per byte)
//by marshmellow
void setDemodBuff(uint8_t *buff, size_t size, size_t start_idx) {
@ -404,6 +404,7 @@ int CmdPrintDemodBuff(const char *Cmd) {
bool hexMode = false;
bool errors = false;
bool lstrip = false;
bool invert = false;
uint32_t offset = 0;
uint32_t length = 512;
char cmdp = 0;
@ -427,7 +428,11 @@ int CmdPrintDemodBuff(const char *Cmd) {
break;
case 's':
lstrip = true;
cmdp ++;
cmdp++;
break;
case 'i':
invert = true;
cmdp++;
break;
default:
PrintAndLogEx(WARNING, "Unknown parameter '%c'", param_getchar(Cmd, cmdp));
@ -453,6 +458,18 @@ int CmdPrintDemodBuff(const char *Cmd) {
}
length = (length > (DemodBufferLen - offset)) ? DemodBufferLen - offset : length;
if (invert) {
char *buf = (char *)(DemodBuffer + offset);
for (uint32_t i = 0; i < length; i++) {
if ( buf[i] == 1 )
buf[i] = 0;
else {
if ( buf[i] == 0 )
buf[i] = 1;
}
}
}
if (hexMode) {
char *buf = (char *)(DemodBuffer + offset);
char hex[512] = {0x00};
@ -2160,7 +2177,6 @@ static command_t CommandTable[] = {
{"dec", CmdDec, AlwaysAvailable, "Decimate samples"},
{"detectclock", CmdDetectClockRate, AlwaysAvailable, "[<a|f|n|p>] Detect ASK, FSK, NRZ, PSK clock rate of wave in GraphBuffer"},
{"fsktonrz", CmdFSKToNRZ, AlwaysAvailable, "Convert fsk2 to nrz wave for alternate fsk demodulating (for weak fsk)"},
{"getbitstream", CmdGetBitStream, AlwaysAvailable, "Convert GraphBuffer's >=1 values to 1 and <1 to 0"},
{"grid", CmdGrid, AlwaysAvailable, "<x> <y> -- overlay grid on graph window, use zero value to turn off either"},
{"hexsamples", CmdHexsamples, IfPm3Present, "<bytes> [<offset>] -- Dump big buffer as hex bytes"},