mirror of
https://github.com/boykopovar/AnyPS5.git
synced 2026-11-07 13:39:55 +00:00
test(relinker): cover executable segment scan boundaries
Check prefixed forbidden instructions at the segment end, outside its file range, and truncated before a byte that remains in the input file. AI-assisted: OpenAI Codex
This commit is contained in:
1 parent
665ad7da74
commit
15602ed32c
1 file changed
+20
-2
@@ -37,10 +37,13 @@ def fixture(second_code: bytes, with_import: bool = False) -> bytearray:
|
||||
return image
|
||||
|
||||
|
||||
def run_case(relinker: Path, work: Path, name: str, args, code: bytes, with_import=False):
|
||||
def run_case(relinker: Path, work: Path, name: str, args, code: bytes, with_import=False, trailing_data=b""):
|
||||
source = work / (name + ".elf")
|
||||
output = work / (name + ".exe")
|
||||
source.write_bytes(fixture(code, with_import))
|
||||
image = fixture(code, with_import)
|
||||
end = 0x800 + len(code)
|
||||
image[end:end + len(trailing_data)] = trailing_data
|
||||
source.write_bytes(image)
|
||||
result = subprocess.run([str(relinker), "--skip-sce-module", "--windows", *args,
|
||||
str(source), str(output)], capture_output=True,
|
||||
text=True, timeout=20)
|
||||
@@ -72,6 +75,21 @@ def main():
|
||||
assert result.returncode == 2 and not output.exists(), (name, result.stdout, result.stderr)
|
||||
assert "Forbidden syscall instruction at code offset 0x1801" in result.stderr, (name, result.stderr)
|
||||
|
||||
for name, instruction in forbidden:
|
||||
result, output = run_case(relinker, work, name + "-at-end", [], b"\x90" + instruction)
|
||||
assert result.returncode == 2 and not output.exists(), (name, result.stdout, result.stderr)
|
||||
assert "Forbidden syscall instruction at code offset 0x1801" in result.stderr, (name, result.stderr)
|
||||
|
||||
for name, instruction in forbidden:
|
||||
result, output = run_case(relinker, work, name + "-outside", [], b"\x90\xc3",
|
||||
trailing_data=instruction)
|
||||
assert result.returncode == 0 and output.exists(), (name, result.stdout, result.stderr)
|
||||
|
||||
result, output = run_case(relinker, work, name + "-truncated", [], b"\x90" + instruction[:-1],
|
||||
trailing_data=instruction[-1:])
|
||||
assert result.returncode == 2 and not output.exists(), (name, result.stdout, result.stderr)
|
||||
assert "Cannot decode instruction" in result.stderr and "offset 0x1801" in result.stderr, (name, result.stderr)
|
||||
|
||||
result, output = run_case(relinker, work, "immediate-decoys", [],
|
||||
b"\x48\xb8\x0f\x05\xcd\x80\x0f\x34\x0f\x07\xc3")
|
||||
assert result.returncode == 0 and output.exists(), (result.stdout, result.stderr)
|
||||
|
||||
Reference in new issue
Block a user