mirror of
https://github.com/flipperdevices/flipperzero-firmware.git
synced 2025-12-12 04:41:26 +04:00
bit_lib and nfc_util refactor (#3383)
* nfc_util functions for processing bytes moved into bit_lib * bitlib test update * bit_lib moved from lfrfid to standalone lib * Added bit functions for any supported data types * Error fix and api add * Added test for 64 * Added doc * Testcase for 64 rewrited * Realization error fix * API version bump * sync api version, fix after-merge old libs usage * fix build errors * build fix * fbt format Co-authored-by: assasinfil <nfa57643@gmail.com> Co-authored-by: gornekich <n.gorbadey@gmail.com> Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
@@ -1,9 +1,8 @@
|
||||
#include "nfc_supported_card_plugin.h"
|
||||
#include <flipper_application/flipper_application.h>
|
||||
#include <nfc/nfc_device.h>
|
||||
#include <nfc/helpers/nfc_util.h>
|
||||
#include <bit_lib/bit_lib.h>
|
||||
#include <nfc/protocols/mf_classic/mf_classic_poller_sync.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#define TAG "MiZIP"
|
||||
#define KEY_LENGTH 6
|
||||
@@ -102,7 +101,7 @@ static bool mizip_verify_type(Nfc* nfc, MfClassicType type) {
|
||||
FURI_LOG_D(TAG, "Verifying sector %lu", cfg.verify_sector);
|
||||
|
||||
MfClassicKey key = {0};
|
||||
nfc_util_num2bytes(cfg.keys[cfg.verify_sector].b, COUNT_OF(key.data), key.data);
|
||||
bit_lib_num_to_bytes_be(cfg.keys[cfg.verify_sector].b, COUNT_OF(key.data), key.data);
|
||||
|
||||
MfClassicAuthContext auth_context;
|
||||
MfClassicError error =
|
||||
@@ -152,16 +151,16 @@ static bool mizip_read(Nfc* nfc, NfcDevice* device) {
|
||||
|
||||
for(size_t i = 0; i < mf_classic_get_total_sectors_num(data->type); i++) {
|
||||
if(cfg.keys[i].a == 0x000000000000 && cfg.keys[i].b == 0x000000000000) {
|
||||
cfg.keys[i].a = nfc_util_bytes2num(keyA[i], KEY_LENGTH);
|
||||
cfg.keys[i].b = nfc_util_bytes2num(keyB[i], KEY_LENGTH);
|
||||
cfg.keys[i].a = bit_lib_bytes_to_num_be(keyA[i], KEY_LENGTH);
|
||||
cfg.keys[i].b = bit_lib_bytes_to_num_be(keyB[i], KEY_LENGTH);
|
||||
}
|
||||
}
|
||||
|
||||
MfClassicDeviceKeys keys = {};
|
||||
for(size_t i = 0; i < mf_classic_get_total_sectors_num(data->type); i++) {
|
||||
nfc_util_num2bytes(cfg.keys[i].a, sizeof(MfClassicKey), keys.key_a[i].data);
|
||||
bit_lib_num_to_bytes_be(cfg.keys[i].a, sizeof(MfClassicKey), keys.key_a[i].data);
|
||||
FURI_BIT_SET(keys.key_a_mask, i);
|
||||
nfc_util_num2bytes(cfg.keys[i].b, sizeof(MfClassicKey), keys.key_b[i].data);
|
||||
bit_lib_num_to_bytes_be(cfg.keys[i].b, sizeof(MfClassicKey), keys.key_b[i].data);
|
||||
FURI_BIT_SET(keys.key_b_mask, i);
|
||||
}
|
||||
|
||||
@@ -197,7 +196,7 @@ static bool mizip_parse(const NfcDevice* device, FuriString* parsed_data) {
|
||||
// Verify key
|
||||
MfClassicSectorTrailer* sec_tr =
|
||||
mf_classic_get_sector_trailer_by_sector(data, cfg.verify_sector);
|
||||
uint64_t key = nfc_util_bytes2num(sec_tr->key_b.data, 6);
|
||||
uint64_t key = bit_lib_bytes_to_num_be(sec_tr->key_b.data, 6);
|
||||
if(key != cfg.keys[cfg.verify_sector].b) return false;
|
||||
|
||||
//Get UID
|
||||
|
||||
Reference in New Issue
Block a user