mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-20 13:23:51 -07:00
hs_mfcsim refactored
add multi cards support
This commit is contained in:
parent
6d673b1063
commit
abb8e9f4c0
1 changed files with 46 additions and 49 deletions
|
@ -30,56 +30,47 @@
|
||||||
* It requires RDV4 hardware (for flash and battery).
|
* It requires RDV4 hardware (for flash and battery).
|
||||||
*
|
*
|
||||||
* On entering stand-alone mode, this module will start simulating.
|
* On entering stand-alone mode, this module will start simulating.
|
||||||
* Data is read from bin dump file uploaded to flash memory (hf_mfcsim_dump.bin).
|
* Data is read from bin dump file uploaded to flash memory (hf_mfcsim_dump_xx.bin).
|
||||||
* Only support mifare classic 1k
|
* Only support mifare classic 1k
|
||||||
*
|
*
|
||||||
* LEDs:
|
|
||||||
* - LED A: initializing
|
|
||||||
* - LED B: simulating
|
|
||||||
* - LED C blinking: data transmiting
|
|
||||||
*
|
|
||||||
* To upload input file (eml format) to flash:
|
* To upload input file (eml format) to flash:
|
||||||
* - mem spiffs upload -s <filename> -d hf_mfcsim_dump.bin
|
* - mem spiffs upload -s <filename> -d hf_mfcsim_dump_xx.bin (Notes: xx is form 01 to 15)
|
||||||
* To delete the input file from flash:
|
* To delete the input file from flash:
|
||||||
* - mem spiffs remove -f hf_mfcsim_dump.bin
|
* - mem spiffs remove -f hf_mfcsim_dump_xx.bin (Notes: xx is form 01 to 15)
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define HF_MFCSIM_INPUTFILE_SIM "hf_mfcsim_dump.bin"
|
#define HF_MFCSIM_DUMPFILE_SIM "hf_mfcsim_dump_%02d.bin"
|
||||||
#define DUMP_SIZE 1024
|
#define DUMP_SIZE 1024
|
||||||
|
|
||||||
static uint8_t uid[10];
|
static char cur_dump_file[22] = {0};
|
||||||
|
|
||||||
static bool ecfill_from_file(char *inputfile) {
|
static bool ecfill_from_file(char *dumpfile) {
|
||||||
|
|
||||||
if (exists_in_spiffs(inputfile)) {
|
|
||||||
uint32_t size = size_in_spiffs(inputfile);
|
|
||||||
uint8_t *mem = BigBuf_malloc(size);
|
|
||||||
if (!mem) {
|
|
||||||
Dbprintf(_RED_("No memory!"));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
//read dumpfile
|
|
||||||
Dbprintf(_YELLOW_("Found dump file %s"), inputfile);
|
|
||||||
rdv40_spiffs_read_as_filetype(inputfile, mem, size, RDV40_SPIFFS_SAFETY_SAFE);
|
|
||||||
|
|
||||||
|
if (exists_in_spiffs(dumpfile)) {
|
||||||
//check dumpfile size
|
//check dumpfile size
|
||||||
Dbprintf(_YELLOW_("File size is %d"), size);
|
uint32_t size = size_in_spiffs(dumpfile);
|
||||||
if (size != DUMP_SIZE) {
|
if (size != DUMP_SIZE) {
|
||||||
Dbprintf(_RED_("Only support Mifare Classic 1K! Please check the dumpfile"));
|
Dbprintf(_RED_("File Size: %dB The dump file size is incorrect! Only support Mifare Classic 1K! Please check it."));
|
||||||
BigBuf_free();
|
BigBuf_free();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//load the dump into emulator memory
|
uint8_t *mem = BigBuf_malloc(size);
|
||||||
Dbprintf(_YELLOW_("Read card data from input file"));
|
if (!mem) {
|
||||||
|
Dbprintf(_RED_("No memory!"));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//read and load dump file
|
||||||
|
if (DBGLEVEL >= DBG_INFO) Dbprintf(_YELLOW_("Found dump file %s. Uploading to emulator memory..."), dumpfile);
|
||||||
|
rdv40_spiffs_read_as_filetype(dumpfile, mem, size, RDV40_SPIFFS_SAFETY_SAFE);
|
||||||
|
emlClearMem();
|
||||||
emlSetMem(mem, 0, MIFARE_1K_MAXBLOCK);
|
emlSetMem(mem, 0, MIFARE_1K_MAXBLOCK);
|
||||||
Dbprintf(_YELLOW_("Uploaded to emulator memory"));
|
|
||||||
BigBuf_free_keep_EM();
|
BigBuf_free_keep_EM();
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
Dbprintf(_RED_("no input file %s"), inputfile);
|
Dbprintf(_RED_("Dump file %s not found!"), dumpfile);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return false;//Shouldn't be here
|
return false;//Shouldn't be here
|
||||||
|
@ -90,31 +81,37 @@ void ModInfo(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void RunMod(void) {
|
void RunMod(void) {
|
||||||
|
//initializing
|
||||||
StandAloneMode();
|
StandAloneMode();
|
||||||
FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
|
FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
|
||||||
|
rdv40_spiffs_lazy_mount();
|
||||||
Dbprintf(_YELLOW_("Standalone mode MFCSIM started!"));
|
Dbprintf(_YELLOW_("Standalone mode MFCSIM started!"));
|
||||||
|
|
||||||
LED_A_ON();
|
bool flag_has_dumpfile = false;
|
||||||
|
for (int i = 1;; i++) {
|
||||||
|
if (i > 15) {
|
||||||
|
if (flag_has_dumpfile) i = 1; //Next loop!
|
||||||
|
else break;//No dump,Exit!
|
||||||
|
}
|
||||||
|
LED(i, 1000);
|
||||||
emlClearMem();
|
emlClearMem();
|
||||||
Dbprintf(_YELLOW_("Emulator memory initialized"));
|
|
||||||
rdv40_spiffs_lazy_mount();
|
sprintf(cur_dump_file, HF_MFCSIM_DUMPFILE_SIM, i);
|
||||||
if (!ecfill_from_file(HF_MFCSIM_INPUTFILE_SIM)) {
|
Dbprintf(_YELLOW_("[Slot: %d] Try to load dump file: %s"), i, cur_dump_file);
|
||||||
Dbprintf(_RED_("Load data failed!"));
|
if (!ecfill_from_file(cur_dump_file)) {
|
||||||
|
Dbprintf(_YELLOW_("[Slot: %d] Dump load Failed, Next one!"), i);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
flag_has_dumpfile = true;
|
||||||
|
|
||||||
|
Dbprintf(_YELLOW_("[Slot: %d] Simulation start, Press button to change next card."), i);
|
||||||
|
uint16_t simflags = FLAG_UID_IN_EMUL | FLAG_MF_1K;
|
||||||
|
Mifare1ksim(simflags, 0, NULL, 0, 0);
|
||||||
|
Dbprintf(_YELLOW_("[Slot: %d] Simulation end, Change to next card!"), i);
|
||||||
|
}
|
||||||
|
Dbprintf("No dump file found, Exit!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Dbprintf(_YELLOW_("Emulator memory filled, simulation ready to start."));
|
|
||||||
Dbprintf(_YELLOW_("Press button to abort simulation at anytime."));
|
|
||||||
|
|
||||||
SpinOff(1000);
|
|
||||||
|
|
||||||
LED_B_ON();
|
|
||||||
Dbprintf(_YELLOW_("Simulation start!"));
|
|
||||||
uint16_t simflags = FLAG_UID_IN_EMUL | FLAG_MF_1K;
|
|
||||||
Mifare1ksim(simflags, 0, uid, 0, 0);
|
|
||||||
|
|
||||||
Dbprintf(_YELLOW_("Simulation end!"));
|
|
||||||
LEDsoff();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue