Skip to content

Commit

Permalink
improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
ftheirs committed Jan 10, 2024
1 parent 0c768a3 commit d3b91bb
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 194 deletions.
170 changes: 0 additions & 170 deletions app/script_s2.ld

This file was deleted.

10 changes: 1 addition & 9 deletions app/src/apdu_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,18 +203,10 @@ __Z_INLINE void handleSign(volatile uint32_t *flags, volatile uint32_t *tx, uint
THROW(APDU_CODE_DATA_INVALID);
}

// Put address in output buffer, we will use it to confirm source address
zxerr_t zxerr = app_fill_address();
if (zxerr != zxerr_ok) {
*tx = 0;
THROW(APDU_CODE_DATA_INVALID);
}

parser_tx_obj.tx_json.own_addr = (const char *) (G_io_apdu_buffer + VIEW_ADDRESS_OFFSET_SECP256K1);
const char *error_msg = tx_parse(sign_type);

if (error_msg != NULL) {
int error_msg_length = strlen(error_msg);
const int error_msg_length = strnlen(error_msg, sizeof(G_io_apdu_buffer));
MEMCPY(G_io_apdu_buffer, error_msg, error_msg_length);
*tx += (error_msg_length);
THROW(APDU_CODE_DATA_INVALID);
Expand Down
4 changes: 2 additions & 2 deletions app/src/parser_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ typedef struct {
} parser_context_t;

typedef struct {
char str1[50];
char str2[50];
const char *str1;
const char *str2;
} key_subst_t;

typedef struct {
Expand Down
19 changes: 14 additions & 5 deletions app/src/tx_display.c
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ __Z_INLINE parser_error_t is_default_chainid(bool *is_default) {
if (is_default == NULL) {
return parser_unexpected_value;
}

CHECK_PARSER_ERR(tx_indexRootFields())
*is_default = display_cache.is_default_chain;

Expand Down Expand Up @@ -355,7 +355,7 @@ __Z_INLINE parser_error_t get_subitem_count(root_item_e root_item, uint8_t *num_

int32_t tmp_num_items = display_cache.root_item_number_subitems[root_item];
bool is_expert_or_default = false;

switch (root_item) {
case root_item_chain_id:
case root_item_sequence:
Expand Down Expand Up @@ -550,9 +550,18 @@ parser_error_t tx_display_make_friendly() {

// post process keys
for (size_t i = 0; i < array_length(key_substitutions); i++) {
if (!strncmp(parser_tx_obj.tx_json.query.out_key, key_substitutions[i].str1, strlen(key_substitutions[i].str1))) {
strncpy_s(parser_tx_obj.tx_json.query.out_key, key_substitutions[i].str2, parser_tx_obj.tx_json.query.out_key_len);
break;
const char* str1 = (const char*) PIC(key_substitutions[i].str1);
const char* str2 = (const char*) PIC(key_substitutions[i].str2);
const uint16_t str1Len = strlen(str1);
const uint16_t str2Len = strlen(str2);


const uint16_t outKeyLen = strnlen(parser_tx_obj.tx_json.query.out_key, parser_tx_obj.tx_json.query.out_key_len);
if ((outKeyLen == str1Len && strncmp(parser_tx_obj.tx_json.query.out_key, str1, str1Len) == 0)
&& parser_tx_obj.tx_json.query.out_key_len >= str2Len) {
MEMZERO(parser_tx_obj.tx_json.query.out_key, parser_tx_obj.tx_json.query.out_key_len);
MEMCPY(parser_tx_obj.tx_json.query.out_key, str2, str2Len);
break;
}
}

Expand Down
17 changes: 9 additions & 8 deletions app/src/tx_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,28 +84,29 @@ parser_error_t tx_getToken(uint16_t token_index,

const char *inValue = parser_tx_obj.tx_json.tx + token_start;
uint16_t inLen = token_end - token_start;

// empty strings are considered the first page
*pageCount = 1;
if (inLen > 0) {
for (uint32_t i = 0; i < array_length(value_substitutions); i++) {
const char *substStr = value_substitutions[i].str1;
const size_t substStrLen = strlen(substStr);
if (inLen == substStrLen && !MEMCMP(inValue, substStr, substStrLen)) {
inValue = value_substitutions[i].str2;
inLen = strlen(value_substitutions[i].str2);
const char* str1 = (const char*) PIC(value_substitutions[i].str1);
const char* str2 = (const char*) PIC(value_substitutions[i].str2);
const uint16_t str1Len = strlen(str1);
const uint16_t str2Len = strlen(str2);

if (inLen == str1Len && strncmp(inValue, str1, str1Len) == 0) {
inValue = str2;
inLen = str2Len;

//Extra Depth level for Multisend type
extraDepthLevel = false;
if (strstr(inValue, "Multi") != NULL) {
extraDepthLevel = true;
}

break;
}
}

pageStringExt(out_val, out_val_len, inValue, inLen, pageIdx, pageCount);

}

if (pageIdx >= *pageCount) {
Expand Down

0 comments on commit d3b91bb

Please sign in to comment.