mirror of
https://github.com/DarkFlippers/unleashed-firmware.git
synced 2024-12-19 03:11:52 +03:00
upd nfc maker / badusb fixes
by @Willy-JL
This commit is contained in:
parent
9d98724dcb
commit
bc0722fe25
@ -257,8 +257,12 @@ static int32_t ducky_parse_line(BadBtScript* bad_bt, FuriString* line) {
|
||||
}
|
||||
if((key & 0xFF00) != 0) {
|
||||
// It's a modifier key
|
||||
line_tmp = &line_tmp[ducky_get_command_len(line_tmp) + 1];
|
||||
key |= ducky_get_keycode(bad_bt, line_tmp, true);
|
||||
uint32_t offset = ducky_get_command_len(line_tmp) + 1;
|
||||
// ducky_get_command_len() returns 0 without space, so check for != 1
|
||||
if(offset != 1 && line_len > offset) {
|
||||
// It's also a key combination
|
||||
key |= ducky_get_keycode(bad_bt, line_tmp + offset, true);
|
||||
}
|
||||
}
|
||||
furi_hal_bt_hid_kb_press(key);
|
||||
furi_delay_ms(bt_timeout);
|
||||
|
@ -18,19 +18,21 @@ void nfc_maker_scene_result_on_enter(void* context) {
|
||||
FlipperFormat* file = flipper_format_file_alloc(furi_record_open(RECORD_STORAGE));
|
||||
FuriString* path = furi_string_alloc();
|
||||
furi_string_printf(path, NFC_APP_FOLDER "/%s" NFC_APP_EXTENSION, app->name_buf);
|
||||
|
||||
uint32_t pages = 135;
|
||||
size_t size = pages * 4;
|
||||
uint8_t* buf = malloc(size);
|
||||
do {
|
||||
if(!flipper_format_file_open_new(file, furi_string_get_cstr(path))) break;
|
||||
|
||||
uint32_t pages = 42;
|
||||
size_t size = pages * 4;
|
||||
uint8_t* buf = malloc(size);
|
||||
|
||||
if(!flipper_format_write_header_cstr(file, "Flipper NFC device", 3)) break;
|
||||
if(!flipper_format_write_string_cstr(file, "Device type", "NTAG203")) break;
|
||||
if(!flipper_format_write_string_cstr(file, "Device type", "NTAG215")) break;
|
||||
|
||||
// Serial number
|
||||
buf[0] = 0x04;
|
||||
furi_hal_random_fill_buf(&buf[1], 8);
|
||||
size_t i = 0;
|
||||
buf[i++] = 0x04;
|
||||
furi_hal_random_fill_buf(&buf[i], 8);
|
||||
i += 8;
|
||||
uint8_t uid[7];
|
||||
memcpy(&uid[0], &buf[0], 3);
|
||||
memcpy(&uid[3], &buf[4], 4);
|
||||
@ -44,7 +46,7 @@ void nfc_maker_scene_result_on_enter(void* context) {
|
||||
"Signature",
|
||||
"00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"))
|
||||
break;
|
||||
if(!flipper_format_write_string_cstr(file, "Mifare version", "00 00 00 00 00 00 00 00"))
|
||||
if(!flipper_format_write_string_cstr(file, "Mifare version", "00 04 04 02 01 00 11 03"))
|
||||
break;
|
||||
|
||||
if(!flipper_format_write_string_cstr(file, "Counter 0", "0")) break;
|
||||
@ -56,233 +58,224 @@ void nfc_maker_scene_result_on_enter(void* context) {
|
||||
if(!flipper_format_write_uint32(file, "Pages total", &pages, 1)) break;
|
||||
|
||||
// Static data
|
||||
buf[9] = 0x48; // Internal
|
||||
buf[10] = 0x00; // Lock bytes
|
||||
buf[11] = 0x00; // ...
|
||||
buf[12] = 0xE1; // Capability container
|
||||
buf[13] = 0x10; // ...
|
||||
buf[14] = 0x12; // ...
|
||||
buf[15] = 0x00; // ...
|
||||
buf[16] = 0x01; // ...
|
||||
buf[17] = 0x03; // ...
|
||||
buf[18] = 0xA0; // ...
|
||||
buf[19] = 0x10; // ...
|
||||
buf[20] = 0x44; // ...
|
||||
buf[21] = 0x03; // Message flags
|
||||
buf[i++] = 0x48; // Internal
|
||||
buf[i++] = 0x00; // Lock bytes
|
||||
buf[i++] = 0x00; // ...
|
||||
buf[i++] = 0xE1; // Capability container
|
||||
buf[i++] = 0x10; // ...
|
||||
buf[i++] = 0x3E; // ...
|
||||
buf[i++] = 0x00; // ...
|
||||
buf[i++] = 0x03; // Message flags
|
||||
size_t start = i++;
|
||||
|
||||
size_t msg_len = 0;
|
||||
switch(scene_manager_get_scene_state(app->scene_manager, NfcMakerSceneMenu)) {
|
||||
case NfcMakerSceneBluetooth: {
|
||||
msg_len = 0x2B;
|
||||
buf[i++] = 0xD2;
|
||||
buf[i++] = 0x20;
|
||||
buf[i++] = 0x08;
|
||||
buf[i++] = 0x61;
|
||||
buf[i++] = 0x70;
|
||||
|
||||
buf[23] = 0xD2;
|
||||
buf[24] = 0x20;
|
||||
buf[25] = 0x08;
|
||||
buf[26] = 0x61;
|
||||
buf[27] = 0x70;
|
||||
buf[i++] = 0x70;
|
||||
buf[i++] = 0x6C;
|
||||
buf[i++] = 0x69;
|
||||
buf[i++] = 0x63;
|
||||
|
||||
buf[28] = 0x70;
|
||||
buf[29] = 0x6C;
|
||||
buf[30] = 0x69;
|
||||
buf[31] = 0x63;
|
||||
buf[i++] = 0x61;
|
||||
buf[i++] = 0x74;
|
||||
buf[i++] = 0x69;
|
||||
buf[i++] = 0x6F;
|
||||
|
||||
buf[32] = 0x61;
|
||||
buf[33] = 0x74;
|
||||
buf[34] = 0x69;
|
||||
buf[35] = 0x6F;
|
||||
buf[i++] = 0x6E;
|
||||
buf[i++] = 0x2F;
|
||||
buf[i++] = 0x76;
|
||||
buf[i++] = 0x6E;
|
||||
|
||||
buf[36] = 0x6E;
|
||||
buf[37] = 0x2F;
|
||||
buf[38] = 0x76;
|
||||
buf[39] = 0x6E;
|
||||
buf[i++] = 0x64;
|
||||
buf[i++] = 0x2E;
|
||||
buf[i++] = 0x62;
|
||||
buf[i++] = 0x6C;
|
||||
|
||||
buf[40] = 0x64;
|
||||
buf[41] = 0x2E;
|
||||
buf[42] = 0x62;
|
||||
buf[43] = 0x6C;
|
||||
buf[i++] = 0x75;
|
||||
buf[i++] = 0x65;
|
||||
buf[i++] = 0x74;
|
||||
buf[i++] = 0x6F;
|
||||
|
||||
buf[44] = 0x75;
|
||||
buf[45] = 0x65;
|
||||
buf[46] = 0x74;
|
||||
buf[47] = 0x6F;
|
||||
buf[i++] = 0x6F;
|
||||
buf[i++] = 0x74;
|
||||
buf[i++] = 0x68;
|
||||
buf[i++] = 0x2E;
|
||||
|
||||
buf[48] = 0x6F;
|
||||
buf[49] = 0x74;
|
||||
buf[50] = 0x68;
|
||||
buf[51] = 0x2E;
|
||||
buf[i++] = 0x65;
|
||||
buf[i++] = 0x70;
|
||||
buf[i++] = 0x2E;
|
||||
buf[i++] = 0x6F;
|
||||
|
||||
buf[52] = 0x65;
|
||||
buf[53] = 0x70;
|
||||
buf[54] = 0x2E;
|
||||
buf[55] = 0x6F;
|
||||
buf[i++] = 0x6F;
|
||||
buf[i++] = 0x62;
|
||||
buf[i++] = 0x08;
|
||||
buf[i++] = 0x00;
|
||||
|
||||
buf[56] = 0x6F;
|
||||
buf[57] = 0x62;
|
||||
buf[58] = 0x08;
|
||||
buf[59] = 0x00;
|
||||
|
||||
memcpy(&buf[60], app->mac_buf, GAP_MAC_ADDR_SIZE);
|
||||
memcpy(&buf[i], app->mac_buf, GAP_MAC_ADDR_SIZE);
|
||||
i += GAP_MAC_ADDR_SIZE;
|
||||
break;
|
||||
}
|
||||
case NfcMakerSceneHttps: {
|
||||
uint8_t data_len = strnlen(app->text_buf, TEXT_INPUT_LEN);
|
||||
msg_len = data_len + 5;
|
||||
|
||||
buf[23] = 0xD1;
|
||||
buf[24] = 0x01;
|
||||
buf[25] = data_len + 1;
|
||||
buf[26] = 0x55;
|
||||
buf[i++] = 0xD1;
|
||||
buf[i++] = 0x01;
|
||||
buf[i++] = data_len + 1;
|
||||
buf[i++] = 0x55;
|
||||
|
||||
buf[27] = 0x04; // Prepend "https://"
|
||||
memcpy(&buf[28], app->text_buf, data_len);
|
||||
buf[i++] = 0x04; // Prepend "https://"
|
||||
memcpy(&buf[i], app->text_buf, data_len);
|
||||
i += data_len;
|
||||
break;
|
||||
}
|
||||
case NfcMakerSceneMail: {
|
||||
uint8_t data_len = strnlen(app->text_buf, TEXT_INPUT_LEN);
|
||||
msg_len = data_len + 5;
|
||||
|
||||
buf[23] = 0xD1;
|
||||
buf[24] = 0x01;
|
||||
buf[25] = data_len + 1;
|
||||
buf[26] = 0x55;
|
||||
buf[i++] = 0xD1;
|
||||
buf[i++] = 0x01;
|
||||
buf[i++] = data_len + 1;
|
||||
buf[i++] = 0x55;
|
||||
|
||||
buf[27] = 0x06; // Prepend "mailto:"
|
||||
memcpy(&buf[28], app->text_buf, data_len);
|
||||
buf[i++] = 0x06; // Prepend "mailto:"
|
||||
memcpy(&buf[i], app->text_buf, data_len);
|
||||
i += data_len;
|
||||
break;
|
||||
}
|
||||
case NfcMakerScenePhone: {
|
||||
uint8_t data_len = strnlen(app->text_buf, TEXT_INPUT_LEN);
|
||||
msg_len = data_len + 5;
|
||||
|
||||
buf[23] = 0xD1;
|
||||
buf[24] = 0x01;
|
||||
buf[25] = data_len + 1;
|
||||
buf[26] = 0x55;
|
||||
buf[i++] = 0xD1;
|
||||
buf[i++] = 0x01;
|
||||
buf[i++] = data_len + 1;
|
||||
buf[i++] = 0x55;
|
||||
|
||||
buf[27] = 0x05; // Prepend "tel:"
|
||||
memcpy(&buf[28], app->text_buf, data_len);
|
||||
buf[i++] = 0x05; // Prepend "tel:"
|
||||
memcpy(&buf[i], app->text_buf, data_len);
|
||||
i += data_len;
|
||||
break;
|
||||
}
|
||||
case NfcMakerSceneText: {
|
||||
uint8_t data_len = strnlen(app->text_buf, TEXT_INPUT_LEN);
|
||||
msg_len = data_len + 7;
|
||||
|
||||
buf[23] = 0xD1;
|
||||
buf[24] = 0x01;
|
||||
buf[25] = data_len + 3;
|
||||
buf[26] = 0x54;
|
||||
buf[i++] = 0xD1;
|
||||
buf[i++] = 0x01;
|
||||
buf[i++] = data_len + 3;
|
||||
buf[i++] = 0x54;
|
||||
|
||||
buf[27] = 0x02;
|
||||
buf[28] = 0x65; // e
|
||||
buf[29] = 0x6E; // n
|
||||
memcpy(&buf[30], app->text_buf, data_len);
|
||||
buf[i++] = 0x02;
|
||||
buf[i++] = 0x65; // e
|
||||
buf[i++] = 0x6E; // n
|
||||
memcpy(&buf[i], app->text_buf, data_len);
|
||||
i += data_len;
|
||||
break;
|
||||
}
|
||||
case NfcMakerSceneUrl: {
|
||||
uint8_t data_len = strnlen(app->text_buf, TEXT_INPUT_LEN);
|
||||
msg_len = data_len + 5;
|
||||
|
||||
buf[23] = 0xD1;
|
||||
buf[24] = 0x01;
|
||||
buf[25] = data_len + 1;
|
||||
buf[26] = 0x55;
|
||||
buf[i++] = 0xD1;
|
||||
buf[i++] = 0x01;
|
||||
buf[i++] = data_len + 1;
|
||||
buf[i++] = 0x55;
|
||||
|
||||
buf[27] = 0x00; // No prepend
|
||||
memcpy(&buf[28], app->text_buf, data_len);
|
||||
buf[i++] = 0x00; // No prepend
|
||||
memcpy(&buf[i], app->text_buf, data_len);
|
||||
i += data_len;
|
||||
break;
|
||||
}
|
||||
case NfcMakerSceneWifi: {
|
||||
uint8_t ssid_len = strnlen(app->text_buf, WIFI_INPUT_LEN);
|
||||
uint8_t pass_len = strnlen(app->pass_buf, WIFI_INPUT_LEN);
|
||||
uint8_t data_len = ssid_len + pass_len;
|
||||
msg_len = data_len + 73;
|
||||
|
||||
buf[23] = 0xD2;
|
||||
buf[24] = 0x17;
|
||||
buf[25] = data_len + 47;
|
||||
buf[26] = 0x61;
|
||||
buf[27] = 0x70;
|
||||
buf[i++] = 0xD2;
|
||||
buf[i++] = 0x17;
|
||||
buf[i++] = data_len + 47;
|
||||
buf[i++] = 0x61;
|
||||
buf[i++] = 0x70;
|
||||
|
||||
buf[28] = 0x70;
|
||||
buf[29] = 0x6C;
|
||||
buf[30] = 0x69;
|
||||
buf[31] = 0x63;
|
||||
buf[i++] = 0x70;
|
||||
buf[i++] = 0x6C;
|
||||
buf[i++] = 0x69;
|
||||
buf[i++] = 0x63;
|
||||
|
||||
buf[32] = 0x61;
|
||||
buf[33] = 0x74;
|
||||
buf[34] = 0x69;
|
||||
buf[35] = 0x6F;
|
||||
buf[i++] = 0x61;
|
||||
buf[i++] = 0x74;
|
||||
buf[i++] = 0x69;
|
||||
buf[i++] = 0x6F;
|
||||
|
||||
buf[36] = 0x6E;
|
||||
buf[37] = 0x2F;
|
||||
buf[38] = 0x76;
|
||||
buf[39] = 0x6E;
|
||||
buf[i++] = 0x6E;
|
||||
buf[i++] = 0x2F;
|
||||
buf[i++] = 0x76;
|
||||
buf[i++] = 0x6E;
|
||||
|
||||
buf[40] = 0x64;
|
||||
buf[41] = 0x2E;
|
||||
buf[42] = 0x77;
|
||||
buf[43] = 0x66;
|
||||
buf[i++] = 0x64;
|
||||
buf[i++] = 0x2E;
|
||||
buf[i++] = 0x77;
|
||||
buf[i++] = 0x66;
|
||||
|
||||
buf[44] = 0x61;
|
||||
buf[45] = 0x2E;
|
||||
buf[46] = 0x77;
|
||||
buf[47] = 0x73;
|
||||
buf[i++] = 0x61;
|
||||
buf[i++] = 0x2E;
|
||||
buf[i++] = 0x77;
|
||||
buf[i++] = 0x73;
|
||||
|
||||
buf[48] = 0x63;
|
||||
buf[49] = 0x10;
|
||||
buf[50] = 0x0E;
|
||||
buf[51] = 0x00;
|
||||
buf[i++] = 0x63;
|
||||
buf[i++] = 0x10;
|
||||
buf[i++] = 0x0E;
|
||||
buf[i++] = 0x00;
|
||||
|
||||
buf[52] = data_len + 43;
|
||||
buf[53] = 0x10;
|
||||
buf[54] = 0x26;
|
||||
buf[55] = 0x00;
|
||||
buf[i++] = data_len + 43;
|
||||
buf[i++] = 0x10;
|
||||
buf[i++] = 0x26;
|
||||
buf[i++] = 0x00;
|
||||
|
||||
buf[56] = 0x01;
|
||||
buf[57] = 0x01;
|
||||
buf[58] = 0x10;
|
||||
buf[59] = 0x45;
|
||||
buf[i++] = 0x01;
|
||||
buf[i++] = 0x01;
|
||||
buf[i++] = 0x10;
|
||||
buf[i++] = 0x45;
|
||||
|
||||
buf[60] = 0x00;
|
||||
buf[61] = ssid_len;
|
||||
memcpy(&buf[62], app->text_buf, ssid_len);
|
||||
size_t ssid = 62 + ssid_len;
|
||||
buf[ssid + 0] = 0x10;
|
||||
buf[ssid + 1] = 0x03;
|
||||
buf[i++] = 0x00;
|
||||
buf[i++] = ssid_len;
|
||||
memcpy(&buf[i], app->text_buf, ssid_len);
|
||||
i += ssid_len;
|
||||
buf[i++] = 0x10;
|
||||
buf[i++] = 0x03;
|
||||
|
||||
buf[ssid + 2] = 0x00;
|
||||
buf[ssid + 3] = 0x02;
|
||||
buf[ssid + 4] = 0x00;
|
||||
buf[ssid + 5] =
|
||||
scene_manager_get_scene_state(app->scene_manager, NfcMakerSceneWifiAuth);
|
||||
buf[i++] = 0x00;
|
||||
buf[i++] = 0x02;
|
||||
buf[i++] = 0x00;
|
||||
buf[i++] = scene_manager_get_scene_state(app->scene_manager, NfcMakerSceneWifiAuth);
|
||||
|
||||
buf[ssid + 6] = 0x10;
|
||||
buf[ssid + 7] = 0x0F;
|
||||
buf[ssid + 8] = 0x00;
|
||||
buf[ssid + 9] = 0x02;
|
||||
buf[i++] = 0x10;
|
||||
buf[i++] = 0x0F;
|
||||
buf[i++] = 0x00;
|
||||
buf[i++] = 0x02;
|
||||
|
||||
buf[ssid + 10] = 0x00;
|
||||
buf[ssid + 11] =
|
||||
scene_manager_get_scene_state(app->scene_manager, NfcMakerSceneWifiEncr);
|
||||
buf[ssid + 12] = 0x10;
|
||||
buf[ssid + 13] = 0x27;
|
||||
buf[i++] = 0x00;
|
||||
buf[i++] = scene_manager_get_scene_state(app->scene_manager, NfcMakerSceneWifiEncr);
|
||||
buf[i++] = 0x10;
|
||||
buf[i++] = 0x27;
|
||||
|
||||
buf[ssid + 14] = 0x00;
|
||||
buf[ssid + 15] = pass_len;
|
||||
memcpy(&buf[ssid + 16], app->pass_buf, pass_len);
|
||||
size_t pass = ssid + 16 + pass_len;
|
||||
buf[pass + 0] = 0x10;
|
||||
buf[pass + 1] = 0x20;
|
||||
buf[i++] = 0x00;
|
||||
buf[i++] = pass_len;
|
||||
memcpy(&buf[i], app->pass_buf, pass_len);
|
||||
i += pass_len;
|
||||
buf[i++] = 0x10;
|
||||
buf[i++] = 0x20;
|
||||
|
||||
buf[pass + 2] = 0x00;
|
||||
buf[pass + 3] = 0x06;
|
||||
buf[pass + 4] = 0xFF;
|
||||
buf[pass + 5] = 0xFF;
|
||||
buf[i++] = 0x00;
|
||||
buf[i++] = 0x06;
|
||||
buf[i++] = 0xFF;
|
||||
buf[i++] = 0xFF;
|
||||
|
||||
buf[pass + 6] = 0xFF;
|
||||
buf[pass + 7] = 0xFF;
|
||||
buf[pass + 8] = 0xFF;
|
||||
buf[pass + 9] = 0xFF;
|
||||
buf[i++] = 0xFF;
|
||||
buf[i++] = 0xFF;
|
||||
buf[i++] = 0xFF;
|
||||
buf[i++] = 0xFF;
|
||||
|
||||
break;
|
||||
}
|
||||
@ -291,15 +284,41 @@ void nfc_maker_scene_result_on_enter(void* context) {
|
||||
}
|
||||
|
||||
// Message length and terminator
|
||||
buf[22] = msg_len;
|
||||
size_t msg_end = 23 + msg_len;
|
||||
buf[msg_end] = 0xFE;
|
||||
buf[start] = i - start - 1;
|
||||
buf[i++] = 0xFE;
|
||||
|
||||
// Padding
|
||||
for(size_t i = msg_end + 1; i < size; i++) {
|
||||
// Padding until last 5 pages
|
||||
for(; i < size - 20; i++) {
|
||||
buf[i] = 0x00;
|
||||
}
|
||||
|
||||
// Last 5 static pages
|
||||
buf[i++] = 0x00;
|
||||
buf[i++] = 0x00;
|
||||
buf[i++] = 0x00;
|
||||
buf[i++] = 0xBD;
|
||||
|
||||
buf[i++] = 0x04;
|
||||
buf[i++] = 0x00;
|
||||
buf[i++] = 0x00;
|
||||
buf[i++] = 0xFF;
|
||||
|
||||
buf[i++] = 0x00;
|
||||
buf[i++] = 0x05;
|
||||
buf[i++] = 0x00;
|
||||
buf[i++] = 0x00;
|
||||
|
||||
buf[i++] = 0xFF;
|
||||
buf[i++] = 0xFF;
|
||||
buf[i++] = 0xFF;
|
||||
buf[i++] = 0xFF;
|
||||
|
||||
buf[i++] = 0x00;
|
||||
buf[i++] = 0x00;
|
||||
buf[i++] = 0x00;
|
||||
buf[i++] = 0x00;
|
||||
|
||||
// Write pages
|
||||
char str[16];
|
||||
bool ok = true;
|
||||
for(size_t page = 0; page < pages; page++) {
|
||||
@ -311,10 +330,11 @@ void nfc_maker_scene_result_on_enter(void* context) {
|
||||
}
|
||||
if(!ok) break;
|
||||
|
||||
free(buf);
|
||||
success = true;
|
||||
|
||||
} while(false);
|
||||
free(buf);
|
||||
|
||||
furi_string_free(path);
|
||||
flipper_format_free(file);
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
|
@ -198,8 +198,12 @@ static int32_t ducky_parse_line(BadUsbScript* bad_usb, FuriString* line) {
|
||||
}
|
||||
if((key & 0xFF00) != 0) {
|
||||
// It's a modifier key
|
||||
line_tmp = &line_tmp[ducky_get_command_len(line_tmp) + 1];
|
||||
key |= ducky_get_keycode(bad_usb, line_tmp, true);
|
||||
uint32_t offset = ducky_get_command_len(line_tmp) + 1;
|
||||
// ducky_get_command_len() returns 0 without space, so check for != 1
|
||||
if(offset != 1 && line_len > offset) {
|
||||
// It's also a key combination
|
||||
key |= ducky_get_keycode(bad_usb, line_tmp + offset, true);
|
||||
}
|
||||
}
|
||||
furi_hal_hid_kb_press(key);
|
||||
furi_hal_hid_kb_release(key);
|
||||
|
Loading…
Reference in New Issue
Block a user