From 77ce517b85449eb3009b028ca92793aa4657728e Mon Sep 17 00:00:00 2001 From: Cuyler36 Date: Tue, 2 Jan 2024 17:11:38 -0500 Subject: [PATCH] Fix diff.py, add support for objdiff --- .gitignore | 1 + configure.py | 26 ++++++++++++++++++++++++++ diff.py | 2 +- diff_settings.py | 2 +- 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 2caee755..fb77e13a 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,4 @@ tools/cli.ini tools/cli.py src/data/bin1 src/data/bin2 +objdiff.json diff --git a/configure.py b/configure.py index c4f3f8ea..3f9f6677 100644 --- a/configure.py +++ b/configure.py @@ -723,6 +723,30 @@ def make_asm_list(path: str, asm_includes: List[AsmInclude]): forcefiles = [] +def remove_prefix(text, prefix): + if text.startswith(prefix): + return text[len(prefix):] + return text + +def make_objdiff_json(sources: List[Source]): + data = { + 'min_version' : "0.4.3", + 'custom_make' : "ninja", + 'target_dir' : f"{c.EXPECTED}/build", + 'base_dir' : f"{c.BUILDDIR}", + 'build_target' : False, + 'objects' : [ + { + 'path' : remove_prefix(src.o_path, "$builddir/"), + 'name' : src.src_path, + } + for src in sources + if src.decompiled + ] + } + with open("objdiff.json", 'w') as f: + json.dump(data, f, indent=4) + dol_sources = load_sources(c.DOL_CTX) dol_gen_includes = find_gen_includes(dol_sources) make_asm_list(c.DOL_ASM_LIST, dol_gen_includes[AsmInclude]) @@ -731,6 +755,8 @@ rel_sources = load_sources(c.REL_CTX) rel_gen_includes = find_gen_includes(rel_sources) make_asm_list(c.REL_ASM_LIST, rel_gen_includes[AsmInclude]) +make_objdiff_json(dol_sources + rel_sources) + ########## # Builds # ########## diff --git a/diff.py b/diff.py index a8b26a01..5000d1d4 100644 --- a/diff.py +++ b/diff.py @@ -1118,7 +1118,7 @@ def search_map_file( find = re.findall( re.compile( # ram elf rom alignment - r" \S+ \S+ (\S+) (\S+) +\S+ " + r" \S+ (\S+) (\S+) +\S+ " + re.escape(fn_name) + r"(?: \(entry of " + re.escape(config.diff_section) diff --git a/diff_settings.py b/diff_settings.py index ca0cdd6d..9078478d 100644 --- a/diff_settings.py +++ b/diff_settings.py @@ -21,4 +21,4 @@ def apply(config, args: Namespace): config["show_line_numbers_default"] = True def add_custom_arguments(parser: ArgumentParser): - parser.add_argument("-r", "--rel", action="store_true", help="(SPM) Diff a function in relF.rel") \ No newline at end of file + parser.add_argument("-r", "--rel", action="store_true", help="(AC) Diff a function in foresta.rel") \ No newline at end of file