rebuild iggy dirty movie state from native code

This commit is contained in:
coah
2026-07-13 03:14:56 -05:00
parent d4ffad27b5
commit 150121e82e
12 changed files with 401 additions and 12 deletions

View File

@@ -14,6 +14,13 @@ typedef struct IggyAs3VmLayoutDurango {
uint8_t bytes[0x6b28];
} IggyAs3VmLayoutDurango;
typedef struct IggySwfMovieStatePrefixLayoutDurango {
uint8_t flags;
uint8_t unknown_0001[0x0037];
void *dirty_older;
void *dirty_newer;
} IggySwfMovieStatePrefixLayoutDurango;
typedef struct IggyInternalLayoutDurango {
uint8_t unknown_0000[0x0008];
void *arena;
@@ -37,7 +44,9 @@ typedef struct IggyInternalLayoutDurango {
double start_time;
uint8_t unknown_2870[0x0080];
IggyAs3VmLayoutDurango *as3_vm;
uint8_t unknown_28f8[0x0436];
uint8_t unknown_28f8[0x0060];
IggySwfMovieStatePrefixLayoutDurango *dirty_movie_head;
uint8_t unknown_2960[0x03ce];
uint16_t audio_device;
uint8_t unknown_2d30[0x07a0];
uint8_t *temporary_memory;
@@ -57,6 +66,9 @@ typedef struct IggyInternalLayoutDurango {
IGGY_LAYOUT_ASSERT(sizeof(void *) == 8, "Durango Iggy layout requires 64-bit pointers");
IGGY_LAYOUT_ASSERT(sizeof(IggyAs3VmLayoutDurango) == 0x6b28, "AS3 VM allocation size");
IGGY_LAYOUT_ASSERT(sizeof(IggySwfMovieStatePrefixLayoutDurango) == 0x48, "SWF movie state prefix size");
IGGY_LAYOUT_ASSERT(offsetof(IggySwfMovieStatePrefixLayoutDurango, dirty_older) == 0x38, "dirty older offset");
IGGY_LAYOUT_ASSERT(offsetof(IggySwfMovieStatePrefixLayoutDurango, dirty_newer) == 0x40, "dirty newer offset");
IGGY_LAYOUT_ASSERT(sizeof(IggyInternalLayoutDurango) == 0x3750, "Iggy allocation size");
IGGY_LAYOUT_ASSERT(offsetof(IggyInternalLayoutDurango, arena) == 0x0008, "arena offset");
IGGY_LAYOUT_ASSERT(offsetof(IggyInternalLayoutDurango, swf_use_direct_blit) == 0x0090, "SWF direct-blit flag offset");
@@ -72,6 +84,7 @@ IGGY_LAYOUT_ASSERT(offsetof(IggyInternalLayoutDurango, initialized) == 0x1f38, "
IGGY_LAYOUT_ASSERT(offsetof(IggyInternalLayoutDurango, start_time_override) == 0x2860, "start-time override offset");
IGGY_LAYOUT_ASSERT(offsetof(IggyInternalLayoutDurango, start_time) == 0x2868, "start time offset");
IGGY_LAYOUT_ASSERT(offsetof(IggyInternalLayoutDurango, as3_vm) == 0x28f0, "AS3 VM offset");
IGGY_LAYOUT_ASSERT(offsetof(IggyInternalLayoutDurango, dirty_movie_head) == 0x2958, "dirty movie head offset");
IGGY_LAYOUT_ASSERT(offsetof(IggyInternalLayoutDurango, audio_device) == 0x2d2e, "audio device offset");
IGGY_LAYOUT_ASSERT(offsetof(IggyInternalLayoutDurango, temporary_memory) == 0x34d0, "temporary memory offset");
IGGY_LAYOUT_ASSERT(offsetof(IggyInternalLayoutDurango, temporary_capacity) == 0x34d8, "temporary capacity offset");

View File

@@ -14,6 +14,13 @@ typedef struct IggyAs3VmLayoutOrbis {
uint8_t bytes[0x6b28];
} IggyAs3VmLayoutOrbis;
typedef struct IggySwfMovieStatePrefixLayoutOrbis {
uint8_t flags;
uint8_t unknown_0001[0x0037];
void *dirty_older;
void *dirty_newer;
} IggySwfMovieStatePrefixLayoutOrbis;
typedef struct IggyInternalLayoutOrbis {
uint8_t unknown_0000[0x0008];
void *arena;
@@ -37,7 +44,9 @@ typedef struct IggyInternalLayoutOrbis {
double start_time;
uint8_t unknown_2870[0x0080];
IggyAs3VmLayoutOrbis *as3_vm;
uint8_t unknown_28f8[0x0436];
uint8_t unknown_28f8[0x0060];
IggySwfMovieStatePrefixLayoutOrbis *dirty_movie_head;
uint8_t unknown_2960[0x03ce];
uint16_t audio_device;
uint8_t unknown_2d30[0x07a0];
uint8_t *temporary_memory;
@@ -57,6 +66,9 @@ typedef struct IggyInternalLayoutOrbis {
IGGY_LAYOUT_ASSERT(sizeof(void *) == 8, "Orbis Iggy layout requires 64-bit pointers");
IGGY_LAYOUT_ASSERT(sizeof(IggyAs3VmLayoutOrbis) == 0x6b28, "AS3 VM allocation size");
IGGY_LAYOUT_ASSERT(sizeof(IggySwfMovieStatePrefixLayoutOrbis) == 0x48, "SWF movie state prefix size");
IGGY_LAYOUT_ASSERT(offsetof(IggySwfMovieStatePrefixLayoutOrbis, dirty_older) == 0x38, "dirty older offset");
IGGY_LAYOUT_ASSERT(offsetof(IggySwfMovieStatePrefixLayoutOrbis, dirty_newer) == 0x40, "dirty newer offset");
IGGY_LAYOUT_ASSERT(sizeof(IggyInternalLayoutOrbis) == 0x3610, "Iggy allocation size");
IGGY_LAYOUT_ASSERT(offsetof(IggyInternalLayoutOrbis, arena) == 0x0008, "arena offset");
IGGY_LAYOUT_ASSERT(offsetof(IggyInternalLayoutOrbis, swf_use_direct_blit) == 0x0090, "SWF direct-blit flag offset");
@@ -72,6 +84,7 @@ IGGY_LAYOUT_ASSERT(offsetof(IggyInternalLayoutOrbis, initialized) == 0x1f38, "in
IGGY_LAYOUT_ASSERT(offsetof(IggyInternalLayoutOrbis, start_time_override) == 0x2860, "start-time override offset");
IGGY_LAYOUT_ASSERT(offsetof(IggyInternalLayoutOrbis, start_time) == 0x2868, "start time offset");
IGGY_LAYOUT_ASSERT(offsetof(IggyInternalLayoutOrbis, as3_vm) == 0x28f0, "AS3 VM offset");
IGGY_LAYOUT_ASSERT(offsetof(IggyInternalLayoutOrbis, dirty_movie_head) == 0x2958, "dirty movie head offset");
IGGY_LAYOUT_ASSERT(offsetof(IggyInternalLayoutOrbis, audio_device) == 0x2d2e, "audio device offset");
IGGY_LAYOUT_ASSERT(offsetof(IggyInternalLayoutOrbis, temporary_memory) == 0x34d0, "temporary memory offset");
IGGY_LAYOUT_ASSERT(offsetof(IggyInternalLayoutOrbis, temporary_capacity) == 0x34d8, "temporary capacity offset");

View File

@@ -16,6 +16,15 @@ typedef struct IggyAs3VmLayoutPs3 {
uint8_t bytes[0x4840];
} IggyAs3VmLayoutPs3;
#define IGGY_SWF_MOVIE_DIRTY_MASK_PS3 UINT32_C(0x20000000)
typedef struct IggySwfMovieStatePrefixLayoutPs3 {
uint32_t flags;
uint8_t unknown_0004[0x001c];
IggyRecoveredPtr32Ps3 dirty_older_address;
IggyRecoveredPtr32Ps3 dirty_newer_address;
} IggySwfMovieStatePrefixLayoutPs3;
typedef struct IggyInternalLayoutPs3 {
uint8_t unknown_0000[0x0004];
IggyRecoveredPtr32Ps3 arena_address;
@@ -39,7 +48,9 @@ typedef struct IggyInternalLayoutPs3 {
double start_time;
uint8_t unknown_2190[0x0078];
IggyRecoveredPtr32Ps3 as3_vm_address;
uint8_t unknown_220c[0x0252];
uint8_t unknown_220c[0x003c];
IggyRecoveredPtr32Ps3 dirty_movie_head_address;
uint8_t unknown_224c[0x0212];
uint16_t audio_device;
uint8_t unknown_2460[0x0720];
IggyRecoveredPtr32Ps3 temporary_memory_address;
@@ -59,6 +70,9 @@ typedef struct IggyInternalLayoutPs3 {
} IggyInternalLayoutPs3;
IGGY_LAYOUT_ASSERT(sizeof(IggyAs3VmLayoutPs3) == 0x4840, "AS3 VM allocation size");
IGGY_LAYOUT_ASSERT(sizeof(IggySwfMovieStatePrefixLayoutPs3) == 0x28, "SWF movie state prefix size");
IGGY_LAYOUT_ASSERT(offsetof(IggySwfMovieStatePrefixLayoutPs3, dirty_older_address) == 0x20, "dirty older offset");
IGGY_LAYOUT_ASSERT(offsetof(IggySwfMovieStatePrefixLayoutPs3, dirty_newer_address) == 0x24, "dirty newer offset");
IGGY_LAYOUT_ASSERT(sizeof(IggyInternalLayoutPs3) == 0x3018, "Iggy allocation size");
IGGY_LAYOUT_ASSERT(offsetof(IggyInternalLayoutPs3, arena_address) == 0x0004, "arena offset");
IGGY_LAYOUT_ASSERT(offsetof(IggyInternalLayoutPs3, swf_use_direct_blit) == 0x0070, "SWF direct-blit flag offset");
@@ -74,6 +88,7 @@ IGGY_LAYOUT_ASSERT(offsetof(IggyInternalLayoutPs3, initialized) == 0x19c8, "init
IGGY_LAYOUT_ASSERT(offsetof(IggyInternalLayoutPs3, start_time_override) == 0x2180, "start-time override offset");
IGGY_LAYOUT_ASSERT(offsetof(IggyInternalLayoutPs3, start_time) == 0x2188, "start time offset");
IGGY_LAYOUT_ASSERT(offsetof(IggyInternalLayoutPs3, as3_vm_address) == 0x2208, "AS3 VM offset");
IGGY_LAYOUT_ASSERT(offsetof(IggyInternalLayoutPs3, dirty_movie_head_address) == 0x2248, "dirty movie head offset");
IGGY_LAYOUT_ASSERT(offsetof(IggyInternalLayoutPs3, audio_device) == 0x245e, "audio device offset");
IGGY_LAYOUT_ASSERT(offsetof(IggyInternalLayoutPs3, temporary_memory_address) == 0x2b80, "temporary memory offset");
IGGY_LAYOUT_ASSERT(offsetof(IggyInternalLayoutPs3, temporary_capacity) == 0x2b84, "temporary capacity offset");

View File

@@ -16,6 +16,13 @@ typedef struct IggyAs3VmLayoutVita {
uint8_t bytes[0x4840];
} IggyAs3VmLayoutVita;
typedef struct IggySwfMovieStatePrefixLayoutVita {
uint8_t flags;
uint8_t unknown_0001[0x001f];
IggyRecoveredPtr32Vita dirty_older_address;
IggyRecoveredPtr32Vita dirty_newer_address;
} IggySwfMovieStatePrefixLayoutVita;
typedef struct IggyInternalLayoutVita {
uint8_t unknown_0000[0x0004];
IggyRecoveredPtr32Vita arena_address;
@@ -39,7 +46,9 @@ typedef struct IggyInternalLayoutVita {
double start_time;
uint8_t unknown_2190[0x0078];
IggyRecoveredPtr32Vita as3_vm_address;
uint8_t unknown_220c[0x0252];
uint8_t unknown_220c[0x003c];
IggyRecoveredPtr32Vita dirty_movie_head_address;
uint8_t unknown_224c[0x0212];
uint16_t audio_device;
uint8_t unknown_2460[0x0720];
IggyRecoveredPtr32Vita temporary_memory_address;
@@ -58,6 +67,9 @@ typedef struct IggyInternalLayoutVita {
} IggyInternalLayoutVita;
IGGY_LAYOUT_ASSERT(sizeof(IggyAs3VmLayoutVita) == 0x4840, "AS3 VM allocation size");
IGGY_LAYOUT_ASSERT(sizeof(IggySwfMovieStatePrefixLayoutVita) == 0x28, "SWF movie state prefix size");
IGGY_LAYOUT_ASSERT(offsetof(IggySwfMovieStatePrefixLayoutVita, dirty_older_address) == 0x20, "dirty older offset");
IGGY_LAYOUT_ASSERT(offsetof(IggySwfMovieStatePrefixLayoutVita, dirty_newer_address) == 0x24, "dirty newer offset");
IGGY_LAYOUT_ASSERT(sizeof(IggyInternalLayoutVita) == 0x2d58, "Iggy allocation size");
IGGY_LAYOUT_ASSERT(offsetof(IggyInternalLayoutVita, arena_address) == 0x0004, "arena offset");
IGGY_LAYOUT_ASSERT(offsetof(IggyInternalLayoutVita, swf_use_direct_blit) == 0x0070, "SWF direct-blit flag offset");
@@ -73,6 +85,7 @@ IGGY_LAYOUT_ASSERT(offsetof(IggyInternalLayoutVita, initialized) == 0x19c8, "ini
IGGY_LAYOUT_ASSERT(offsetof(IggyInternalLayoutVita, start_time_override) == 0x2180, "start-time override offset");
IGGY_LAYOUT_ASSERT(offsetof(IggyInternalLayoutVita, start_time) == 0x2188, "start time offset");
IGGY_LAYOUT_ASSERT(offsetof(IggyInternalLayoutVita, as3_vm_address) == 0x2208, "AS3 VM offset");
IGGY_LAYOUT_ASSERT(offsetof(IggyInternalLayoutVita, dirty_movie_head_address) == 0x2248, "dirty movie head offset");
IGGY_LAYOUT_ASSERT(offsetof(IggyInternalLayoutVita, audio_device) == 0x245e, "audio device offset");
IGGY_LAYOUT_ASSERT(offsetof(IggyInternalLayoutVita, temporary_memory_address) == 0x2b80, "temporary memory offset");
IGGY_LAYOUT_ASSERT(offsetof(IggyInternalLayoutVita, temporary_capacity) == 0x2b84, "temporary capacity offset");

View File

@@ -28,3 +28,6 @@ add_library(
iggy_api_functions_global.c
)
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)

View File

@@ -16,6 +16,11 @@ global API wrappers, and sync-check state. Relocations recover the exact global
structures and their field offsets; the keycode bitmap and 32/64-bit player
offsets are reconciled across all four platform archives.
`swf_state.c` reconstructs both dirty-movie list operations. The recovered
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.
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.

View File

@@ -1,3 +1,4 @@
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
1 module source_functions external_functions platforms status
2 rrMath 17 15 durango,orbis,ps3,vita complete
3 iggy_api_functions_global 39 37 durango,orbis,ps3,vita complete
4 swf_state 2 2 durango,orbis,ps3,vita complete

View File

@@ -0,0 +1,50 @@
#include "swf_state.h"
#if UINTPTR_MAX == UINT64_MAX
#define IGGY_DIRTY_MOVIE_HEAD_OFFSET 0x2958
#else
#define IGGY_DIRTY_MOVIE_HEAD_OFFSET 0x2248
#endif
#if defined(__CELLOS_LV2__)
#define IGGY_SWF_MOVIE_DIRTY_MASK UINT32_C(0x20000000)
#else
#define IGGY_SWF_MOVIE_DIRTY_MASK UINT8_C(0x04)
#endif
static IggySwfMovieStatePrefix **iggy_dirty_movie_head(Iggy *iggy) {
return (IggySwfMovieStatePrefix **)((uint8_t *)iggy + IGGY_DIRTY_MOVIE_HEAD_OFFSET);
}
void iggy_mark_movie_dirty(Iggy *iggy, IggySwfMovieStatePrefix *movie) {
IggySwfMovieStatePrefix **head;
if ((movie->flags & IGGY_SWF_MOVIE_DIRTY_MASK) != 0) {
return;
}
movie->flags |= IGGY_SWF_MOVIE_DIRTY_MASK;
head = iggy_dirty_movie_head(iggy);
movie->dirty_older = *head;
if (*head != NULL) {
(*head)->dirty_newer = movie;
}
movie->dirty_newer = NULL;
*head = movie;
}
void iggy_clear_movie_dirty(Iggy *iggy, IggySwfMovieStatePrefix *movie) {
if ((movie->flags & IGGY_SWF_MOVIE_DIRTY_MASK) == 0) {
return;
}
movie->flags &= ~IGGY_SWF_MOVIE_DIRTY_MASK;
if (movie->dirty_newer == NULL) {
*iggy_dirty_movie_head(iggy) = movie->dirty_older;
} else {
movie->dirty_newer->dirty_older = movie->dirty_older;
}
if (movie->dirty_older != NULL) {
movie->dirty_older->dirty_newer = movie->dirty_newer;
}
}

View File

@@ -0,0 +1,55 @@
#ifndef IGGY_RECONSTRUCTED_SWF_STATE_H
#define IGGY_RECONSTRUCTED_SWF_STATE_H
#include <stddef.h>
#include <stdint.h>
#if defined(__cplusplus)
#define IGGY_SWF_STATE_ASSERT(condition, message) static_assert(condition, message)
extern "C" {
#else
#define IGGY_SWF_STATE_ASSERT(condition, message) _Static_assert(condition, message)
#endif
typedef struct Iggy Iggy;
typedef struct IggySwfMovieStatePrefix {
#if defined(__CELLOS_LV2__)
uint32_t flags;
uint8_t unknown_0004[0x1c];
#elif UINTPTR_MAX == UINT64_MAX
uint8_t flags;
uint8_t unknown_0001[0x37];
#elif UINTPTR_MAX == UINT32_MAX
uint8_t flags;
uint8_t unknown_0001[0x1f];
#else
#error Unsupported pointer width
#endif
#if defined(__CELLOS_LV2__) && UINTPTR_MAX != UINT32_MAX
#error PS3 Iggy layout requires 32-bit pointers
#endif
struct IggySwfMovieStatePrefix *dirty_older;
struct IggySwfMovieStatePrefix *dirty_newer;
} IggySwfMovieStatePrefix;
void iggy_mark_movie_dirty(Iggy *iggy, IggySwfMovieStatePrefix *movie);
void iggy_clear_movie_dirty(Iggy *iggy, IggySwfMovieStatePrefix *movie);
#if UINTPTR_MAX == UINT64_MAX
IGGY_SWF_STATE_ASSERT(sizeof(IggySwfMovieStatePrefix) == 0x48, "SWF movie state prefix size");
IGGY_SWF_STATE_ASSERT(offsetof(IggySwfMovieStatePrefix, dirty_older) == 0x38, "dirty older offset");
IGGY_SWF_STATE_ASSERT(offsetof(IggySwfMovieStatePrefix, dirty_newer) == 0x40, "dirty newer offset");
#else
IGGY_SWF_STATE_ASSERT(sizeof(IggySwfMovieStatePrefix) == 0x28, "SWF movie state prefix size");
IGGY_SWF_STATE_ASSERT(offsetof(IggySwfMovieStatePrefix, dirty_older) == 0x20, "dirty older offset");
IGGY_SWF_STATE_ASSERT(offsetof(IggySwfMovieStatePrefix, dirty_newer) == 0x24, "dirty newer offset");
#endif
#if defined(__cplusplus)
}
#endif
#undef IGGY_SWF_STATE_ASSERT
#endif

View File

@@ -25,19 +25,37 @@ class InternalLayoutTests(unittest.TestCase):
self.compile_header("iggy_internal_vita.h")
def test_ghidra_durango_overlay_matches_layout(self):
self.compile_overlay("_DURANGO", 0x3750, 0x0098, 0x28F0, 0x2D2E, 0x3534)
self.compile_overlay(
"_DURANGO", 0x3750, 0x0098, 0x28F0, 0x2958, 0x2D2E, 0x3534
)
def test_ghidra_orbis_overlay_matches_layout(self):
self.compile_overlay("__ORBIS__", 0x3610, 0x0098, 0x28F0, 0x2D2E, 0x3534)
self.compile_overlay(
"__ORBIS__", 0x3610, 0x0098, 0x28F0, 0x2958, 0x2D2E, 0x3534
)
def test_ghidra_ps3_overlay_matches_layout(self):
self.compile_overlay(
"__CELLOS_LV2__", 0x3018, 0x0078, 0x2208, 0x245E, 0x2BC0, ["-m32"]
"__CELLOS_LV2__",
0x3018,
0x0078,
0x2208,
0x2248,
0x245E,
0x2BC0,
["-m32"],
)
def test_ghidra_vita_overlay_matches_layout(self):
self.compile_overlay(
"__psp2__", 0x2D58, 0x0078, 0x2208, 0x245E, 0x2BC0, ["-m32"]
"__psp2__",
0x2D58,
0x0078,
0x2208,
0x2248,
0x245E,
0x2BC0,
["-m32"],
)
def compile_header(self, header_name):
@@ -73,6 +91,7 @@ class InternalLayoutTests(unittest.TestCase):
expected_size,
resource_entries_offset,
as3_vm_offset,
dirty_movie_head_offset,
audio_device_offset,
api_lock_offset,
extra_flags=None,
@@ -87,6 +106,7 @@ _Static_assert(sizeof(struct Iggy) == {expected_size}, "Iggy size");
_Static_assert(sizeof(struct IggyGeneric) == {expected_size}, "IggyGeneric size");
_Static_assert(__builtin_offsetof(struct Iggy, resource_entries) == {resource_entries_offset}, "resource entries");
_Static_assert(__builtin_offsetof(struct Iggy, as3_vm) == {as3_vm_offset}, "AS3 VM");
_Static_assert(__builtin_offsetof(struct Iggy, dirty_movie_head) == {dirty_movie_head_offset}, "dirty movie head");
_Static_assert(__builtin_offsetof(struct Iggy, audio_device) == {audio_device_offset}, "audio device");
_Static_assert(__builtin_offsetof(struct Iggy, api_lock) == {api_lock_offset}, "API lock");
int main(void) {{ return 0; }}

View File

@@ -0,0 +1,193 @@
import ctypes
from pathlib import Path
import subprocess
import tempfile
import unittest
ROOT = Path(__file__).resolve().parents[1]
SOURCE = ROOT / "iggy-decompiled/src/reconstructed/swf_state.c"
RECONSTRUCTED = ROOT / "iggy-decompiled/src/reconstructed"
INCLUDE = ROOT / "iggy-decompiled/include"
class IggySwfMovieStatePrefix(ctypes.Structure):
pass
IggySwfMovieStatePrefix._fields_ = [
("flags", ctypes.c_uint8),
("unknown_0001", ctypes.c_uint8 * 0x37),
("dirty_older", ctypes.POINTER(IggySwfMovieStatePrefix)),
("dirty_newer", ctypes.POINTER(IggySwfMovieStatePrefix)),
]
class ReconstructedSwfStateTests(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.temporary_directory = tempfile.TemporaryDirectory()
library_path = Path(cls.temporary_directory.name) / "libswf_state.dylib"
result = subprocess.run(
[
"clang",
"-dynamiclib",
"-std=c11",
"-Wall",
"-Wextra",
"-Werror",
"-I",
str(INCLUDE),
"-I",
str(RECONSTRUCTED),
str(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))
pointer = ctypes.POINTER(IggySwfMovieStatePrefix)
cls.library.iggy_mark_movie_dirty.argtypes = [ctypes.c_void_p, pointer]
cls.library.iggy_clear_movie_dirty.argtypes = [ctypes.c_void_p, pointer]
@classmethod
def tearDownClass(cls):
cls.temporary_directory.cleanup()
def setUp(self):
self.player = (ctypes.c_uint8 * 0x3750)()
self.first = IggySwfMovieStatePrefix()
self.second = IggySwfMovieStatePrefix()
def head(self):
address = ctypes.c_void_p.from_buffer(self.player, 0x2958).value
if address is None:
return None
return ctypes.cast(address, ctypes.POINTER(IggySwfMovieStatePrefix))
def mark(self, movie):
self.library.iggy_mark_movie_dirty(ctypes.byref(self.player), ctypes.byref(movie))
def clear(self, movie):
self.library.iggy_clear_movie_dirty(ctypes.byref(self.player), ctypes.byref(movie))
def test_recovered_native_layout(self):
self.assertEqual(ctypes.sizeof(IggySwfMovieStatePrefix), 0x48)
self.assertEqual(IggySwfMovieStatePrefix.dirty_older.offset, 0x38)
self.assertEqual(IggySwfMovieStatePrefix.dirty_newer.offset, 0x40)
def test_32bit_vita_and_ps3_codegen_uses_recovered_flag_widths(self):
vita_ir = self.compile_32bit_ir()
self.assertRegex(vita_ir, r"and i8 %\d+, 4")
self.assertRegex(vita_ir, r"or(?: disjoint)? i8 %\d+, 4")
self.assertRegex(vita_ir, r"and i8 %\d+, -5")
self.assertIn("ptr %0, i32 8776", vita_ir)
ps3_ir = self.compile_32bit_ir("__CELLOS_LV2__")
self.assertRegex(ps3_ir, r"and i32 %\d+, 536870912")
self.assertRegex(ps3_ir, r"or(?: disjoint)? i32 %\d+, 536870912")
self.assertRegex(ps3_ir, r"and i32 %\d+, -536870913")
self.assertIn("ptr %0, i32 8776", ps3_ir)
def test_mark_prepends_once_and_preserves_other_flags(self):
self.first.flags = 0x81
self.first.unknown_0001[:] = bytes([0xCC]) * 0x37
self.mark(self.first)
player_after_first_mark = bytes(self.player)
movie_after_first_mark = bytes(self.first)
self.mark(self.first)
self.assertEqual(self.first.flags, 0x85)
self.assertEqual(bytes(self.first.unknown_0001), bytes([0xCC]) * 0x37)
self.assertEqual(bytes(self.player), player_after_first_mark)
self.assertEqual(bytes(self.first), movie_after_first_mark)
self.assertEqual(ctypes.addressof(self.head().contents), ctypes.addressof(self.first))
self.assertFalse(self.first.dirty_older)
self.assertFalse(self.first.dirty_newer)
self.mark(self.second)
self.assertEqual(ctypes.addressof(self.head().contents), ctypes.addressof(self.second))
self.assertEqual(
ctypes.addressof(self.second.dirty_older.contents),
ctypes.addressof(self.first),
)
self.assertEqual(
ctypes.addressof(self.first.dirty_newer.contents),
ctypes.addressof(self.second),
)
self.assertFalse(self.second.dirty_newer)
def test_clear_unlinks_tail_middle_and_head_idempotently(self):
third = IggySwfMovieStatePrefix()
self.mark(self.first)
self.mark(self.second)
self.mark(third)
second_links = bytes(self.second)[0x38:0x48]
self.clear(self.second)
self.assertEqual(bytes(self.second)[0x38:0x48], second_links)
self.assertEqual(
ctypes.addressof(third.dirty_older.contents),
ctypes.addressof(self.first),
)
self.assertEqual(
ctypes.addressof(self.first.dirty_newer.contents),
ctypes.addressof(third),
)
self.clear(self.first)
self.assertFalse(third.dirty_older)
self.assertEqual(ctypes.addressof(self.head().contents), ctypes.addressof(third))
stale_links = bytes(third)[0x38:0x48]
self.clear(third)
self.clear(third)
self.assertIsNone(self.head())
self.assertEqual(third.flags & 0x04, 0)
self.assertEqual(bytes(third)[0x38:0x48], stale_links)
def test_unmarked_clear_and_separate_players_are_exact_noops(self):
other_player = (ctypes.c_uint8 * 0x3750)()
other_movie = IggySwfMovieStatePrefix()
self.mark(self.first)
self.library.iggy_mark_movie_dirty(
ctypes.byref(other_player), ctypes.byref(other_movie)
)
player_before = bytes(self.player)
first_before = bytes(self.first)
other_player_before = bytes(other_player)
other_movie_before = bytes(other_movie)
self.clear(self.second)
self.assertEqual(bytes(self.player), player_before)
self.assertEqual(bytes(self.first), first_before)
self.assertEqual(bytes(other_player), other_player_before)
self.assertEqual(bytes(other_movie), other_movie_before)
def compile_32bit_ir(self, platform_define=None):
command = [
"clang",
"-m32",
"-O2",
"-std=c11",
"-Wall",
"-Wextra",
"-Werror",
"-S",
"-emit-llvm",
]
if platform_define is not None:
command.append(f"-D{platform_define}=1")
command.extend([str(SOURCE), "-o", "-"])
result = subprocess.run(command, capture_output=True, text=True)
self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
return result.stdout
if __name__ == "__main__":
unittest.main()

View File

@@ -25,7 +25,9 @@ struct Iggy {
double start_time;
unsigned char unknown_2870[0x0080];
struct IggyAs3Vm *as3_vm;
unsigned char unknown_28f8[0x0436];
unsigned char unknown_28f8[0x0060];
void *dirty_movie_head;
unsigned char unknown_2960[0x03ce];
unsigned short audio_device;
unsigned char unknown_2d30[0x07a0];
unsigned char *temporary_memory;
@@ -55,7 +57,9 @@ struct IggyGeneric {
unsigned int initialized;
unsigned char unknown_1f3c[0x09b4];
struct IggyAs3Vm *as3_vm;
unsigned char unknown_28f8[0x0436];
unsigned char unknown_28f8[0x0060];
void *dirty_movie_head;
unsigned char unknown_2960[0x03ce];
unsigned short audio_device;
unsigned char unknown_2d30[0x0804];
int api_lock;
@@ -91,7 +95,9 @@ struct Iggy {
double start_time;
unsigned char unknown_2190[0x0078];
struct IggyAs3Vm *as3_vm;
unsigned char unknown_220c[0x0252];
unsigned char unknown_220c[0x003c];
void *dirty_movie_head;
unsigned char unknown_224c[0x0212];
unsigned short audio_device;
unsigned char unknown_2460[0x0720];
unsigned char *temporary_memory;
@@ -123,7 +129,9 @@ struct IggyGeneric {
unsigned int initialized;
unsigned char unknown_19cc[0x083c];
struct IggyAs3Vm *as3_vm;
unsigned char unknown_220c[0x0252];
unsigned char unknown_220c[0x003c];
void *dirty_movie_head;
unsigned char unknown_224c[0x0212];
unsigned short audio_device;
unsigned char unknown_2460[0x0760];
int api_lock;