Merge pull request #2741 from Donny-Guo/hidbrute
[RRG-proxmark3.git] / armsrc / Standalone / dankarmulti.h
blob617b99f10931125dd73dfe5ad507e7f6318e282c
1 //-----------------------------------------------------------------------------
2 // Copyright (C) Daniel Karling, 2021
3 // Copyright (C) Proxmark3 contributors. See AUTHORS.md for details.
4 //
5 // This program is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // See LICENSE.txt for the text of the license.
16 //-----------------------------------------------------------------------------
17 // main code for Multi Loader
18 //-----------------------------------------------------------------------------
19 #ifndef _DANKARMULTI_H_
20 #define _DANKARMULTI_H_
22 #ifdef MODE_NAME
23 #error "Do not define MODE_NAME when including this first time"
24 #endif
26 #ifdef MODE_FILE
27 #error "Do not define MODE_FILE when including this first time"
28 #endif
30 #define STRINGIZE(X) STRINGIZE2(X)
31 #define STRINGIZE2(X) #X
33 #define CONCAT(X,Y) CONCAT2(X,Y)
34 #define CONCAT2(X, Y) X##Y
36 typedef void (*func_ptr)(void);
38 typedef struct mode_t {
39 const char *name;
40 func_ptr run;
41 func_ptr info;
42 } mode_t;
44 #define MODE_INTERNAL_NAME(name) CONCAT(standalone_mode, CONCAT(_,name))
45 #define MODE_INFO_FUNC(name) CONCAT(ModInfo, CONCAT(_,name))
46 #define MODE_RUN_FUNC(name) CONCAT(RunMod, CONCAT(_,name))
48 #define START_MODE_LIST mode_t *mode_list[] = {
49 #define ADD_MODE(name) &MODE_INTERNAL_NAME(name),
50 #define END_MODE_LIST }; static const int NUM_MODES = ARRAYLEN(mode_list);
52 #else
54 #ifndef MODE_NAME
55 #error "Define LOAD_MODE before including this file multiple times"
56 #endif
58 #ifndef MODE_FILE
59 #error "Define LOAD_MODE before including this file multiple times"
60 #endif
62 void MODE_INFO_FUNC(MODE_NAME)(void);
63 void MODE_RUN_FUNC(MODE_NAME)(void);
65 #define ModInfo MODE_INFO_FUNC(MODE_NAME)
66 #define RunMod MODE_RUN_FUNC(MODE_NAME)
68 void ModInfo(void);
69 void RunMod(void);
71 #include MODE_FILE
73 static mode_t MODE_INTERNAL_NAME(MODE_NAME) = {
74 .name = STRINGIZE(MODE_NAME),
75 .run = RunMod,
76 .info = ModInfo
79 #undef ModInfo
80 #undef RunMod
81 #undef MODE_FILE
82 #undef MODE_NAME
84 #endif