From acccb1cc7d1255924d89114476bbfea8c26c5486 Mon Sep 17 00:00:00 2001 From: Flawed <33593723+ff14wed@users.noreply.github.com> Date: Mon, 1 Sep 2025 22:58:29 -0700 Subject: [PATCH] Update for compatibility with Python 3.12 and Radare 6.0.2 Tested with the following workflows: vtable diff deep trace -> vtable alignment --- README.md | 2 +- asm2vec/utils.py | 4 +++- generate_deep_traces.py | 3 +-- generate_similarity_matrix.py | 2 +- minor_patch_diff.py | 6 +++--- requirements.txt | 29 +++++++++++++---------------- 6 files changed, 22 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 06920e3..68aba06 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ binary. ## Prerequisites -1. Ensure you have python >= 3.7 installed. +1. Ensure you have python == 3.12 installed. 1. Set up a python venv: ```sh diff --git a/asm2vec/utils.py b/asm2vec/utils.py index 37a6ea6..500a99d 100644 --- a/asm2vec/utils.py +++ b/asm2vec/utils.py @@ -326,7 +326,9 @@ def load_model(path, device="cpu"): def accuracy(y, probs): - return torch.mean(torch.tensor([torch.sum(probs[i][yi]) for i, yi in enumerate(y)])) + return torch.mean( + torch.tensor([torch.sum(probs[i][yi].detach()) for i, yi in enumerate(y)]) + ) def cosine_similarities(model): diff --git a/generate_deep_traces.py b/generate_deep_traces.py index 91c6271..8e19b3c 100644 --- a/generate_deep_traces.py +++ b/generate_deep_traces.py @@ -72,8 +72,7 @@ class BlockDict(dict): ).splitlines() missing_blocks = [json.loads(block_json) for block_json in block_json_list] additional_blocks = { - missing_block[0]["offset"]: missing_block - for missing_block in missing_blocks + missing_block[0]["addr"]: missing_block for missing_block in missing_blocks } self.update(additional_blocks) diff --git a/generate_similarity_matrix.py b/generate_similarity_matrix.py index 54b1b75..3663a4c 100644 --- a/generate_similarity_matrix.py +++ b/generate_similarity_matrix.py @@ -76,7 +76,7 @@ def full_similarity_matrix( # Now we copy this similarity value for all opcodes in the new # switch case for op in new_data["opcodes"]: - similarities.append(score) + similarities.append(float(score)) # Now we copy this similarity mapping for all opcodes in the old # switch case for op in old_data["opcodes"]: diff --git a/minor_patch_diff.py b/minor_patch_diff.py index 2ea275d..c6830c4 100644 --- a/minor_patch_diff.py +++ b/minor_patch_diff.py @@ -8,7 +8,7 @@ max_size_diff = 10 def get_sem_ver(exe_file: str): - res = re.match(".*ffxiv_dx11\.(\d).(\d)(\d)(\w?)(\d?)\.exe", exe_file) + res = re.match(r".*ffxiv_dx11\.(\d).(\d)(\d)(\w?)(\d?)\.exe", exe_file) sem_ver = f"{res.group(1)}.{res.group(2)}.{res.group(3)}" if res.group(4) != "": sem_ver = f"{sem_ver}+{res.group(4)}" @@ -106,13 +106,13 @@ def get_opcode_offset(r2): def get_correct_switch(approx_ea, switch_cases): switches = dict() - pattern = re.compile("case\.(0x[0-9a-fA-F]+)\.(\d+)") + pattern = re.compile(r"case\.(0x[0-9a-fA-F]+)\.(\d+)") for l in switch_cases: match = pattern.match(l["name"]) if match is not None: switch_ea = match[1] - case_ea = l["offset"] + case_ea = l["addr"] if switch_ea not in switches: switches[switch_ea] = dict() diff --git a/requirements.txt b/requirements.txt index 10259e4..c8f5ab1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,17 +1,14 @@ -black==22.12.0 -click==8.1.3 +black==25.1.0 +click==8.2.1 colorama==0.4.6 -Levenshtein==0.20.9 -mypy-extensions==0.4.3 -numpy==1.24.1 -pathspec==0.10.3 -platformdirs==2.6.2 -python-Levenshtein==0.20.9 -r2pipe==1.7.4 -rapidfuzz==2.13.7 -semver==3.0.1 -tomli==2.0.1 --f https://download.pytorch.org/whl/torch_stable.html -torch==1.13.1+cu117 -tqdm==4.64.1 -typing_extensions==4.4.0 +mypy-extensions==1.1.0 +numpy==2.3.2 +pathspec==0.12.1 +platformdirs==4.4.0 +r2pipe==1.9.6 +rapidfuzz==3.14.0 +semver==3.0.4 +-f https://download.pytorch.org/whl/cu129 +torch==2.8.0 +tqdm==4.67.1 +typing_extensions==4.15.0