Less pointer abuse casting --nobuild

This commit is contained in:
Willy-JL
2024-01-10 23:19:51 +00:00
parent 8f00047305
commit ab3fc6413e

View File

@@ -6,6 +6,7 @@
#include "nfc_supported_card_plugin.h" #include "nfc_supported_card_plugin.h"
#include <nfc/helpers/nfc_util.h>
#include <flipper_application/flipper_application.h> #include <flipper_application/flipper_application.h>
#include <nfc/protocols/mf_ultralight/mf_ultralight.h> #include <nfc/protocols/mf_ultralight/mf_ultralight.h>
@@ -161,18 +162,18 @@ static void parse_ndef_wifi(FuriString* str, const uint8_t* payload, uint32_t pa
size_t i = 0; size_t i = 0;
while(i < payload_len) { while(i < payload_len) {
uint16_t field_id = __REV16(*(uint16_t*)&payload[i]); uint16_t field_id = nfc_util_bytes2num(payload + i, 2);
i += 2; i += 2;
uint16_t field_len = __REV16(*(uint16_t*)&payload[i]); uint16_t field_len = nfc_util_bytes2num(payload + i, 2);
i += 2; i += 2;
if(field_id == CREDENTIAL_FIELD_ID) { if(field_id == CREDENTIAL_FIELD_ID) {
furi_string_cat(str, "WiFi\n"); furi_string_cat(str, "WiFi\n");
size_t start_position = i; size_t start_position = i;
while(i < start_position + field_len) { while(i < start_position + field_len) {
uint16_t cfg_id = __REV16(*(uint16_t*)&payload[i]); uint16_t cfg_id = nfc_util_bytes2num(payload + i, 2);
i += 2; i += 2;
uint16_t cfg_len = __REV16(*(uint16_t*)&payload[i]); uint16_t cfg_len = nfc_util_bytes2num(payload + i, 2);
i += 2; i += 2;
if(i + cfg_len > start_position + field_len) { if(i + cfg_len > start_position + field_len) {
@@ -195,7 +196,7 @@ static void parse_ndef_wifi(FuriString* str, const uint8_t* payload, uint32_t pa
if(cfg_len != AUTH_TYPE_EXPECTED_SIZE) { if(cfg_len != AUTH_TYPE_EXPECTED_SIZE) {
return; return;
} }
short auth_type = __REV16(*(uint16_t*)&payload[i]); short auth_type = nfc_util_bytes2num(payload + i, 2);
i += 2; i += 2;
const char* auth; const char* auth;
switch(auth_type) { switch(auth_type) {
@@ -317,7 +318,7 @@ static const uint8_t* parse_ndef_message(
if(short_record) { if(short_record) {
payload_len = *cur++; payload_len = *cur++;
} else { } else {
payload_len = __REV(*(uint32_t*)cur); payload_len = nfc_util_bytes2num(cur, 4);
cur += 4; cur += 4;
} }
@@ -390,7 +391,7 @@ static bool ndef_parse(const NfcDevice* device, FuriString* parsed_data) {
cur = end; cur = end;
break; break;
} }
len = __REV16(*(uint16_t*)(++cur)); len = nfc_util_bytes2num(++cur, 2);
cur += 2; cur += 2;
} }
if(cur + len >= end) { if(cur + len >= end) {
@@ -432,7 +433,7 @@ static bool ndef_parse(const NfcDevice* device, FuriString* parsed_data) {
cur = end; cur = end;
break; break;
} }
cur += __REV16(*(uint16_t*)(cur + 1)) + 3; // Shift by TLV length cur += nfc_util_bytes2num(cur + 1, 2) + 3; // Shift by TLV length
} }
break; break;