From abf2b474277015a2d15e2c6c982819e9f4a9617d Mon Sep 17 00:00:00 2001 From: nocato Date: Fri, 17 Nov 2023 19:23:44 +0100 Subject: [PATCH] Suggest to run uninitializer in cases it will help --- .gitignore | 1 + build/compare.py | 24 ++++++++++++++++++++++++ build/uninitializer.py | 13 +++++++------ 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index cf97406e7..fc65ee2c9 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ *.cpe *.obj *.exe +*.matching.bin *.pyc .ninja* build.ninja diff --git a/build/compare.py b/build/compare.py index ae908fe69..1fb57c371 100755 --- a/build/compare.py +++ b/build/compare.py @@ -7,6 +7,7 @@ import shutil import locale from colorama import init as colorama_init from termcolor import colored +from uninitializer import extract TARGET_HASH = '4b8252b65953a02021486406cfcdca1c7670d1d1a8f3cf6e750ef6e360dc3a2f' TARGET_VR_HASH = 'c370f8e41ec8fb78238bfe2ddbfc25a6d37ec8f0972c86ebfde075ecd4ee8dca' @@ -298,6 +299,14 @@ def cache_good_exe(): if not os.path.exists(CACHED_GOOD_EXE): shutil.copy(OBJ_EXE, CACHED_GOOD_EXE) +def cached_good_overlay_path(overlay): + return f"{overlay}.matching.bin" + +def cache_good_overlay(overlay, overlay_path): + cached_overlay = cached_good_overlay_path(overlay) + if not os.path.exists(cached_overlay): + shutil.copy(overlay_path, cached_overlay) + def green(msg): extra = ' 👌' if SUPPORTS_EMOJIS else '' print(colored(msg, 'green') + extra) @@ -370,8 +379,23 @@ def main(): if overlay_hash != overlay_target_hash: fail(overlay_path) failed = True + + # Is it only uninitialized memory? + good_overlay = cached_good_overlay_path(overlay) + if os.path.exists(good_overlay): + try: + extract(os.path.join(OVERLAY_EXE_PATH, f"{overlay}_lhs.bin"), + os.path.join(OVERLAY_EXE_PATH, f"{overlay}_rhs.bin"), + good_overlay, None) + print(colored("... but the only difference is uninitialized memory!", 'yellow')) + print(colored("... You can fix it by rerunning extraction with this command:", 'yellow')) + print(colored(f"{sys.executable} uninitializer.py extract ../obj/{overlay}_lhs.bin ../obj/{overlay}_rhs.bin {good_overlay} ../um/{overlay}.bin", 'yellow')) + except: + # Extraction failed + pass else: ok(overlay_path) + cache_good_overlay(overlay, overlay_path) if failed: sys.exit(1) diff --git a/build/uninitializer.py b/build/uninitializer.py index cc6dd3d56..688734427 100644 --- a/build/uninitializer.py +++ b/build/uninitializer.py @@ -138,13 +138,14 @@ def extract(lhs, rhs, target, uninitialized_out): while uninitialized_out_arr and uninitialized_out_arr[-1] == 0: uninitialized_out_arr.pop() - open(uninitialized_out, 'wb').write(bytes(uninitialized_out_arr)) + if uninitialized_out is not None: + open(uninitialized_out, 'wb').write(bytes(uninitialized_out_arr)) - print("Extracted", len(uninitialized_out_arr), "bytes of uninitialized memory") - print(f"({nonzero_uninitialized} non-zero bytes)") - print() - uninitialized_out_arr = [c for c in uninitialized_out_arr if c in bytes(string.printable, encoding='ascii')] - print(bytes(uninitialized_out_arr).decode('ascii')) + print("Extracted", len(uninitialized_out_arr), "bytes of uninitialized memory") + print(f"({nonzero_uninitialized} non-zero bytes)") + print() + uninitialized_out_arr = [c for c in uninitialized_out_arr if c in bytes(string.printable, encoding='ascii')] + print(bytes(uninitialized_out_arr).decode('ascii')) if __name__ == '__main__': if sys.argv[1] == 'inject':