Added standalone mode that can load multiple different modes

This commit is contained in:
Daniel Karling 2021-11-20 22:01:09 +01:00
commit 315e58dac4
6 changed files with 214 additions and 1 deletions

View file

@ -35,6 +35,7 @@ This project uses the changelog in accordance with [keepchangelog](http://keepac
- Fixed `hf mfdes` - increase response buffer length (@merlokk)
- Fixed `SimulateTagLowFrequencyEx` ignoring the `ledcontrol` argument (@zabszk)
- Added ledcontrol argument to LF operations (@zabszk)
- Added new standalone mode `dankarmulti` - select and run multiple standalone modes (@dankar)
## [crimson.4.14434][2021-09-18]
- Fixed `hf mf staticnested` - flashmem / non loop now works (@horrordash)

View file

@ -86,10 +86,13 @@ define KNOWN_STANDALONE_DEFINITIONS
| HF_YOUNG | Mifare sniff/simulation |
| | - Craig Young |
+----------------------------------------------------------+
| DANKARMULTI | Load multiple standalone modes. |
| | - Daniel Karling |
+----------------------------------------------------------+
endef
STANDALONE_MODES := LF_SKELETON LF_EM4100EMUL LF_EM4100RSWB LF_EM4100RWC LF_HIDBRUTE LF_HIDFCBRUTE LF_ICEHID LF_PROXBRUTE LF_SAMYRUN LF_THAREXDE LF_NEXID
STANDALONE_MODES += HF_14ASNIFF HF_AVEFUL HF_BOG HF_COLIN HF_CRAFTBYTE HF_ICECLASS HF_LEGIC HF_MATTYRUN HF_MFCSIM HF_MSDSAL HF_TCPRST HF_TMUDFORD HF_YOUNG HF_REBLAY
STANDALONE_MODES += HF_14ASNIFF HF_AVEFUL HF_BOG HF_COLIN HF_CRAFTBYTE HF_ICECLASS HF_LEGIC HF_MATTYRUN HF_MFCSIM HF_MSDSAL HF_TCPRST HF_TMUDFORD HF_YOUNG HF_REBLAY DANKARMULTI
STANDALONE_MODES_REQ_BT := HF_REBLAY
STANDALONE_MODES_REQ_SMARTCARD :=
STANDALONE_MODES_REQ_FLASH := LF_HIDFCBRUTE LF_ICEHID LF_NEXID LF_THAREXDE HF_14ASNIFF HF_BOG HF_COLIN HF_ICECLASS HF_MFCSIM

View file

@ -101,3 +101,7 @@ endif
ifneq (,$(findstring WITH_STANDALONE_HF_MFCSIM,$(APP_CFLAGS)))
SRC_STANDALONE = hf_mfcsim.c
endif
ifneq (,$(findstring WITH_STANDALONE_DANKARMULTI,$(APP_CFLAGS)))
SRC_STANDALONE = dankarmulti.c
endif

View file

@ -0,0 +1,138 @@
//-----------------------------------------------------------------------------
// Daniel Karling, 2021
//
// 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 Multi Loader
//-----------------------------------------------------------------------------
#include "standalone.h" // standalone definitions
#include "proxmark3_arm.h"
#include "appmain.h"
#include "fpgaloader.h"
#include "ticks.h"
#include "util.h"
#include "dbprint.h"
/*
* This mode will allow you to access multiple different standalone
* modes at the same time. The below section defines which modes are
* available. Modes are added to the mode list according to the
* following:
*
* 1) Include "dankarmulti.h"
* 2) Define MODE_NAME and MODE_FILE for a mode (MODE_NAME can
* of your choosing, but must be a valid C token. I.e. pretend
* that you are naming a variable)
* 3) Include "dankarmulti.h" again
* 4) Repeat steps 2 and 3 for additional modes.
* 5) Use the macros START_MODE_LIST, ADD_MODE and END_MODE_LIST
* to create the list of modes. You need to use the same names
* here as defined earlier.
*
* Usage:
* Single press to cycle between the modes.
* The LEDs will show the currently selected mode.
* Hold button to start the selected mode.
*
* How many modes can you have at the same time? Depends on memory,
* but the LEDs will overflow after 15.
*
* I don't know if this works with all the different standalone modes.
* I would imagine that it doesn't. If two modes are included with
* functions that collide (name-wise) there will be issues.
*
* NOTE: You will have to keep track of if the included modes require
* external memory or bluetooth yourself. The mode selection in
* the Makefiles is not able to do it.
*/
/*******************
* Begin mode list *
*******************/
#include "dankarmulti.h"
#define MODE_NAME sniff14a
#define MODE_FILE "hf_14asniff.c"
#include "dankarmulti.h"
#define MODE_NAME em4100
#define MODE_FILE "lf_em4100rswb.c"
#include "dankarmulti.h"
#define MODE_NAME icehid
#define MODE_FILE "lf_icehid.c"
#include "dankarmulti.h"
START_MODE_LIST
ADD_MODE(sniff14a)
ADD_MODE(em4100)
ADD_MODE(icehid)
END_MODE_LIST
/*******************
* End mode list *
*******************/
void update_mode(int selected);
void ModInfo(void) {
DbpString(" Multi standalone loader aka dankarmulti (Daniel Karling)");
}
void update_mode(int selected) {
if (selected >= NUM_MODES) {
SpinDown(100);
Dbprintf("Invalid mode selected");
LEDsoff();
} else {
Dbprintf("Selected mode: '%s'", mode_list[selected]->name);
LEDsoff();
LED(selected + 1, 0);
}
}
void RunMod(void) {
int selected_mode = 0;
StandAloneMode();
Dbprintf("[=] Multi standalone loader aka dankarmulti (Daniel Karling)");
Dbprintf("[=] Available modes:");
for (int i = 0; i < NUM_MODES; i++) {
Dbprintf("[=] '%s'", mode_list[i]->name);
}
update_mode(selected_mode);
// the main loop for your standalone mode
for (;;) {
WDT_HIT();
// exit from RunMod, send a usbcommand.
if (data_available()) break;
// Was our button held down or pressed?
int button_pressed = BUTTON_HELD(1000);
switch (button_pressed) {
case BUTTON_SINGLE_CLICK:
selected_mode = (selected_mode + 1) % NUM_MODES;
update_mode(selected_mode);
SpinDelay(300);
break;
case BUTTON_HOLD:
Dbprintf("Starting selected mode ('%s')", mode_list[selected_mode]->name);
mode_list[selected_mode]->run();
Dbprintf("Exited from selected mode");
return;
default:
break;
}
}
DbpString("[=] exiting");
LEDsoff();
}

View file

@ -0,0 +1,66 @@
#ifndef _DANKARMULTI_H_
#define _DANKARMULTI_H_
#ifdef MODE_NAME
#error "Do not define MODE_NAME when including this first time"
#endif
#ifdef MODE_FILE
#error "Do not define MODE_FILE when including this first time"
#endif
#define STRINGIZE(X) STRINGIZE2(X)
#define STRINGIZE2(X) #X
#define CONCAT(X,Y) CONCAT2(X,Y)
#define CONCAT2(X, Y) X##Y
typedef void (*func_ptr)(void);
typedef struct mode_t {
const char *name;
func_ptr run;
func_ptr info;
} mode_t;
#define MODE_INTERNAL_NAME(name) CONCAT(standalone_mode, CONCAT(_,name))
#define MODE_INFO_FUNC(name) CONCAT(ModInfo, CONCAT(_,name))
#define MODE_RUN_FUNC(name) CONCAT(RunMod, CONCAT(_,name))
#define START_MODE_LIST mode_t *mode_list[] = {
#define ADD_MODE(name) &MODE_INTERNAL_NAME(name),
#define END_MODE_LIST }; static const int NUM_MODES = sizeof(mode_list) / sizeof(mode_t*);
#else
#ifndef MODE_NAME
#error "Define LOAD_MODE before including this file multiple times"
#endif
#ifndef MODE_FILE
#error "Define LOAD_MODE before including this file multiple times"
#endif
void MODE_INFO_FUNC(MODE_NAME)(void);
void MODE_RUN_FUNC(MODE_NAME)(void);
#define ModInfo MODE_INFO_FUNC(MODE_NAME)
#define RunMod MODE_RUN_FUNC(MODE_NAME)
void ModInfo(void);
void RunMod(void);
#include MODE_FILE
static mode_t MODE_INTERNAL_NAME(MODE_NAME) = {
.name = STRINGIZE(MODE_NAME),
.run = RunMod,
.info = ModInfo
};
#undef ModInfo
#undef RunMod
#undef MODE_FILE
#undef MODE_NAME
#endif

View file

@ -104,6 +104,7 @@ Here are the supported values you can assign to `STANDALONE` in `Makefile.platfo
| HF_TCPRST | IKEA Rothult ST25TA, Standalone Master Key Dump/Emulation - Nick Draffen
| HF_TMUDFORD | Read and emulate ISO15693 card UID - Tim Mudford
| HF_YOUNG | Mifare sniff/simulation - Craig Young
| DANKARMULTI | Standalone mode that bakes together multiple other standalone modes. - dankar
By default `STANDALONE=LF_SAMYRUN`.