From d258e0827b39c5c7f128b8470432893369e5e822 Mon Sep 17 00:00:00 2001 From: Abaresk Date: Mon, 10 Jun 2024 03:33:38 +0000 Subject: [PATCH 1/4] Follow-up from jump table PR --- diff.py | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/diff.py b/diff.py index a38fa4d..870c64e 100755 --- a/diff.py +++ b/diff.py @@ -1895,7 +1895,7 @@ def _jump_table_entries_count(self, raw_lines: List[str], line_no: int) -> int: for i in reversed(range(line_no)): cmp_match = re.search(ARM32_COMPARE_IMM_PATTERN, raw_lines[i]) if cmp_match: - value = immediate_to_int(cmp_match.group(2)) + value = int(cmp_match.group(2).lstrip("#"), 0) if value > 0: return value + 1 return 0 @@ -2630,14 +2630,6 @@ class ArchSettings: M68K_SETTINGS, ] - -def immediate_to_int(immediate: str) -> int: - imm_match = re.match(r"#?(0x)?([0-9a-f]+)", immediate) - assert imm_match - base = 16 if imm_match.group(1) else 10 - return int(imm_match.group(2), base) - - def is_hexstring(value: str) -> bool: try: int(value, 16) From 1802c947966fa83e1567187226e6a531fb756fd6 Mon Sep 17 00:00:00 2001 From: Abaresk Date: Mon, 10 Jun 2024 03:51:09 +0000 Subject: [PATCH 2/4] Remove excess padding after a function --- diff.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/diff.py b/diff.py index 870c64e..71c9539 100755 --- a/diff.py +++ b/diff.py @@ -1831,6 +1831,10 @@ def short_table_entry( new_lines = [] lines = objdump.splitlines() for i, jump_table_entry in self._lines_iterator(lines): + # Normalize the assembly by removing any excess padding. + if i == len(lines) - 1 and re.search(r"\.short.*0000", lines[i]): + continue + if jump_table_entry is None: new_lines.append(lines[i]) continue From ef2fb96feb6167f9435793037f9f74e5f06e1c75 Mon Sep 17 00:00:00 2001 From: Abaresk Date: Mon, 10 Jun 2024 19:08:12 +0000 Subject: [PATCH 3/4] Normalize instructions without destination register --- diff.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/diff.py b/diff.py index 71c9539..aae4bf4 100755 --- a/diff.py +++ b/diff.py @@ -1795,6 +1795,21 @@ def is_end_of_function(self, mnemonic: str, args: str) -> bool: return mnemonic == "blr" +ARM32_DEST_OPTIONAL = { + "add", + "sub", + "rsb", + "sbc", + "and", + "orr", + "eor", + "bic", + "asr", + "lsl", + "lsr", + "ror", +} + # Example: "cmp r0, #0x10" ARM32_COMPARE_IMM_PATTERN = r"cmp\s+(r[0-9]|1[0-3]),\s+#(\w+)" @@ -1904,6 +1919,18 @@ def _jump_table_entries_count(self, raw_lines: List[str], line_no: int) -> int: return value + 1 return 0 + def pre_process( + self, mnemonic: str, args: str, next_row: Optional[str], comment: Optional[str] + ) -> Tuple[str, str]: + arg_parts = args.split() + # Normalize instructions that omit the destination register. + if len(arg_parts) == 2 and any( + [insn in mnemonic for insn in ARM32_DEST_OPTIONAL] + ): + arg_parts.insert(1, arg_parts[0]) + return mnemonic, " ".join(arg_parts) + return mnemonic, args + def process_reloc(self, row: str, prev: str) -> Tuple[str, Optional[str]]: arch = self.config.arch if "R_ARM_V4BX" in row: @@ -2634,6 +2661,7 @@ class ArchSettings: M68K_SETTINGS, ] + def is_hexstring(value: str) -> bool: try: int(value, 16) From 07d37b621397c8d8acb86eef08a917d5a69e2259 Mon Sep 17 00:00:00 2001 From: Abaresk Date: Fri, 21 Jun 2024 05:58:30 +0000 Subject: [PATCH 4/4] Address comments --- diff.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/diff.py b/diff.py index aae4bf4..b83b3dc 100755 --- a/diff.py +++ b/diff.py @@ -1924,9 +1924,7 @@ def pre_process( ) -> Tuple[str, str]: arg_parts = args.split() # Normalize instructions that omit the destination register. - if len(arg_parts) == 2 and any( - [insn in mnemonic for insn in ARM32_DEST_OPTIONAL] - ): + if len(arg_parts) == 2 and any(ins in mnemonic for ins in ARM32_DEST_OPTIONAL): arg_parts.insert(1, arg_parts[0]) return mnemonic, " ".join(arg_parts) return mnemonic, args