@@ -69,44 +69,64 @@ void mifare_fuzzer_scene_emulator_on_enter(void* context) {
69
69
/// @return
70
70
bool mifare_fuzzer_scene_emulator_on_event (void * context , SceneManagerEvent event ) {
71
71
//FURI_LOG_D(TAG, "mifare_fuzzer_scene_emulator_on_event()");
72
- Iso14443_3aData nfc_data ;
73
-
74
72
MifareFuzzerApp * app = context ;
75
73
MifareFuzzerEmulator * emulator = app -> emulator_view ;
76
-
77
74
bool consumed = false;
78
75
79
76
if (event .type == SceneManagerEventTypeCustom ) {
80
77
if (event .event == MifareFuzzerEventStartAttack ) {
81
- //FURI_LOG_D(TAG, "mifare_fuzzer_scene_emulator_on_event() :: MifareFuzzerEventStartAttack");
78
+ NfcDevice * nfc_device = NULL ;
79
+ const MfClassicData * mf_classic_data = NULL ;
80
+ if (app -> card_file_path ) {
81
+ nfc_device = app -> worker -> nfc_device ;
82
+ const char * path = furi_string_get_cstr (app -> card_file_path );
83
+ if (nfc_device_load (nfc_device , path )) {
84
+ mf_classic_data = nfc_device_get_data (nfc_device , NfcProtocolMfClassic );
85
+ if (mf_classic_data -> type == MfClassicType1k ) {
86
+ app -> card = MifareCardClassic1k ;
87
+ } else if (mf_classic_data -> type == MfClassicType4k ) {
88
+ app -> card = MifareCardClassic4k ;
89
+ } else if (nfc_device_get_protocol (nfc_device ) == NfcProtocolMfUltralight ) {
90
+ app -> card = MifareCardUltralight ;
91
+ }
92
+ mifare_fuzzer_emulator_set_card (emulator , app -> card , app -> card_file_path );
93
+ }
94
+ }
95
+
96
+ Iso14443_3aData * nfc_data ;
97
+ if (mf_classic_data ) {
98
+ nfc_data = mf_classic_data -> iso14443_3a_data ;
99
+ } else {
100
+ nfc_data = iso14443_3a_alloc ();
101
+ }
82
102
83
103
// Stop worker
84
104
mifare_fuzzer_worker_stop (app -> worker );
85
105
86
106
// Set card type
87
107
// TODO: Move somewhere else, I do not like this to be there
88
108
if (app -> card == MifareCardClassic1k ) {
89
- nfc_data . atqa [0 ] = 0x04 ;
90
- nfc_data . atqa [1 ] = 0x00 ;
91
- nfc_data . sak = 0x08 ;
92
- nfc_data . uid_len = 0x04 ;
109
+ nfc_data -> atqa [0 ] = 0x04 ;
110
+ nfc_data -> atqa [1 ] = 0x00 ;
111
+ nfc_data -> sak = 0x08 ;
112
+ nfc_data -> uid_len = 0x04 ;
93
113
} else if (app -> card == MifareCardClassic4k ) {
94
- nfc_data . atqa [0 ] = 0x02 ;
95
- nfc_data . atqa [1 ] = 0x00 ;
96
- nfc_data . sak = 0x18 ;
97
- nfc_data . uid_len = 0x04 ;
114
+ nfc_data -> atqa [0 ] = 0x02 ;
115
+ nfc_data -> atqa [1 ] = 0x00 ;
116
+ nfc_data -> sak = 0x18 ;
117
+ nfc_data -> uid_len = 0x04 ;
98
118
} else if (app -> card == MifareCardUltralight ) {
99
- nfc_data . atqa [0 ] = 0x44 ;
100
- nfc_data . atqa [1 ] = 0x00 ;
101
- nfc_data . sak = 0x00 ;
102
- nfc_data . uid_len = 0x07 ;
119
+ nfc_data -> atqa [0 ] = 0x44 ;
120
+ nfc_data -> atqa [1 ] = 0x00 ;
121
+ nfc_data -> sak = 0x00 ;
122
+ nfc_data -> uid_len = 0x07 ;
103
123
}
104
124
105
125
// Set UIDs
106
126
if (app -> attack == MifareFuzzerAttackTestValues ) {
107
127
// Load test UIDs
108
- for (uint8_t i = 0 ; i < nfc_data . uid_len ; i ++ ) {
109
- nfc_data . uid [i ] = id_uid_test [attack_step ][i ];
128
+ for (uint8_t i = 0 ; i < nfc_data -> uid_len ; i ++ ) {
129
+ nfc_data -> uid [i ] = id_uid_test [attack_step ][i ];
110
130
}
111
131
// Next UIDs on next loop
112
132
if (attack_step >= 8 ) {
@@ -123,13 +143,13 @@ bool mifare_fuzzer_scene_emulator_on_event(void* context, SceneManagerEvent even
123
143
124
144
// TODO: Manufacture-code must be selectable from a list
125
145
// use a fixed manufacture-code for now: 0x04 = NXP Semiconductors Germany
126
- nfc_data . uid [0 ] = 0x04 ;
127
- for (uint8_t i = 1 ; i < nfc_data . uid_len ; i ++ ) {
128
- nfc_data . uid [i ] = (furi_hal_random_get () & 0xFF );
146
+ nfc_data -> uid [0 ] = 0x04 ;
147
+ for (uint8_t i = 1 ; i < nfc_data -> uid_len ; i ++ ) {
148
+ nfc_data -> uid [i ] = (furi_hal_random_get () & 0xFF );
129
149
}
130
150
} else {
131
- for (uint8_t i = 0 ; i < nfc_data . uid_len ; i ++ ) {
132
- nfc_data . uid [i ] = (furi_hal_random_get () & 0xFF );
151
+ for (uint8_t i = 0 ; i < nfc_data -> uid_len ; i ++ ) {
152
+ nfc_data -> uid [i ] = (furi_hal_random_get () & 0xFF );
133
153
}
134
154
}
135
155
} else if (app -> attack == MifareFuzzerAttackLoadUidsFromFile ) {
@@ -157,29 +177,32 @@ bool mifare_fuzzer_scene_emulator_on_event(void* context, SceneManagerEvent even
157
177
158
178
// parse string to UID
159
179
// TODO: a better validation on input?
160
- for (uint8_t i = 0 ; i < nfc_data . uid_len ; i ++ ) {
180
+ for (uint8_t i = 0 ; i < nfc_data -> uid_len ; i ++ ) {
161
181
if (i <= ((furi_string_size (app -> uid_str ) - 1 ) / 2 )) {
162
182
char temp_str [3 ];
163
183
temp_str [0 ] = furi_string_get_cstr (app -> uid_str )[i * 2 ];
164
184
temp_str [1 ] = furi_string_get_cstr (app -> uid_str )[i * 2 + 1 ];
165
185
temp_str [2 ] = '\0' ;
166
- nfc_data . uid [i ] = (uint8_t )strtol (temp_str , NULL , 16 );
186
+ nfc_data -> uid [i ] = (uint8_t )strtol (temp_str , NULL , 16 );
167
187
} else {
168
- nfc_data . uid [i ] = 0x00 ;
188
+ nfc_data -> uid [i ] = 0x00 ;
169
189
}
170
190
}
171
191
}
172
192
173
- mifare_fuzzer_worker_set_nfc_data (app -> worker , nfc_data );
174
- mifare_fuzzer_emulator_set_nfc_data (app -> emulator_view , nfc_data );
193
+ mifare_fuzzer_emulator_set_nfc_data (app -> emulator_view , * nfc_data );
194
+ if (nfc_device_parsed ) {
195
+ mifare_fuzzer_worker_set_nfc_device (app -> worker , nfc_device );
196
+ } else {
197
+ mifare_fuzzer_worker_set_nfc_data (app -> worker , * nfc_data );
198
+ }
175
199
176
200
// Reset tick_counter
177
201
tick_counter = 0 ;
178
202
mifare_fuzzer_emulator_set_tick_num (app -> emulator_view , tick_counter );
179
203
180
204
// Start worker
181
205
mifare_fuzzer_worker_start (app -> worker );
182
-
183
206
} else if (event .event == MifareFuzzerEventStopAttack ) {
184
207
//FURI_LOG_D(TAG, "mifare_fuzzer_scene_emulator_on_event() :: MifareFuzzerEventStopAttack");
185
208
// Stop worker
0 commit comments