From 52838003c8c60874b16d07caa5d25624111fa9ed Mon Sep 17 00:00:00 2001 From: Stefano Moioli Date: Fri, 5 Apr 2024 00:15:24 +0200 Subject: [PATCH] find_*_instruction_with_mem_operand --- xzre.h | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ xzre.lds | 9 +++++++++ 2 files changed, 59 insertions(+) diff --git a/xzre.h b/xzre.h index 5fdcacc..6ba661d 100644 --- a/xzre.h +++ b/xzre.h @@ -452,6 +452,56 @@ extern BOOL find_call_instruction(u8 *code_start, u8 *code_end, u8 *call_target, */ extern BOOL find_lea_instruction(u8 *code_start, u8 *code_end, u64 displacement); +/** + * @brief finds a LEA or MOV instruction with an immediate memory operand + * + * @param code_start address to start searching from + * @param code_end address to stop searching at + * @param dctx disassembler context to hold the state + * @param mem_address the expected address of the memory access + * @return BOOL TRUE if found, FALSE otherwise + */ +extern BOOL find_instruction_with_mem_operand( + u8 *code_start, + u8 *code_end, + dasm_ctx_t *dctx, + u8 *mem_address +); + +/** + * @brief finds a LEA instruction with an immediate memory operand + * + * @param code_start address to start searching from + * @param code_end address to stop searching at + * @param dctx disassembler context to hold the state + * @param mem_address the expected address of the memory access + * @return BOOL TRUE if found, FALSE otherwise + */ +extern BOOL find_lea_instruction_with_mem_operand( + u8 *code_start, + u8 *code_end, + dasm_ctx_t *dctx, + u8 *mem_address +); + +/** + * @brief finds an instruction with an immediate memory operand + * + * @param code_start address to start searching from + * @param code_end address to stop searching at + * @param dctx disassembler context to hold the state + * @param opcode opcode to look for, in encoded form (+0x80) + * @param mem_address the expected address of the memory access + * @return BOOL TRUE if found, FALSE otherwise + */ +extern BOOL find_instruction_with_mem_operand_ex( + u8 *code_start, + u8 *code_end, + dasm_ctx_t *dctx, + int opcode, + u8 *mem_address +); + /** * @brief finds a reg2reg instruction * diff --git a/xzre.lds b/xzre.lds index 20dc2cc..148bd30 100644 --- a/xzre.lds +++ b/xzre.lds @@ -9,6 +9,15 @@ SECTIONS { "find_lea_instruction" = "."; *(.text.lzma_raw_encodea); + "find_instruction_with_mem_operand" = "."; + *(.text.stream_encoder_mt_inia); + + "find_lea_instruction_with_mem_operand" = "."; + *(.text.lzma_mt_block_siza); + + "find_instruction_with_mem_operand_ex" = "."; + *(.text.lzma_properties_siza); + "find_function_prologue" = "."; *(.text.lzma_raw_coder_memusaga);