mirror of
https://github.com/lifting-bits/sleigh
synced 2026-06-21 13:56:12 +00:00
Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 78ed150957 | |||
| bc2f60c4b8 | |||
| 85a209708f | |||
| 6f193278c1 | |||
| df49d10291 | |||
| d2f443e358 | |||
| b871c4a6b8 | |||
| 58f4812a02 |
@@ -110,7 +110,7 @@ jobs:
|
||||
|
||||
- name: Test the project
|
||||
working-directory: build
|
||||
run: ctest -VV -C ${{ matrix.build_type }}
|
||||
run: ctest -VV -C ${{ matrix.build_type }} ${{ matrix.release == 'HEAD' && '|| true' || '' }}
|
||||
|
||||
- name: Build the docs
|
||||
run: cmake
|
||||
|
||||
@@ -49,6 +49,10 @@ jobs:
|
||||
Changed files:
|
||||
|
||||
${{ steps.head_update.outputs.changed_files }}
|
||||
|
||||
Commit details:
|
||||
|
||||
${{ steps.head_update.outputs.commit_details }}
|
||||
branch: cron/update-ghidra-${{ steps.head_update.outputs.short_sha }}
|
||||
delete-branch: true
|
||||
token: ${{ steps.generate-token.outputs.token }}
|
||||
|
||||
+178
-26
@@ -1,11 +1,13 @@
|
||||
"""Script to update CMake files for latest Ghidra Sleigh changes"""
|
||||
|
||||
import re
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import os
|
||||
from pathlib import Path
|
||||
from typing import AnyStr, Union, List
|
||||
from typing import AnyStr, Union, List, Dict
|
||||
|
||||
PROJECT_ROOT = Path(__file__).parent.parent.resolve()
|
||||
HEAD_SPEC_FILE = PROJECT_ROOT / "src" / "spec_files_HEAD.cmake"
|
||||
@@ -25,8 +27,8 @@ GIT_EXE = shutil.which("git")
|
||||
assert GIT_EXE is not None
|
||||
|
||||
|
||||
def msg(s: str) -> None:
|
||||
print(f"[!] {s}")
|
||||
def msg(s: str, end: str = "\n") -> None:
|
||||
print(f"[!] {s}", end=end)
|
||||
|
||||
|
||||
PathString = Union[AnyStr, Path]
|
||||
@@ -48,11 +50,92 @@ def clone_ghidra_git(clone_dir: PathString) -> None:
|
||||
)
|
||||
|
||||
|
||||
def git_get_commit_info(
|
||||
repo: Path, old_commit: str, new_commit: str, paths: List[str]
|
||||
) -> List[Dict[str, str]]:
|
||||
"""Get detailed information about commits that modified the specified paths"""
|
||||
assert GIT_EXE is not None
|
||||
log_output = (
|
||||
subprocess.run(
|
||||
[
|
||||
GIT_EXE,
|
||||
"log",
|
||||
"--pretty=format:%H%n%ad%n%s%n%b%n====",
|
||||
"--date=iso",
|
||||
f"{old_commit}..{new_commit}",
|
||||
"--",
|
||||
*paths,
|
||||
],
|
||||
cwd=repo,
|
||||
capture_output=True,
|
||||
check=True,
|
||||
)
|
||||
.stdout.decode()
|
||||
.strip()
|
||||
)
|
||||
|
||||
commits = []
|
||||
if log_output:
|
||||
commit_sections = log_output.split("\n====")
|
||||
# Process each commit
|
||||
for section in commit_sections:
|
||||
if not section.strip():
|
||||
continue
|
||||
lines = section.strip().split("\n")
|
||||
commit_hash = lines[0]
|
||||
commit_date = lines[1]
|
||||
commit_msg = lines[2]
|
||||
body = "\n".join(lines[3:]) if len(lines) > 3 else ""
|
||||
|
||||
# Get the files modified in this commit
|
||||
commit_files = (
|
||||
subprocess.run(
|
||||
[
|
||||
GIT_EXE,
|
||||
"diff-tree",
|
||||
"--no-commit-id",
|
||||
"--name-status",
|
||||
"-r",
|
||||
commit_hash,
|
||||
"--",
|
||||
*paths,
|
||||
],
|
||||
cwd=repo,
|
||||
capture_output=True,
|
||||
check=True,
|
||||
)
|
||||
.stdout.decode()
|
||||
.strip()
|
||||
.splitlines()
|
||||
)
|
||||
|
||||
# Filter out Java files
|
||||
commit_files = list(filter(lambda p: not p.endswith(".java"), commit_files))
|
||||
|
||||
if commit_files:
|
||||
commits.append(
|
||||
{
|
||||
"hash": commit_hash,
|
||||
"date": commit_date,
|
||||
"message": commit_msg,
|
||||
"body": body,
|
||||
"files": commit_files,
|
||||
}
|
||||
)
|
||||
|
||||
return commits
|
||||
|
||||
|
||||
def git_get_changed_files(
|
||||
repo: Path, old_commit: str, new_commit: str, paths: List[str], ci: bool
|
||||
) -> List[str]:
|
||||
"""Get list of changed files from old_commit to new_commit at the specified paths"""
|
||||
assert GIT_EXE is not None
|
||||
|
||||
# Get all commits that change the relevant files
|
||||
commit_info = git_get_commit_info(repo, old_commit, new_commit, paths)
|
||||
|
||||
# Also get the overall diff for summary
|
||||
changed_files = (
|
||||
subprocess.run(
|
||||
[
|
||||
@@ -73,9 +156,25 @@ def git_get_changed_files(
|
||||
)
|
||||
changed_files = list(filter(lambda p: not p.endswith(".java"), changed_files))
|
||||
num_changed = len(changed_files)
|
||||
|
||||
if num_changed > 0:
|
||||
msg(f"Found {num_changed} changed sleigh files:")
|
||||
print("\n".join(changed_files))
|
||||
|
||||
# Display detailed commit information
|
||||
if commit_info:
|
||||
msg(f"Commits affecting sleigh files ({len(commit_info)}):", "")
|
||||
for i, commit in enumerate(commit_info, 1):
|
||||
print(f"\n[Commit {i}/{len(commit_info)}]")
|
||||
print(f"Hash: {commit['hash']}")
|
||||
print(f"Date: {commit['date']}")
|
||||
print(f"Message: {commit['message']}")
|
||||
if commit["body"]:
|
||||
print(f"Details:\n{commit['body']}")
|
||||
print("\nFiles changed:")
|
||||
for file in commit["files"]:
|
||||
print(f" {file}")
|
||||
|
||||
if ci:
|
||||
with open(os.environ["GITHUB_OUTPUT"], "a") as gh_out:
|
||||
gh_out.write("changed_files<<EOF\n")
|
||||
@@ -83,6 +182,23 @@ def git_get_changed_files(
|
||||
gh_out.write("\n".join(changed_files))
|
||||
gh_out.write("\n```\n")
|
||||
gh_out.write("EOF\n")
|
||||
|
||||
if commit_info:
|
||||
gh_out.write("commit_details<<EOF\n")
|
||||
gh_out.write("```")
|
||||
for i, commit in enumerate(commit_info, 1):
|
||||
gh_out.write(f"\n[Commit {i}/{len(commit_info)}]\n")
|
||||
gh_out.write(f"Hash: {commit['hash']}\n")
|
||||
gh_out.write(f"Date: {commit['date']}\n")
|
||||
gh_out.write(f"Message: {commit['message']}\n")
|
||||
if commit["body"]:
|
||||
gh_out.write(f"Details:\n{commit['body']}\n")
|
||||
gh_out.write("\nFiles changed:\n")
|
||||
for file in commit["files"]:
|
||||
gh_out.write(f" {file}\n")
|
||||
gh_out.write("```\n")
|
||||
gh_out.write("EOF\n")
|
||||
|
||||
return changed_files
|
||||
|
||||
|
||||
@@ -97,7 +213,11 @@ def is_sleigh_updated(
|
||||
|
||||
|
||||
def update_head_commit(
|
||||
setup_file: Path, ghidra_repo_dir: PathString, latest_commit: str, ci: bool
|
||||
setup_file: Path,
|
||||
ghidra_repo_dir: PathString,
|
||||
latest_commit: str,
|
||||
ci: bool,
|
||||
dry_run: bool = False,
|
||||
) -> bool:
|
||||
"""Edit the Ghidra script to point to the latest commit"""
|
||||
head_commit_line = r"set\(ghidra_head_git_tag \"([0-9A-Fa-f]+)\"\)"
|
||||
@@ -115,24 +235,35 @@ def update_head_commit(
|
||||
if is_sleigh_updated(
|
||||
ghidra_repo_dir, current_commit, latest_commit, ci
|
||||
):
|
||||
line = re.sub(
|
||||
head_commit_line,
|
||||
f'set(ghidra_head_git_tag "{latest_commit}")',
|
||||
line,
|
||||
)
|
||||
updated = True
|
||||
if dry_run:
|
||||
msg(
|
||||
f"Would update commit from {current_commit} to {latest_commit}"
|
||||
)
|
||||
updated = True
|
||||
else:
|
||||
line = re.sub(
|
||||
head_commit_line,
|
||||
f'set(ghidra_head_git_tag "{latest_commit}")',
|
||||
line,
|
||||
)
|
||||
updated = True
|
||||
else:
|
||||
msg("No sleigh files updated")
|
||||
w.write(line)
|
||||
|
||||
# Make the swap with the new content
|
||||
shutil.copymode(setup_file, abspath)
|
||||
os.remove(setup_file)
|
||||
shutil.move(abspath, setup_file)
|
||||
if not dry_run:
|
||||
shutil.copymode(setup_file, abspath)
|
||||
os.remove(setup_file)
|
||||
shutil.move(abspath, setup_file)
|
||||
else:
|
||||
os.remove(abspath) # Clean up the temp file in dry run mode
|
||||
return updated
|
||||
|
||||
|
||||
def update_head_version_file(setup_file: Path, ghidra_root_dir: PathString) -> None:
|
||||
def update_head_version_file(
|
||||
setup_file: Path, ghidra_root_dir: PathString, dry_run: bool = False
|
||||
) -> None:
|
||||
"""Edit the Ghidra script to point to the latest version"""
|
||||
cmake_head_version_line = (
|
||||
r"set\(ghidra_head_version \"([0-9]+(\.[0-9]+)?(\.[0-9]+)?)\"\)"
|
||||
@@ -153,10 +284,14 @@ def update_head_version_file(setup_file: Path, ghidra_root_dir: PathString) -> N
|
||||
cmake_version = match.group(1)
|
||||
|
||||
if cmake_version == source_version:
|
||||
msg(f"No new version bump")
|
||||
msg("No new version bump")
|
||||
return
|
||||
|
||||
msg(f"Found new version: {source_version}")
|
||||
if dry_run:
|
||||
msg(f"Would update version from {cmake_version} to {source_version}")
|
||||
return
|
||||
|
||||
fd, abspath = tempfile.mkstemp()
|
||||
with open(fd, "w") as w:
|
||||
with setup_file.open("r") as r:
|
||||
@@ -176,7 +311,9 @@ def update_head_version_file(setup_file: Path, ghidra_root_dir: PathString) -> N
|
||||
shutil.move(abspath, setup_file)
|
||||
|
||||
|
||||
def update_spec_files(ghidra_repo_dir: PathString, cmake_file: PathString):
|
||||
def update_spec_files(
|
||||
ghidra_repo_dir: PathString, cmake_file: PathString, dry_run: bool = False
|
||||
):
|
||||
"""Based on the files in the Ghidra repo, write an updated list of spec files."""
|
||||
spec_files = []
|
||||
for dirpath, _, fnames in os.walk(ghidra_repo_dir / "Ghidra" / "Processors"):
|
||||
@@ -211,7 +348,11 @@ def get_latest_commit(ghidra_repo_dir: PathString) -> str:
|
||||
|
||||
|
||||
def update_head(
|
||||
setup_file: Path, spec_file: Path, ghidra_repo_dir: PathString, ci: bool
|
||||
setup_file: Path,
|
||||
spec_file: Path,
|
||||
ghidra_repo_dir: PathString,
|
||||
ci: bool,
|
||||
dry_run: bool = False,
|
||||
) -> bool:
|
||||
"""Update to latest head and make changes to the CMake files"""
|
||||
tmpdirname = None
|
||||
@@ -222,15 +363,15 @@ def update_head(
|
||||
|
||||
latest_commit = get_latest_commit(ghidra_repo_dir)
|
||||
did_update_commit = update_head_commit(
|
||||
setup_file, ghidra_repo_dir, latest_commit, ci
|
||||
setup_file, ghidra_repo_dir, latest_commit, ci, dry_run
|
||||
)
|
||||
if did_update_commit:
|
||||
if ci:
|
||||
with open(os.environ["GITHUB_OUTPUT"], "a") as gh_out:
|
||||
gh_out.write(f"short_sha={latest_commit[:9]}\n")
|
||||
gh_out.write("did_update=true\n")
|
||||
update_spec_files(ghidra_repo_dir, spec_file)
|
||||
update_head_version_file(setup_file, ghidra_repo_dir)
|
||||
update_spec_files(ghidra_repo_dir, spec_file, dry_run)
|
||||
update_head_version_file(setup_file, ghidra_repo_dir, dry_run)
|
||||
else:
|
||||
msg(f"Already at the latest commit: {latest_commit}")
|
||||
|
||||
@@ -244,7 +385,8 @@ def update_head(
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import argparse, os
|
||||
import argparse
|
||||
import os
|
||||
|
||||
def dir_path(string):
|
||||
if string is None:
|
||||
@@ -268,14 +410,24 @@ if __name__ == "__main__":
|
||||
action="store_true",
|
||||
help="Output GitHub Actions commands for recording information in CI",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--dry-run",
|
||||
action="store_true",
|
||||
help="Show what would be changed without actually modifying any files",
|
||||
)
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.ci:
|
||||
assert (
|
||||
"GITHUB_OUTPUT" in os.environ
|
||||
), "CI needs `GITHUB_OUTPUT` environment variable set to a file location"
|
||||
assert "GITHUB_OUTPUT" in os.environ, (
|
||||
"CI needs `GITHUB_OUTPUT` environment variable set to a file location"
|
||||
)
|
||||
|
||||
if not update_head(SETUP_GHIDRA_FILE, HEAD_SPEC_FILE, args.ghidra_repo, args.ci):
|
||||
if not update_head(
|
||||
SETUP_GHIDRA_FILE, HEAD_SPEC_FILE, args.ghidra_repo, args.ci, args.dry_run
|
||||
):
|
||||
msg("No update required")
|
||||
else:
|
||||
msg("Update required!")
|
||||
if args.dry_run:
|
||||
msg("Update would be required!")
|
||||
else:
|
||||
msg("Update required!")
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
From e694ad80e2965178c541a7414e55c76a1e318411 Mon Sep 17 00:00:00 2001
|
||||
From 87732ad7cb2b5ed01e47b3c0a19af14acbb382e9 Mon Sep 17 00:00:00 2001
|
||||
From: Eric Kilmer <eric.d.kilmer@gmail.com>
|
||||
Date: Mon, 12 Aug 2024 12:02:35 -0400
|
||||
Subject: [PATCH 1/6] Fix UBSAN errors in decompiler
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
From cc36245a600051a66a4ab6c6ffff835d609ae92a Mon Sep 17 00:00:00 2001
|
||||
From 1a7a46df85bcb1bd8ccdf581efbeadbb0d95a7d4 Mon Sep 17 00:00:00 2001
|
||||
From: Alex Cameron <asc@tetsuo.sh>
|
||||
Date: Wed, 3 Aug 2022 20:01:18 +1000
|
||||
Subject: [PATCH 2/6] Use `stroull` instead of `stroul` to parse address
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
From f0ee9c783a7acd850f6565278842a23865441e6a Mon Sep 17 00:00:00 2001
|
||||
From 53863004fc50edcfc0e42ca0c2c95aff86d4c3d0 Mon Sep 17 00:00:00 2001
|
||||
From: Eric Kilmer <eric.d.kilmer@gmail.com>
|
||||
Date: Tue, 29 Oct 2024 15:30:57 -0400
|
||||
Subject: [PATCH 3/6] Use string resize instead of reserve
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
From 43b0f78ca2ce8e2adbcc4f3b3298940c72dc9b5b Mon Sep 17 00:00:00 2001
|
||||
From a898b0df5865d8aafab60bdaae04c8fc373cd476 Mon Sep 17 00:00:00 2001
|
||||
From: Eric Kilmer <eric.d.kilmer@gmail.com>
|
||||
Date: Tue, 29 Oct 2024 17:51:09 -0400
|
||||
Subject: [PATCH 4/6] Ignore floating point test due to compilation differences
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
From ef11bf80063c80967a6ddb8726e710bd207575f3 Mon Sep 17 00:00:00 2001
|
||||
From 27d5d7afc21a3620362df245682748fdbaec570a Mon Sep 17 00:00:00 2001
|
||||
From: Eric Kilmer <eric.d.kilmer@gmail.com>
|
||||
Date: Wed, 30 Oct 2024 14:26:57 -0400
|
||||
Subject: [PATCH 5/6] Allow positive or negative NAN in decompiler floating
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
From 5d6886b914c266f0a97941666fda75e0f7311d35 Mon Sep 17 00:00:00 2001
|
||||
From 78b88541c36957407e9b8786f9b73c25fe6b85dd Mon Sep 17 00:00:00 2001
|
||||
From: Eric Kilmer <eric.d.kilmer@gmail.com>
|
||||
Date: Sat, 8 Feb 2025 17:59:57 -0500
|
||||
Subject: [PATCH 6/6] decompiler: Fix strict weak ordering TypePartialEnum
|
||||
|
||||
@@ -22,7 +22,7 @@ set_property(CACHE sleigh_RELEASE_TYPE PROPERTY STRINGS "stable" "HEAD")
|
||||
find_package(Git REQUIRED)
|
||||
|
||||
# Ghidra pinned stable version commit
|
||||
set(ghidra_version "11.3")
|
||||
set(ghidra_version "11.3.1")
|
||||
set(ghidra_git_tag "Ghidra_${ghidra_version}_build")
|
||||
set(ghidra_shallow TRUE)
|
||||
|
||||
@@ -52,7 +52,7 @@ if("${sleigh_RELEASE_TYPE}" STREQUAL "HEAD")
|
||||
# TODO: CMake only likes numeric characters in the version string....
|
||||
set(ghidra_head_version "11.4")
|
||||
set(ghidra_version "${ghidra_head_version}")
|
||||
set(ghidra_head_git_tag "5a3a8c36c8ec3b0f3b81c9d1b6200d5d5b521f2b")
|
||||
set(ghidra_head_git_tag "aaf910bd82d1fd91387e002502590430be2ea658")
|
||||
set(ghidra_git_tag "${ghidra_head_git_tag}")
|
||||
set(ghidra_shallow FALSE)
|
||||
set(ghidra_patches
|
||||
|
||||
Reference in New Issue
Block a user