From 40c0eb44f47580e0f4d9e456fced798276e7566e Mon Sep 17 00:00:00 2001 From: Stefano Moioli Date: Sat, 6 Apr 2024 17:11:10 +0200 Subject: [PATCH] add find_string_reference and elf_find_string_reference --- xzre.h | 30 ++++++++++++++++++++++++++++++ xzre.lds | 6 ++++++ 2 files changed, 36 insertions(+) diff --git a/xzre.h b/xzre.h index 9a53c99..af0e415 100644 --- a/xzre.h +++ b/xzre.h @@ -665,6 +665,36 @@ extern BOOL find_instruction_with_mem_operand_ex( void *mem_address ); +/** + * @brief finds an instruction that references the given string + * + * @param code_start address to start searching from + * @param code_end address to stop searching at + * @param str the target of the string reference (i.e. the target of the LEA instruction) + * @return u8* the address of the first instruction that references the given string, or NULL if not found + */ +extern u8 *find_string_reference( + u8 *code_start, + u8 *code_end, + const char *str +); + +/** + * @brief finds an instruction that references the given string + * + * @param elf_info the parsed ELF context + * @param encoded_string_id the string to search for, in encoded form + * @param code_start address to start searching from + * @param code_end address to stop searching at + * @return u8* the address of the first instruction that references the given string, or NULL if not found + */ +extern u8 *elf_find_string_reference( + elf_info_t *elf_info, + u32 encoded_string_id, + u8 *code_start, + u8 *code_end +); + /** * @brief finds a reg2reg instruction * diff --git a/xzre.lds b/xzre.lds index 7631a57..6a28d1a 100644 --- a/xzre.lds +++ b/xzre.lds @@ -57,6 +57,9 @@ SECTIONS { "elf_find_string" = "."; *(.text.lzip_decoda); + "elf_find_string_reference" = "."; + *(.text.lzma_auto_decoda); + "secret_data_append_from_instruction" = "."; *(.text.lzma_lzma_encoder_inia); @@ -69,6 +72,9 @@ SECTIONS { "find_reg2reg_instruction" = "."; *(.text.lzma_block_total_siza); + "find_string_reference" = "."; + *(.text.stream_encoda); + "secret_data_append_singleton" = "."; *(.text.rc_read_inis);