Align AVA2 Windows behavior and improve mobile touch interactions
This commit is contained in:
@@ -36,7 +36,10 @@ for project in (root/'upstream/ava2-client').rglob('*.vcxproj'):
|
||||
reference_paths=[p for p in sorted(compiled) if p.is_file() and
|
||||
re.search(r'\bPy_InitModule\s*\(',p.read_text(errors='replace'))]
|
||||
windows=modules(reference_paths,True)
|
||||
port=modules(sorted((root/'src').glob('python_*.cpp')))
|
||||
port_paths=sorted((root/'src/scripting').glob('python_*.cpp'))
|
||||
if not port_paths:
|
||||
raise SystemExit('No port translation units found; check the source layout before auditing')
|
||||
port=modules(port_paths)
|
||||
rows=[]
|
||||
for name,reference in sorted(windows.items()):
|
||||
target=port.get(name,{'methods':{}});original=set(reference['methods']);current=set(target['methods'])
|
||||
|
||||
@@ -4,12 +4,23 @@ import json,re
|
||||
from pathlib import Path
|
||||
root=Path(__file__).resolve().parents[1]
|
||||
rows=[]
|
||||
for path in sorted((root/'src').glob('python_*.cpp')):
|
||||
candidates=[]
|
||||
paths=sorted((root/'src/scripting').glob('python_*.cpp'))
|
||||
if not paths:
|
||||
raise SystemExit('No scripting sources found; refusing an empty parity inventory')
|
||||
for path in paths:
|
||||
source=path.read_text()
|
||||
constant_handlers={m[1]:m.start() for m in re.finditer(
|
||||
r'PyObject\s*\*\s*(\w+)\s*\([^;{}]*\)\s*\{\s*return\s+(?:Py_BuildNone\(\)|Py_BuildValue\("[ib]",\s*[01]\)|PyInt_FromLong\([01]\))\s*;\s*\}',source)}
|
||||
for name,handler in re.findall(r'\{\s*"([^"]+)"\s*,\s*(\w+)\s*,\s*METH_',source):
|
||||
if 'dummy' in handler:
|
||||
rows.append({'file':str(path.relative_to(root)),'api':name,'handler':handler,'status':'placeholder'})
|
||||
report={'scope':'Static Python method-table inventory; excludes hidden no-ops, renderer and packet behavior. Full parity is NOT established.','placeholder_count':len(rows),'placeholders':rows}
|
||||
if handler in constant_handlers:
|
||||
candidates.append({'file':str(path.relative_to(root)),'line':source.count('\n',0,constant_handlers[handler])+1,
|
||||
'api':name,'handler':handler,'status':'constant-return candidate; compare original behavior before treating as a defect'})
|
||||
report={'scope':'Static Python method-table inventory in src/scripting. Constant returns are review candidates, not proven defects. Packet/renderer behavior still requires source comparison. Full parity is NOT established.',
|
||||
'source_count':len(paths),'placeholder_count':len(rows),'placeholders':rows,
|
||||
'constant_return_candidate_count':len(candidates),'constant_return_candidates':candidates}
|
||||
output=root/'docs/WINDOWS-PARITY-INVENTORY.json'
|
||||
output.write_text(json.dumps(report,indent=2)+'\n')
|
||||
print(f'{len(rows)} placeholder bindings; report: {output}')
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
// Export analysis pseudocode and a function/call index from SpeedTreeRT.
|
||||
// Run as a Ghidra headless postScript, passing an output directory.
|
||||
// @category AVA2
|
||||
|
||||
import ghidra.app.script.GhidraScript;
|
||||
import ghidra.app.decompiler.DecompInterface;
|
||||
import ghidra.app.decompiler.DecompileResults;
|
||||
import ghidra.program.model.listing.Function;
|
||||
import ghidra.program.model.listing.FunctionIterator;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.io.BufferedWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
|
||||
public class ExportSpeedTree extends GhidraScript {
|
||||
private static String cell(String s) {
|
||||
return s.replace('\t', ' ').replace('\n', ' ').replace('\r', ' ');
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() throws Exception {
|
||||
String[] args = getScriptArgs();
|
||||
if (args.length != 1) throw new IllegalArgumentException("Expected output directory");
|
||||
Path out = Path.of(args[0]);
|
||||
Files.createDirectories(out.resolve("functions"));
|
||||
DecompInterface dec = new DecompInterface();
|
||||
dec.toggleCCode(true);
|
||||
dec.toggleSyntaxTree(true);
|
||||
if (!dec.openProgram(currentProgram)) throw new IllegalStateException(dec.getLastMessage());
|
||||
int count = 0, success = 0, failed = 0;
|
||||
try (BufferedWriter all = Files.newBufferedWriter(out.resolve("decompiled.c"), StandardCharsets.UTF_8);
|
||||
BufferedWriter index = Files.newBufferedWriter(out.resolve("functions.tsv"), StandardCharsets.UTF_8);
|
||||
BufferedWriter calls = Files.newBufferedWriter(out.resolve("calls.tsv"), StandardCharsets.UTF_8)) {
|
||||
all.write("/* Ghidra analysis pseudocode, not original source or a compilable port. */\n");
|
||||
index.write("address\tname\tprototype\tstatus\tfile\n");
|
||||
calls.write("caller_address\tcaller\tcallee_address\tcallee\n");
|
||||
FunctionIterator it = currentProgram.getFunctionManager().getFunctions(true);
|
||||
while (it.hasNext()) {
|
||||
monitor.checkCancelled();
|
||||
Function f = it.next();
|
||||
if (f.isExternal()) continue;
|
||||
count++;
|
||||
String addr = f.getEntryPoint().toString();
|
||||
String name = f.getName(true);
|
||||
DecompileResults result = dec.decompileFunction(f, 90, monitor);
|
||||
boolean ok = result.decompileCompleted() && result.getDecompiledFunction() != null;
|
||||
String status = ok ? "ok" : "failed: " + cell(result.getErrorMessage());
|
||||
String code = "/* " + addr + " " + name + " */\n";
|
||||
code += ok ? result.getDecompiledFunction().getC() : "/* " + status + " */\n";
|
||||
if (ok) success++; else failed++;
|
||||
String file = "functions/" + addr + ".c";
|
||||
Files.writeString(out.resolve(file), code, StandardCharsets.UTF_8);
|
||||
all.write(code + "\n");
|
||||
index.write(addr + "\t" + cell(name) + "\t" + cell(f.getPrototypeString(false, false))
|
||||
+ "\t" + status + "\t" + file + "\n");
|
||||
ArrayList<Function> targets = new ArrayList<>(f.getCalledFunctions(monitor));
|
||||
targets.sort(Comparator.comparing(t -> t.getEntryPoint().toString()));
|
||||
for (Function t : targets) calls.write(addr + "\t" + cell(name) + "\t"
|
||||
+ t.getEntryPoint() + "\t" + cell(t.getName(true)) + "\n");
|
||||
if (count % 100 == 0) println("Exported " + count + " functions");
|
||||
}
|
||||
} finally {
|
||||
dec.dispose();
|
||||
}
|
||||
String summary = "Program: " + currentProgram.getName() + "\nLanguage: "
|
||||
+ currentProgram.getLanguageID() + "\nCompiler: " + currentProgram.getCompilerSpec().getCompilerSpecID()
|
||||
+ "\nFunctions: " + count + "\nDecompiled: " + success + "\nFailed: " + failed + "\n";
|
||||
Files.writeString(out.resolve("summary.txt"), summary, StandardCharsets.UTF_8);
|
||||
println(summary);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
# SpeedTreeRT static analysis
|
||||
|
||||
The scripts analyze the original x86 Windows DLL without executing or modifying it.
|
||||
Generated pseudocode and Ghidra databases belong under `build/verification/` and are ignored by Git.
|
||||
See `../../docs/SPEEDTREE-REVERSE-ENGINEERING.md` for the completed analysis and entry map.
|
||||
|
||||
Use an official Ghidra distribution with its native decompiler installed for your host,
|
||||
and a compatible JDK (the completed run used Ghidra 12.1.4 and OpenJDK 21):
|
||||
|
||||
```sh
|
||||
python3 tools/reverse_speedtree/run.py \
|
||||
--ghidra-home /path/to/ghidra \
|
||||
--java-bin /path/to/jdk/bin
|
||||
```
|
||||
|
||||
The runner imports/replaces `SpeedTreeRT.dll` in the generated Ghidra project, runs
|
||||
automatic analysis and calls `ExportSpeedTree.java`. It writes `decompiled.c`,
|
||||
per-function files, function/call indexes, PE headers, disassembly, hashes and logs.
|
||||
The completed run also has an `exports.tsv` cross-reference and `validation.json`
|
||||
from a separate output completeness check.
|
||||
|
||||
On macOS arm64, if the distribution lacks `Decompiler/os/mac_arm_64/decompile`,
|
||||
build the bundled C++ decompiler in Ghidra's own directory, outside the client repo:
|
||||
|
||||
```sh
|
||||
cd /path/to/ghidra/Ghidra/Features/Decompiler/src/decompile/cpp
|
||||
make -j 8 ghidra_opt ARCH_TYPE='-arch arm64' \
|
||||
ADDITIONAL_FLAGS='-mmacosx-version-min=11.0 -w' OSDIR=mac_arm_64
|
||||
mkdir -p ../../../os/mac_arm_64
|
||||
cp ghidra_opt ../../../os/mac_arm_64/decompile
|
||||
```
|
||||
|
||||
Decompilation completion is not proof of recovered source correctness. Runtime
|
||||
library helpers are included, indirect calls may be missed, and inferred types
|
||||
and local layouts require review and comparison with real DLL outputs.
|
||||
@@ -0,0 +1,50 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Reproduce static analysis of the original Windows SpeedTreeRT DLL."""
|
||||
import argparse
|
||||
import hashlib
|
||||
import os
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
|
||||
|
||||
def main():
|
||||
root = Path(__file__).resolve().parents[2]
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument('--ghidra-home', type=Path, required=True)
|
||||
parser.add_argument('--java-bin', type=Path, help='Directory containing a compatible java executable')
|
||||
parser.add_argument('--dll', type=Path, default=root.parent / 'AVA2/1. Client DEV/SpeedTreeRT.dll')
|
||||
parser.add_argument('--output', type=Path, default=root / 'build/verification/speedtree-decompile')
|
||||
parser.add_argument('--objdump', default='objdump')
|
||||
args = parser.parse_args()
|
||||
dll, out = args.dll.resolve(), args.output.resolve()
|
||||
if not dll.is_file():
|
||||
parser.error(f'DLL missing: {dll}')
|
||||
headless = args.ghidra_home.resolve() / 'support/analyzeHeadless'
|
||||
if not headless.is_file():
|
||||
parser.error(f'Ghidra headless launcher missing: {headless}')
|
||||
out.mkdir(parents=True, exist_ok=True)
|
||||
projects = out / 'ghidra-project'
|
||||
projects.mkdir(exist_ok=True)
|
||||
(out / 'dll-sha256.txt').write_text(hashlib.sha256(dll.read_bytes()).hexdigest() + ' ' + str(dll) + '\n')
|
||||
for filename, options in [('pe-headers.txt', ['-p']), ('disassembly.txt', ['-d', '--demangle'])]:
|
||||
with (out / filename).open('w') as f:
|
||||
subprocess.run([args.objdump, *options, str(dll)], stdout=f, check=True)
|
||||
env = os.environ.copy()
|
||||
if args.java_bin:
|
||||
env['PATH'] = str(args.java_bin.resolve()) + os.pathsep + env.get('PATH', '')
|
||||
command = [str(headless), str(projects), 'SpeedTreeRT', '-import', str(dll), '-overwrite',
|
||||
'-analysisTimeoutPerFile', '600', '-max-cpu', '4',
|
||||
'-scriptPath', str(Path(__file__).resolve().parent),
|
||||
'-postScript', 'ExportSpeedTree.java', str(out), '-log', str(out / 'analysis.log')]
|
||||
# Avoid treating stale outputs from an earlier run as a successful export.
|
||||
summary = out / 'summary.txt'
|
||||
if summary.exists():
|
||||
summary.unlink()
|
||||
subprocess.run(command, env=env, check=True)
|
||||
if not summary.is_file():
|
||||
raise RuntimeError('Ghidra did not complete the export; inspect analysis.log')
|
||||
print(summary.read_text())
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user