code cleanup, gui fixes

This commit is contained in:
Methodius 2024-02-02 17:32:02 +09:00 committed by Nikita Vostokov
parent b1674711a1
commit ec356626fa
6 changed files with 45 additions and 64 deletions

View file

@ -63,11 +63,6 @@ void nfc_render_emv_pan(const uint8_t* data, const uint8_t len, FuriString* str)
furi_string_cat_printf(str, "\n");
}
void nfc_render_emv_expired(const EmvApplication* apl, FuriString* str) {
if(apl->exp_month == 0) return;
furi_string_cat_printf(str, "Exp: %02X/%02X\n", apl->exp_month, apl->exp_year);
}
void nfc_render_emv_currency(uint16_t cur_code, FuriString* str) {
if(!cur_code) return;
@ -88,37 +83,9 @@ void nfc_render_emv_application(const EmvApplication* apl, FuriString* str) {
return;
}
furi_string_cat_printf(str, "Application:\n");
if(strlen(apl->label)) {
furi_string_cat_printf(str, " Label: %s", apl->label);
furi_string_cat_printf(str, "\n");
}
if(strlen(apl->name)) {
furi_string_cat_printf(str, " Name: %s", apl->name);
furi_string_cat_printf(str, "\n");
}
furi_string_cat_printf(str, " AID:");
for(uint8_t i = 0; i < len; i++) furi_string_cat_printf(str, "%02X", apl->aid[i]);
furi_string_cat_printf(str, "\n");
if(apl->eff_month) {
furi_string_cat_printf(
str, " Effective: 20%02X/%02X/%02X", apl->eff_year, apl->eff_month, apl->eff_day);
furi_string_cat_printf(str, "\n");
}
if(apl->exp_month) {
furi_string_cat_printf(
str, " Expire: 20%02X/%02X/%02X", apl->exp_year, apl->exp_month, apl->exp_day);
furi_string_cat_printf(str, "\n");
}
}
static void nfc_render_emv_pin_try_counter(uint8_t counter, FuriString* str) {
if(counter == 0xff) return;
furi_string_cat_printf(str, "PIN attempts left: %d\n", counter);
}
void nfc_render_emv_transactions(const EmvApplication* apl, FuriString* str) {
@ -207,5 +174,4 @@ void nfc_render_emv_extra(const EmvData* data, FuriString* str) {
nfc_render_emv_currency(data->emv_application.currency_code, str);
nfc_render_emv_country(data->emv_application.country_code, str);
nfc_render_emv_pin_try_counter(data->emv_application.pin_try_counter, str);
}

View file

@ -17,8 +17,6 @@ void nfc_render_emv_application(const EmvApplication* data, FuriString* str);
void nfc_render_emv_extra(const EmvData* data, FuriString* str);
void nfc_render_emv_expired(const EmvApplication* apl, FuriString* str);
void nfc_render_emv_country(uint16_t country_code, FuriString* str);
void nfc_render_emv_currency(uint16_t cur_code, FuriString* str);

View file

@ -73,8 +73,8 @@ static bool emv_parse(const NfcDevice* device, FuriString* parsed_data) {
const EmvApplication app = data->emv_application;
do {
if(strlen(app.label))
furi_string_cat_printf(parsed_data, "\e#%s\n", app.label);
if(strlen(app.payment_sys))
furi_string_cat_printf(parsed_data, "\e#%s\n", app.payment_sys);
else
furi_string_cat_printf(parsed_data, "\e#%s\n", "EMV");
@ -87,12 +87,29 @@ static bool emv_parse(const NfcDevice* device, FuriString* parsed_data) {
// Cut padding 'F' from card number
size_t end = furi_string_search_rchar(pan, 'F');
if(end) furi_string_left(pan, end);
furi_string_cat_printf(pan, "\n");
furi_string_cat(parsed_data, pan);
furi_string_free(pan);
}
if(app.exp_month | app.exp_year)
furi_string_cat_printf(parsed_data, "\nExp: %02X/%02X\n", app.exp_month, app.exp_year);
if(strlen(app.name)) furi_string_cat_printf(parsed_data, "Name: %s\n", app.name);
if(app.issue_month)
furi_string_cat_printf(
parsed_data,
"Issue: %02X.%02X.20%02X\n",
app.issue_day,
app.issue_month,
app.issue_year);
if(app.exp_month)
furi_string_cat_printf(
parsed_data,
"Expires: %02X.%02X.20%02X\n",
app.exp_day,
app.exp_month,
app.exp_year);
FuriString* str = furi_string_alloc();
bool storage_readed = emv_get_country_name(app.country_code, str);

View file

@ -80,8 +80,8 @@ bool emv_load(EmvData* data, FlipperFormat* ff, uint32_t version) {
strcpy(app->name, furi_string_get_cstr(temp_str));
//Read label
if(!flipper_format_read_string(ff, "Label", temp_str)) break;
strcpy(app->label, furi_string_get_cstr(temp_str));
if(!flipper_format_read_string(ff, "Payment system", temp_str)) break;
strcpy(app->payment_sys, furi_string_get_cstr(temp_str));
uint32_t pan_len;
if(!flipper_format_read_uint32(ff, "PAN length", &pan_len, 1)) break;
@ -103,9 +103,9 @@ bool emv_load(EmvData* data, FlipperFormat* ff, uint32_t version) {
if(!flipper_format_read_hex(ff, "Expiration month", &app->exp_month, 1)) break;
if(!flipper_format_read_hex(ff, "Expiration day", &app->exp_day, 1)) break;
if(!flipper_format_read_hex(ff, "Effective year", &app->eff_year, 1)) break;
if(!flipper_format_read_hex(ff, "Effective month", &app->eff_month, 1)) break;
if(!flipper_format_read_hex(ff, "Effective day", &app->eff_day, 1)) break;
if(!flipper_format_read_hex(ff, "Issue year", &app->issue_year, 1)) break;
if(!flipper_format_read_hex(ff, "Issue month", &app->issue_month, 1)) break;
if(!flipper_format_read_hex(ff, "Issue day", &app->issue_day, 1)) break;
uint32_t pin_try_counter;
if(!flipper_format_read_uint32(ff, "PIN counter", &pin_try_counter, 1)) break;
@ -133,7 +133,7 @@ bool emv_save(const EmvData* data, FlipperFormat* ff) {
if(!flipper_format_write_string_cstr(ff, "Name", app.name)) break;
if(!flipper_format_write_string_cstr(ff, "Label", app.label)) break;
if(!flipper_format_write_string_cstr(ff, "Payment system", app.payment_sys)) break;
uint32_t pan_len = app.pan_len;
if(!flipper_format_write_uint32(ff, "PAN length", &pan_len, 1)) break;
@ -153,9 +153,9 @@ bool emv_save(const EmvData* data, FlipperFormat* ff) {
if(!flipper_format_write_hex(ff, "Expiration month", (uint8_t*)&app.exp_month, 1)) break;
if(!flipper_format_write_hex(ff, "Expiration day", (uint8_t*)&app.exp_day, 1)) break;
if(!flipper_format_write_hex(ff, "Effective year", (uint8_t*)&app.eff_year, 1)) break;
if(!flipper_format_write_hex(ff, "Effective month", (uint8_t*)&app.eff_month, 1)) break;
if(!flipper_format_write_hex(ff, "Effective day", (uint8_t*)&app.eff_day, 1)) break;
if(!flipper_format_write_hex(ff, "Issue year", (uint8_t*)&app.issue_year, 1)) break;
if(!flipper_format_write_hex(ff, "Issue month", (uint8_t*)&app.issue_month, 1)) break;
if(!flipper_format_write_hex(ff, "Issue day", (uint8_t*)&app.issue_day, 1)) break;
if(!flipper_format_write_uint32(ff, "PIN counter", (uint32_t*)&app.pin_try_counter, 1))
break;

View file

@ -13,9 +13,9 @@ extern "C" {
#define EMV_TAG_AID 0x4F
#define EMV_TAG_PRIORITY 0x87
#define EMV_TAG_PDOL 0x9F38
#define EMV_TAG_APPL_LABEL 0x50
#define EMV_TAG_APPL_PAYMENT_SYS 0x50
#define EMV_TAG_APPL_NAME 0x9F12
#define EMV_TAG_APPL_EFFECTIVE 0x5F25
#define EMV_TAG_APPL_ISSUE 0x5F25
#define EMV_TAG_PIN_TRY_COUNTER 0x9F17
#define EMV_TAG_LOG_ENTRY 0x9F4D
#define EMV_TAG_LOG_FMT 0x9F4F
@ -79,15 +79,15 @@ typedef struct {
uint8_t aid[16];
uint8_t aid_len;
char name[16 + 1];
char label[16 + 1];
char payment_sys[16 + 1];
uint8_t pan[10]; // card_number
uint8_t pan_len;
uint8_t exp_day;
uint8_t exp_month;
uint8_t exp_year;
uint8_t eff_day;
uint8_t eff_month;
uint8_t eff_year;
uint8_t issue_day;
uint8_t issue_month;
uint8_t issue_year;
uint16_t country_code;
uint16_t currency_code;
uint8_t pin_try_counter;

View file

@ -114,11 +114,11 @@ static bool
success = true;
FURI_LOG_T(TAG, "found EMV_TAG_APP_PRIORITY %X: %d", tag, app->priority);
break;
case EMV_TAG_APPL_LABEL:
memcpy(app->label, &buff[i], tlen);
app->label[tlen] = '\0';
case EMV_TAG_APPL_PAYMENT_SYS:
memcpy(app->payment_sys, &buff[i], tlen);
app->payment_sys[tlen] = '\0';
success = true;
FURI_LOG_T(TAG, "found EMV_TAG_APPL_LABEL %x: %s", tag, app->label);
FURI_LOG_T(TAG, "found EMV_TAG_APPL_PAYMENT_SYS %x: %s", tag, app->payment_sys);
break;
case EMV_TAG_APPL_NAME:
furi_check(tlen < sizeof(app->name));
@ -127,12 +127,12 @@ static bool
success = true;
FURI_LOG_T(TAG, "found EMV_TAG_APPL_NAME %x: %s", tag, app->name);
break;
case EMV_TAG_APPL_EFFECTIVE:
app->eff_year = buff[i];
app->eff_month = buff[i + 1];
app->eff_day = buff[i + 2];
case EMV_TAG_APPL_ISSUE:
app->issue_year = buff[i];
app->issue_month = buff[i + 1];
app->issue_day = buff[i + 2];
success = true;
FURI_LOG_T(TAG, "found EMV_TAG_APPL_EFFECTIVE %x:", tag);
FURI_LOG_T(TAG, "found EMV_TAG_APPL_ISSUE %x:", tag);
break;
case EMV_TAG_PDOL:
memcpy(app->pdol.data, &buff[i], tlen);