mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-04-27 03:49:58 -07:00
Merge branch '420' of https://github.com/RogueMaster/flipperzero-firmware-wPlugins into dev
This commit is contained in:
@@ -4,7 +4,8 @@
|
||||
|
||||
// Algorithm from https://github.com/RfidResearchGroup/proxmark3.git
|
||||
|
||||
#define SWAPENDIAN(x) (x = (x >> 8 & 0xff00ff) | (x & 0xff00ff) << 8, x = x >> 16 | x << 16)
|
||||
#define SWAPENDIAN(x) \
|
||||
((x) = ((x) >> 8 & 0xff00ff) | ((x)&0xff00ff) << 8, (x) = (x) >> 16 | (x) << 16)
|
||||
#define LF_POLY_ODD (0x29CE5C)
|
||||
#define LF_POLY_EVEN (0x870804)
|
||||
|
||||
|
||||
@@ -245,7 +245,8 @@ bool mf_classic_is_allowed_access_sector_trailer(
|
||||
case MfClassicActionKeyARead: {
|
||||
return false;
|
||||
}
|
||||
case MfClassicActionKeyAWrite: {
|
||||
case MfClassicActionKeyAWrite:
|
||||
case MfClassicActionKeyBWrite: {
|
||||
return (
|
||||
(key == MfClassicKeyA && (AC == 0x00 || AC == 0x01)) ||
|
||||
(key == MfClassicKeyB && (AC == 0x04 || AC == 0x03)));
|
||||
@@ -253,11 +254,6 @@ bool mf_classic_is_allowed_access_sector_trailer(
|
||||
case MfClassicActionKeyBRead: {
|
||||
return (key == MfClassicKeyA && (AC == 0x00 || AC == 0x02 || AC == 0x01));
|
||||
}
|
||||
case MfClassicActionKeyBWrite: {
|
||||
return (
|
||||
(key == MfClassicKeyA && (AC == 0x00 || AC == 0x01)) ||
|
||||
(key == MfClassicKeyB && (AC == 0x04 || AC == 0x03)));
|
||||
}
|
||||
case MfClassicActionACRead: {
|
||||
return (
|
||||
(key == MfClassicKeyA) ||
|
||||
@@ -755,7 +751,7 @@ bool mf_classic_emulator(MfClassicEmulator* emulator, FuriHalNfcTxRxContext* tx_
|
||||
MfClassicKey access_key = MfClassicKeyA;
|
||||
|
||||
// Read command
|
||||
while(!command_processed) {
|
||||
while(!command_processed) { //-V654
|
||||
if(!is_encrypted) {
|
||||
crypto1_reset(&emulator->crypto);
|
||||
memcpy(plain_data, tx_rx->rx_data, tx_rx->rx_bits / 8);
|
||||
@@ -871,7 +867,7 @@ bool mf_classic_emulator(MfClassicEmulator* emulator, FuriHalNfcTxRxContext* tx_
|
||||
if(mf_classic_is_sector_trailer(block)) {
|
||||
if(!mf_classic_is_allowed_access(
|
||||
emulator, block, access_key, MfClassicActionKeyARead)) {
|
||||
memset(block_data, 0, 6);
|
||||
memset(block_data, 0, 6); //-V1086
|
||||
}
|
||||
if(!mf_classic_is_allowed_access(
|
||||
emulator, block, access_key, MfClassicActionKeyBRead)) {
|
||||
@@ -881,22 +877,16 @@ bool mf_classic_emulator(MfClassicEmulator* emulator, FuriHalNfcTxRxContext* tx_
|
||||
emulator, block, access_key, MfClassicActionACRead)) {
|
||||
memset(&block_data[6], 0, 4);
|
||||
}
|
||||
} else {
|
||||
if(!mf_classic_is_allowed_access(
|
||||
emulator, block, access_key, MfClassicActionDataRead)) {
|
||||
// Send NACK
|
||||
uint8_t nack = 0x04;
|
||||
if(is_encrypted) {
|
||||
crypto1_encrypt(
|
||||
&emulator->crypto, NULL, &nack, 4, tx_rx->tx_data, tx_rx->tx_parity);
|
||||
} else {
|
||||
tx_rx->tx_data[0] = nack;
|
||||
}
|
||||
tx_rx->tx_rx_type = FuriHalNfcTxRxTransparent;
|
||||
tx_rx->tx_bits = 4;
|
||||
furi_hal_nfc_tx_rx(tx_rx, 300);
|
||||
break;
|
||||
}
|
||||
} else if(!mf_classic_is_allowed_access(
|
||||
emulator, block, access_key, MfClassicActionDataRead)) {
|
||||
// Send NACK
|
||||
uint8_t nack = 0x04;
|
||||
crypto1_encrypt(
|
||||
&emulator->crypto, NULL, &nack, 4, tx_rx->tx_data, tx_rx->tx_parity);
|
||||
tx_rx->tx_rx_type = FuriHalNfcTxRxTransparent;
|
||||
tx_rx->tx_bits = 4;
|
||||
furi_hal_nfc_tx_rx(tx_rx, 300);
|
||||
break;
|
||||
}
|
||||
nfca_append_crc16(block_data, 16);
|
||||
|
||||
@@ -929,7 +919,7 @@ bool mf_classic_emulator(MfClassicEmulator* emulator, FuriHalNfcTxRxContext* tx_
|
||||
if(mf_classic_is_sector_trailer(block)) {
|
||||
if(mf_classic_is_allowed_access(
|
||||
emulator, block, access_key, MfClassicActionKeyAWrite)) {
|
||||
memcpy(block_data, plain_data, 6);
|
||||
memcpy(block_data, plain_data, 6); //-V1086
|
||||
}
|
||||
if(mf_classic_is_allowed_access(
|
||||
emulator, block, access_key, MfClassicActionKeyBWrite)) {
|
||||
@@ -945,7 +935,7 @@ bool mf_classic_emulator(MfClassicEmulator* emulator, FuriHalNfcTxRxContext* tx_
|
||||
memcpy(block_data, plain_data, MF_CLASSIC_BLOCK_SIZE);
|
||||
}
|
||||
}
|
||||
if(memcmp(block_data, emulator->data.block[block].value, MF_CLASSIC_BLOCK_SIZE)) {
|
||||
if(memcmp(block_data, emulator->data.block[block].value, MF_CLASSIC_BLOCK_SIZE) != 0) {
|
||||
memcpy(emulator->data.block[block].value, block_data, MF_CLASSIC_BLOCK_SIZE);
|
||||
emulator->data_changed = true;
|
||||
}
|
||||
@@ -1081,7 +1071,8 @@ bool mf_classic_write_sector(
|
||||
bool write_success = true;
|
||||
for(size_t i = first_block; i < first_block + total_blocks; i++) {
|
||||
// Compare blocks
|
||||
if(memcmp(dest_data->block[i].value, src_data->block[i].value, MF_CLASSIC_BLOCK_SIZE)) {
|
||||
if(memcmp(dest_data->block[i].value, src_data->block[i].value, MF_CLASSIC_BLOCK_SIZE) !=
|
||||
0) {
|
||||
bool key_a_write_allowed = mf_classic_is_allowed_access_data_block(
|
||||
dest_data, i, MfClassicKeyA, MfClassicActionDataWrite);
|
||||
bool key_b_write_allowed = mf_classic_is_allowed_access_data_block(
|
||||
|
||||
@@ -108,7 +108,7 @@ void mf_df_cat_version(MifareDesfireVersion* version, FuriString* out) {
|
||||
}
|
||||
|
||||
void mf_df_cat_free_mem(MifareDesfireFreeMemory* free_mem, FuriString* out) {
|
||||
furi_string_cat_printf(out, "freeMem %ld\n", free_mem->bytes);
|
||||
furi_string_cat_printf(out, "freeMem %lu\n", free_mem->bytes);
|
||||
}
|
||||
|
||||
void mf_df_cat_key_settings(MifareDesfireKeySettings* ks, FuriString* out) {
|
||||
@@ -191,10 +191,10 @@ void mf_df_cat_file(MifareDesfireFile* file, FuriString* out) {
|
||||
case MifareDesfireFileTypeValue:
|
||||
size = 4;
|
||||
furi_string_cat_printf(
|
||||
out, "lo %ld hi %ld\n", file->settings.value.lo_limit, file->settings.value.hi_limit);
|
||||
out, "lo %lu hi %lu\n", file->settings.value.lo_limit, file->settings.value.hi_limit);
|
||||
furi_string_cat_printf(
|
||||
out,
|
||||
"limit %ld enabled %d\n",
|
||||
"limit %lu enabled %d\n",
|
||||
file->settings.value.limited_credit_value,
|
||||
file->settings.value.limited_credit_enabled);
|
||||
break;
|
||||
@@ -203,7 +203,7 @@ void mf_df_cat_file(MifareDesfireFile* file, FuriString* out) {
|
||||
size = file->settings.record.size;
|
||||
num = file->settings.record.cur;
|
||||
furi_string_cat_printf(out, "size %d\n", size);
|
||||
furi_string_cat_printf(out, "num %d max %ld\n", num, file->settings.record.max);
|
||||
furi_string_cat_printf(out, "num %d max %lu\n", num, file->settings.record.max);
|
||||
break;
|
||||
}
|
||||
uint8_t* data = file->contents;
|
||||
@@ -220,8 +220,9 @@ void mf_df_cat_file(MifareDesfireFile* file, FuriString* out) {
|
||||
}
|
||||
}
|
||||
for(int i = 0; i < 4 && ch + i < size; i++) {
|
||||
if(isprint(data[rec * size + ch + i])) {
|
||||
furi_string_cat_printf(out, "%c", data[rec * size + ch + i]);
|
||||
const size_t data_index = rec * size + ch + i;
|
||||
if(isprint(data[data_index])) {
|
||||
furi_string_cat_printf(out, "%c", data[data_index]);
|
||||
} else {
|
||||
furi_string_cat_printf(out, ".");
|
||||
}
|
||||
@@ -547,7 +548,8 @@ bool mf_df_read_card(FuriHalNfcTxRxContext* tx_rx, MifareDesfireData* data) {
|
||||
for(MifareDesfireApplication* app = data->app_head; app; app = app->next) {
|
||||
tx_rx->tx_bits = 8 * mf_df_prepare_select_application(tx_rx->tx_data, app->id);
|
||||
if(!furi_hal_nfc_tx_rx_full(tx_rx) ||
|
||||
!mf_df_parse_select_application_response(tx_rx->rx_data, tx_rx->rx_bits / 8)) {
|
||||
!mf_df_parse_select_application_response(
|
||||
tx_rx->rx_data, tx_rx->rx_bits / 8)) { //-V1051
|
||||
FURI_LOG_W(TAG, "Bad exchange selecting application");
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -170,6 +170,7 @@ bool mf_ultralight_read_version(
|
||||
}
|
||||
|
||||
bool mf_ultralight_authenticate(FuriHalNfcTxRxContext* tx_rx, uint32_t key, uint16_t* pack) {
|
||||
furi_assert(pack);
|
||||
bool authenticated = false;
|
||||
|
||||
do {
|
||||
@@ -189,9 +190,7 @@ bool mf_ultralight_authenticate(FuriHalNfcTxRxContext* tx_rx, uint32_t key, uint
|
||||
break;
|
||||
}
|
||||
|
||||
if(pack != NULL) {
|
||||
*pack = (tx_rx->rx_data[1] << 8) | tx_rx->rx_data[0];
|
||||
}
|
||||
*pack = (tx_rx->rx_data[1] << 8) | tx_rx->rx_data[0];
|
||||
|
||||
FURI_LOG_I(TAG, "Auth success. Password: %08lX. PACK: %04X", key, *pack);
|
||||
authenticated = true;
|
||||
@@ -492,7 +491,7 @@ MfUltralightConfigPages* mf_ultralight_get_config_pages(MfUltralightData* data)
|
||||
} else if(
|
||||
data->type >= MfUltralightTypeNTAGI2CPlus1K &&
|
||||
data->type <= MfUltralightTypeNTAGI2CPlus2K) {
|
||||
return (MfUltralightConfigPages*)&data->data[0xe3 * 4];
|
||||
return (MfUltralightConfigPages*)&data->data[0xe3 * 4]; //-V641
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
@@ -561,7 +560,7 @@ bool mf_ultralight_read_pages_direct(
|
||||
FURI_LOG_D(TAG, "Failed to read pages %d - %d", start_index, start_index + 3);
|
||||
return false;
|
||||
}
|
||||
memcpy(data, tx_rx->rx_data, 16);
|
||||
memcpy(data, tx_rx->rx_data, 16); //-V1086
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -584,7 +583,8 @@ bool mf_ultralight_read_pages(
|
||||
curr_sector_index = tag_sector;
|
||||
}
|
||||
|
||||
FURI_LOG_D(TAG, "Reading pages %d - %d", i, i + (valid_pages > 4 ? 4 : valid_pages) - 1);
|
||||
FURI_LOG_D(
|
||||
TAG, "Reading pages %zu - %zu", i, i + (valid_pages > 4 ? 4 : valid_pages) - 1U);
|
||||
tx_rx->tx_data[0] = MF_UL_READ_CMD;
|
||||
tx_rx->tx_data[1] = tag_page;
|
||||
tx_rx->tx_bits = 16;
|
||||
@@ -593,9 +593,9 @@ bool mf_ultralight_read_pages(
|
||||
if(!furi_hal_nfc_tx_rx(tx_rx, 50) || tx_rx->rx_bits < 16 * 8) {
|
||||
FURI_LOG_D(
|
||||
TAG,
|
||||
"Failed to read pages %d - %d",
|
||||
"Failed to read pages %zu - %zu",
|
||||
i,
|
||||
i + (valid_pages > 4 ? 4 : valid_pages) - 1);
|
||||
i + (valid_pages > 4 ? 4 : valid_pages) - 1U);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -857,7 +857,7 @@ static void mf_ul_ntag_i2c_fill_cross_area_read(
|
||||
}
|
||||
|
||||
if(apply) {
|
||||
while(tx_page_offset < 0 && page_length > 0) {
|
||||
while(tx_page_offset < 0 && page_length > 0) { //-V614
|
||||
++tx_page_offset;
|
||||
++data_page_offset;
|
||||
--page_length;
|
||||
@@ -987,9 +987,9 @@ static bool mf_ul_check_lock(MfUltralightEmulator* emulator, int16_t write_page)
|
||||
switch(emulator->data.type) {
|
||||
// low byte LSB range, MSB range
|
||||
case MfUltralightTypeNTAG203:
|
||||
if(write_page >= 16 && write_page <= 27)
|
||||
if(write_page >= 16 && write_page <= 27) //-V560
|
||||
shift = (write_page - 16) / 4 + 1;
|
||||
else if(write_page >= 28 && write_page <= 39)
|
||||
else if(write_page >= 28 && write_page <= 39) //-V560
|
||||
shift = (write_page - 28) / 4 + 5;
|
||||
else if(write_page == 41)
|
||||
shift = 12;
|
||||
@@ -1216,7 +1216,7 @@ static void mf_ul_emulate_write(
|
||||
page_buff[0] = new_locks & 0xff;
|
||||
page_buff[1] = new_locks >> 8;
|
||||
page_buff[2] = new_block_locks;
|
||||
if(emulator->data.type >= MfUltralightTypeUL21 &&
|
||||
if(emulator->data.type >= MfUltralightTypeUL21 && //-V1016
|
||||
emulator->data.type <= MfUltralightTypeNTAG216)
|
||||
page_buff[3] = MF_UL_TEARING_FLAG_DEFAULT;
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user