M*LIB: non-inlined strings, FuriString primitive (#1795)
* Quicksave 1 * Header stage complete * Source stage complete * Lint & merge fixes * Includes * Documentation step 1 * FBT: output free size considering BT STACK * Documentation step 2 * py lint * Fix music player plugin * unit test stage 1: string allocator, mem, getters, setters, appends, compare, search. * unit test: string equality * unit test: string replace * unit test: string start_with, end_with * unit test: string trim * unit test: utf-8 * Rename * Revert fw_size changes * Simplify CLI backspace handling * Simplify CLI character insert * Merge fixes * Furi: correct filenaming and spelling * Bt: remove furi string include Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
This commit is contained in:
@@ -66,15 +66,15 @@ MfClassicDict* mf_classic_dict_alloc(MfClassicDictType dict_type) {
|
||||
}
|
||||
|
||||
// Read total amount of keys
|
||||
string_t next_line;
|
||||
string_init(next_line);
|
||||
FuriString* next_line;
|
||||
next_line = furi_string_alloc();
|
||||
while(true) {
|
||||
if(!stream_read_line(dict->stream, next_line)) break;
|
||||
if(string_get_char(next_line, 0) == '#') continue;
|
||||
if(string_size(next_line) != NFC_MF_CLASSIC_KEY_LEN) continue;
|
||||
if(furi_string_get_char(next_line, 0) == '#') continue;
|
||||
if(furi_string_size(next_line) != NFC_MF_CLASSIC_KEY_LEN) continue;
|
||||
dict->total_keys++;
|
||||
}
|
||||
string_clear(next_line);
|
||||
furi_string_free(next_line);
|
||||
stream_rewind(dict->stream);
|
||||
|
||||
dict_loaded = true;
|
||||
@@ -99,20 +99,20 @@ void mf_classic_dict_free(MfClassicDict* dict) {
|
||||
free(dict);
|
||||
}
|
||||
|
||||
static void mf_classic_dict_int_to_str(uint8_t* key_int, string_t key_str) {
|
||||
string_reset(key_str);
|
||||
static void mf_classic_dict_int_to_str(uint8_t* key_int, FuriString* key_str) {
|
||||
furi_string_reset(key_str);
|
||||
for(size_t i = 0; i < 6; i++) {
|
||||
string_cat_printf(key_str, "%02X", key_int[i]);
|
||||
furi_string_cat_printf(key_str, "%02X", key_int[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void mf_classic_dict_str_to_int(string_t key_str, uint64_t* key_int) {
|
||||
static void mf_classic_dict_str_to_int(FuriString* key_str, uint64_t* key_int) {
|
||||
uint8_t key_byte_tmp;
|
||||
|
||||
*key_int = 0ULL;
|
||||
for(uint8_t i = 0; i < 12; i += 2) {
|
||||
args_char_to_hex(
|
||||
string_get_char(key_str, i), string_get_char(key_str, i + 1), &key_byte_tmp);
|
||||
furi_string_get_char(key_str, i), furi_string_get_char(key_str, i + 1), &key_byte_tmp);
|
||||
*key_int |= (uint64_t)key_byte_tmp << 8 * (5 - i / 2);
|
||||
}
|
||||
}
|
||||
@@ -130,17 +130,17 @@ bool mf_classic_dict_rewind(MfClassicDict* dict) {
|
||||
return stream_rewind(dict->stream);
|
||||
}
|
||||
|
||||
bool mf_classic_dict_get_next_key_str(MfClassicDict* dict, string_t key) {
|
||||
bool mf_classic_dict_get_next_key_str(MfClassicDict* dict, FuriString* key) {
|
||||
furi_assert(dict);
|
||||
furi_assert(dict->stream);
|
||||
|
||||
bool key_read = false;
|
||||
string_reset(key);
|
||||
furi_string_reset(key);
|
||||
while(!key_read) {
|
||||
if(!stream_read_line(dict->stream, key)) break;
|
||||
if(string_get_char(key, 0) == '#') continue;
|
||||
if(string_size(key) != NFC_MF_CLASSIC_KEY_LEN) continue;
|
||||
string_left(key, 12);
|
||||
if(furi_string_get_char(key, 0) == '#') continue;
|
||||
if(furi_string_size(key) != NFC_MF_CLASSIC_KEY_LEN) continue;
|
||||
furi_string_left(key, 12);
|
||||
key_read = true;
|
||||
}
|
||||
|
||||
@@ -151,53 +151,53 @@ bool mf_classic_dict_get_next_key(MfClassicDict* dict, uint64_t* key) {
|
||||
furi_assert(dict);
|
||||
furi_assert(dict->stream);
|
||||
|
||||
string_t temp_key;
|
||||
string_init(temp_key);
|
||||
FuriString* temp_key;
|
||||
temp_key = furi_string_alloc();
|
||||
bool key_read = mf_classic_dict_get_next_key_str(dict, temp_key);
|
||||
if(key_read) {
|
||||
mf_classic_dict_str_to_int(temp_key, key);
|
||||
}
|
||||
string_clear(temp_key);
|
||||
furi_string_free(temp_key);
|
||||
return key_read;
|
||||
}
|
||||
|
||||
bool mf_classic_dict_is_key_present_str(MfClassicDict* dict, string_t key) {
|
||||
bool mf_classic_dict_is_key_present_str(MfClassicDict* dict, FuriString* key) {
|
||||
furi_assert(dict);
|
||||
furi_assert(dict->stream);
|
||||
|
||||
string_t next_line;
|
||||
string_init(next_line);
|
||||
FuriString* next_line;
|
||||
next_line = furi_string_alloc();
|
||||
|
||||
bool key_found = false;
|
||||
stream_rewind(dict->stream);
|
||||
while(!key_found) {
|
||||
if(!stream_read_line(dict->stream, next_line)) break;
|
||||
if(string_get_char(next_line, 0) == '#') continue;
|
||||
if(string_size(next_line) != NFC_MF_CLASSIC_KEY_LEN) continue;
|
||||
string_left(next_line, 12);
|
||||
if(!string_equal_p(key, next_line)) continue;
|
||||
if(furi_string_get_char(next_line, 0) == '#') continue;
|
||||
if(furi_string_size(next_line) != NFC_MF_CLASSIC_KEY_LEN) continue;
|
||||
furi_string_left(next_line, 12);
|
||||
if(!furi_string_equal(key, next_line)) continue;
|
||||
key_found = true;
|
||||
}
|
||||
|
||||
string_clear(next_line);
|
||||
furi_string_free(next_line);
|
||||
return key_found;
|
||||
}
|
||||
|
||||
bool mf_classic_dict_is_key_present(MfClassicDict* dict, uint8_t* key) {
|
||||
string_t temp_key;
|
||||
FuriString* temp_key;
|
||||
|
||||
string_init(temp_key);
|
||||
temp_key = furi_string_alloc();
|
||||
mf_classic_dict_int_to_str(key, temp_key);
|
||||
bool key_found = mf_classic_dict_is_key_present_str(dict, temp_key);
|
||||
string_clear(temp_key);
|
||||
furi_string_free(temp_key);
|
||||
return key_found;
|
||||
}
|
||||
|
||||
bool mf_classic_dict_add_key_str(MfClassicDict* dict, string_t key) {
|
||||
bool mf_classic_dict_add_key_str(MfClassicDict* dict, FuriString* key) {
|
||||
furi_assert(dict);
|
||||
furi_assert(dict->stream);
|
||||
|
||||
string_cat_printf(key, "\n");
|
||||
furi_string_cat_printf(key, "\n");
|
||||
|
||||
bool key_added = false;
|
||||
do {
|
||||
@@ -207,7 +207,7 @@ bool mf_classic_dict_add_key_str(MfClassicDict* dict, string_t key) {
|
||||
key_added = true;
|
||||
} while(false);
|
||||
|
||||
string_left(key, 12);
|
||||
furi_string_left(key, 12);
|
||||
return key_added;
|
||||
}
|
||||
|
||||
@@ -215,35 +215,35 @@ bool mf_classic_dict_add_key(MfClassicDict* dict, uint8_t* key) {
|
||||
furi_assert(dict);
|
||||
furi_assert(dict->stream);
|
||||
|
||||
string_t temp_key;
|
||||
string_init(temp_key);
|
||||
FuriString* temp_key;
|
||||
temp_key = furi_string_alloc();
|
||||
mf_classic_dict_int_to_str(key, temp_key);
|
||||
bool key_added = mf_classic_dict_add_key_str(dict, temp_key);
|
||||
|
||||
string_clear(temp_key);
|
||||
furi_string_free(temp_key);
|
||||
return key_added;
|
||||
}
|
||||
|
||||
bool mf_classic_dict_get_key_at_index_str(MfClassicDict* dict, string_t key, uint32_t target) {
|
||||
bool mf_classic_dict_get_key_at_index_str(MfClassicDict* dict, FuriString* key, uint32_t target) {
|
||||
furi_assert(dict);
|
||||
furi_assert(dict->stream);
|
||||
|
||||
string_t next_line;
|
||||
FuriString* next_line;
|
||||
uint32_t index = 0;
|
||||
string_init(next_line);
|
||||
string_reset(key);
|
||||
next_line = furi_string_alloc();
|
||||
furi_string_reset(key);
|
||||
|
||||
bool key_found = false;
|
||||
while(!key_found) {
|
||||
if(!stream_read_line(dict->stream, next_line)) break;
|
||||
if(string_get_char(next_line, 0) == '#') continue;
|
||||
if(string_size(next_line) != NFC_MF_CLASSIC_KEY_LEN) continue;
|
||||
if(furi_string_get_char(next_line, 0) == '#') continue;
|
||||
if(furi_string_size(next_line) != NFC_MF_CLASSIC_KEY_LEN) continue;
|
||||
if(index++ != target) continue;
|
||||
string_set_n(key, next_line, 0, 12);
|
||||
furi_string_set_n(key, next_line, 0, 12);
|
||||
key_found = true;
|
||||
}
|
||||
|
||||
string_clear(next_line);
|
||||
furi_string_free(next_line);
|
||||
return key_found;
|
||||
}
|
||||
|
||||
@@ -251,37 +251,37 @@ bool mf_classic_dict_get_key_at_index(MfClassicDict* dict, uint64_t* key, uint32
|
||||
furi_assert(dict);
|
||||
furi_assert(dict->stream);
|
||||
|
||||
string_t temp_key;
|
||||
string_init(temp_key);
|
||||
FuriString* temp_key;
|
||||
temp_key = furi_string_alloc();
|
||||
bool key_found = mf_classic_dict_get_key_at_index_str(dict, temp_key, target);
|
||||
if(key_found) {
|
||||
mf_classic_dict_str_to_int(temp_key, key);
|
||||
}
|
||||
string_clear(temp_key);
|
||||
furi_string_free(temp_key);
|
||||
return key_found;
|
||||
}
|
||||
|
||||
bool mf_classic_dict_find_index_str(MfClassicDict* dict, string_t key, uint32_t* target) {
|
||||
bool mf_classic_dict_find_index_str(MfClassicDict* dict, FuriString* key, uint32_t* target) {
|
||||
furi_assert(dict);
|
||||
furi_assert(dict->stream);
|
||||
|
||||
string_t next_line;
|
||||
string_init(next_line);
|
||||
FuriString* next_line;
|
||||
next_line = furi_string_alloc();
|
||||
|
||||
bool key_found = false;
|
||||
uint32_t index = 0;
|
||||
stream_rewind(dict->stream);
|
||||
while(!key_found) {
|
||||
if(!stream_read_line(dict->stream, next_line)) break;
|
||||
if(string_get_char(next_line, 0) == '#') continue;
|
||||
if(string_size(next_line) != NFC_MF_CLASSIC_KEY_LEN) continue;
|
||||
string_left(next_line, 12);
|
||||
if(!string_equal_p(key, next_line)) continue;
|
||||
if(furi_string_get_char(next_line, 0) == '#') continue;
|
||||
if(furi_string_size(next_line) != NFC_MF_CLASSIC_KEY_LEN) continue;
|
||||
furi_string_left(next_line, 12);
|
||||
if(!furi_string_equal(key, next_line)) continue;
|
||||
key_found = true;
|
||||
*target = index;
|
||||
}
|
||||
|
||||
string_clear(next_line);
|
||||
furi_string_free(next_line);
|
||||
return key_found;
|
||||
}
|
||||
|
||||
@@ -289,12 +289,12 @@ bool mf_classic_dict_find_index(MfClassicDict* dict, uint8_t* key, uint32_t* tar
|
||||
furi_assert(dict);
|
||||
furi_assert(dict->stream);
|
||||
|
||||
string_t temp_key;
|
||||
string_init(temp_key);
|
||||
FuriString* temp_key;
|
||||
temp_key = furi_string_alloc();
|
||||
mf_classic_dict_int_to_str(key, temp_key);
|
||||
bool key_found = mf_classic_dict_find_index_str(dict, temp_key, target);
|
||||
|
||||
string_clear(temp_key);
|
||||
furi_string_free(temp_key);
|
||||
return key_found;
|
||||
}
|
||||
|
||||
@@ -302,15 +302,15 @@ bool mf_classic_dict_delete_index(MfClassicDict* dict, uint32_t target) {
|
||||
furi_assert(dict);
|
||||
furi_assert(dict->stream);
|
||||
|
||||
string_t next_line;
|
||||
string_init(next_line);
|
||||
FuriString* next_line;
|
||||
next_line = furi_string_alloc();
|
||||
uint32_t index = 0;
|
||||
|
||||
bool key_removed = false;
|
||||
while(!key_removed) {
|
||||
if(!stream_read_line(dict->stream, next_line)) break;
|
||||
if(string_get_char(next_line, 0) == '#') continue;
|
||||
if(string_size(next_line) != NFC_MF_CLASSIC_KEY_LEN) continue;
|
||||
if(furi_string_get_char(next_line, 0) == '#') continue;
|
||||
if(furi_string_size(next_line) != NFC_MF_CLASSIC_KEY_LEN) continue;
|
||||
if(index++ != target) continue;
|
||||
stream_seek(dict->stream, -NFC_MF_CLASSIC_KEY_LEN, StreamOffsetFromCurrent);
|
||||
if(!stream_delete(dict->stream, NFC_MF_CLASSIC_KEY_LEN)) break;
|
||||
@@ -318,6 +318,6 @@ bool mf_classic_dict_delete_index(MfClassicDict* dict, uint32_t target) {
|
||||
key_removed = true;
|
||||
}
|
||||
|
||||
string_clear(next_line);
|
||||
furi_string_free(next_line);
|
||||
return key_removed;
|
||||
}
|
||||
|
@@ -48,11 +48,11 @@ bool mf_classic_dict_rewind(MfClassicDict* dict);
|
||||
|
||||
bool mf_classic_dict_is_key_present(MfClassicDict* dict, uint8_t* key);
|
||||
|
||||
bool mf_classic_dict_is_key_present_str(MfClassicDict* dict, string_t key);
|
||||
bool mf_classic_dict_is_key_present_str(MfClassicDict* dict, FuriString* key);
|
||||
|
||||
bool mf_classic_dict_get_next_key(MfClassicDict* dict, uint64_t* key);
|
||||
|
||||
bool mf_classic_dict_get_next_key_str(MfClassicDict* dict, string_t key);
|
||||
bool mf_classic_dict_get_next_key_str(MfClassicDict* dict, FuriString* key);
|
||||
|
||||
/** Get key at target offset as uint64_t
|
||||
*
|
||||
@@ -72,7 +72,7 @@ bool mf_classic_dict_get_key_at_index(MfClassicDict* dict, uint64_t* key, uint32
|
||||
*
|
||||
* @return true on success
|
||||
*/
|
||||
bool mf_classic_dict_get_key_at_index_str(MfClassicDict* dict, string_t key, uint32_t target);
|
||||
bool mf_classic_dict_get_key_at_index_str(MfClassicDict* dict, FuriString* key, uint32_t target);
|
||||
|
||||
bool mf_classic_dict_add_key(MfClassicDict* dict, uint8_t* key);
|
||||
|
||||
@@ -83,11 +83,11 @@ bool mf_classic_dict_add_key(MfClassicDict* dict, uint8_t* key);
|
||||
*
|
||||
* @return true on success
|
||||
*/
|
||||
bool mf_classic_dict_add_key_str(MfClassicDict* dict, string_t key);
|
||||
bool mf_classic_dict_add_key_str(MfClassicDict* dict, FuriString* key);
|
||||
|
||||
bool mf_classic_dict_find_index(MfClassicDict* dict, uint8_t* key, uint32_t* target);
|
||||
|
||||
bool mf_classic_dict_find_index_str(MfClassicDict* dict, string_t key, uint32_t* target);
|
||||
bool mf_classic_dict_find_index_str(MfClassicDict* dict, FuriString* key, uint32_t* target);
|
||||
|
||||
/** Delete key at target offset
|
||||
*
|
||||
|
@@ -91,9 +91,7 @@ void mfkey32_set_callback(Mfkey32* instance, Mfkey32ParseDataCallback callback,
|
||||
}
|
||||
|
||||
static bool mfkey32_write_params(Mfkey32* instance, Mfkey32Params* params) {
|
||||
string_t str;
|
||||
string_init_printf(
|
||||
str,
|
||||
FuriString* str = furi_string_alloc_printf(
|
||||
"Sector %d key %c cuid %08x nt0 %08x nr0 %08x ar0 %08x nt1 %08x nr1 %08x ar1 %08x\n",
|
||||
params->sector,
|
||||
params->key == MfClassicKeyA ? 'A' : 'B',
|
||||
@@ -105,7 +103,7 @@ static bool mfkey32_write_params(Mfkey32* instance, Mfkey32Params* params) {
|
||||
params->nr1,
|
||||
params->ar1);
|
||||
bool write_success = stream_write_string(instance->file_stream, str);
|
||||
string_clear(str);
|
||||
furi_string_free(str);
|
||||
return write_success;
|
||||
}
|
||||
|
||||
@@ -199,14 +197,14 @@ void mfkey32_process_data(
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t mfkey32_get_auth_sectors(string_t data_str) {
|
||||
uint16_t mfkey32_get_auth_sectors(FuriString* data_str) {
|
||||
furi_assert(data_str);
|
||||
|
||||
uint16_t nonces_num = 0;
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
Stream* file_stream = buffered_file_stream_alloc(storage);
|
||||
string_t temp_str;
|
||||
string_init(temp_str);
|
||||
FuriString* temp_str;
|
||||
temp_str = furi_string_alloc();
|
||||
|
||||
do {
|
||||
if(!buffered_file_stream_open(
|
||||
@@ -214,17 +212,17 @@ uint16_t mfkey32_get_auth_sectors(string_t data_str) {
|
||||
break;
|
||||
while(true) {
|
||||
if(!stream_read_line(file_stream, temp_str)) break;
|
||||
size_t uid_pos = string_search_str(temp_str, "cuid");
|
||||
string_left(temp_str, uid_pos);
|
||||
string_push_back(temp_str, '\n');
|
||||
string_cat(data_str, temp_str);
|
||||
size_t uid_pos = furi_string_search(temp_str, "cuid");
|
||||
furi_string_left(temp_str, uid_pos);
|
||||
furi_string_push_back(temp_str, '\n');
|
||||
furi_string_cat(data_str, temp_str);
|
||||
nonces_num++;
|
||||
}
|
||||
} while(false);
|
||||
|
||||
buffered_file_stream_close(file_stream);
|
||||
stream_free(file_stream);
|
||||
string_clear(temp_str);
|
||||
furi_string_free(temp_str);
|
||||
|
||||
return nonces_num;
|
||||
}
|
||||
|
@@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <lib/nfc/protocols/mifare_classic.h>
|
||||
#include <m-string.h>
|
||||
|
||||
typedef struct Mfkey32 Mfkey32;
|
||||
|
||||
@@ -24,4 +23,4 @@ void mfkey32_process_data(
|
||||
|
||||
void mfkey32_set_callback(Mfkey32* instance, Mfkey32ParseDataCallback callback, void* context);
|
||||
|
||||
uint16_t mfkey32_get_auth_sectors(string_t string);
|
||||
uint16_t mfkey32_get_auth_sectors(FuriString* string);
|
||||
|
@@ -1,6 +1,5 @@
|
||||
#include "nfc_debug_log.h"
|
||||
|
||||
#include <m-string.h>
|
||||
#include <storage/storage.h>
|
||||
#include <stream/buffered_file_stream.h>
|
||||
|
||||
@@ -10,7 +9,7 @@
|
||||
|
||||
struct NfcDebugLog {
|
||||
Stream* file_stream;
|
||||
string_t data_str;
|
||||
FuriString* data_str;
|
||||
};
|
||||
|
||||
NfcDebugLog* nfc_debug_log_alloc() {
|
||||
@@ -30,7 +29,7 @@ NfcDebugLog* nfc_debug_log_alloc() {
|
||||
free(instance);
|
||||
instance = NULL;
|
||||
} else {
|
||||
string_init(instance->data_str);
|
||||
instance->data_str = furi_string_alloc();
|
||||
}
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
|
||||
@@ -44,7 +43,7 @@ void nfc_debug_log_free(NfcDebugLog* instance) {
|
||||
|
||||
buffered_file_stream_close(instance->file_stream);
|
||||
stream_free(instance->file_stream);
|
||||
string_clear(instance->data_str);
|
||||
furi_string_free(instance->data_str);
|
||||
|
||||
free(instance);
|
||||
}
|
||||
@@ -61,12 +60,12 @@ void nfc_debug_log_process_data(
|
||||
furi_assert(data);
|
||||
UNUSED(crc_dropped);
|
||||
|
||||
string_printf(instance->data_str, "%lu %c:", furi_get_tick(), reader_to_tag ? 'R' : 'T');
|
||||
furi_string_printf(instance->data_str, "%lu %c:", furi_get_tick(), reader_to_tag ? 'R' : 'T');
|
||||
uint16_t data_len = len;
|
||||
for(size_t i = 0; i < data_len; i++) {
|
||||
string_cat_printf(instance->data_str, " %02x", data[i]);
|
||||
furi_string_cat_printf(instance->data_str, " %02x", data[i]);
|
||||
}
|
||||
string_push_back(instance->data_str, '\n');
|
||||
furi_string_push_back(instance->data_str, '\n');
|
||||
|
||||
stream_write_string(instance->file_stream, instance->data_str);
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -60,7 +60,7 @@ typedef struct {
|
||||
MfClassicData mf_classic_data;
|
||||
MifareDesfireData mf_df_data;
|
||||
};
|
||||
string_t parsed_data;
|
||||
FuriString* parsed_data;
|
||||
} NfcDeviceData;
|
||||
|
||||
typedef struct {
|
||||
@@ -68,7 +68,7 @@ typedef struct {
|
||||
DialogsApp* dialogs;
|
||||
NfcDeviceData dev_data;
|
||||
char dev_name[NFC_DEV_NAME_MAX_LEN + 1];
|
||||
string_t load_path;
|
||||
FuriString* load_path;
|
||||
NfcDeviceSaveFormat format;
|
||||
bool shadow_file_exist;
|
||||
|
||||
|
@@ -107,7 +107,7 @@ bool all_in_one_parser_parse(NfcDeviceData* dev_data) {
|
||||
dev_data->mf_ul_data.data[4 * 4 + 5] << 4 | (dev_data->mf_ul_data.data[4 * 4 + 6] >> 4);
|
||||
|
||||
// Format string for rides count
|
||||
string_printf(
|
||||
furi_string_printf(
|
||||
dev_data->parsed_data, "\e#All-In-One\nNumber: %u\nRides left: %u", serial, ride_count);
|
||||
return true;
|
||||
}
|
@@ -4,8 +4,6 @@
|
||||
#include "../nfc_worker.h"
|
||||
#include "../nfc_device.h"
|
||||
|
||||
#include <m-string.h>
|
||||
|
||||
typedef enum {
|
||||
NfcSupportedCardTypePlantain,
|
||||
NfcSupportedCardTypeTroika,
|
||||
|
@@ -118,36 +118,36 @@ bool plantain_4k_parser_parse(NfcDeviceData* dev_data) {
|
||||
card_number = (card_number << 8) | card_number_arr[i];
|
||||
}
|
||||
// Convert card number to string
|
||||
string_t card_number_str;
|
||||
string_init(card_number_str);
|
||||
FuriString* card_number_str;
|
||||
card_number_str = furi_string_alloc();
|
||||
// Should look like "361301047292848684"
|
||||
// %llu doesn't work for some reason in sprintf, so we use string_push_uint64 instead
|
||||
string_push_uint64(card_number, card_number_str);
|
||||
// Add suffix with luhn checksum (1 digit) to the card number string
|
||||
string_t card_number_suffix;
|
||||
string_init(card_number_suffix);
|
||||
FuriString* card_number_suffix;
|
||||
card_number_suffix = furi_string_alloc();
|
||||
|
||||
// The number to calculate the checksum on doesn't fit into uint64_t, idk
|
||||
//uint8_t luhn_checksum = plantain_calculate_luhn(card_number);
|
||||
|
||||
// // Convert luhn checksum to string
|
||||
// string_t luhn_checksum_str;
|
||||
// string_init(luhn_checksum_str);
|
||||
// FuriString* luhn_checksum_str;
|
||||
// luhn_checksum_str = furi_string_alloc();
|
||||
// string_push_uint64(luhn_checksum, luhn_checksum_str);
|
||||
|
||||
string_cat_printf(card_number_suffix, "-");
|
||||
furi_string_cat_printf(card_number_suffix, "-");
|
||||
// FURI_LOG_D("plant4k", "Card checksum: %d", luhn_checksum);
|
||||
string_cat_printf(card_number_str, string_get_cstr(card_number_suffix));
|
||||
furi_string_cat_printf(card_number_str, furi_string_get_cstr(card_number_suffix));
|
||||
// Free all not needed strings
|
||||
string_clear(card_number_suffix);
|
||||
// string_clear(luhn_checksum_str);
|
||||
furi_string_free(card_number_suffix);
|
||||
// furi_string_free(luhn_checksum_str);
|
||||
|
||||
string_printf(
|
||||
furi_string_printf(
|
||||
dev_data->parsed_data,
|
||||
"\e#Plantain\nN:%s\nBalance:%d\n",
|
||||
string_get_cstr(card_number_str),
|
||||
furi_string_get_cstr(card_number_str),
|
||||
balance);
|
||||
string_clear(card_number_str);
|
||||
furi_string_free(card_number_str);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@@ -55,7 +55,7 @@ bool plantain_parser_read(NfcWorker* nfc_worker, FuriHalNfcTxRxContext* tx_rx) {
|
||||
return mf_classic_read_card(tx_rx, &reader, &nfc_worker->dev_data->mf_classic_data) == 16;
|
||||
}
|
||||
|
||||
void string_push_uint64(uint64_t input, string_t output) {
|
||||
void string_push_uint64(uint64_t input, FuriString* output) {
|
||||
const uint8_t base = 10;
|
||||
|
||||
do {
|
||||
@@ -66,14 +66,15 @@ void string_push_uint64(uint64_t input, string_t output) {
|
||||
c += '0';
|
||||
else
|
||||
c += 'A' - 10;
|
||||
string_push_back(output, c);
|
||||
furi_string_push_back(output, c);
|
||||
} while(input);
|
||||
|
||||
// reverse string
|
||||
for(uint8_t i = 0; i < string_size(output) / 2; i++) {
|
||||
char c = string_get_char(output, i);
|
||||
string_set_char(output, i, string_get_char(output, string_size(output) - i - 1));
|
||||
string_set_char(output, string_size(output) - i - 1, c);
|
||||
for(uint8_t i = 0; i < furi_string_size(output) / 2; i++) {
|
||||
char c = furi_string_get_char(output, i);
|
||||
furi_string_set_char(
|
||||
output, i, furi_string_get_char(output, furi_string_size(output) - i - 1));
|
||||
furi_string_set_char(output, furi_string_size(output) - i - 1, c);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,36 +113,36 @@ bool plantain_parser_parse(NfcDeviceData* dev_data) {
|
||||
card_number = (card_number << 8) | card_number_arr[i];
|
||||
}
|
||||
// Convert card number to string
|
||||
string_t card_number_str;
|
||||
string_init(card_number_str);
|
||||
FuriString* card_number_str;
|
||||
card_number_str = furi_string_alloc();
|
||||
// Should look like "361301047292848684"
|
||||
// %llu doesn't work for some reason in sprintf, so we use string_push_uint64 instead
|
||||
string_push_uint64(card_number, card_number_str);
|
||||
// Add suffix with luhn checksum (1 digit) to the card number string
|
||||
string_t card_number_suffix;
|
||||
string_init(card_number_suffix);
|
||||
FuriString* card_number_suffix;
|
||||
card_number_suffix = furi_string_alloc();
|
||||
|
||||
// The number to calculate the checksum on doesn't fit into uint64_t, idk
|
||||
//uint8_t luhn_checksum = plantain_calculate_luhn(card_number);
|
||||
|
||||
// // Convert luhn checksum to string
|
||||
// string_t luhn_checksum_str;
|
||||
// string_init(luhn_checksum_str);
|
||||
// FuriString* luhn_checksum_str;
|
||||
// luhn_checksum_str = furi_string_alloc();
|
||||
// string_push_uint64(luhn_checksum, luhn_checksum_str);
|
||||
|
||||
string_cat_printf(card_number_suffix, "-");
|
||||
furi_string_cat_printf(card_number_suffix, "-");
|
||||
// FURI_LOG_D("plant4k", "Card checksum: %d", luhn_checksum);
|
||||
string_cat_printf(card_number_str, string_get_cstr(card_number_suffix));
|
||||
furi_string_cat_printf(card_number_str, furi_string_get_cstr(card_number_suffix));
|
||||
// Free all not needed strings
|
||||
string_clear(card_number_suffix);
|
||||
// string_clear(luhn_checksum_str);
|
||||
furi_string_free(card_number_suffix);
|
||||
// furi_string_free(luhn_checksum_str);
|
||||
|
||||
string_printf(
|
||||
furi_string_printf(
|
||||
dev_data->parsed_data,
|
||||
"\e#Plantain\nN:%s\nBalance:%d\n",
|
||||
string_get_cstr(card_number_str),
|
||||
furi_string_get_cstr(card_number_str),
|
||||
balance);
|
||||
string_clear(card_number_str);
|
||||
furi_string_free(card_number_str);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@@ -8,6 +8,6 @@ bool plantain_parser_read(NfcWorker* nfc_worker, FuriHalNfcTxRxContext* tx_rx);
|
||||
|
||||
bool plantain_parser_parse(NfcDeviceData* dev_data);
|
||||
|
||||
void string_push_uint64(uint64_t input, string_t output);
|
||||
void string_push_uint64(uint64_t input, FuriString* output);
|
||||
|
||||
uint8_t plantain_calculate_luhn(uint64_t number);
|
||||
|
@@ -98,7 +98,8 @@ bool troika_4k_parser_parse(NfcDeviceData* dev_data) {
|
||||
}
|
||||
number >>= 4;
|
||||
|
||||
string_printf(dev_data->parsed_data, "\e#Troika\nNum: %ld\nBalance: %d rur.", number, balance);
|
||||
furi_string_printf(
|
||||
dev_data->parsed_data, "\e#Troika\nNum: %ld\nBalance: %d rur.", number, balance);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@@ -78,7 +78,7 @@ bool troika_parser_parse(NfcDeviceData* dev_data) {
|
||||
}
|
||||
number >>= 4;
|
||||
|
||||
string_printf(
|
||||
furi_string_printf(
|
||||
dev_data->parsed_data, "\e#Troika\nNum: %ld\nBalance: %d rur.", number, balance);
|
||||
troika_parsed = true;
|
||||
} while(false);
|
||||
|
@@ -118,29 +118,29 @@ bool two_cities_parser_parse(NfcDeviceData* dev_data) {
|
||||
card_number = (card_number << 8) | card_number_arr[i];
|
||||
}
|
||||
// Convert card number to string
|
||||
string_t card_number_str;
|
||||
string_init(card_number_str);
|
||||
FuriString* card_number_str;
|
||||
card_number_str = furi_string_alloc();
|
||||
// Should look like "361301047292848684"
|
||||
// %llu doesn't work for some reason in sprintf, so we use string_push_uint64 instead
|
||||
string_push_uint64(card_number, card_number_str);
|
||||
// Add suffix with luhn checksum (1 digit) to the card number string
|
||||
string_t card_number_suffix;
|
||||
string_init(card_number_suffix);
|
||||
FuriString* card_number_suffix;
|
||||
card_number_suffix = furi_string_alloc();
|
||||
|
||||
// The number to calculate the checksum on doesn't fit into uint64_t, idk
|
||||
//uint8_t luhn_checksum = two_cities_calculate_luhn(card_number);
|
||||
|
||||
// // Convert luhn checksum to string
|
||||
// string_t luhn_checksum_str;
|
||||
// string_init(luhn_checksum_str);
|
||||
// FuriString* luhn_checksum_str;
|
||||
// luhn_checksum_str = furi_string_alloc();
|
||||
// string_push_uint64(luhn_checksum, luhn_checksum_str);
|
||||
|
||||
string_cat_printf(card_number_suffix, "-");
|
||||
furi_string_cat_printf(card_number_suffix, "-");
|
||||
// FURI_LOG_D("plant4k", "Card checksum: %d", luhn_checksum);
|
||||
string_cat_printf(card_number_str, string_get_cstr(card_number_suffix));
|
||||
furi_string_cat_printf(card_number_str, furi_string_get_cstr(card_number_suffix));
|
||||
// Free all not needed strings
|
||||
string_clear(card_number_suffix);
|
||||
// string_clear(luhn_checksum_str);
|
||||
furi_string_free(card_number_suffix);
|
||||
// furi_string_free(luhn_checksum_str);
|
||||
|
||||
// =====
|
||||
// --PLANTAIN--
|
||||
@@ -158,14 +158,14 @@ bool two_cities_parser_parse(NfcDeviceData* dev_data) {
|
||||
}
|
||||
troika_number >>= 4;
|
||||
|
||||
string_printf(
|
||||
furi_string_printf(
|
||||
dev_data->parsed_data,
|
||||
"\e#Troika+Plantain\nPN: %s\nPB: %d rur.\nTN: %d\nTB: %d rur.\n",
|
||||
string_get_cstr(card_number_str),
|
||||
furi_string_get_cstr(card_number_str),
|
||||
balance,
|
||||
troika_number,
|
||||
troika_balance);
|
||||
string_clear(card_number_str);
|
||||
furi_string_free(card_number_str);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@@ -42,14 +42,14 @@ void mf_df_clear(MifareDesfireData* data) {
|
||||
data->app_head = NULL;
|
||||
}
|
||||
|
||||
void mf_df_cat_data(MifareDesfireData* data, string_t out) {
|
||||
void mf_df_cat_data(MifareDesfireData* data, FuriString* out) {
|
||||
mf_df_cat_card_info(data, out);
|
||||
for(MifareDesfireApplication* app = data->app_head; app; app = app->next) {
|
||||
mf_df_cat_application(app, out);
|
||||
}
|
||||
}
|
||||
|
||||
void mf_df_cat_card_info(MifareDesfireData* data, string_t out) {
|
||||
void mf_df_cat_card_info(MifareDesfireData* data, FuriString* out) {
|
||||
mf_df_cat_version(&data->version, out);
|
||||
if(data->free_memory) {
|
||||
mf_df_cat_free_mem(data->free_memory, out);
|
||||
@@ -59,8 +59,8 @@ void mf_df_cat_card_info(MifareDesfireData* data, string_t out) {
|
||||
}
|
||||
}
|
||||
|
||||
void mf_df_cat_version(MifareDesfireVersion* version, string_t out) {
|
||||
string_cat_printf(
|
||||
void mf_df_cat_version(MifareDesfireVersion* version, FuriString* out) {
|
||||
furi_string_cat_printf(
|
||||
out,
|
||||
"%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
|
||||
version->uid[0],
|
||||
@@ -70,7 +70,7 @@ void mf_df_cat_version(MifareDesfireVersion* version, string_t out) {
|
||||
version->uid[4],
|
||||
version->uid[5],
|
||||
version->uid[6]);
|
||||
string_cat_printf(
|
||||
furi_string_cat_printf(
|
||||
out,
|
||||
"hw %02x type %02x sub %02x\n"
|
||||
" maj %02x min %02x\n"
|
||||
@@ -82,7 +82,7 @@ void mf_df_cat_version(MifareDesfireVersion* version, string_t out) {
|
||||
version->hw_minor,
|
||||
version->hw_storage,
|
||||
version->hw_proto);
|
||||
string_cat_printf(
|
||||
furi_string_cat_printf(
|
||||
out,
|
||||
"sw %02x type %02x sub %02x\n"
|
||||
" maj %02x min %02x\n"
|
||||
@@ -94,7 +94,7 @@ void mf_df_cat_version(MifareDesfireVersion* version, string_t out) {
|
||||
version->sw_minor,
|
||||
version->sw_storage,
|
||||
version->sw_proto);
|
||||
string_cat_printf(
|
||||
furi_string_cat_printf(
|
||||
out,
|
||||
"batch %02x:%02x:%02x:%02x:%02x\n"
|
||||
"week %d year %d\n",
|
||||
@@ -107,40 +107,40 @@ void mf_df_cat_version(MifareDesfireVersion* version, string_t out) {
|
||||
version->prod_year);
|
||||
}
|
||||
|
||||
void mf_df_cat_free_mem(MifareDesfireFreeMemory* free_mem, string_t out) {
|
||||
string_cat_printf(out, "freeMem %d\n", free_mem->bytes);
|
||||
void mf_df_cat_free_mem(MifareDesfireFreeMemory* free_mem, FuriString* out) {
|
||||
furi_string_cat_printf(out, "freeMem %d\n", free_mem->bytes);
|
||||
}
|
||||
|
||||
void mf_df_cat_key_settings(MifareDesfireKeySettings* ks, string_t out) {
|
||||
string_cat_printf(out, "changeKeyID %d\n", ks->change_key_id);
|
||||
string_cat_printf(out, "configChangeable %d\n", ks->config_changeable);
|
||||
string_cat_printf(out, "freeCreateDelete %d\n", ks->free_create_delete);
|
||||
string_cat_printf(out, "freeDirectoryList %d\n", ks->free_directory_list);
|
||||
string_cat_printf(out, "masterChangeable %d\n", ks->master_key_changeable);
|
||||
void mf_df_cat_key_settings(MifareDesfireKeySettings* ks, FuriString* out) {
|
||||
furi_string_cat_printf(out, "changeKeyID %d\n", ks->change_key_id);
|
||||
furi_string_cat_printf(out, "configChangeable %d\n", ks->config_changeable);
|
||||
furi_string_cat_printf(out, "freeCreateDelete %d\n", ks->free_create_delete);
|
||||
furi_string_cat_printf(out, "freeDirectoryList %d\n", ks->free_directory_list);
|
||||
furi_string_cat_printf(out, "masterChangeable %d\n", ks->master_key_changeable);
|
||||
if(ks->flags) {
|
||||
string_cat_printf(out, "flags %d\n", ks->flags);
|
||||
furi_string_cat_printf(out, "flags %d\n", ks->flags);
|
||||
}
|
||||
string_cat_printf(out, "maxKeys %d\n", ks->max_keys);
|
||||
furi_string_cat_printf(out, "maxKeys %d\n", ks->max_keys);
|
||||
for(MifareDesfireKeyVersion* kv = ks->key_version_head; kv; kv = kv->next) {
|
||||
string_cat_printf(out, "key %d version %d\n", kv->id, kv->version);
|
||||
furi_string_cat_printf(out, "key %d version %d\n", kv->id, kv->version);
|
||||
}
|
||||
}
|
||||
|
||||
void mf_df_cat_application_info(MifareDesfireApplication* app, string_t out) {
|
||||
string_cat_printf(out, "Application %02x%02x%02x\n", app->id[0], app->id[1], app->id[2]);
|
||||
void mf_df_cat_application_info(MifareDesfireApplication* app, FuriString* out) {
|
||||
furi_string_cat_printf(out, "Application %02x%02x%02x\n", app->id[0], app->id[1], app->id[2]);
|
||||
if(app->key_settings) {
|
||||
mf_df_cat_key_settings(app->key_settings, out);
|
||||
}
|
||||
}
|
||||
|
||||
void mf_df_cat_application(MifareDesfireApplication* app, string_t out) {
|
||||
void mf_df_cat_application(MifareDesfireApplication* app, FuriString* out) {
|
||||
mf_df_cat_application_info(app, out);
|
||||
for(MifareDesfireFile* file = app->file_head; file; file = file->next) {
|
||||
mf_df_cat_file(file, out);
|
||||
}
|
||||
}
|
||||
|
||||
void mf_df_cat_file(MifareDesfireFile* file, string_t out) {
|
||||
void mf_df_cat_file(MifareDesfireFile* file, FuriString* out) {
|
||||
char* type = "unknown";
|
||||
switch(file->type) {
|
||||
case MifareDesfireFileTypeStandard:
|
||||
@@ -171,9 +171,9 @@ void mf_df_cat_file(MifareDesfireFile* file, string_t out) {
|
||||
comm = "enciphered";
|
||||
break;
|
||||
}
|
||||
string_cat_printf(out, "File %d\n", file->id);
|
||||
string_cat_printf(out, "%s %s\n", type, comm);
|
||||
string_cat_printf(
|
||||
furi_string_cat_printf(out, "File %d\n", file->id);
|
||||
furi_string_cat_printf(out, "%s %s\n", type, comm);
|
||||
furi_string_cat_printf(
|
||||
out,
|
||||
"r %d w %d rw %d c %d\n",
|
||||
file->access_rights >> 12 & 0xF,
|
||||
@@ -186,13 +186,13 @@ void mf_df_cat_file(MifareDesfireFile* file, string_t out) {
|
||||
case MifareDesfireFileTypeStandard:
|
||||
case MifareDesfireFileTypeBackup:
|
||||
size = file->settings.data.size;
|
||||
string_cat_printf(out, "size %d\n", size);
|
||||
furi_string_cat_printf(out, "size %d\n", size);
|
||||
break;
|
||||
case MifareDesfireFileTypeValue:
|
||||
size = 4;
|
||||
string_cat_printf(
|
||||
furi_string_cat_printf(
|
||||
out, "lo %d hi %d\n", file->settings.value.lo_limit, file->settings.value.hi_limit);
|
||||
string_cat_printf(
|
||||
furi_string_cat_printf(
|
||||
out,
|
||||
"limit %d enabled %d\n",
|
||||
file->settings.value.limited_credit_value,
|
||||
@@ -202,33 +202,33 @@ void mf_df_cat_file(MifareDesfireFile* file, string_t out) {
|
||||
case MifareDesfireFileTypeCyclicRecord:
|
||||
size = file->settings.record.size;
|
||||
num = file->settings.record.cur;
|
||||
string_cat_printf(out, "size %d\n", size);
|
||||
string_cat_printf(out, "num %d max %d\n", num, file->settings.record.max);
|
||||
furi_string_cat_printf(out, "size %d\n", size);
|
||||
furi_string_cat_printf(out, "num %d max %d\n", num, file->settings.record.max);
|
||||
break;
|
||||
}
|
||||
uint8_t* data = file->contents;
|
||||
if(data) {
|
||||
for(int rec = 0; rec < num; rec++) {
|
||||
string_cat_printf(out, "record %d\n", rec);
|
||||
furi_string_cat_printf(out, "record %d\n", rec);
|
||||
for(int ch = 0; ch < size; ch += 4) {
|
||||
string_cat_printf(out, "%03x|", ch);
|
||||
furi_string_cat_printf(out, "%03x|", ch);
|
||||
for(int i = 0; i < 4; i++) {
|
||||
if(ch + i < size) {
|
||||
string_cat_printf(out, "%02x ", data[rec * size + ch + i]);
|
||||
furi_string_cat_printf(out, "%02x ", data[rec * size + ch + i]);
|
||||
} else {
|
||||
string_cat_printf(out, " ");
|
||||
furi_string_cat_printf(out, " ");
|
||||
}
|
||||
}
|
||||
for(int i = 0; i < 4 && ch + i < size; i++) {
|
||||
if(isprint(data[rec * size + ch + i])) {
|
||||
string_cat_printf(out, "%c", data[rec * size + ch + i]);
|
||||
furi_string_cat_printf(out, "%c", data[rec * size + ch + i]);
|
||||
} else {
|
||||
string_cat_printf(out, ".");
|
||||
furi_string_cat_printf(out, ".");
|
||||
}
|
||||
}
|
||||
string_cat_printf(out, "\n");
|
||||
furi_string_cat_printf(out, "\n");
|
||||
}
|
||||
string_cat_printf(out, " \n");
|
||||
furi_string_cat_printf(out, " \n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,6 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include <m-string.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
@@ -120,14 +119,14 @@ typedef struct {
|
||||
|
||||
void mf_df_clear(MifareDesfireData* data);
|
||||
|
||||
void mf_df_cat_data(MifareDesfireData* data, string_t out);
|
||||
void mf_df_cat_card_info(MifareDesfireData* data, string_t out);
|
||||
void mf_df_cat_version(MifareDesfireVersion* version, string_t out);
|
||||
void mf_df_cat_free_mem(MifareDesfireFreeMemory* free_mem, string_t out);
|
||||
void mf_df_cat_key_settings(MifareDesfireKeySettings* ks, string_t out);
|
||||
void mf_df_cat_application_info(MifareDesfireApplication* app, string_t out);
|
||||
void mf_df_cat_application(MifareDesfireApplication* app, string_t out);
|
||||
void mf_df_cat_file(MifareDesfireFile* file, string_t out);
|
||||
void mf_df_cat_data(MifareDesfireData* data, FuriString* out);
|
||||
void mf_df_cat_card_info(MifareDesfireData* data, FuriString* out);
|
||||
void mf_df_cat_version(MifareDesfireVersion* version, FuriString* out);
|
||||
void mf_df_cat_free_mem(MifareDesfireFreeMemory* free_mem, FuriString* out);
|
||||
void mf_df_cat_key_settings(MifareDesfireKeySettings* ks, FuriString* out);
|
||||
void mf_df_cat_application_info(MifareDesfireApplication* app, FuriString* out);
|
||||
void mf_df_cat_application(MifareDesfireApplication* app, FuriString* out);
|
||||
void mf_df_cat_file(MifareDesfireFile* file, FuriString* out);
|
||||
|
||||
bool mf_df_check_card_type(uint8_t ATQA0, uint8_t ATQA1, uint8_t SAK);
|
||||
|
||||
|
@@ -4,7 +4,6 @@
|
||||
#include "nfc_util.h"
|
||||
#include <furi.h>
|
||||
#include "furi_hal_nfc.h"
|
||||
#include <m-string.h>
|
||||
|
||||
#define TAG "MfUltralight"
|
||||
|
||||
@@ -1005,7 +1004,7 @@ static bool mf_ul_check_lock(MfUltralightEmulator* emulator, int16_t write_page)
|
||||
return (dynamic_lock_bytes & (1 << shift)) == 0;
|
||||
}
|
||||
|
||||
static void mf_ul_make_ascii_mirror(MfUltralightEmulator* emulator, string_t str) {
|
||||
static void mf_ul_make_ascii_mirror(MfUltralightEmulator* emulator, FuriString* str) {
|
||||
// Locals to improve readability
|
||||
uint8_t mirror_page = emulator->config->mirror_page;
|
||||
uint8_t mirror_byte = emulator->config->mirror.mirror_byte;
|
||||
@@ -1020,14 +1019,14 @@ static void mf_ul_make_ascii_mirror(MfUltralightEmulator* emulator, string_t str
|
||||
if(mirror_conf == MfUltralightMirrorUid) return;
|
||||
// NTAG21x has the peculiar behavior when UID+counter selected, if UID does not fit but
|
||||
// counter will fit, it will actually mirror the counter
|
||||
string_cat_str(str, " ");
|
||||
furi_string_cat(str, " ");
|
||||
} else {
|
||||
for(int i = 0; i < 3; ++i) {
|
||||
string_cat_printf(str, "%02X", emulator->data.data[i]);
|
||||
furi_string_cat_printf(str, "%02X", emulator->data.data[i]);
|
||||
}
|
||||
// Skip BCC0
|
||||
for(int i = 4; i < 8; ++i) {
|
||||
string_cat_printf(str, "%02X", emulator->data.data[i]);
|
||||
furi_string_cat_printf(str, "%02X", emulator->data.data[i]);
|
||||
}
|
||||
uid_printed = true;
|
||||
}
|
||||
@@ -1049,9 +1048,9 @@ static void mf_ul_make_ascii_mirror(MfUltralightEmulator* emulator, string_t str
|
||||
if(mirror_page == last_user_page_index - 1 && mirror_byte > 2) return;
|
||||
|
||||
if(mirror_conf == MfUltralightMirrorUidCounter)
|
||||
string_cat_str(str, uid_printed ? "x" : " ");
|
||||
furi_string_cat(str, uid_printed ? "x" : " ");
|
||||
|
||||
string_cat_printf(str, "%06X", emulator->data.counter[2]);
|
||||
furi_string_cat_printf(str, "%06X", emulator->data.counter[2]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1267,14 +1266,14 @@ bool mf_ul_prepare_emulation_response(
|
||||
bool reset_idle = false;
|
||||
|
||||
#ifdef FURI_DEBUG
|
||||
string_t debug_buf;
|
||||
string_init(debug_buf);
|
||||
FuriString* debug_buf;
|
||||
debug_buf = furi_string_alloc();
|
||||
for(int i = 0; i < (buff_rx_len + 7) / 8; ++i) {
|
||||
string_cat_printf(debug_buf, "%02x ", buff_rx[i]);
|
||||
furi_string_cat_printf(debug_buf, "%02x ", buff_rx[i]);
|
||||
}
|
||||
string_strim(debug_buf);
|
||||
FURI_LOG_T(TAG, "Emu RX (%d): %s", buff_rx_len, string_get_cstr(debug_buf));
|
||||
string_reset(debug_buf);
|
||||
furi_string_trim(debug_buf);
|
||||
FURI_LOG_T(TAG, "Emu RX (%d): %s", buff_rx_len, furi_string_get_cstr(debug_buf));
|
||||
furi_string_reset(debug_buf);
|
||||
#endif
|
||||
|
||||
// Check composite commands
|
||||
@@ -1328,7 +1327,7 @@ bool mf_ul_prepare_emulation_response(
|
||||
uint8_t src_page = start_page;
|
||||
uint8_t last_page_plus_one = start_page + 4;
|
||||
uint8_t pwd_page = emulator->page_num - 2;
|
||||
string_t ascii_mirror;
|
||||
FuriString* ascii_mirror = NULL;
|
||||
size_t ascii_mirror_len = 0;
|
||||
const char* ascii_mirror_cptr = NULL;
|
||||
uint8_t ascii_mirror_curr_page = 0;
|
||||
@@ -1353,10 +1352,10 @@ bool mf_ul_prepare_emulation_response(
|
||||
if(last_page_plus_one > ascii_mirror_curr_page &&
|
||||
start_page + 3 >= ascii_mirror_curr_page &&
|
||||
start_page <= ascii_mirror_curr_page + 6) {
|
||||
string_init(ascii_mirror);
|
||||
ascii_mirror = furi_string_alloc();
|
||||
mf_ul_make_ascii_mirror(emulator, ascii_mirror);
|
||||
ascii_mirror_len = string_length_u(ascii_mirror);
|
||||
ascii_mirror_cptr = string_get_cstr(ascii_mirror);
|
||||
ascii_mirror_len = furi_string_utf8_length(ascii_mirror);
|
||||
ascii_mirror_cptr = furi_string_get_cstr(ascii_mirror);
|
||||
// Move pointer to where it should be to start copying
|
||||
if(ascii_mirror_len > 0 &&
|
||||
ascii_mirror_curr_page < start_page &&
|
||||
@@ -1414,8 +1413,8 @@ bool mf_ul_prepare_emulation_response(
|
||||
++src_page;
|
||||
if(src_page >= last_page_plus_one) src_page = 0;
|
||||
}
|
||||
if(ascii_mirror_cptr != NULL) {
|
||||
string_clear(ascii_mirror);
|
||||
if(ascii_mirror != NULL) {
|
||||
furi_string_free(ascii_mirror);
|
||||
}
|
||||
*data_type = FURI_HAL_NFC_TXRX_DEFAULT;
|
||||
command_parsed = true;
|
||||
@@ -1512,12 +1511,13 @@ bool mf_ul_prepare_emulation_response(
|
||||
// Copy ASCII mirror
|
||||
// Less stringent check here, because expecting FAST_READ to
|
||||
// only be issued once rather than repeatedly
|
||||
string_t ascii_mirror;
|
||||
string_init(ascii_mirror);
|
||||
FuriString* ascii_mirror;
|
||||
ascii_mirror = furi_string_alloc();
|
||||
mf_ul_make_ascii_mirror(emulator, ascii_mirror);
|
||||
size_t ascii_mirror_len = string_length_u(ascii_mirror);
|
||||
size_t ascii_mirror_len =
|
||||
furi_string_utf8_length(ascii_mirror);
|
||||
const char* ascii_mirror_cptr =
|
||||
string_get_cstr(ascii_mirror);
|
||||
furi_string_get_cstr(ascii_mirror);
|
||||
int16_t mirror_start_offset =
|
||||
(emulator->config->mirror_page - start_page) * 4 +
|
||||
emulator->config->mirror.mirror_byte;
|
||||
@@ -1547,7 +1547,7 @@ bool mf_ul_prepare_emulation_response(
|
||||
++ascii_mirror_cptr;
|
||||
}
|
||||
}
|
||||
string_clear(ascii_mirror);
|
||||
furi_string_free(ascii_mirror);
|
||||
}
|
||||
|
||||
if(emulator->supported_features & MfUltralightSupportAuth) {
|
||||
@@ -1851,11 +1851,11 @@ bool mf_ul_prepare_emulation_response(
|
||||
} else if(*buff_tx_len > 0) {
|
||||
int count = (*buff_tx_len + 7) / 8;
|
||||
for(int i = 0; i < count; ++i) {
|
||||
string_cat_printf(debug_buf, "%02x ", buff_tx[i]);
|
||||
furi_string_cat_printf(debug_buf, "%02x ", buff_tx[i]);
|
||||
}
|
||||
string_strim(debug_buf);
|
||||
FURI_LOG_T(TAG, "Emu TX (%d): %s", *buff_tx_len, string_get_cstr(debug_buf));
|
||||
string_clear(debug_buf);
|
||||
furi_string_trim(debug_buf);
|
||||
FURI_LOG_T(TAG, "Emu TX (%d): %s", *buff_tx_len, furi_string_get_cstr(debug_buf));
|
||||
furi_string_free(debug_buf);
|
||||
} else {
|
||||
FURI_LOG_T(TAG, "Emu TX: HALT");
|
||||
}
|
||||
|
Reference in New Issue
Block a user