From 6e64c27ca70ab0644ed0c2e10db682adc2016752 Mon Sep 17 00:00:00 2001 From: CinderSocket Date: Fri, 27 Mar 2026 23:02:44 -0700 Subject: [PATCH] asn1: move metadata tables out of RAM --- hf_interface_fal/hf.c | 2 +- lib/asn1/INTEGER.h | 2 +- lib/asn1/OCTET_STRING.h | 2 +- lib/asn1/constr_CHOICE.c | 2 +- lib/asn1/constr_CHOICE.h | 2 +- lib/asn1/constr_SEQUENCE.c | 2 +- lib/asn1/constr_SEQUENCE.h | 2 +- lib/asn1/constr_TYPE.h | 14 +++++++------- lib/asn1/per_opentype.c | 4 ++-- lib/asn1/per_support.h | 4 ++-- lib/asn1_skeletons/INTEGER.h | 2 +- lib/asn1_skeletons/NativeReal.h | 2 +- lib/asn1_skeletons/OCTET_STRING.h | 2 +- lib/asn1_skeletons/constr_CHOICE.c | 2 +- lib/asn1_skeletons/constr_CHOICE.h | 2 +- lib/asn1_skeletons/constr_SEQUENCE.c | 2 +- lib/asn1_skeletons/constr_SEQUENCE.h | 2 +- lib/asn1_skeletons/constr_SET.h | 2 +- lib/asn1_skeletons/constr_SET_OF.h | 2 +- lib/asn1_skeletons/constr_TYPE.h | 14 +++++++------- lib/asn1_skeletons/per_opentype.c | 4 ++-- lib/asn1_skeletons/per_support.h | 4 ++-- sam_api.c | 9 ++++++--- scenes/seader_scene_start.c | 4 +--- seader_worker.c | 3 ++- trace_log.h | 20 ++++++++++---------- 26 files changed, 57 insertions(+), 55 deletions(-) diff --git a/hf_interface_fal/hf.c b/hf_interface_fal/hf.c index 247989a..cad0912 100644 --- a/hf_interface_fal/hf.c +++ b/hf_interface_fal/hf.c @@ -12,7 +12,7 @@ #include #include -#define TAG "PluginHF" +#define TAG "PluginHF" #define HF_DIAG_D(...) SEADER_VERBOSE_D(TAG, __VA_ARGS__) #define HF_DIAG_I(...) SEADER_VERBOSE_I(TAG, __VA_ARGS__) diff --git a/lib/asn1/INTEGER.h b/lib/asn1/INTEGER.h index d080b46..f03a858 100644 --- a/lib/asn1/INTEGER.h +++ b/lib/asn1/INTEGER.h @@ -25,7 +25,7 @@ typedef struct asn_INTEGER_enum_map_s { } asn_INTEGER_enum_map_t; /* This type describes an enumeration for INTEGER and ENUMERATED types */ -typedef struct asn_INTEGER_specifics_s { +typedef const struct asn_INTEGER_specifics_s { const asn_INTEGER_enum_map_t *value2enum; /* N -> "tag"; sorted by N */ const unsigned int *enum2value; /* "tag" => N; sorted by tag */ int map_count; /* Elements in either map */ diff --git a/lib/asn1/OCTET_STRING.h b/lib/asn1/OCTET_STRING.h index 458408e..f16c99f 100644 --- a/lib/asn1/OCTET_STRING.h +++ b/lib/asn1/OCTET_STRING.h @@ -73,7 +73,7 @@ OCTET_STRING_t *OCTET_STRING_new_fromBuf(const asn_TYPE_descriptor_t *td, * Internally useful stuff. * ****************************/ -typedef struct asn_OCTET_STRING_specifics_s { +typedef const struct asn_OCTET_STRING_specifics_s { /* * Target structure description. */ diff --git a/lib/asn1/constr_CHOICE.c b/lib/asn1/constr_CHOICE.c index 6e64b93..f5c34f1 100644 --- a/lib/asn1/constr_CHOICE.c +++ b/lib/asn1/constr_CHOICE.c @@ -190,7 +190,7 @@ CHOICE_decode_ber(const asn_codec_ctx_t *opt_codec_ctx, do { const asn_TYPE_tag2member_t *t2m; - asn_TYPE_tag2member_t key; + struct asn_TYPE_tag2member_s key; key.el_tag = tlv_tag; t2m = (const asn_TYPE_tag2member_t *)bsearch(&key, diff --git a/lib/asn1/constr_CHOICE.h b/lib/asn1/constr_CHOICE.h index 7649480..5e1fb7a 100644 --- a/lib/asn1/constr_CHOICE.h +++ b/lib/asn1/constr_CHOICE.h @@ -11,7 +11,7 @@ extern "C" { #endif -typedef struct asn_CHOICE_specifics_s { +typedef const struct asn_CHOICE_specifics_s { /* * Target structure description. */ diff --git a/lib/asn1/constr_SEQUENCE.c b/lib/asn1/constr_SEQUENCE.c index c750898..b1ad061 100644 --- a/lib/asn1/constr_SEQUENCE.c +++ b/lib/asn1/constr_SEQUENCE.c @@ -304,7 +304,7 @@ SEQUENCE_decode_ber(const asn_codec_ctx_t *opt_codec_ctx, * sorted array of tags. */ const asn_TYPE_tag2member_t *t2m; - asn_TYPE_tag2member_t key = {0, 0, 0, 0}; + struct asn_TYPE_tag2member_s key = {0, 0, 0, 0}; key.el_tag = tlv_tag; key.el_no = edx; t2m = (const asn_TYPE_tag2member_t *)bsearch(&key, diff --git a/lib/asn1/constr_SEQUENCE.h b/lib/asn1/constr_SEQUENCE.h index f9dd4e5..161d11f 100644 --- a/lib/asn1/constr_SEQUENCE.h +++ b/lib/asn1/constr_SEQUENCE.h @@ -11,7 +11,7 @@ extern "C" { #endif -typedef struct asn_SEQUENCE_specifics_s { +typedef const struct asn_SEQUENCE_specifics_s { /* * Target structure description. */ diff --git a/lib/asn1/constr_TYPE.h b/lib/asn1/constr_TYPE.h index 10bb0f3..6793b29 100644 --- a/lib/asn1/constr_TYPE.h +++ b/lib/asn1/constr_TYPE.h @@ -141,7 +141,7 @@ typedef asn_type_selector_result_t(asn_type_selector_f)( * Generalized functions for dealing with the speciic type. * May be directly invoked by applications. */ -typedef struct asn_TYPE_operation_s { +typedef const struct asn_TYPE_operation_s { asn_struct_free_f *free_struct; /* Free the structure */ asn_struct_print_f *print_struct; /* Human readable output */ asn_struct_compare_f *compare_struct; /* Compare two structures */ @@ -169,7 +169,7 @@ typedef struct asn_encoding_constraints_s { /* * The definitive description of the destination language's structure. */ -typedef struct asn_TYPE_descriptor_s { +typedef const struct asn_TYPE_descriptor_s { const char *name; /* A name of the ASN.1 type. "" in some cases. */ const char *xml_tag; /* Name used in XML tag */ @@ -177,7 +177,7 @@ typedef struct asn_TYPE_descriptor_s { * Generalized functions for dealing with the specific type. * May be directly invoked by applications. */ - asn_TYPE_operation_t *op; + const asn_TYPE_operation_t *op; /*********************************************************************** * Internally useful members. Not to be used by applications directly. * @@ -197,7 +197,7 @@ typedef struct asn_TYPE_descriptor_s { /* * An ASN.1 production type members (members of SEQUENCE, SET, CHOICE). */ - struct asn_TYPE_member_s *elements; + const struct asn_TYPE_member_s *elements; unsigned elements_count; /* @@ -217,13 +217,13 @@ typedef struct asn_TYPE_descriptor_s { ATF_OPEN_TYPE = 0x02, /* Open Type */ ATF_ANY_TYPE = 0x04 /* ANY type (deprecated!) */ }; -typedef struct asn_TYPE_member_s { +typedef const struct asn_TYPE_member_s { enum asn_TYPE_flags_e flags; /* Element's presentation flags */ unsigned optional; /* Following optional members, including current */ unsigned memb_offset; /* Offset of the element */ ber_tlv_tag_t tag; /* Outmost (most immediate) tag */ int tag_mode; /* IMPLICIT/no/EXPLICIT tag at current level */ - asn_TYPE_descriptor_t *type; /* Member type descriptor */ + const asn_TYPE_descriptor_t *type; /* Member type descriptor */ asn_type_selector_f *type_selector; /* IoS runtime type selector */ asn_encoding_constraints_t encoding_constraints; int (*default_value_cmp)(const void *sptr); /* Compare DEFAULT */ @@ -234,7 +234,7 @@ typedef struct asn_TYPE_member_s { /* * BER tag to element number mapping. */ -typedef struct asn_TYPE_tag2member_s { +typedef const struct asn_TYPE_tag2member_s { ber_tlv_tag_t el_tag; /* Outmost tag of the member */ unsigned el_no; /* Index of the associated member, base 0 */ int toff_first; /* First occurence of the el_tag, relative */ diff --git a/lib/asn1/per_opentype.c b/lib/asn1/per_opentype.c index f86dad7..99fe0fc 100644 --- a/lib/asn1/per_opentype.c +++ b/lib/asn1/per_opentype.c @@ -265,8 +265,8 @@ uper_open_type_get(const asn_codec_ctx_t *ctx, const asn_TYPE_descriptor_t *td, int uper_open_type_skip(const asn_codec_ctx_t *ctx, asn_per_data_t *pd) { - asn_TYPE_descriptor_t s_td; - asn_TYPE_operation_t s_op; + struct asn_TYPE_descriptor_s s_td = {0}; + struct asn_TYPE_operation_s s_op = {0}; asn_dec_rval_t rv; s_td.name = ""; diff --git a/lib/asn1/per_support.h b/lib/asn1/per_support.h index 3e905a8..a421919 100644 --- a/lib/asn1/per_support.h +++ b/lib/asn1/per_support.h @@ -15,7 +15,7 @@ extern "C" { /* * Pre-computed PER constraints. */ -typedef struct asn_per_constraint_s { +typedef const struct asn_per_constraint_s { enum asn_per_constraint_flags { APC_UNCONSTRAINED = 0x0, /* No PER visible constraints */ APC_SEMI_CONSTRAINED = 0x1, /* Constrained at "lb" */ @@ -27,7 +27,7 @@ typedef struct asn_per_constraint_s { long lower_bound; /* "lb" value */ long upper_bound; /* "ub" value */ } asn_per_constraint_t; -typedef struct asn_per_constraints_s { +typedef const struct asn_per_constraints_s { asn_per_constraint_t value; asn_per_constraint_t size; int (*value2code)(unsigned int value); diff --git a/lib/asn1_skeletons/INTEGER.h b/lib/asn1_skeletons/INTEGER.h index d080b46..f03a858 100644 --- a/lib/asn1_skeletons/INTEGER.h +++ b/lib/asn1_skeletons/INTEGER.h @@ -25,7 +25,7 @@ typedef struct asn_INTEGER_enum_map_s { } asn_INTEGER_enum_map_t; /* This type describes an enumeration for INTEGER and ENUMERATED types */ -typedef struct asn_INTEGER_specifics_s { +typedef const struct asn_INTEGER_specifics_s { const asn_INTEGER_enum_map_t *value2enum; /* N -> "tag"; sorted by N */ const unsigned int *enum2value; /* "tag" => N; sorted by tag */ int map_count; /* Elements in either map */ diff --git a/lib/asn1_skeletons/NativeReal.h b/lib/asn1_skeletons/NativeReal.h index b6d16d6..f279f1a 100644 --- a/lib/asn1_skeletons/NativeReal.h +++ b/lib/asn1_skeletons/NativeReal.h @@ -17,7 +17,7 @@ extern "C" { #endif -typedef struct asn_NativeReal_specifics_s { +typedef const struct asn_NativeReal_specifics_s { unsigned float_size; /* sizeof(float) or sizeof(double) */ } asn_NativeReal_specifics_t; diff --git a/lib/asn1_skeletons/OCTET_STRING.h b/lib/asn1_skeletons/OCTET_STRING.h index 458408e..f16c99f 100644 --- a/lib/asn1_skeletons/OCTET_STRING.h +++ b/lib/asn1_skeletons/OCTET_STRING.h @@ -73,7 +73,7 @@ OCTET_STRING_t *OCTET_STRING_new_fromBuf(const asn_TYPE_descriptor_t *td, * Internally useful stuff. * ****************************/ -typedef struct asn_OCTET_STRING_specifics_s { +typedef const struct asn_OCTET_STRING_specifics_s { /* * Target structure description. */ diff --git a/lib/asn1_skeletons/constr_CHOICE.c b/lib/asn1_skeletons/constr_CHOICE.c index 6e64b93..f5c34f1 100644 --- a/lib/asn1_skeletons/constr_CHOICE.c +++ b/lib/asn1_skeletons/constr_CHOICE.c @@ -190,7 +190,7 @@ CHOICE_decode_ber(const asn_codec_ctx_t *opt_codec_ctx, do { const asn_TYPE_tag2member_t *t2m; - asn_TYPE_tag2member_t key; + struct asn_TYPE_tag2member_s key; key.el_tag = tlv_tag; t2m = (const asn_TYPE_tag2member_t *)bsearch(&key, diff --git a/lib/asn1_skeletons/constr_CHOICE.h b/lib/asn1_skeletons/constr_CHOICE.h index 7649480..5e1fb7a 100644 --- a/lib/asn1_skeletons/constr_CHOICE.h +++ b/lib/asn1_skeletons/constr_CHOICE.h @@ -11,7 +11,7 @@ extern "C" { #endif -typedef struct asn_CHOICE_specifics_s { +typedef const struct asn_CHOICE_specifics_s { /* * Target structure description. */ diff --git a/lib/asn1_skeletons/constr_SEQUENCE.c b/lib/asn1_skeletons/constr_SEQUENCE.c index c750898..b1ad061 100644 --- a/lib/asn1_skeletons/constr_SEQUENCE.c +++ b/lib/asn1_skeletons/constr_SEQUENCE.c @@ -304,7 +304,7 @@ SEQUENCE_decode_ber(const asn_codec_ctx_t *opt_codec_ctx, * sorted array of tags. */ const asn_TYPE_tag2member_t *t2m; - asn_TYPE_tag2member_t key = {0, 0, 0, 0}; + struct asn_TYPE_tag2member_s key = {0, 0, 0, 0}; key.el_tag = tlv_tag; key.el_no = edx; t2m = (const asn_TYPE_tag2member_t *)bsearch(&key, diff --git a/lib/asn1_skeletons/constr_SEQUENCE.h b/lib/asn1_skeletons/constr_SEQUENCE.h index f9dd4e5..161d11f 100644 --- a/lib/asn1_skeletons/constr_SEQUENCE.h +++ b/lib/asn1_skeletons/constr_SEQUENCE.h @@ -11,7 +11,7 @@ extern "C" { #endif -typedef struct asn_SEQUENCE_specifics_s { +typedef const struct asn_SEQUENCE_specifics_s { /* * Target structure description. */ diff --git a/lib/asn1_skeletons/constr_SET.h b/lib/asn1_skeletons/constr_SET.h index d64a00f..ee663a1 100644 --- a/lib/asn1_skeletons/constr_SET.h +++ b/lib/asn1_skeletons/constr_SET.h @@ -12,7 +12,7 @@ extern "C" { #endif -typedef struct asn_SET_specifics_s { +typedef const struct asn_SET_specifics_s { /* * Target structure description. */ diff --git a/lib/asn1_skeletons/constr_SET_OF.h b/lib/asn1_skeletons/constr_SET_OF.h index f32e607..8992812 100644 --- a/lib/asn1_skeletons/constr_SET_OF.h +++ b/lib/asn1_skeletons/constr_SET_OF.h @@ -11,7 +11,7 @@ extern "C" { #endif -typedef struct asn_SET_OF_specifics_s { +typedef const struct asn_SET_OF_specifics_s { /* * Target structure description. */ diff --git a/lib/asn1_skeletons/constr_TYPE.h b/lib/asn1_skeletons/constr_TYPE.h index 10bb0f3..6793b29 100644 --- a/lib/asn1_skeletons/constr_TYPE.h +++ b/lib/asn1_skeletons/constr_TYPE.h @@ -141,7 +141,7 @@ typedef asn_type_selector_result_t(asn_type_selector_f)( * Generalized functions for dealing with the speciic type. * May be directly invoked by applications. */ -typedef struct asn_TYPE_operation_s { +typedef const struct asn_TYPE_operation_s { asn_struct_free_f *free_struct; /* Free the structure */ asn_struct_print_f *print_struct; /* Human readable output */ asn_struct_compare_f *compare_struct; /* Compare two structures */ @@ -169,7 +169,7 @@ typedef struct asn_encoding_constraints_s { /* * The definitive description of the destination language's structure. */ -typedef struct asn_TYPE_descriptor_s { +typedef const struct asn_TYPE_descriptor_s { const char *name; /* A name of the ASN.1 type. "" in some cases. */ const char *xml_tag; /* Name used in XML tag */ @@ -177,7 +177,7 @@ typedef struct asn_TYPE_descriptor_s { * Generalized functions for dealing with the specific type. * May be directly invoked by applications. */ - asn_TYPE_operation_t *op; + const asn_TYPE_operation_t *op; /*********************************************************************** * Internally useful members. Not to be used by applications directly. * @@ -197,7 +197,7 @@ typedef struct asn_TYPE_descriptor_s { /* * An ASN.1 production type members (members of SEQUENCE, SET, CHOICE). */ - struct asn_TYPE_member_s *elements; + const struct asn_TYPE_member_s *elements; unsigned elements_count; /* @@ -217,13 +217,13 @@ typedef struct asn_TYPE_descriptor_s { ATF_OPEN_TYPE = 0x02, /* Open Type */ ATF_ANY_TYPE = 0x04 /* ANY type (deprecated!) */ }; -typedef struct asn_TYPE_member_s { +typedef const struct asn_TYPE_member_s { enum asn_TYPE_flags_e flags; /* Element's presentation flags */ unsigned optional; /* Following optional members, including current */ unsigned memb_offset; /* Offset of the element */ ber_tlv_tag_t tag; /* Outmost (most immediate) tag */ int tag_mode; /* IMPLICIT/no/EXPLICIT tag at current level */ - asn_TYPE_descriptor_t *type; /* Member type descriptor */ + const asn_TYPE_descriptor_t *type; /* Member type descriptor */ asn_type_selector_f *type_selector; /* IoS runtime type selector */ asn_encoding_constraints_t encoding_constraints; int (*default_value_cmp)(const void *sptr); /* Compare DEFAULT */ @@ -234,7 +234,7 @@ typedef struct asn_TYPE_member_s { /* * BER tag to element number mapping. */ -typedef struct asn_TYPE_tag2member_s { +typedef const struct asn_TYPE_tag2member_s { ber_tlv_tag_t el_tag; /* Outmost tag of the member */ unsigned el_no; /* Index of the associated member, base 0 */ int toff_first; /* First occurence of the el_tag, relative */ diff --git a/lib/asn1_skeletons/per_opentype.c b/lib/asn1_skeletons/per_opentype.c index f86dad7..99fe0fc 100644 --- a/lib/asn1_skeletons/per_opentype.c +++ b/lib/asn1_skeletons/per_opentype.c @@ -265,8 +265,8 @@ uper_open_type_get(const asn_codec_ctx_t *ctx, const asn_TYPE_descriptor_t *td, int uper_open_type_skip(const asn_codec_ctx_t *ctx, asn_per_data_t *pd) { - asn_TYPE_descriptor_t s_td; - asn_TYPE_operation_t s_op; + struct asn_TYPE_descriptor_s s_td = {0}; + struct asn_TYPE_operation_s s_op = {0}; asn_dec_rval_t rv; s_td.name = ""; diff --git a/lib/asn1_skeletons/per_support.h b/lib/asn1_skeletons/per_support.h index 3e905a8..a421919 100644 --- a/lib/asn1_skeletons/per_support.h +++ b/lib/asn1_skeletons/per_support.h @@ -15,7 +15,7 @@ extern "C" { /* * Pre-computed PER constraints. */ -typedef struct asn_per_constraint_s { +typedef const struct asn_per_constraint_s { enum asn_per_constraint_flags { APC_UNCONSTRAINED = 0x0, /* No PER visible constraints */ APC_SEMI_CONSTRAINED = 0x1, /* Constrained at "lb" */ @@ -27,7 +27,7 @@ typedef struct asn_per_constraint_s { long lower_bound; /* "lb" value */ long upper_bound; /* "ub" value */ } asn_per_constraint_t; -typedef struct asn_per_constraints_s { +typedef const struct asn_per_constraints_s { asn_per_constraint_t value; asn_per_constraint_t size; int (*value2code)(unsigned int value); diff --git a/sam_api.c b/sam_api.c index 44fdc05..7a181f1 100644 --- a/sam_api.c +++ b/sam_api.c @@ -908,7 +908,8 @@ bool seader_parse_version(Seader* seader, uint8_t* buf, size_t size) { #endif if(version.version.size == 2) { memcpy(seader->sam_version, version.version.buf, version.version.size); - SEADER_VERBOSE_I(TAG, "SAM Version: %d.%d", seader->sam_version[0], seader->sam_version[1]); + SEADER_VERBOSE_I( + TAG, "SAM Version: %d.%d", seader->sam_version[0], seader->sam_version[1]); } rtn = true; @@ -1588,7 +1589,8 @@ void seader_mfc_transmit( void seader_parse_nfc_command_transmit(Seader* seader, NFCSend_t* nfcSend) { #ifdef ASN1_DEBUG - SEADER_VERBOSE_HEX(FuriLogLevelDebug, TAG, "Transmit data", nfcSend->data.buf, nfcSend->data.size); + SEADER_VERBOSE_HEX( + FuriLogLevelDebug, TAG, "Transmit data", nfcSend->data.buf, nfcSend->data.size); #endif PluginHfAction action = { @@ -1829,7 +1831,8 @@ NfcCommand seader_worker_card_detect( SeaderCredential* credential = seader->credential; CardDetails_t cardDetails = {0}; - SEADER_VERBOSE_D(TAG, "Build card_detect sak=%02x uid_len=%u ats_len=%u", sak, uid_len, ats_len); + SEADER_VERBOSE_D( + TAG, "Build card_detect sak=%02x uid_len=%u ats_len=%u", sak, uid_len, ats_len); /* The UID is reused as the current diversifier seed for formats that need one. This is not universal across all media, but it is the intentional behavior for the cards Seader diff --git a/scenes/seader_scene_start.c b/scenes/seader_scene_start.c index 75367d5..0d9e793 100644 --- a/scenes/seader_scene_start.c +++ b/scenes/seader_scene_start.c @@ -26,9 +26,7 @@ static void seader_scene_start_begin_detection(Seader* seader) { seader); } -static void seader_scene_start_finish_board_auto_recover( - Seader* seader, - bool preserve_read_type) { +static void seader_scene_start_finish_board_auto_recover(Seader* seader, bool preserve_read_type) { if(!seader) { return; } diff --git a/seader_worker.c b/seader_worker.c index 25c1807..aebfe44 100644 --- a/seader_worker.c +++ b/seader_worker.c @@ -557,7 +557,8 @@ void seader_worker_reading(Seader* seader) { seader->hf_read_failure_reason = SeaderHfReadFailureReasonNone; seader->hf_read_last_progress_tick = 0U; } - SEADER_VERBOSE_D(TAG, "HF loop selected type=%d stage=%d", type_to_read, seader_worker->stage); + SEADER_VERBOSE_D( + TAG, "HF loop selected type=%d stage=%d", type_to_read, seader_worker->stage); if(type_to_read == SeaderCredentialTypeNone) { SeaderCredentialType detected_types[SEADER_MAX_DETECTED_CARD_TYPES] = {0}; diff --git a/trace_log.h b/trace_log.h index ea1b7ad..861a30f 100644 --- a/trace_log.h +++ b/trace_log.h @@ -29,20 +29,20 @@ void seader_verbose_hex( seader_verbose_hex(level, tag, prefix, data, len) #else #define SEADER_VERBOSE_D(tag, format, ...) \ - do { \ - (void)(tag); \ + do { \ + (void)(tag); \ } while(0) #define SEADER_VERBOSE_I(tag, format, ...) \ - do { \ - (void)(tag); \ + do { \ + (void)(tag); \ } while(0) #define SEADER_VERBOSE_HEX(level, tag, prefix, data, len) \ - do { \ - (void)(level); \ - (void)(tag); \ - (void)(prefix); \ - (void)(data); \ - (void)(len); \ + do { \ + (void)(level); \ + (void)(tag); \ + (void)(prefix); \ + (void)(data); \ + (void)(len); \ } while(0) #endif