recover the compiled-out avm2 diagnostic hooks
This commit is contained in:
@@ -31,3 +31,19 @@ configure_iggy_reconstructed_target(iggy_reconstructed_api_global c_std_11)
|
||||
|
||||
add_library(iggy_reconstructed_swf_state STATIC swf_state.c)
|
||||
configure_iggy_reconstructed_target(iggy_reconstructed_swf_state c_std_11)
|
||||
|
||||
add_library(
|
||||
iggy_reconstructed_as3vm_debugger_interface
|
||||
STATIC
|
||||
as3vm_debugger_interface.c
|
||||
)
|
||||
configure_iggy_reconstructed_target(
|
||||
iggy_reconstructed_as3vm_debugger_interface
|
||||
c_std_11
|
||||
)
|
||||
|
||||
add_library(iggy_reconstructed_as3vm_op_strings STATIC as3vm_op_strings.c)
|
||||
configure_iggy_reconstructed_target(
|
||||
iggy_reconstructed_as3vm_op_strings
|
||||
c_std_11
|
||||
)
|
||||
|
||||
@@ -21,6 +21,13 @@ intrusive-list prefix, player head offsets, and platform flag layout match
|
||||
the Durango, Orbis, PS3, and Vita objects, including the PS3 compiler's
|
||||
big-endian physical mask.
|
||||
|
||||
`as3vm_debugger_interface.c` and `as3vm_op_strings.c` preserve the three
|
||||
intentional zero-return stubs in the shipping archives. Every platform object
|
||||
contains the same compiled-out behavior with no debugger metadata, opcode
|
||||
table, globals, or runtime relocations. The opcode argument is recovered from
|
||||
verifier call sites; debugger result types stay pointer-width and non-semantic
|
||||
where the native callers cannot prove a stronger type.
|
||||
|
||||
Configure this directory directly with CMake to build the reconstructed units.
|
||||
Every added module must compile independently and have behavioral tests before
|
||||
it is listed in `modules.tsv` as complete.
|
||||
|
||||
13
iggy-decompiled/src/reconstructed/as3vm_debugger_interface.c
Normal file
13
iggy-decompiled/src/reconstructed/as3vm_debugger_interface.c
Normal file
@@ -0,0 +1,13 @@
|
||||
#include "as3vm_debugger_interface.h"
|
||||
|
||||
As3VmDebuggerStubResult as3vm_debugger_info(void) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
As3VmDebuggerStubResult as3vm_watch(
|
||||
const char *watch_name, void *value, const char *value_type) {
|
||||
(void)watch_name;
|
||||
(void)value;
|
||||
(void)value_type;
|
||||
return 0;
|
||||
}
|
||||
20
iggy-decompiled/src/reconstructed/as3vm_debugger_interface.h
Normal file
20
iggy-decompiled/src/reconstructed/as3vm_debugger_interface.h
Normal file
@@ -0,0 +1,20 @@
|
||||
#ifndef IGGY_RECONSTRUCTED_AS3VM_DEBUGGER_INTERFACE_H
|
||||
#define IGGY_RECONSTRUCTED_AS3VM_DEBUGGER_INTERFACE_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
typedef uintptr_t As3VmDebuggerStubResult;
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
As3VmDebuggerStubResult as3vm_debugger_info(void);
|
||||
As3VmDebuggerStubResult as3vm_watch(
|
||||
const char *watch_name, void *value, const char *value_type);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
8
iggy-decompiled/src/reconstructed/as3vm_op_strings.c
Normal file
8
iggy-decompiled/src/reconstructed/as3vm_op_strings.c
Normal file
@@ -0,0 +1,8 @@
|
||||
#include "as3vm_op_strings.h"
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
const char *as3vm_opcode_name(uint8_t opcode) {
|
||||
(void)opcode;
|
||||
return NULL;
|
||||
}
|
||||
16
iggy-decompiled/src/reconstructed/as3vm_op_strings.h
Normal file
16
iggy-decompiled/src/reconstructed/as3vm_op_strings.h
Normal file
@@ -0,0 +1,16 @@
|
||||
#ifndef IGGY_RECONSTRUCTED_AS3VM_OP_STRINGS_H
|
||||
#define IGGY_RECONSTRUCTED_AS3VM_OP_STRINGS_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
const char *as3vm_opcode_name(uint8_t opcode);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -2,3 +2,5 @@ module source_functions external_functions platforms status
|
||||
rrMath 17 15 durango,orbis,ps3,vita complete
|
||||
iggy_api_functions_global 39 37 durango,orbis,ps3,vita complete
|
||||
swf_state 2 2 durango,orbis,ps3,vita complete
|
||||
as3vm_debugger_interface 2 2 durango,orbis,ps3,vita complete
|
||||
as3vm_op_strings 1 1 durango,orbis,ps3,vita complete
|
||||
|
||||
|
206
tests/test_reconstructed_as3vm_diagnostics.py
Normal file
206
tests/test_reconstructed_as3vm_diagnostics.py
Normal file
@@ -0,0 +1,206 @@
|
||||
import ctypes
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
RECONSTRUCTED = ROOT / "iggy-decompiled/src/reconstructed"
|
||||
DEBUGGER_SOURCE = RECONSTRUCTED / "as3vm_debugger_interface.c"
|
||||
OPCODE_SOURCE = RECONSTRUCTED / "as3vm_op_strings.c"
|
||||
|
||||
|
||||
class ReconstructedAs3VmDiagnosticsTests(unittest.TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
cls.temporary_directory = tempfile.TemporaryDirectory()
|
||||
library_path = Path(cls.temporary_directory.name) / "libas3vm_diagnostics.dylib"
|
||||
result = subprocess.run(
|
||||
[
|
||||
"clang",
|
||||
"-dynamiclib",
|
||||
"-std=c11",
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"-Werror",
|
||||
"-I",
|
||||
str(RECONSTRUCTED),
|
||||
str(DEBUGGER_SOURCE),
|
||||
str(OPCODE_SOURCE),
|
||||
"-o",
|
||||
str(library_path),
|
||||
],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
)
|
||||
if result.returncode != 0:
|
||||
raise AssertionError(result.stdout + result.stderr)
|
||||
cls.library = ctypes.CDLL(str(library_path), use_errno=True)
|
||||
cls.library.as3vm_debugger_info.restype = ctypes.c_size_t
|
||||
cls.library.as3vm_watch.argtypes = [
|
||||
ctypes.c_char_p,
|
||||
ctypes.c_void_p,
|
||||
ctypes.c_char_p,
|
||||
]
|
||||
cls.library.as3vm_watch.restype = ctypes.c_size_t
|
||||
cls.library.as3vm_opcode_name.argtypes = [ctypes.c_uint8]
|
||||
cls.library.as3vm_opcode_name.restype = ctypes.c_char_p
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
cls.temporary_directory.cleanup()
|
||||
|
||||
def test_retail_debugger_interface_is_disabled(self):
|
||||
value = ctypes.c_uint64(0x1122334455667788)
|
||||
expression = ctypes.create_string_buffer(b"&vm->timeline")
|
||||
value_type = ctypes.create_string_buffer(b"as3value")
|
||||
expression_before = bytes(expression)
|
||||
value_type_before = bytes(value_type)
|
||||
ctypes.set_errno(73)
|
||||
|
||||
self.assertEqual(self.library.as3vm_debugger_info(), 0)
|
||||
self.assertEqual(
|
||||
self.library.as3vm_watch(
|
||||
ctypes.cast(expression, ctypes.c_char_p),
|
||||
ctypes.byref(value),
|
||||
ctypes.cast(value_type, ctypes.c_char_p),
|
||||
),
|
||||
0,
|
||||
)
|
||||
self.assertEqual(value.value, 0x1122334455667788)
|
||||
self.assertEqual(bytes(expression), expression_before)
|
||||
self.assertEqual(bytes(value_type), value_type_before)
|
||||
self.assertEqual(self.library.as3vm_watch(None, None, None), 0)
|
||||
self.assertEqual(ctypes.get_errno(), 73)
|
||||
|
||||
def test_retail_opcode_names_are_disabled_for_every_opcode(self):
|
||||
self.assertTrue(
|
||||
all(self.library.as3vm_opcode_name(opcode) is None for opcode in range(256))
|
||||
)
|
||||
|
||||
def test_reconstructed_objects_have_only_the_recovered_zero_stubs(self):
|
||||
debugger_symbols, debugger_ir = self.compile_object(DEBUGGER_SOURCE)
|
||||
opcode_symbols, opcode_ir = self.compile_object(OPCODE_SOURCE)
|
||||
|
||||
self.assertEqual(
|
||||
debugger_symbols, {"as3vm_debugger_info", "as3vm_watch"}
|
||||
)
|
||||
self.assertEqual(opcode_symbols, {"as3vm_opcode_name"})
|
||||
self.assertEqual(debugger_ir.count("ret i64 0"), 2)
|
||||
self.assertEqual(opcode_ir.count("ret ptr null"), 1)
|
||||
|
||||
def test_recovered_headers_link_from_cpp(self):
|
||||
temporary_path = Path(self.temporary_directory.name)
|
||||
harness_path = temporary_path / "as3vm_diagnostics_cpp.cpp"
|
||||
harness_path.write_text(
|
||||
'#include "as3vm_debugger_interface.h"\n'
|
||||
'#include "as3vm_op_strings.h"\n'
|
||||
'int main() { return as3vm_debugger_info() != 0 || '
|
||||
'as3vm_watch(nullptr, nullptr, nullptr) != 0 || '
|
||||
'as3vm_opcode_name(0) != nullptr; }\n',
|
||||
encoding="utf-8",
|
||||
)
|
||||
objects = []
|
||||
for source in (DEBUGGER_SOURCE, OPCODE_SOURCE):
|
||||
object_path = temporary_path / f"{source.stem}.o"
|
||||
compile_result = subprocess.run(
|
||||
[
|
||||
"clang",
|
||||
"-std=c11",
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"-Werror",
|
||||
"-Wstrict-prototypes",
|
||||
"-I",
|
||||
str(RECONSTRUCTED),
|
||||
"-c",
|
||||
str(source),
|
||||
"-o",
|
||||
str(object_path),
|
||||
],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
)
|
||||
self.assertEqual(
|
||||
compile_result.returncode,
|
||||
0,
|
||||
compile_result.stdout + compile_result.stderr,
|
||||
)
|
||||
objects.append(str(object_path))
|
||||
result = subprocess.run(
|
||||
[
|
||||
"clang++",
|
||||
"-std=c++17",
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"-Werror",
|
||||
"-I",
|
||||
str(RECONSTRUCTED),
|
||||
str(harness_path),
|
||||
*objects,
|
||||
"-o",
|
||||
str(temporary_path / "as3vm_diagnostics_cpp"),
|
||||
],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
)
|
||||
self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
|
||||
|
||||
def compile_object(self, source):
|
||||
temporary_path = Path(self.temporary_directory.name)
|
||||
object_path = temporary_path / f"{source.stem}.obj"
|
||||
result = subprocess.run(
|
||||
[
|
||||
"clang",
|
||||
"-target",
|
||||
"x86_64-pc-windows-msvc",
|
||||
"-O2",
|
||||
"-ffunction-sections",
|
||||
"-std=c11",
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"-Werror",
|
||||
"-c",
|
||||
str(source),
|
||||
"-o",
|
||||
str(object_path),
|
||||
],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
)
|
||||
self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
|
||||
|
||||
symbols = subprocess.run(
|
||||
[
|
||||
"xcrun",
|
||||
"llvm-nm",
|
||||
"--defined-only",
|
||||
"--extern-only",
|
||||
str(object_path),
|
||||
],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
)
|
||||
self.assertEqual(symbols.returncode, 0, symbols.stdout + symbols.stderr)
|
||||
symbol_names = {line.split()[-1] for line in symbols.stdout.splitlines()}
|
||||
|
||||
undefined = subprocess.run(
|
||||
["xcrun", "llvm-nm", "--undefined-only", str(object_path)],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
)
|
||||
self.assertEqual(undefined.returncode, 0, undefined.stdout + undefined.stderr)
|
||||
self.assertEqual(undefined.stdout.strip(), "")
|
||||
|
||||
ir = subprocess.run(
|
||||
["clang", "-O2", "-std=c11", "-S", "-emit-llvm", str(source), "-o", "-"],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
)
|
||||
self.assertEqual(ir.returncode, 0, ir.stdout + ir.stderr)
|
||||
return symbol_names, ir.stdout
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user