Skip to content

Commit 75ee4ef

Browse files
committed
Fix ibtn fuzzer file loading (temp)
1 parent 5a2fbf4 commit 75ee4ef

File tree

2 files changed

+144
-30
lines changed

2 files changed

+144
-30
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
-----
44
* Only in release 052 -> **Multiple Extra pack apps was fixed!** -> TAMA P1, Flizzer Tracker, Video Player, Music Tracker
55
* NFC V: Remove delay from emulation loop. This improves compatibility when the reader is Android.
6+
* Plugins: iButton Fuzzer -> Fix v2 key files load (all new saved files)
67
### Previous changes
78
* SubGHz Remote: Fixed BinRAW support, + many other fixes (by @gid9798 | PR #492)
89
* SubGHz: Fix KL: Stilmatic support + add manually support

applications/external/ibtn_fuzzer/scene/ibtnfuzzer_scene_load_file.c

+143-30
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ bool ibtnfuzzer_load(iBtnFuzzerState* context, const char* file_path) {
1010
FlipperFormat* fff_data_file = flipper_format_file_alloc(storage);
1111
FuriString* temp_str;
1212
temp_str = furi_string_alloc();
13+
bool key_v2 = false;
1314
do {
1415
if(!flipper_format_file_open_existing(fff_data_file, file_path)) {
1516
FURI_LOG_E(TAG, "Error open file %s", file_path);
@@ -30,10 +31,43 @@ bool ibtnfuzzer_load(iBtnFuzzerState* context, const char* file_path) {
3031

3132
// Key type
3233
if(!flipper_format_read_string(fff_data_file, "Key type", temp_str)) {
33-
FURI_LOG_E(TAG, "Missing or incorrect Key type");
34-
furi_string_reset(context->notification_msg);
35-
furi_string_set(context->notification_msg, "Missing or incorrect Key type");
36-
break;
34+
FURI_LOG_E(TAG, "Missing or incorrect Key type, checking for typ2..");
35+
36+
if(!flipper_format_rewind(fff_data_file)) {
37+
FURI_LOG_E(TAG, "Failed to rewind file");
38+
break;
39+
}
40+
if(!flipper_format_read_string(fff_data_file, "Protocol", temp_str)) {
41+
furi_string_reset(context->notification_msg);
42+
furi_string_set(
43+
context->notification_msg, "Missing or incorrect Protocol or Key type");
44+
break;
45+
}
46+
FURI_LOG_I(TAG, "Key type V2: %s", furi_string_get_cstr(temp_str));
47+
key_v2 = true;
48+
49+
if(context->proto == DS1990) {
50+
if(strcmp(furi_string_get_cstr(temp_str), "DS1990") != 0) {
51+
FURI_LOG_E(TAG, "Unsupported Key type");
52+
furi_string_reset(context->notification_msg);
53+
furi_string_set(context->notification_msg, "Unsupported Key type");
54+
break;
55+
}
56+
} else if(context->proto == Cyfral) {
57+
if(strcmp(furi_string_get_cstr(temp_str), "Cyfral") != 0) {
58+
FURI_LOG_E(TAG, "Unsupported Key type");
59+
furi_string_reset(context->notification_msg);
60+
furi_string_set(context->notification_msg, "Unsupported Key type");
61+
break;
62+
}
63+
} else {
64+
if(strcmp(furi_string_get_cstr(temp_str), "Metakom") != 0) {
65+
FURI_LOG_E(TAG, "Unsupported Key type");
66+
furi_string_reset(context->notification_msg);
67+
furi_string_set(context->notification_msg, "Unsupported Key type");
68+
break;
69+
}
70+
}
3771
} else {
3872
FURI_LOG_I(TAG, "Key type: %s", furi_string_get_cstr(temp_str));
3973

@@ -60,46 +94,125 @@ bool ibtnfuzzer_load(iBtnFuzzerState* context, const char* file_path) {
6094
}
6195
}
6296
}
97+
if(!key_v2) {
98+
// Data
99+
if(!flipper_format_read_string(fff_data_file, "Data", context->data_str)) {
100+
FURI_LOG_E(TAG, "Missing or incorrect Data");
101+
furi_string_reset(context->notification_msg);
102+
furi_string_set(context->notification_msg, "Missing or incorrect Key");
103+
break;
104+
} else {
105+
FURI_LOG_I(TAG, "Key: %s", furi_string_get_cstr(context->data_str));
63106

64-
// Data
65-
if(!flipper_format_read_string(fff_data_file, "Data", context->data_str)) {
66-
FURI_LOG_E(TAG, "Missing or incorrect Data");
67-
furi_string_reset(context->notification_msg);
68-
furi_string_set(context->notification_msg, "Missing or incorrect Key");
69-
break;
70-
} else {
71-
FURI_LOG_I(TAG, "Key: %s", furi_string_get_cstr(context->data_str));
107+
if(context->proto == DS1990) {
108+
if(furi_string_size(context->data_str) != 23) {
109+
FURI_LOG_E(TAG, "Incorrect Key length");
110+
furi_string_reset(context->notification_msg);
111+
furi_string_set(context->notification_msg, "Incorrect Key length");
112+
break;
113+
}
114+
} else if(context->proto == Cyfral) {
115+
if(furi_string_size(context->data_str) != 5) {
116+
FURI_LOG_E(TAG, "Incorrect Key length");
117+
furi_string_reset(context->notification_msg);
118+
furi_string_set(context->notification_msg, "Incorrect Key length");
119+
break;
120+
}
121+
} else {
122+
if(furi_string_size(context->data_str) != 11) {
123+
FURI_LOG_E(TAG, "Incorrect Key length");
124+
furi_string_reset(context->notification_msg);
125+
furi_string_set(context->notification_msg, "Incorrect Key length");
126+
break;
127+
}
128+
}
72129

130+
// String to uint8_t
131+
for(uint8_t i = 0; i < 8; i++) {
132+
char temp_str2[3];
133+
temp_str2[0] = furi_string_get_cstr(context->data_str)[i * 3];
134+
temp_str2[1] = furi_string_get_cstr(context->data_str)[i * 3 + 1];
135+
temp_str2[2] = '\0';
136+
context->data[i] = (uint8_t)strtol(temp_str2, NULL, 16);
137+
}
138+
}
139+
} else {
140+
// Data
73141
if(context->proto == DS1990) {
74-
if(furi_string_size(context->data_str) != 23) {
75-
FURI_LOG_E(TAG, "Incorrect Key length");
142+
if(!flipper_format_read_string(fff_data_file, "Rom Data", context->data_str)) {
143+
FURI_LOG_E(TAG, "Missing or incorrect Rom Data");
76144
furi_string_reset(context->notification_msg);
77-
furi_string_set(context->notification_msg, "Incorrect Key length");
145+
furi_string_set(context->notification_msg, "Missing or incorrect Rom Data");
78146
break;
147+
} else {
148+
FURI_LOG_I(TAG, "Key: %s", furi_string_get_cstr(context->data_str));
149+
150+
if(furi_string_size(context->data_str) != 23) {
151+
FURI_LOG_E(TAG, "Incorrect Key length");
152+
furi_string_reset(context->notification_msg);
153+
furi_string_set(context->notification_msg, "Incorrect Key length");
154+
break;
155+
}
156+
157+
// String to uint8_t
158+
for(uint8_t i = 0; i < 8; i++) {
159+
char temp_str2[3];
160+
temp_str2[0] = furi_string_get_cstr(context->data_str)[i * 3];
161+
temp_str2[1] = furi_string_get_cstr(context->data_str)[i * 3 + 1];
162+
temp_str2[2] = '\0';
163+
context->data[i] = (uint8_t)strtol(temp_str2, NULL, 16);
164+
}
79165
}
80166
} else if(context->proto == Cyfral) {
81-
if(furi_string_size(context->data_str) != 5) {
82-
FURI_LOG_E(TAG, "Incorrect Key length");
167+
if(!flipper_format_read_string(fff_data_file, "Data", context->data_str)) {
168+
FURI_LOG_E(TAG, "Missing or incorrect Data");
83169
furi_string_reset(context->notification_msg);
84-
furi_string_set(context->notification_msg, "Incorrect Key length");
170+
furi_string_set(context->notification_msg, "Missing or incorrect Data");
85171
break;
172+
} else {
173+
FURI_LOG_I(TAG, "Key: %s", furi_string_get_cstr(context->data_str));
174+
175+
if(furi_string_size(context->data_str) != 5) {
176+
FURI_LOG_E(TAG, "Incorrect Key length");
177+
furi_string_reset(context->notification_msg);
178+
furi_string_set(context->notification_msg, "Incorrect Key length");
179+
break;
180+
}
181+
182+
// String to uint8_t
183+
for(uint8_t i = 0; i < 8; i++) {
184+
char temp_str2[3];
185+
temp_str2[0] = furi_string_get_cstr(context->data_str)[i * 3];
186+
temp_str2[1] = furi_string_get_cstr(context->data_str)[i * 3 + 1];
187+
temp_str2[2] = '\0';
188+
context->data[i] = (uint8_t)strtol(temp_str2, NULL, 16);
189+
}
86190
}
87191
} else {
88-
if(furi_string_size(context->data_str) != 11) {
89-
FURI_LOG_E(TAG, "Incorrect Key length");
192+
if(!flipper_format_read_string(fff_data_file, "Data", context->data_str)) {
193+
FURI_LOG_E(TAG, "Missing or incorrect Data");
90194
furi_string_reset(context->notification_msg);
91-
furi_string_set(context->notification_msg, "Incorrect Key length");
195+
furi_string_set(context->notification_msg, "Missing or incorrect Data");
92196
break;
93-
}
94-
}
197+
} else {
198+
FURI_LOG_I(TAG, "Key: %s", furi_string_get_cstr(context->data_str));
95199

96-
// String to uint8_t
97-
for(uint8_t i = 0; i < 8; i++) {
98-
char temp_str2[3];
99-
temp_str2[0] = furi_string_get_cstr(context->data_str)[i * 3];
100-
temp_str2[1] = furi_string_get_cstr(context->data_str)[i * 3 + 1];
101-
temp_str2[2] = '\0';
102-
context->data[i] = (uint8_t)strtol(temp_str2, NULL, 16);
200+
if(furi_string_size(context->data_str) != 11) {
201+
FURI_LOG_E(TAG, "Incorrect Key length");
202+
furi_string_reset(context->notification_msg);
203+
furi_string_set(context->notification_msg, "Incorrect Key length");
204+
break;
205+
}
206+
207+
// String to uint8_t
208+
for(uint8_t i = 0; i < 8; i++) {
209+
char temp_str2[3];
210+
temp_str2[0] = furi_string_get_cstr(context->data_str)[i * 3];
211+
temp_str2[1] = furi_string_get_cstr(context->data_str)[i * 3 + 1];
212+
temp_str2[2] = '\0';
213+
context->data[i] = (uint8_t)strtol(temp_str2, NULL, 16);
214+
}
215+
}
103216
}
104217
}
105218

0 commit comments

Comments
 (0)