Skip to content

Compare reimplementation #1074

Compare reimplementation

Compare reimplementation #1074

Workflow file for this run

name: Compare reimplementation
on:
workflow_run:
workflows: [Build binary]
types: [completed]
workflow_dispatch:
inputs:
workflow_id:
required: true
type: number
jobs:
compare:
runs-on: windows-latest
permissions:
statuses: write
steps:
- name: Report tests check
if: ${{ github.event_name == 'workflow_run' }}
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
github.rest.repos.createCommitStatus({
owner: context.repo.owner,
repo: context.repo.repo,
sha: context.payload.workflow_run.head_sha,
state: 'pending',
target_url: `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`,
description: 'Comparison checks',
context: 'comparison-checks',
})
- uses: actions/checkout@v3
- uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: '21'
- name: Install prefix
run: python scripts/create_devenv.py --only objdiff --only ghidra scripts/dls scripts/prefix
- name: Fetch game binary from cache.
uses: actions/cache@v4
id: cache
with:
path: resources/game.exe
key: 9f76483c46256804792399296619c1274363c31cd8f1775fafb55106fb852245
- name: Download original game binary for comparison
if: steps.cache.outputs.cache-hit != 'true'
run: |
curl -L $env:ORIGINAL_URL -o resources/game.exe
$hash = (Get-FileHash resources/game.exe).Hash
if ($hash -ne "9f76483c46256804792399296619c1274363c31cd8f1775fafb55106fb852245") {
Write-Host "Downloaded file with unexpected hash."
Write-Host "Expected: 9f76483c46256804792399296619c1274363c31cd8f1775fafb55106fb852245"
Write-Host "Got: $hash"
exit 1
}
env:
ORIGINAL_URL: ${{ secrets.ORIGINAL_URL }}
- name: Download reimplemented game binary for comparison (1/2)
uses: actions/github-script@v6
with:
script: |
let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: context.payload.workflow_run ? context.payload.workflow_run.id : context.payload.inputs.workflow_id,
});
let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => {
return artifact.name == "th06e-diff"
})[0];
let download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});
let fs = require('fs');
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/th06e.zip`, Buffer.from(download.data));
- name: Download reimplemented game binary for comparison (2/2)
run: |
mkdir -p build/objdiff/reimpl
unzip th06e.zip -d build/objdiff/reimpl
- name: Get information on workflow ID
uses: actions/github-script@v6
id: workflow_run_info
with:
script: |
// get info from workflow_id
let workflowRunInfo = await github.rest.actions.getWorkflowRun({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: context.payload.workflow_run ? context.payload.workflow_run.id : context.payload.inputs.workflow_id,
})
core.setOutput("head_repository_full_name", workflowRunInfo.data.head_repository.full_name)
core.setOutput("head_sha", workflowRunInfo.data.head_sha)
console.log(workflowRunInfo.data.head_repository.full_name, workflowRunInfo.data.head_sha)
- name: Use implemented.csv from target repo
run: curl -L https://raw.githubusercontent.com/${{steps.workflow_run_info.outputs.head_repository_full_name}}/${{steps.workflow_run_info.outputs.head_sha}}/config/implemented.csv -o config/implemented.csv --fail
- name: Use ghidra_ns_to_obj.csv from target repo
run: curl -L https://raw.githubusercontent.com/${{steps.workflow_run_info.outputs.head_repository_full_name}}/${{steps.workflow_run_info.outputs.head_sha}}/config/ghidra_ns_to_obj.csv -o config/ghidra_ns_to_obj.csv --fail
- name: Use objdiff.json from target repo
run: curl -L https://raw.githubusercontent.com/${{steps.workflow_run_info.outputs.head_repository_full_name}}/${{steps.workflow_run_info.outputs.head_sha}}/objdiff.json -o objdiff.json --fail
- name: Use mapping.csv from target repo
run: curl -L https://raw.githubusercontent.com/${{steps.workflow_run_info.outputs.head_repository_full_name}}/${{steps.workflow_run_info.outputs.head_sha}}/config/mapping.csv -o config/mapping.csv --fail
- name: Generate objs using ghidra-delinker
run: python scripts/export_ghidra_objs.py --import-csv
- name: Create diff summary
run: python scripts/diff_all_functions.py --diff-method=objdiff > $env:GITHUB_STEP_SUMMARY
- name: Report tests check
if: ${{ github.event_name == 'workflow_run' && success() }}
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
github.rest.repos.createCommitStatus({
owner: context.repo.owner,
repo: context.repo.repo,
sha: context.payload.workflow_run.head_sha,
state: 'success',
target_url: `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`,
description: 'Comparison checks',
context: 'comparison-checks',
})
- name: Report tests check
if: ${{ github.event_name == 'workflow_run' && failure() }}
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
github.rest.repos.createCommitStatus({
owner: context.repo.owner,
repo: context.repo.repo,
sha: context.payload.workflow_run.head_sha,
state: 'failure',
target_url: `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`,
description: 'Comparison checks',
context: 'comparison-checks',
})