From 26fcb860d7c3ae3d05e83fe1c3f84ec71bc3e5cb Mon Sep 17 00:00:00 2001 From: kabiskac Date: Tue, 28 May 2024 18:59:51 +0200 Subject: [PATCH] Added compatibility for decomp-toolkit macros --- m2c/asm_file.py | 12 ++++++++++-- m2c/flow_graph.py | 4 ++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/m2c/asm_file.py b/m2c/asm_file.py index dea0eb81..9b3b093d 100644 --- a/m2c/asm_file.py +++ b/m2c/asm_file.py @@ -339,7 +339,9 @@ def re_comment_replacer(match: Match[str]) -> str: re_whitespace_or_string = re.compile(r'\s+|"(?:\\.|[^\\"])*"') re_local_glabel = re.compile("L(_.*_)?[0-9A-F]{8}") re_local_label = re.compile("loc_|locret_|def_|lbl_|LAB_|jump_") - re_label = re.compile(r'(?:([a-zA-Z0-9_.$]+)|"([a-zA-Z0-9_.$<>@,-]+)"):') + re_label = re.compile( + r'(?:(?:\.obj )?([a-zA-Z0-9_.$]+)|"([a-zA-Z0-9_.$<>@,-]+)")[:,]' + ) T = TypeVar("T") @@ -528,7 +530,13 @@ def process_label(label: str, *, kind: LabelKind) -> None: for w in args: fval = try_parse(lambda: float(w)) asm_file.new_data_bytes(struct.pack(">d", fval)) - elif directive in (".asci", ".asciz", ".ascii", ".asciiz"): + elif directive in ( + ".asci", + ".asciz", + ".ascii", + ".asciiz", + "string", + ): z = directive.endswith("z") asm_file.new_data_bytes( parse_ascii_directive(line, z), is_string=True diff --git a/m2c/flow_graph.py b/m2c/flow_graph.py index 66512e81..adac1f0e 100644 --- a/m2c/flow_graph.py +++ b/m2c/flow_graph.py @@ -862,7 +862,7 @@ def find_block_by_label(label: str) -> Optional[Block]: and isinstance(arg.argument, AsmGlobalSymbol) and any( arg.argument.symbol_name.startswith(prefix) - for prefix in ("jtbl", "jpt_", "lbl_") + for prefix in ("jtbl", "jpt_", "lbl_", "jumptable_") ) ): jtbl_names.add(arg.argument.symbol_name) @@ -879,7 +879,7 @@ def find_block_by_label(label: str) -> Optional[Block]: raise DecompFailure( f"Unable to determine jump table for {jump.mnemonic} instruction {jump.meta.loc_str()}.\n\n" "There must be a read of a variable before the instruction\n" - 'which has a name starting with with "jtbl"/"jpt_"/"lbl_".' + 'which has a name starting with with "jtbl"/"jpt_"/"lbl_"/"jumptable_".' ) jtbl_name = list(jtbl_names)[0]