proxmark3/armsrc/Standalone/lf_samyrun.c

142 lines
3.5 KiB
C
Raw Normal View History

2017-08-26 19:01:35 +08:00
//-----------------------------------------------------------------------------
// Samy Kamkar, 2012
// Christian Herrmann, 2017
//
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
// at your option, any later version. See the LICENSE.txt file for the text of
// the license.
//-----------------------------------------------------------------------------
// main code for LF aka SamyRun by Samy Kamkar
//-----------------------------------------------------------------------------
#include "lf_samyrun.h"
// samy's sniff and repeat routine for LF
void RunMod() {
StandAloneMode();
FpgaDownloadAndGo(FPGA_BITSTREAM_LF);
uint32_t high[OPTS], low[OPTS];
2017-08-26 19:01:35 +08:00
int selected = 0;
int playing = 0;
int cardRead = 0;
bool gotCard;
2017-08-26 19:01:35 +08:00
// Turn on selected LED
LED(selected + 1, 0);
for (;;) {
WDT_HIT();
// exit from SamyRun, send a usbcommand.
if (usb_poll_validate_length()) break;
// Was our button held down or pressed?
int button_pressed = BUTTON_HELD(1000);
Dbprintf("button %d", button_pressed);
SpinDelay(300);
2017-08-26 19:01:35 +08:00
// Button was held for a second, begin recording
if (button_pressed > 0 && cardRead == 0) {
LEDsoff();
LED(selected + 1, 0);
LED(LED_RED2, 0);
// record
DbpString("[=] starting recording");
2017-08-26 19:01:35 +08:00
// wait for button to be released
2018-02-08 17:31:23 +08:00
while (BUTTON_PRESS())
2017-08-26 19:01:35 +08:00
WDT_HIT();
/* need this delay to prevent catching some weird data */
SpinDelay(500);
CmdHIDdemodFSK(1, &high[selected], &low[selected], 0);
Dbprintf("[=] recorded bank %x | %x %08x", selected, high[selected], low[selected]);
2017-08-26 19:01:35 +08:00
LEDsoff();
LED(selected + 1, 0);
// Finished recording
// If we were previously playing, set playing off
// so next button push begins playing what we recorded
playing = 0;
cardRead = 1;
gotCard = true;
2017-08-26 19:01:35 +08:00
}
else if (button_pressed > 0 && cardRead == 1) {
LEDsoff();
LED(selected + 1, 0);
LED(LED_ORANGE, 0);
// record
Dbprintf("[=] cloning %x %x %08x", selected, high[selected], low[selected]);
2017-08-26 19:01:35 +08:00
// wait for button to be released
2018-02-22 22:04:49 +08:00
while (BUTTON_PRESS())
2017-08-26 19:01:35 +08:00
WDT_HIT();
/* need this delay to prevent catching some weird data */
SpinDelay(500);
CopyHIDtoT55x7(0, high[selected], low[selected], 0);
Dbprintf("[=] cloned %x %x %08x", selected, high[selected], low[selected]);
2017-08-26 19:01:35 +08:00
LEDsoff();
LED(selected + 1, 0);
// Finished recording
// If we were previously playing, set playing off
// so next button push begins playing what we recorded
playing = 0;
cardRead = 0;
}
// Change where to record (or begin playing)
else if (button_pressed && gotCard) {
2017-08-26 19:01:35 +08:00
// Next option if we were previously playing
if (playing)
selected = (selected + 1) % OPTS;
2017-08-26 19:01:35 +08:00
playing = !playing;
LEDsoff();
LED(selected + 1, 0);
// Begin transmitting
if (playing) {
2017-08-26 19:01:35 +08:00
LED(LED_GREEN, 0);
DbpString("[=] playing");
2017-08-26 19:01:35 +08:00
// wait for button to be released
2018-02-08 17:31:23 +08:00
while (BUTTON_PRESS())
2017-08-26 19:01:35 +08:00
WDT_HIT();
Dbprintf("[=] %x %x %08x", selected, high[selected], low[selected]);
2018-02-22 22:13:43 +08:00
CmdHIDsimTAG(high[selected], low[selected], false);
DbpString("[=] done playing");
2017-08-26 19:01:35 +08:00
if (BUTTON_HELD(1000) > 0)
goto out;
2017-08-26 19:01:35 +08:00
/* We pressed a button so ignore it here with a delay */
SpinDelay(300);
// when done, we're done playing, move to next option
selected = (selected + 1) % OPTS;
playing = !playing;
LEDsoff();
LED(selected + 1, 0);
}
else {
2018-02-22 22:04:49 +08:00
while (BUTTON_PRESS())
2017-08-26 19:01:35 +08:00
WDT_HIT();
}
}
}
out:
DbpString("[=] exiting");
LEDsoff();
}