rebuild iggy's native as3 flash.events binding
This commit is contained in:
@@ -1047,3 +1047,33 @@ foreach(platform IN ITEMS durango orbis ps3 vita)
|
||||
target_compile_options(${target} PRIVATE /Oi-)
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
# swf_as3vm_flash_events -- Iggy's AVM2 flash.events binding layer (Event /
|
||||
# EventDispatcher / FocusEvent / KeyboardEvent / MouseEvent / TextEvent /
|
||||
# TimerEvent and siblings). 118 exports on every platform, invariant ABI; the
|
||||
# per-platform source_functions diverges (durango 123 / orbis 121 / ps3 120 /
|
||||
# vita 122) because the RISC toolchains keep more file-static dispatch helpers
|
||||
# separate. Owns no exported data global -- the durango R symbols are all
|
||||
# ??_C@ MSVC string COMDATs, and ps3's D symbols are .opd function descriptors.
|
||||
# The three-phase capture/target/bubble dispatch machinery and the do_*_event_GC
|
||||
# entry points are reconstructed from the durango raw + object and the ps3/vita
|
||||
# 32-bit layouts; the genuinely-unbuilt text/display engine is reached only
|
||||
# through the frozen 32-symbol cross-module import set. ps3 is 32-bit
|
||||
# big-endian (Event flag / phase writes are byte-wise); vita is 32-bit hard-
|
||||
# float with no soft-float helper. Guard the memcpy / memset against builtin
|
||||
# re-synthesis with -fno-builtin (clang/gcc) or /Oi- (MSVC).
|
||||
foreach(platform IN ITEMS durango orbis ps3 vita)
|
||||
string(TOUPPER ${platform} platform_upper)
|
||||
set(target iggy_reconstructed_swf_as3vm_flash_events_${platform})
|
||||
add_library(${target} STATIC swf_as3vm_flash_events.c)
|
||||
target_compile_definitions(
|
||||
${target}
|
||||
PRIVATE IGGY_RECONSTRUCT_SWF_AS3VM_FLASH_EVENTS_${platform_upper}
|
||||
)
|
||||
configure_iggy_reconstructed_target(${target} c_std_11)
|
||||
if(CMAKE_C_COMPILER_ID MATCHES "Clang|GNU")
|
||||
target_compile_options(${target} PRIVATE -fno-builtin)
|
||||
elseif(MSVC)
|
||||
target_compile_options(${target} PRIVATE /Oi-)
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
@@ -921,6 +921,34 @@ exported data globals, and it pulls no ARM soft-float helper; everything the rev
|
||||
named is source-equivalent, with the value-level behavior of the deep layout queries
|
||||
deferred to the still-unbuilt text engine.
|
||||
|
||||
`swf_as3vm_flash_events.c` restores Iggy's AVM2 flash.events binding layer — the
|
||||
`Event`, `EventDispatcher`, `FocusEvent`, `KeyboardEvent`, `MouseEvent`,
|
||||
`TextEvent`, and `TimerEvent` classes — behind its 118 exports (invariant across
|
||||
all four platforms). It reconstructs the full binding, not just the pinned
|
||||
surface: the constructors' field writes and the get_/set_ property boxing (bool
|
||||
getters indexing `makebool`, small-int getters storing `field*2`, the type
|
||||
field/VM-fallback selection); the `addEventListener`/`removeEventListener`/
|
||||
`hasEventListener`/`willTrigger` list mechanics with their width-gated
|
||||
listener-node and entry structs; and — the hardest part — the file-static
|
||||
three-phase capture→target→bubble dispatch machinery
|
||||
(`dispatch_event_GC`, `dispatch_lazy_event_GC`, `dispatch_loop_GC`,
|
||||
`dispatch_event_local_GC`) plus the `do_*_event_GC` engine entry points that
|
||||
seed each lazy event's class, interned type name, bubbles/cancelable flags, and
|
||||
the extended input fields (Focus keyCode, Keyboard keyCode/charCode/keyLocation,
|
||||
Mouse buttonDown/clickCount/delta/localX/localY). An initial pass had stubbed
|
||||
the propagation walk to the direct-target stage; three independent review rounds
|
||||
against all four decompiles restored it in full and corrected a dense cluster of
|
||||
harness-invisible defects — a capture-flag helper that scanned only one listener
|
||||
list (silently killing normal bubbling dispatch), several `*vm` context-deref
|
||||
bases dropped from `make_lazy`/`get_movie`/the modifier-key reads, swapped
|
||||
bubbles/defaultPrevented seeds on Mouse/Keyboard/Focus, dropped input-field
|
||||
marshalling, an off-by-one `TimerEvent` name slot, an endian-unsafe `u16` phase
|
||||
write on big-endian ps3, and the `formatToString` string-value indirection. Every
|
||||
32-bit offset is grounded directly in the ps3/vita raw (not halved durango), the
|
||||
module owns no exported data global, and it pulls no ARM soft-float helper; the
|
||||
value-level behavior of the deep display-tree paths is deferred to the still-
|
||||
unbuilt display/text engine reached through the frozen import set.
|
||||
|
||||
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.
|
||||
|
||||
@@ -177,3 +177,7 @@ swf_as3_textfield 129 126 durango complete
|
||||
swf_as3_textfield 127 126 orbis complete
|
||||
swf_as3_textfield 127 126 ps3 complete
|
||||
swf_as3_textfield 127 126 vita complete
|
||||
swf_as3vm_flash_events 123 118 durango complete
|
||||
swf_as3vm_flash_events 121 118 orbis complete
|
||||
swf_as3vm_flash_events 120 118 ps3 complete
|
||||
swf_as3vm_flash_events 122 118 vita complete
|
||||
|
||||
|
393
iggy-decompiled/src/reconstructed/swf_as3vm_flash_events.c
Normal file
393
iggy-decompiled/src/reconstructed/swf_as3vm_flash_events.c
Normal file
@@ -0,0 +1,393 @@
|
||||
/*
|
||||
* swf_as3vm_flash_events.c -- source-equivalent reconstruction of Iggy
|
||||
* 1.2.30's AS3 / AVM2 flash.events binding layer: the Event, EventDispatcher,
|
||||
* FocusEvent, KeyboardEvent, Keyboard, LoaderInfo, MouseEvent, TextEvent,
|
||||
* TimerEvent and Timer classes plus the lazy-event / dispatch / clone helper
|
||||
* family. Recovered by reconciling all four Ghidra decompiles
|
||||
* (raw/{durango,orbis,ps3,vita}/swf_as3vm_flash_events.c) against the retail
|
||||
* objects work/iggy-native-decomp/<platform>-objects/swf_as3vm_flash_events.obj
|
||||
* (durango llvm-objdump -d used to resolve the jump-table / symbolic-offset
|
||||
* cases Ghidra rendered as &DAT_/&_pdata_ aliases).
|
||||
*
|
||||
* Canonical retail source path: c:\projects\g\src\flash\swf_as3vm_flash_events.c
|
||||
*
|
||||
* FOUR PLATFORMS. durango / orbis are 64-bit LE; ps3 is 32-bit BIG-ENDIAN
|
||||
* (GCC PowerPC, .opd descriptors); vita is 32-bit LE (clang ARM -mthumb).
|
||||
* Every recovered struct field byte-offset is pointer-width dependent, so all
|
||||
* offsets are expressed through the IGGY_PTR64 table below. The 64-bit values
|
||||
* come from durango/orbis raw; the 32-bit values are taken DIRECTLY from the
|
||||
* ps3/vita raw (which are byte-identical to each other -- same source, same
|
||||
* pointer width -- differing only in endianness), NOT by halving the 64-bit
|
||||
* set. ps3 and vita agree on every offset checked (Event bubbles@0x25,
|
||||
* type@0x43, keyCode@0x17, timer delay@0x1f, VM stack@0x4834, ...).
|
||||
*
|
||||
* ENDIANNESS. The only endianness-sensitive spot is Event.flags: durango
|
||||
* stores a u16 0x200 at obj+0x38 (low byte = propagation-stop bits, high byte =
|
||||
* eventPhase). On big-endian ps3 the two bytes land in the opposite lanes, so
|
||||
* the retail ps3 code writes the flag byte and the phase byte individually.
|
||||
* This reconstruction always writes the two bytes separately (flag byte := 0,
|
||||
* phase byte := 2), which is byte-identical to the durango u16 store on LE and
|
||||
* correct on BE -- gated only where a wider reinterpret would otherwise flip.
|
||||
*
|
||||
* BODY CLASSIFICATION. 118 exports on every platform. The runtime harness
|
||||
* (durango-only dylib) pins the deterministic getter/setter/mutator/constructor
|
||||
* behavior and the reject paths; the listener-table mechanics
|
||||
* (addEventListener / removeEventListener / dispatchEvent happy path,
|
||||
* dispatch_event_GC / dispatch_lazy_event_GC / dispatch_loop_GC), the toString /
|
||||
* formatToString string assembly, make_lazy_event_GC and the do_*_event_GC
|
||||
* engine entry points are reconstructed in full from the raw + object. Where a
|
||||
* path bottoms out in an unbuilt engine import (as3vm_do_func_call_*_GC,
|
||||
* as3vm_do_method_call_GC, iggy_transform, ...) the imported hook is called --
|
||||
* that is faithful, not a stub.
|
||||
*/
|
||||
|
||||
/* ---- Platform selection (one #error idiom). ------------------------------ */
|
||||
#if defined(IGGY_RECONSTRUCT_SWF_AS3VM_FLASH_EVENTS_DURANGO)
|
||||
# define IGGY_PTR64 1
|
||||
#elif defined(IGGY_RECONSTRUCT_SWF_AS3VM_FLASH_EVENTS_ORBIS)
|
||||
# define IGGY_PTR64 1
|
||||
#elif defined(IGGY_RECONSTRUCT_SWF_AS3VM_FLASH_EVENTS_PS3)
|
||||
# define IGGY_PTR64 0
|
||||
# define IGGY_BIG_ENDIAN 1
|
||||
#elif defined(IGGY_RECONSTRUCT_SWF_AS3VM_FLASH_EVENTS_VITA)
|
||||
# define IGGY_PTR64 0
|
||||
#else
|
||||
# error "define one of IGGY_RECONSTRUCT_SWF_AS3VM_FLASH_EVENTS_{DURANGO,ORBIS,PS3,VITA}"
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
#include "swf_as3vm_flash_events.h"
|
||||
|
||||
/* Provenance: the canonical Iggy source path (retail embeds this exact string
|
||||
* via iggy_malloc_fileline on all four platforms; durango additionally carries
|
||||
* its build .obj path, emitted here so both survive -O2). */
|
||||
static const char *const iggy_swf_as3vm_flash_events_source_path
|
||||
__attribute__((used)) = "c:\\projects\\g\\src\\flash\\swf_as3vm_flash_events.c";
|
||||
#if defined(IGGY_RECONSTRUCT_SWF_AS3VM_FLASH_EVENTS_DURANGO)
|
||||
static const char *const iggy_swf_as3vm_flash_events_obj_path
|
||||
__attribute__((used)) =
|
||||
"c:\\projects\\g\\build\\release\\temps\\libdu\\iggy_durango"
|
||||
"\\swf_as3vm_flash_events.obj";
|
||||
#endif
|
||||
|
||||
/* libc the retail optimizer emitted (Event/MouseEvent toString buffers,
|
||||
* dispatcher struct copies). Declared locally so a -ffreestanding -fno-builtin
|
||||
* build stays clean; both are in the tolerated libc allowlist. */
|
||||
extern void *memcpy(void *dest, const void *src, __SIZE_TYPE__ n);
|
||||
extern void *memset(void *dest, int c, __SIZE_TYPE__ n);
|
||||
|
||||
/* ---- Recovered runtime imports (satisfied by DONE sibling modules). ------ */
|
||||
extern void as3vm_exception_GC(void *vm, int code);
|
||||
extern void *as3vm_make_number_GC(void *vm, double value);
|
||||
extern void *as3vm_make_string_GC(void *vm, void *stringdata);
|
||||
extern void *as3vm_make_string_wc_GC(void *vm, void *text, int len);
|
||||
extern void *as3vm_make_stringdata_GC(void *vm, void *text, int len);
|
||||
extern void *as3vm_make_object_no_constructor_GC(void *vm, void *cls);
|
||||
extern void *as3vm_create_interleaved_string_GC(void *vm, int count, ...);
|
||||
extern void *as3vm_ToString_GC(void *vm, void *value);
|
||||
extern void *as3vm_get_public_string_GC(void *vm, void *obj, intptr_t index);
|
||||
extern void *as3vm_get_movie_as3value_GC(void *vm, void *movie);
|
||||
extern void *as3vm_string_interned(void *vm, void *text);
|
||||
extern void *as3vm_string_interned_nocreate(void *vm, void *text);
|
||||
extern int as3vm_is_ofclass(void *obj, void *cls);
|
||||
extern void as3vm_write_barrier_slowpath(void *vm, void *obj, void *value);
|
||||
extern int as3vm_component_parse_arguments_GC(void *frame, const char *fmt, ...);
|
||||
extern void as3vmcomp_set_value(void *vm, void *obj, int kind, ...);
|
||||
extern void as3vm_do_method_call_GC(void *vm, void *result, void *fn,
|
||||
void *args, int argc);
|
||||
extern void as3vm_do_func_call_vmc_GC(void *vm, void *result, void *fn,
|
||||
void *self, void *args, int argc);
|
||||
extern void as3vm_do_func_call_vv_GC(void *vm, void *result, void *fn);
|
||||
extern void *as3vm_pool_alloc(void *vm, void *arena, int size);
|
||||
extern void as3vm_pool_free(void *ptr);
|
||||
extern void iggy_free_alloc(void *arena, void *ptr);
|
||||
extern void *iggy_malloc_fileline(void *arena, int flags, int size, int tag,
|
||||
const char *file, int line);
|
||||
extern void iggy_get_o2w(void *movie, void *node, void *out);
|
||||
extern void iggy_transform(void *out_x, void *out_y, void *matrix, int value);
|
||||
extern void iggy_inverse_transform(void *out_x, void *out_y, void *matrix,
|
||||
int value);
|
||||
extern void iggy_uncaught_exception_warning(void *vm);
|
||||
extern int rr_isnan_f(float value);
|
||||
|
||||
/* DATA singletons owned by as3vm_interpreter; this module only indexes them.
|
||||
* as3vm_makebool is a table of boxed AS3 booleans indexed by a byte (entry
|
||||
* width = one pointer, so as3vm_makebool[byte] scales on both widths). The
|
||||
* "true"/"false"/"undefined" cells are the two truefalse/nullundef DATA
|
||||
* imports; retail aliased them to a single rodata run (&DAT_00009229..9239). */
|
||||
extern void *as3vm_makebool[];
|
||||
extern float as3vm_NaNf;
|
||||
extern uint8_t as3vm_truefalse_storage[];
|
||||
extern uint8_t as3vm_nullundef_storage[];
|
||||
|
||||
#define EV_FALSE_CELL ((void *)&as3vm_truefalse_storage[1]) /* DAT_9229 */
|
||||
#define EV_TRUE_CELL ((void *)&as3vm_truefalse_storage[9]) /* DAT_9231 */
|
||||
#define EV_UNDEF_CELL ((void *)&as3vm_nullundef_storage[1]) /* DAT_9239 */
|
||||
|
||||
/* ---- Pointer-width dependent recovered offsets. --------------------------
|
||||
* 64-bit: durango/orbis raw. 32-bit: ps3/vita raw (identical to each other).
|
||||
* Every 32-bit value is annotated *ps3* when read directly from the ps3/vita
|
||||
* decompile or *derived* when reconstructed from a sibling field. */
|
||||
#if IGGY_PTR64
|
||||
/* Event base fields (obj = *this_slot; native state stored directly). */
|
||||
# define EV_BUBBLES 0x35
|
||||
# define EV_CANCELABLE 0x36
|
||||
# define EV_DEFPREV 0x37
|
||||
# define EV_FLAGS 0x38 /* u16: low byte stop-bits, high byte phase. */
|
||||
# define EV_PHASE 0x39 /* == EV_FLAGS + 1. */
|
||||
# define EV_LAZYCLONE 0x3a
|
||||
# define EV_TYPE 0x57
|
||||
/* Input-event extended fields. */
|
||||
# define EV_KEYCODE 0x27 /* Focus/Keyboard keyCode int. */
|
||||
# define EV_CHARCODE 0x2b /* KeyboardEvent charCode int. */
|
||||
# define EV_KEYLOCATION 0x2f /* KeyboardEvent keyLocation byte. */
|
||||
# define EV_ALTKEY 0x30
|
||||
# define EV_COMMANDKEY 0x31
|
||||
# define EV_CONTROLKEY 0x32
|
||||
# define EV_SHIFTKEY 0x33
|
||||
# define EV_LOCALX 0x3b /* MouseEvent localX float. */
|
||||
# define EV_LOCALY 0x3f /* MouseEvent localY float. */
|
||||
# define EV_CLICKCOUNT 0x43 /* MouseEvent clickCount short. */
|
||||
# define EV_DELTA 0x45 /* MouseEvent delta short. */
|
||||
# define EV_BUTTONDOWN 0x47
|
||||
/* Timer fields. */
|
||||
# define TM_ELAPSED 0x3f /* double. */
|
||||
# define TM_DELAY 0x37 /* double. */
|
||||
# define TM_CURRENTCOUNT 0x47 /* int. */
|
||||
# define TM_REPEATCOUNT 0x4b /* int. */
|
||||
# define TM_RUNNING 0x4f /* int. */
|
||||
# define TM_NEXT 0x57 /* timer-list link (reuses the type slot). */
|
||||
/* Object header / slot descriptor. */
|
||||
# define OFF_CLSREC 7 /* obj -> class record (packed; both widths).*/
|
||||
# define SLOT_TAB 0x58 /* class record -> AS3 slot descriptor table.*/
|
||||
/* Listener node struct (allocated by addEventListener). */
|
||||
# define ND_KEY 0x00 /* node[0] interned type key. */
|
||||
# define ND_LISTBYBUB 0x18 /* node[3] capture-phase (useCapture) head. */
|
||||
# define ND_LISTBYCAP 0x20 /* node[4] bubble/target-phase head. */
|
||||
# define ND_CHAINNEXT 0x28 /* node[5] next node (same table). */
|
||||
# define ND_COUNT 0x0c /* listener count (int). */
|
||||
# define ND_GROUP_ARENA 0x10 /* node[2] pool arena. */
|
||||
# define ND_CLEANNEXT 0x40 /* cleanup-list link. */
|
||||
# define ND_DEAD 0x48 /* "dead" flag byte. */
|
||||
# define ND_ALLOC 0x50 /* listener-node malloc size (raw:820). */
|
||||
# define LE_ALLOC 0x20 /* listener-entry malloc size (raw:863). */
|
||||
/* Listener entry struct. */
|
||||
# define LE_HANDLE 0x00 /* entry[0] boxed listener value. */
|
||||
# define LE_SELF 0x08 /* entry[1] method self / bound this. */
|
||||
# define LE_NEXT 0x10 /* entry[2] next entry. */
|
||||
# define LE_PRIO 0x18 /* priority int. */
|
||||
# define LE_PHASE 0x1c /* dispatch generation short. */
|
||||
# define LE_USECAP 0x1e /* useCapture byte. */
|
||||
/* VM-relative offsets. */
|
||||
# define VM_STACK 0x6b18 /* value-stack pointer. */
|
||||
# define VM_CLEANLIST 0xd20 /* cleanup-list head. */
|
||||
# define VM_DEPTH 0xd30 /* dispatch depth counter (short). */
|
||||
# define VM_DIRECTCNT 0xd33 /* direct-listener count byte. */
|
||||
# define VM_TYPEFALLBACK 0x27a1 /* default type string base. */
|
||||
# define VM_EMPTYSTR 0xe18 /* cached empty-string cell. */
|
||||
# define VM_LISTENER 0xf0 /* listener tables (base; + byte * word). */
|
||||
# define VM_EVENTNAMES 0x520 /* event-type name pool (+ byte * word). */
|
||||
# define VM_TIMERNAMES 0x698 /* timer-event name pool. */
|
||||
# define VM_EVENTCLASS 0x25d0 /* flash.events.Event class slot. */
|
||||
# define VM_TIMEREVCLASS 0x25c0 /* TimerEvent class slot. */
|
||||
# define VM_KBEVCLASS 0x26a8 /* KeyboardEvent class slot (KEY_DOWN path). */
|
||||
# define VM_KBEVCLASS2 0x26b8 /* KeyboardEvent class slot (other path). */
|
||||
# define VM_MOUSECLASS 0x26b0 /* MouseEvent class slot (toString vm[0x4d6]).*/
|
||||
# define VM_FOCUSCLASS 0x26c0 /* FocusEvent class slot (toString vm[0x4d8]).*/
|
||||
# define VM_MODKEYS 0x2970 /* live modifier-key byte quad. */
|
||||
# define VM_EXCFLAG 0x2908 /* pending-exception flag (vm[0x521]). */
|
||||
# define VM_CLONEMETHOD 0x6e40 /* Event.clone bound method. */
|
||||
# define VM_DEFAULTOBJ 0x2650 /* default relatedObject cell. */
|
||||
# define VM_TIMERLIST 0x88 /* active-timer list head. */
|
||||
# define VM_LOADERPARAMS 0x2618 /* LoaderInfo.parameters object class. */
|
||||
# define EV_DIRECTLIST 0x2f /* dispatcher obj -> direct-listener head. */
|
||||
# define EV_TYPEPHASE 0x2a /* interned type -> phase-type index byte. */
|
||||
# define CLS_CLONECLASS 0x20 /* class record -> instance class (clone). */
|
||||
# define LZ_CLASS 0x60 /* lazy scratch -> event class. */
|
||||
# define LZ_TYPE 0x58 /* lazy scratch -> interned type. */
|
||||
# define LZ_FLD0 0x28 /* lazy scratch -> first copied field. */
|
||||
# define LZ_CANCELABLE 0x36 /* lazy scratch -> cancelable byte. */
|
||||
# define LZ_DEFPREV 0x37 /* lazy scratch -> defaultPrevented byte. */
|
||||
# define LZ_MODKEY 0x2c /* lazy scratch -> modifier-key char. */
|
||||
# define LZ_BYTES 0x68 /* lazy scratch struct size (memset). */
|
||||
#else /* 32-bit (ps3 / vita). */
|
||||
# define EV_BUBBLES 0x25 /* *ps3* */
|
||||
# define EV_CANCELABLE 0x26 /* *ps3* */
|
||||
# define EV_DEFPREV 0x27 /* *ps3* */
|
||||
# define EV_FLAGS 0x28 /* *ps3* (stopPropagation byte). */
|
||||
# define EV_PHASE 0x29 /* *ps3* (get_eventPhase byte). */
|
||||
# define EV_LAZYCLONE 0x2a /* *ps3* */
|
||||
# define EV_TYPE 0x43 /* *ps3* */
|
||||
# define EV_KEYCODE 0x17 /* *ps3* */
|
||||
# define EV_CHARCODE 0x1b /* *ps3* */
|
||||
# define EV_KEYLOCATION 0x1f /* *ps3* */
|
||||
# define EV_ALTKEY 0x20 /* *ps3* */
|
||||
# define EV_COMMANDKEY 0x21 /* *ps3* */
|
||||
# define EV_CONTROLKEY 0x22 /* *ps3* */
|
||||
# define EV_SHIFTKEY 0x23 /* *ps3* */
|
||||
# define EV_LOCALX 0x2b /* *ps3* (MouseEvent construct) */
|
||||
# define EV_LOCALY 0x2f /* *ps3* */
|
||||
# define EV_CLICKCOUNT 0x33 /* *ps3* */
|
||||
# define EV_DELTA 0x35 /* *ps3* */
|
||||
# define EV_BUTTONDOWN 0x37 /* *ps3* */
|
||||
# define TM_ELAPSED 0x27 /* *ps3* (Timer_stop / reset) */
|
||||
# define TM_DELAY 0x1f /* *ps3* (Timer_set_delay) */
|
||||
# define TM_CURRENTCOUNT 0x2f /* *ps3* */
|
||||
# define TM_REPEATCOUNT 0x33 /* *ps3* */
|
||||
# define TM_RUNNING 0x37 /* *ps3* */
|
||||
# define TM_NEXT 0x3b /* *ps3* (Timer__construct list link) */
|
||||
# define OFF_CLSREC 7 /* *ps3* */
|
||||
# define SLOT_TAB 0x34 /* *ps3* */
|
||||
# define ND_KEY 0x00 /* *ps3* */
|
||||
# define ND_LISTBYBUB 0x10 /* *ps3* (node[4]; dispatch_event_local:1304)*/
|
||||
# define ND_LISTBYCAP 0x14 /* *ps3* (node[5]; hasEventListener:965) */
|
||||
# define ND_CHAINNEXT 0x18 /* *ps3* (node[6]; hasEventListener:961) */
|
||||
# define ND_COUNT 0x08 /* *ps3* (node[2]; addEventListener:2311) */
|
||||
# define ND_GROUP_ARENA 0x0c /* *ps3* (node[3]) */
|
||||
# define ND_CLEANNEXT 0x24 /* *ps3* (needs_cleaning) */
|
||||
# define ND_DEAD 0x2c /* *derived* */
|
||||
# define ND_ALLOC 0x2c /* *ps3* (addEventListener malloc 0x2c) */
|
||||
# define LE_ALLOC 0x14 /* *ps3* (addEventListener malloc 0x14) */
|
||||
# define LE_HANDLE 0x00 /* *ps3* */
|
||||
# define LE_SELF 0x04 /* *derived* */
|
||||
# define LE_NEXT 0x08 /* *ps3* (entry[2] via piVar[2]) */
|
||||
# define LE_PRIO 0x0c /* *derived* */
|
||||
# define LE_PHASE 0x10 /* *derived* */
|
||||
# define LE_USECAP 0x12 /* *derived* */
|
||||
# define VM_STACK 0x4834 /* *ps3* (end_lazy_event) */
|
||||
# define VM_CLEANLIST 0x8b0 /* *ps3* (needs_cleaning) */
|
||||
# define VM_DEPTH 0x8b8 /* *ps3* (do_direct depth) */
|
||||
# define VM_DIRECTCNT 0x8bb /* *derived* (depth + 3) */
|
||||
# define VM_TYPEFALLBACK 0x1615 /* *ps3* (get_type fallback) */
|
||||
# define VM_EMPTYSTR 0x948 /* *ps3* (TextEvent construct default) */
|
||||
# define VM_LISTENER 0x98 /* *ps3* (hasEventListener / do_direct) */
|
||||
# define VM_EVENTNAMES 0x4b0 /* *ps3* (do_event) */
|
||||
# define VM_TIMERNAMES 0x56c /* *vita* (2444: names 0x4b0 + 0x2f*4, which=0)*/
|
||||
# define VM_EVENTCLASS 0x1528 /* *ps3* (dispatchEvent is_ofclass) */
|
||||
# define VM_TIMEREVCLASS 0x1520 /* *derived* */
|
||||
# define VM_KBEVCLASS 0x1594 /* *ps3* (do_keyboard / make_lazy) */
|
||||
# define VM_KBEVCLASS2 0x159c /* *ps3* (do_keyboard) */
|
||||
# define VM_MOUSECLASS 0x1598 /* *obj* (vita Event_toString vm[0x566]) */
|
||||
# define VM_FOCUSCLASS 0x1560 /* *obj* (vita Event_toString vm[0x568]) */
|
||||
# define VM_MODKEYS 0x2258 /* *ps3* (make_lazy_event modifier quad) */
|
||||
# define VM_EXCFLAG 0x16e8 /* *ps3* (vm[0x5ba]; dispatch_loop:451) */
|
||||
# define VM_CLONEMETHOD 0x920 /* *ps3* (clone_GC / dispatchEvent) */
|
||||
# define VM_DEFAULTOBJ 0x1568 /* *ps3* (FocusEvent construct default) */
|
||||
# define VM_TIMERLIST 0x4c /* *ps3* (Timer__construct list link) */
|
||||
# define VM_LOADERPARAMS 0x167c /* *ps3* (LoaderInfo_get_parameters) */
|
||||
# define EV_DIRECTLIST 0x1b /* *ps3* (removeEventListener direct head) */
|
||||
# define EV_TYPEPHASE 0x1a /* *ps3* (hasEventListener phase byte) */
|
||||
# define CLS_CLONECLASS 0x18 /* *ps3* (Event_clone new class) */
|
||||
# define LZ_CLASS 0x48 /* *ps3* (make_lazy scratch class) */
|
||||
# define LZ_TYPE 0x44 /* *ps3* (make_lazy scratch type) */
|
||||
# define LZ_FLD0 0x18 /* *ps3* (make_lazy first copied field) */
|
||||
# define LZ_CANCELABLE 0x26 /* *ps3* (prep_lazy cancelable) */
|
||||
# define LZ_DEFPREV 0x27 /* *ps3* (prep_lazy defaultPrevented) */
|
||||
# define LZ_MODKEY 0x1c /* *derived* */
|
||||
# define LZ_BYTES 0x4c /* *ps3* (prep_lazy memset) */
|
||||
#endif
|
||||
|
||||
/* String-object header offsets (packed; identical on 32 / 64-bit): char count
|
||||
* at +STR_HDR, UTF-16 char data at +STR_DATA. */
|
||||
#define STR_HDR 7
|
||||
#define STR_DATA 0xb
|
||||
|
||||
/* On big-endian ps3 a packed multi-byte reinterpret lands in the opposite lane;
|
||||
* the module only reinterprets Event.flags, which we always write byte-wise. */
|
||||
|
||||
/* ---- Frame / field access helpers (auto-scale with pointer width). --------
|
||||
* frame[0]=vm, frame[1]=&result, frame[2]=argc, frame[3]=&this-slot,
|
||||
* frame[4]=&extra. Indexing a void ** by n gives n*sizeof(void*), i.e. the
|
||||
* native frame stride (8 on 64-bit, 4 on 32-bit). */
|
||||
#define FR(p) ((void **)(p))
|
||||
#define VM(p) (FR(p)[0])
|
||||
#define RESULT(p) (FR(p)[1])
|
||||
#define ARGC(p) ((int)((intptr_t *)(p))[2])
|
||||
#define THISOBJ(p) (*(void **)FR(p)[3])
|
||||
#define AT(base, off) ((char *)(void *)(base) + (off))
|
||||
|
||||
/* Box writers into *frame[1]. */
|
||||
static inline void store_ptr(void *frame, void *value) {
|
||||
*(void **)RESULT(frame) = value;
|
||||
}
|
||||
static inline void store_word(void *frame, intptr_t value) {
|
||||
*(intptr_t *)RESULT(frame) = value;
|
||||
}
|
||||
|
||||
/* as3vm_makebool[byte] -- the boxed AS3 boolean for a 0/1 (or any) byte. */
|
||||
static inline void *ev_makebool(unsigned byte_value) {
|
||||
return as3vm_makebool[byte_value];
|
||||
}
|
||||
|
||||
/* Box a signed-integer field as an AS3 small int (value << 1, the int tag). */
|
||||
static inline void store_astag(void *frame, int32_t value) {
|
||||
store_word(frame, (intptr_t)((uint32_t)value * 2u));
|
||||
}
|
||||
|
||||
/* Widen a stored float to double for as3vm_make_number_GC (recurring). */
|
||||
static inline double ev_float_to_double(float value) { return (double)value; }
|
||||
|
||||
/* ---- parse_arguments format literals. The retail durango ??_C@ COMDATs; the
|
||||
* as3_component_helpers grammar is one spec char per argument ('?' = optional,
|
||||
* 'I' = interned string, 'b' = Boolean, 'u' = uint, 'd' = int, 'f' = Number,
|
||||
* 'F' = float, 's' = String, 'O' = Object). Exact spec bytes are not runtime-
|
||||
* or ABI-validated (see residuals); the argument shape is reconstructed from
|
||||
* the recovered out-slot marshalling. */
|
||||
#define EVFMT_EVENT "I?b?b"
|
||||
#define EVFMT_FOCUS "I?b?b?O?b?u"
|
||||
#define EVFMT_KEYBOARD "s?b?b?u?u?u?b?b?b?b?b"
|
||||
#define EVFMT_MOUSE "s?b?b?F?F?O?b?b?b?b?d?b?d?b"
|
||||
#define EVFMT_TEXT "I?b?b?s"
|
||||
#define EVFMT_TIMER "f?d"
|
||||
#define EVFMT_INTERN "I"
|
||||
#define EVFMT_INTERN_BOOL "I?b"
|
||||
#define EVFMT_BOOL "b"
|
||||
#define EVFMT_UINT "u"
|
||||
#define EVFMT_INT "d"
|
||||
#define EVFMT_FLOAT "F"
|
||||
#define EVFMT_NUMBER "f"
|
||||
#define EVFMT_STRING "s"
|
||||
#define EVFMT_OBJECT "O"
|
||||
|
||||
/* ---- File-static dispatch helpers (defined in the .inc units). ----------- */
|
||||
static unsigned char dispatch_event_GC(void *vm, void *event, void *dispatcher,
|
||||
void *type, int allow_capture);
|
||||
static int dispatch_event_local_GC(void *vm, void *node, void *event,
|
||||
int capture, void *type);
|
||||
static uintptr_t dispatch_lazy_event_GC(void *vm, void *scratch,
|
||||
void *dispatcher, void *target,
|
||||
int32_t *out_handled);
|
||||
static void *dispatch_loop_GC(void *vm, void *entry, void *node, void *event,
|
||||
unsigned generation);
|
||||
static void setup_event(void *vm, void *event, unsigned char phase,
|
||||
void *target);
|
||||
|
||||
/* Read the AS3 currentTarget/target/relatedObject value for `obj` through its
|
||||
* class slot descriptor (slot index at classrec->slottab + `delta`). */
|
||||
static void *ev_slot_value(void *obj, int delta) {
|
||||
void *clsrec = *(void **)AT(obj, OFF_CLSREC);
|
||||
void *desc = *(void **)AT(clsrec, SLOT_TAB);
|
||||
uint16_t slot = *(uint16_t *)AT(desc, delta);
|
||||
return *(void **)((char *)obj + (intptr_t)slot - 1);
|
||||
}
|
||||
|
||||
/* Push one word onto the VM value stack (vm+VM_STACK) and advance it. */
|
||||
static inline void ev_push(void *vm, void *value) {
|
||||
void **sp = *(void ***)AT(vm, VM_STACK);
|
||||
*sp = value;
|
||||
*(void ***)AT(vm, VM_STACK) = sp + 1;
|
||||
}
|
||||
|
||||
/* Pop the VM value stack by one word. */
|
||||
static inline void ev_pop(void *vm) {
|
||||
void **sp = *(void ***)AT(vm, VM_STACK);
|
||||
*(void ***)AT(vm, VM_STACK) = sp - 1;
|
||||
}
|
||||
|
||||
/* ---- Reconstructed bodies (split into feature .inc units, < 800 lines). --- */
|
||||
#include "swf_as3vm_flash_events_event.inc"
|
||||
#include "swf_as3vm_flash_events_inputevents.inc"
|
||||
#include "swf_as3vm_flash_events_timer.inc"
|
||||
#include "swf_as3vm_flash_events_eventdispatcher.inc"
|
||||
#include "swf_as3vm_flash_events_dispatch.inc"
|
||||
#include "swf_as3vm_flash_events_doevents.inc"
|
||||
185
iggy-decompiled/src/reconstructed/swf_as3vm_flash_events.h
Normal file
185
iggy-decompiled/src/reconstructed/swf_as3vm_flash_events.h
Normal file
@@ -0,0 +1,185 @@
|
||||
/*
|
||||
* swf_as3vm_flash_events.h -- reconstructed public ABI for Iggy 1.2.30's AS3 /
|
||||
* AVM2 flash.events binding layer: the Event, EventDispatcher, FocusEvent,
|
||||
* KeyboardEvent, Keyboard, LoaderInfo, MouseEvent, TextEvent, TimerEvent and
|
||||
* Timer classes plus the lazy-event / dispatch / clone helpers
|
||||
* (as3vm_make_lazy_event_GC, as3vm_clone_GC, as3vm_do_*_event_GC,
|
||||
* as3vm_ev_setbool, as3vm_needs_cleaning, as3vm_end_lazy_event,
|
||||
* as3vm_prep_lazy_event, as3vm_clean_listeners, as3vm_clear_direct_listeners).
|
||||
*
|
||||
* Exactly 118 externally visible entry points on all four platforms
|
||||
* (durango / orbis / ps3 / vita). The per-platform source_functions count is
|
||||
* larger (123 durango / 121 orbis / 120 ps3 / 122 vita) because each Ghidra
|
||||
* decompile keeps a different subset of the file-static dispatch helpers
|
||||
* (dispatch_event_GC / dispatch_lazy_event_GC / dispatch_loop_GC /
|
||||
* dispatch_event_local_GC / setup_event) as separate functions; those are NOT
|
||||
* part of the exported ABI.
|
||||
*
|
||||
* Canonical retail source path (embedded for provenance):
|
||||
* c:\projects\g\src\flash\swf_as3vm_flash_events.c
|
||||
*
|
||||
* C11 and C++17 includable; all entry points are C-linkage.
|
||||
*/
|
||||
#ifndef IGGY_RECONSTRUCTED_SWF_AS3VM_FLASH_EVENTS_H
|
||||
#define IGGY_RECONSTRUCTED_SWF_AS3VM_FLASH_EVENTS_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* flash.events.EventDispatcher. */
|
||||
void as3vm_EventDispatcher__construct(void *frame);
|
||||
void as3vm_EventDispatcher__finalize(void *frame);
|
||||
void as3vm_EventDispatcher_addEventListener(void *frame);
|
||||
void as3vm_EventDispatcher_dispatchEvent(void *frame);
|
||||
void as3vm_EventDispatcher_hasEventListener(void *frame);
|
||||
void as3vm_EventDispatcher_removeEventListener(void *frame);
|
||||
void as3vm_EventDispatcher_willTrigger(void *frame);
|
||||
|
||||
/* flash.events.Event. */
|
||||
void as3vm_Event__construct(void *frame);
|
||||
void as3vm_Event_clone(void *frame);
|
||||
void as3vm_Event_formatToString(void *frame);
|
||||
void as3vm_Event_get_bubbles(void *frame);
|
||||
void as3vm_Event_get_cancelable(void *frame);
|
||||
void as3vm_Event_get_currentTarget(void *frame);
|
||||
void as3vm_Event_get_eventPhase(void *frame);
|
||||
void as3vm_Event_get_target(void *frame);
|
||||
void as3vm_Event_get_type(void *frame);
|
||||
void as3vm_Event_isDefaultPrevented(void *frame);
|
||||
void as3vm_Event_preventDefault(void *frame);
|
||||
void as3vm_Event_stopImmediatePropagation(void *frame);
|
||||
void as3vm_Event_stopPropagation(void *frame);
|
||||
void as3vm_Event_toString(void *frame);
|
||||
|
||||
/* flash.events.FocusEvent. */
|
||||
void as3vm_FocusEvent__construct(void *frame);
|
||||
void as3vm_FocusEvent_clone(void *frame);
|
||||
void as3vm_FocusEvent_get_keyCode(void *frame);
|
||||
void as3vm_FocusEvent_get_relatedObject(void *frame);
|
||||
void as3vm_FocusEvent_get_shiftKey(void *frame);
|
||||
void as3vm_FocusEvent_set_keyCode(void *frame);
|
||||
void as3vm_FocusEvent_set_relatedObject(void *frame);
|
||||
void as3vm_FocusEvent_set_shiftKey(void *frame);
|
||||
|
||||
/* flash.events.KeyboardEvent. */
|
||||
void as3vm_KeyboardEvent__construct(void *frame);
|
||||
void as3vm_KeyboardEvent_clone(void *frame);
|
||||
void as3vm_KeyboardEvent_get_altKey(void *frame);
|
||||
void as3vm_KeyboardEvent_get_charCode(void *frame);
|
||||
void as3vm_KeyboardEvent_get_commandKey(void *frame);
|
||||
void as3vm_KeyboardEvent_get_controlKey(void *frame);
|
||||
void as3vm_KeyboardEvent_get_ctrlKey(void *frame);
|
||||
void as3vm_KeyboardEvent_get_keyCode(void *frame);
|
||||
void as3vm_KeyboardEvent_get_keyLocation(void *frame);
|
||||
void as3vm_KeyboardEvent_get_shiftKey(void *frame);
|
||||
void as3vm_KeyboardEvent_set_altKey(void *frame);
|
||||
void as3vm_KeyboardEvent_set_charCode(void *frame);
|
||||
void as3vm_KeyboardEvent_set_commandKey(void *frame);
|
||||
void as3vm_KeyboardEvent_set_controlKey(void *frame);
|
||||
void as3vm_KeyboardEvent_set_ctrlKey(void *frame);
|
||||
void as3vm_KeyboardEvent_set_keyCode(void *frame);
|
||||
void as3vm_KeyboardEvent_set_keyLocation(void *frame);
|
||||
void as3vm_KeyboardEvent_set_shiftKey(void *frame);
|
||||
void as3vm_KeyboardEvent_toString(void *frame);
|
||||
void as3vm_KeyboardEvent_updateAfterEvent(void *frame);
|
||||
|
||||
/* flash.ui.Keyboard. */
|
||||
void as3vm_Keyboard__construct(void *frame);
|
||||
void as3vm_Keyboard_get_capsLock(void *frame);
|
||||
void as3vm_Keyboard_get_numLock(void *frame);
|
||||
void as3vm_Keyboard_isAccessible(void *frame);
|
||||
|
||||
/* flash.display.LoaderInfo. */
|
||||
void as3vm_LoaderInfo__construct(void *frame);
|
||||
void as3vm_LoaderInfo_get_bytes(void *frame);
|
||||
void as3vm_LoaderInfo_get_bytesLoaded(void *frame);
|
||||
void as3vm_LoaderInfo_get_bytesTotal(void *frame);
|
||||
void as3vm_LoaderInfo_get_parameters(void *frame);
|
||||
void as3vm_LoaderInfo_get_url(void *frame);
|
||||
|
||||
/* flash.events.MouseEvent. */
|
||||
void as3vm_MouseEvent__construct(void *frame);
|
||||
void as3vm_MouseEvent_get_altKey(void *frame);
|
||||
void as3vm_MouseEvent_get_buttonDown(void *frame);
|
||||
void as3vm_MouseEvent_get_clickCount(void *frame);
|
||||
void as3vm_MouseEvent_get_commandKey(void *frame);
|
||||
void as3vm_MouseEvent_get_controlKey(void *frame);
|
||||
void as3vm_MouseEvent_get_ctrlKey(void *frame);
|
||||
void as3vm_MouseEvent_get_delta(void *frame);
|
||||
void as3vm_MouseEvent_get_localX(void *frame);
|
||||
void as3vm_MouseEvent_get_localY(void *frame);
|
||||
void as3vm_MouseEvent_get_relatedObject(void *frame);
|
||||
void as3vm_MouseEvent_get_shiftKey(void *frame);
|
||||
void as3vm_MouseEvent_get_stageX(void *frame);
|
||||
void as3vm_MouseEvent_get_stageY(void *frame);
|
||||
void as3vm_MouseEvent_set_altKey(void *frame);
|
||||
void as3vm_MouseEvent_set_buttonDown(void *frame);
|
||||
void as3vm_MouseEvent_set_commandKey(void *frame);
|
||||
void as3vm_MouseEvent_set_controlKey(void *frame);
|
||||
void as3vm_MouseEvent_set_ctrlKey(void *frame);
|
||||
void as3vm_MouseEvent_set_delta(void *frame);
|
||||
void as3vm_MouseEvent_set_localX(void *frame);
|
||||
void as3vm_MouseEvent_set_localY(void *frame);
|
||||
void as3vm_MouseEvent_set_relatedObject(void *frame);
|
||||
void as3vm_MouseEvent_set_shiftKey(void *frame);
|
||||
void as3vm_MouseEvent_updateAfterEvent(void *frame);
|
||||
|
||||
/* flash.events.TextEvent. */
|
||||
void as3vm_TextEvent__construct(void *frame);
|
||||
void as3vm_TextEvent_clone(void *frame);
|
||||
void as3vm_TextEvent_get_text(void *frame);
|
||||
void as3vm_TextEvent_set_text(void *frame);
|
||||
void as3vm_TextEvent_toString(void *frame);
|
||||
|
||||
/* flash.events.TimerEvent. */
|
||||
void as3vm_TimerEvent__construct(void *frame);
|
||||
void as3vm_TimerEvent_clone(void *frame);
|
||||
void as3vm_TimerEvent_toString(void *frame);
|
||||
void as3vm_TimerEvent_updateAfterEvent(void *frame);
|
||||
|
||||
/* flash.utils.Timer. */
|
||||
void as3vm_Timer__construct(void *frame);
|
||||
void as3vm_Timer_get_currentCount(void *frame);
|
||||
void as3vm_Timer_get_delay(void *frame);
|
||||
void as3vm_Timer_get_repeatCount(void *frame);
|
||||
void as3vm_Timer_get_running(void *frame);
|
||||
void as3vm_Timer_reset(void *frame);
|
||||
void as3vm_Timer_set_delay(void *frame);
|
||||
void as3vm_Timer_set_repeatCount(void *frame);
|
||||
void as3vm_Timer_start(void *frame);
|
||||
void as3vm_Timer_stop(void *frame);
|
||||
|
||||
/* Listener-table maintenance + lazy-event / dispatch / clone helpers. These are
|
||||
* exported (part of the 118) but are not frame-shaped VM thunks; the engine
|
||||
* calls them directly. */
|
||||
void as3vm_clean_listeners(void *vm);
|
||||
void as3vm_clear_direct_listeners(void *vm);
|
||||
void *as3vm_clone_GC(void *vm, void *value);
|
||||
void as3vm_do_direct_event_GC(void *vm, int index);
|
||||
int as3vm_do_displayobject_event_GC(void *vm, void *obj, unsigned char index,
|
||||
unsigned char flag);
|
||||
int as3vm_do_event_GC(void *vm, void *obj, unsigned char index,
|
||||
unsigned char flag);
|
||||
void as3vm_do_event_timer_GC(void *vm, void *obj, int which);
|
||||
void as3vm_do_focus_event_GC(void *vm, void *obj, uintptr_t index,
|
||||
void *related, int32_t param, unsigned char flag);
|
||||
void as3vm_do_keyboard_event_GC(void *vm, void *obj, unsigned char index,
|
||||
int32_t a, int32_t b, unsigned char flag);
|
||||
void as3vm_do_mouse_event_GC(void *vm, void *point, void *node, uintptr_t index,
|
||||
void *related, unsigned char flag, void *extra);
|
||||
void as3vm_end_lazy_event(void *vm);
|
||||
void as3vm_ev_setbool(void *frame, int field);
|
||||
void *as3vm_make_lazy_event_GC(void *vm, void *scratch);
|
||||
void as3vm_needs_cleaning(void *vm, void *node);
|
||||
void as3vm_prep_lazy_event(void *scratch, void *vm, void *cls, void *type,
|
||||
unsigned char cancelable, unsigned char def_prevented,
|
||||
void *value);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /* IGGY_RECONSTRUCTED_SWF_AS3VM_FLASH_EVENTS_H */
|
||||
@@ -0,0 +1,612 @@
|
||||
/*
|
||||
* swf_as3vm_flash_events_dispatch.inc -- the lazy-event / clone / dispatch
|
||||
* helper family plus the file-static three-phase dispatch machinery. The
|
||||
* simple helpers (ev_setbool, needs_cleaning, end_lazy_event) are pinned by the
|
||||
* runtime harness; the propagation machinery is reconstructed from the durango
|
||||
* raw (authoritative 64-bit) + object and bottoms out in the engine call
|
||||
* imports. Included by swf_as3vm_flash_events.c.
|
||||
*/
|
||||
|
||||
/* Display-node fields walked during propagation, plus the dispatcher's display
|
||||
* node handle. DN_VALUE holds the node's boxed AS3 value; ND_PARENT the parent
|
||||
* transform; DN_GEN a re-entrancy counter (short); DN_FLAGS the "leaf" byte. */
|
||||
#if IGGY_PTR64
|
||||
# define MV_VALUESLOT 0x20 /* iggy_get_movie_as3value_GC output slot. */
|
||||
# define DISP_NODE 0x27 /* dispatcher obj -> display node. */
|
||||
# define DN_VALUE 0x20 /* display node -> boxed AS3 value. */
|
||||
# define ND_PARENT 0x80 /* display node -> parent transform. */
|
||||
#else
|
||||
# define MV_VALUESLOT 0x14 /* *ps3* (do_focus) */
|
||||
# define DISP_NODE 0x17 /* *vita* (dispatch_event_GC:534) */
|
||||
# define DN_VALUE 0x14 /* *vita* (dispatch_event_GC:569) */
|
||||
# define ND_PARENT 0x44 /* *vita* (dispatch_event_GC:535) */
|
||||
#endif
|
||||
#define DN_GEN 6 /* display node re-entrancy counter (short). */
|
||||
#define DN_FLAGS 1 /* display node leaf/skip flag byte. */
|
||||
|
||||
/* Lazy-event scratch offsets for the extended input-event fields (each is the
|
||||
* event field offset + 1, since make_lazy copies scratch+N -> obj+N-1; grounded
|
||||
* from vita do_keyboard:2760-2797 / do_mouse:2638-2674). */
|
||||
#if IGGY_PTR64
|
||||
# define SC_KEYCODE 0x28 /* = LZ_FLD0; Focus/Keyboard keyCode. */
|
||||
# define SC_CHARCODE 0x2c /* Keyboard charCode. */
|
||||
# define SC_KEYLOCATION 0x30 /* Keyboard keyLocation. */
|
||||
# define SC_LOCALX 0x3c /* Mouse localX (float). */
|
||||
# define SC_LOCALY 0x40 /* Mouse localY (float). */
|
||||
# define SC_CLICKCOUNT 0x44 /* Mouse clickCount (short). */
|
||||
# define SC_DELTA 0x46 /* Mouse delta (short). */
|
||||
# define SC_BUTTONDOWN 0x48 /* Mouse buttonDown (byte). */
|
||||
# define SC_MOUSEFLAG 0x49 /* Mouse "has value" marker byte (:=1). */
|
||||
#else
|
||||
# define SC_KEYCODE 0x18 /* *vita* (do_focus:2733 / do_keyboard:2797) */
|
||||
# define SC_CHARCODE 0x1c /* *vita* (do_keyboard:2795) */
|
||||
# define SC_KEYLOCATION 0x20 /* *vita* (do_keyboard:2796) */
|
||||
# define SC_LOCALX 0x2c /* *vita* (do_mouse:2676) */
|
||||
# define SC_LOCALY 0x30 /* *vita* (do_mouse:2677) */
|
||||
# define SC_CLICKCOUNT 0x34 /* *vita* (do_mouse:2671) */
|
||||
# define SC_DELTA 0x36 /* *vita* (do_mouse:2672) */
|
||||
# define SC_BUTTONDOWN 0x38 /* *vita* (do_mouse:2670) */
|
||||
# define SC_MOUSEFLAG 0x39 /* *vita* (do_mouse:2673) */
|
||||
#endif
|
||||
|
||||
/* Listener-node cleanup helper shared by dispatch_loop_GC and
|
||||
* removeEventListener (link the node into the VM cleanup list once). */
|
||||
static void ev_link_cleanup(void *vm, void *node) {
|
||||
if (*(void **)AT(node, ND_CLEANNEXT) == (void *)0) {
|
||||
*(void **)AT(node, ND_CLEANNEXT) = *(void **)AT(vm, VM_CLEANLIST);
|
||||
*(void **)AT(vm, VM_CLEANLIST) = node;
|
||||
}
|
||||
}
|
||||
|
||||
/* ---- Pinned helpers ------------------------------------------------------ */
|
||||
|
||||
/* Real: pop the VM value stack by one word (raw:3135-3138). */
|
||||
void as3vm_end_lazy_event(void *vm) { ev_pop(vm); }
|
||||
|
||||
/* Real: parse a bool and write it at obj-1+field (raw:3146-3157). */
|
||||
void as3vm_ev_setbool(void *frame, int field) {
|
||||
uint8_t v[16];
|
||||
if (as3vm_component_parse_arguments_GC(frame, EVFMT_BOOL, v) != 0) {
|
||||
as3vm_exception_GC(VM(frame), 0x78);
|
||||
return;
|
||||
}
|
||||
*(uint8_t *)((char *)THISOBJ(frame) - 1 + field) = v[0];
|
||||
}
|
||||
|
||||
/* Real: link a node into the VM cleanup list iff not already linked
|
||||
* (raw:3206-3212). */
|
||||
void as3vm_needs_cleaning(void *vm, void *node) { ev_link_cleanup(vm, node); }
|
||||
|
||||
/* Real: prep a lazy-event scratch struct (raw:3220-3235). */
|
||||
void as3vm_prep_lazy_event(void *scratch, void *vm, void *cls, void *type,
|
||||
unsigned char cancelable, unsigned char def_prevented,
|
||||
void *value) {
|
||||
void *intern;
|
||||
memset(scratch, 0, LZ_BYTES);
|
||||
intern = as3vm_string_interned(vm, type);
|
||||
*(void **)AT(scratch, LZ_CLASS) = cls;
|
||||
*(void **)AT(scratch, LZ_TYPE) = intern;
|
||||
*(uint8_t *)AT(scratch, LZ_CANCELABLE) = cancelable;
|
||||
*(uint8_t *)AT(scratch, LZ_DEFPREV) = def_prevented;
|
||||
ev_push(vm, value);
|
||||
}
|
||||
|
||||
/* Real: clone an AS3 value by calling its bound Event.clone method through the
|
||||
* VM value stack (raw:2814-2828). */
|
||||
void *as3vm_clone_GC(void *vm, void *value) {
|
||||
void **sp;
|
||||
ev_push(vm, (void *)0);
|
||||
ev_push(vm, value);
|
||||
sp = *(void ***)AT(vm, VM_STACK);
|
||||
as3vm_do_method_call_GC(vm, sp - 2, *(void **)AT(vm, VM_CLONEMETHOD), sp - 1,
|
||||
0);
|
||||
sp = *(void ***)AT(vm, VM_STACK) - 2;
|
||||
*(void ***)AT(vm, VM_STACK) = sp;
|
||||
return *sp;
|
||||
}
|
||||
|
||||
/* Real: build a lazy Event object from a prepared scratch struct, copying the
|
||||
* extended field region and seeding the live modifier-key state (raw:3165-
|
||||
* 3200). DEFERRED structurally (needs the live VM value stack + class slots). */
|
||||
void *as3vm_make_lazy_event_GC(void *vm, void *scratch) {
|
||||
void *newobj =
|
||||
as3vm_make_object_no_constructor_GC(vm, *(void **)AT(scratch, LZ_CLASS));
|
||||
void *target;
|
||||
memcpy(AT(newobj, EV_KEYCODE), AT(scratch, LZ_FLD0),
|
||||
(__SIZE_TYPE__)(EV_TYPE + (int)sizeof(void *) - EV_KEYCODE));
|
||||
if (*(void **)AT(scratch, LZ_CLASS) == *(void **)AT(vm, VM_KBEVCLASS)) {
|
||||
uint16_t mod = *(uint16_t *)AT(scratch, LZ_MODKEY);
|
||||
ev_push(vm, newobj);
|
||||
target = as3vm_make_string_wc_GC(vm, &mod, 1);
|
||||
ev_pop(vm);
|
||||
newobj = *(*(void ***)AT(vm, VM_STACK));
|
||||
} else {
|
||||
target = *(*(void ***)AT(vm, VM_STACK) - 1);
|
||||
}
|
||||
as3vmcomp_set_value(vm, (char *)newobj - 1, 2, target);
|
||||
/* The live modifier-key quad lives in the context at vm[0], not the outer VM
|
||||
* struct (durango 3195-3198 / vita 2539-2541; objdump make_lazy+0xbc). */
|
||||
{
|
||||
void *ctx = *(void **)vm;
|
||||
*(uint8_t *)AT(newobj, EV_SHIFTKEY) = *(uint8_t *)AT(ctx, VM_MODKEYS + 3);
|
||||
*(uint8_t *)AT(newobj, EV_COMMANDKEY) = *(uint8_t *)AT(ctx, VM_MODKEYS + 2);
|
||||
*(uint8_t *)AT(newobj, EV_CONTROLKEY) = *(uint8_t *)AT(ctx, VM_MODKEYS + 1);
|
||||
*(uint8_t *)AT(newobj, EV_ALTKEY) = *(uint8_t *)AT(ctx, VM_MODKEYS + 0);
|
||||
}
|
||||
return newobj;
|
||||
}
|
||||
|
||||
/* ---- File-static propagation machinery ----------------------------------- */
|
||||
|
||||
/* Seed a lazy event's phase + capture flag and set its slots (raw:3717-3724). */
|
||||
static void setup_event(void *vm, void *event, unsigned char phase,
|
||||
void *target) {
|
||||
*(uint8_t *)AT(event, EV_PHASE) = phase;
|
||||
*(uint8_t *)AT(event, EV_LAZYCLONE) = 1;
|
||||
as3vmcomp_set_value(vm, (char *)event - 1, 0, target);
|
||||
as3vmcomp_set_value(vm, (char *)event - 1, 1, target);
|
||||
}
|
||||
|
||||
/* Invoke every live listener entry of one node in list order, honouring the
|
||||
* generation gate and the stopImmediatePropagation flag (raw:3670-3711 /
|
||||
* vita:413-467). The do_func_call result goes into a throwaway local so it can
|
||||
* never clobber the stacked argument the next iteration reads (raw:3698). */
|
||||
static void *dispatch_loop_GC(void *vm, void *entry, void *node, void *event,
|
||||
unsigned generation) {
|
||||
void *result;
|
||||
void *call_result;
|
||||
ev_push(vm, (void *)0);
|
||||
ev_push(vm, event);
|
||||
for (; entry != (void *)0; entry = *(void **)AT(entry, LE_NEXT)) {
|
||||
void *handle = *(void **)AT(entry, LE_HANDLE);
|
||||
if (handle == (void *)0) {
|
||||
continue;
|
||||
}
|
||||
if ((int)generation >= 0 &&
|
||||
*(uint16_t *)AT(entry, LE_PHASE) != (uint16_t)generation) {
|
||||
continue;
|
||||
}
|
||||
if (*(void **)handle == (void *)7) {
|
||||
ev_link_cleanup(vm, node);
|
||||
} else {
|
||||
void **sp = *(void ***)AT(vm, VM_STACK);
|
||||
if (*(void **)AT(entry, LE_SELF) == (void *)0) {
|
||||
as3vm_do_func_call_vv_GC(vm, &call_result, *(void **)handle);
|
||||
} else {
|
||||
as3vm_do_func_call_vmc_GC(vm, &call_result, *(void **)handle,
|
||||
*(void **)AT(entry, LE_SELF), sp - 2, 1);
|
||||
}
|
||||
if (*(void **)AT(vm, VM_EXCFLAG) != (void *)0) {
|
||||
iggy_uncaught_exception_warning(*(void **)vm); /* durango 3701 / ps3 1327.*/
|
||||
}
|
||||
{
|
||||
void **top = *(void ***)AT(vm, VM_STACK);
|
||||
if ((*(uint8_t *)AT(*(top - 1), EV_FLAGS) & 2) != 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
{
|
||||
void **sp = *(void ***)AT(vm, VM_STACK) - 1;
|
||||
result = *sp;
|
||||
*(void ***)AT(vm, VM_STACK) = sp - 1;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/* Read the event's stop-propagation flag off the current stack top. */
|
||||
static int ev_stopped(void *vm) {
|
||||
return *(char *)AT(*(*(void ***)AT(vm, VM_STACK) - 1), EV_FLAGS) != '\0';
|
||||
}
|
||||
|
||||
/* Dispatch one dispatcher's listeners for `type` in the given phase list
|
||||
* (capture list on capture==1, bubble/target list otherwise) (raw:3393-3419 /
|
||||
* vita:dispatch_event_local inline). */
|
||||
static int dispatch_event_local_GC(void *vm, void *dispatcher, void *event,
|
||||
int capture, void *type) {
|
||||
void *node;
|
||||
for (node = *(void **)AT(dispatcher, EV_DIRECTLIST); node != (void *)0;
|
||||
node = *(void **)AT(node, ND_CHAINNEXT)) {
|
||||
if (*(void **)AT(node, ND_KEY) == type) {
|
||||
void *chain =
|
||||
*(void **)AT(node, capture == 0 ? ND_LISTBYCAP : ND_LISTBYBUB);
|
||||
if (chain != (void *)0) {
|
||||
as3vmcomp_set_value(vm, (char *)event - 1, 1, dispatcher);
|
||||
dispatch_loop_GC(vm, chain, node, event, 0xffffffffu);
|
||||
}
|
||||
return *(void **)AT(node, ND_LISTBYCAP) != (void *)0;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Does `inner`'s listener node for `type` carry a live capture-phase entry?
|
||||
* (the has_event_listener(mode=capture) helper inlined into dispatch_lazy,
|
||||
* raw:3504-3521 / vita:2209 has_event_listener(...,3)). */
|
||||
static int ev_has_capture_listener(void *vm, void *inner, void *type) {
|
||||
void **slot;
|
||||
void *node;
|
||||
void *entry;
|
||||
uint8_t phase = *(uint8_t *)AT(type, EV_TYPEPHASE);
|
||||
if ((uint8_t)(phase - 1) < 5) {
|
||||
slot = (void **)AT(vm, VM_LISTENER + (intptr_t)phase * (int)sizeof(void *));
|
||||
} else {
|
||||
slot = (void **)AT(inner, EV_DIRECTLIST);
|
||||
}
|
||||
for (node = *slot; node != (void *)0;
|
||||
node = *(void **)AT(node, ND_CHAINNEXT)) {
|
||||
if (*(void **)AT(node, ND_KEY) == type) {
|
||||
/* has_event_listener(mode=3) scans BOTH lists -- the bubble/target list
|
||||
* (ND_LISTBYCAP) first, then the capture list (ND_LISTBYBUB) -- and
|
||||
* reports a live entry from either (vita has_event_listener:229-242 with
|
||||
* mode 3; durango 3515/3539; ps3 3262/3266). A default useCapture=false
|
||||
* listener lives in ND_LISTBYCAP, so scanning only ND_LISTBYBUB would
|
||||
* miss every ordinary bubbling listener. */
|
||||
for (entry = *(void **)AT(node, ND_LISTBYCAP); entry != (void *)0;
|
||||
entry = *(void **)AT(entry, LE_NEXT)) {
|
||||
void *h = *(void **)AT(entry, LE_HANDLE);
|
||||
if (h != (void *)0 && *(void **)h != (void *)7) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
for (entry = *(void **)AT(node, ND_LISTBYBUB); entry != (void *)0;
|
||||
entry = *(void **)AT(entry, LE_NEXT)) {
|
||||
void *h = *(void **)AT(entry, LE_HANDLE);
|
||||
if (h != (void *)0 && *(void **)h != (void *)7) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Full capture -> target -> bubble propagation of an already-boxed event down a
|
||||
* DisplayObject ancestor chain (raw:3242-3387 / vita:471-685). `allow_bubble`
|
||||
* enables the bubble stage; returns the event's defaultPrevented flag. */
|
||||
static unsigned char dispatch_event_GC(void *vm, void *dispatcher, void *event,
|
||||
void *type, int allow_bubble) {
|
||||
void *ancestors[100];
|
||||
int depth = 0;
|
||||
int i;
|
||||
void *node;
|
||||
void *target;
|
||||
unsigned char def_prevented;
|
||||
|
||||
/* Clone the lazy event if it is still shared. */
|
||||
if (*(char *)AT(event, EV_LAZYCLONE) != '\0') {
|
||||
ev_push(vm, dispatcher);
|
||||
event = as3vm_clone_GC(vm, event);
|
||||
dispatcher = *(*(void ***)AT(vm, VM_STACK) - 1);
|
||||
if (*(void **)AT(vm, VM_EXCFLAG) != (void *)0) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
*(uint8_t *)AT(event, EV_LAZYCLONE) = 1;
|
||||
node = *(void **)AT(dispatcher, DISP_NODE);
|
||||
|
||||
/* No DisplayObject ancestors: dispatch the target stage only. */
|
||||
if (node == (void *)0 || *(void **)AT(node, ND_PARENT) == (void *)0 ||
|
||||
(*(uint8_t *)AT(node, DN_FLAGS) & 8) != 0) {
|
||||
ev_push(vm, event);
|
||||
dispatch_event_local_GC(vm, dispatcher, event, 0, type);
|
||||
node = *(*(void ***)AT(vm, VM_STACK) - 1);
|
||||
def_prevented = *(uint8_t *)AT(node, EV_DEFPREV);
|
||||
ev_pop(vm);
|
||||
return def_prevented;
|
||||
}
|
||||
|
||||
/* Build the ancestor array, bumping each node's re-entrancy counter. */
|
||||
for (;;) {
|
||||
*(uint16_t *)AT(node, DN_GEN) += 1;
|
||||
ancestors[depth] = node;
|
||||
if ((*(uint8_t *)AT(node, DN_FLAGS) & 8) != 0 ||
|
||||
(node = *(void **)AT(node, ND_PARENT)) == (void *)0) {
|
||||
break;
|
||||
}
|
||||
++depth;
|
||||
if (depth >= 100) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
target = *(void **)(*(void **)AT(ancestors[0], DN_VALUE));
|
||||
*(uint8_t *)AT(event, EV_PHASE) = 1;
|
||||
as3vmcomp_set_value(vm, (char *)event - 1, 0, target);
|
||||
as3vmcomp_set_value(vm, (char *)event - 1, 1, target);
|
||||
ev_push(vm, event);
|
||||
|
||||
if (!ev_stopped(vm)) {
|
||||
/* Capture phase: outermost ancestor inward. */
|
||||
for (i = depth; i > 0; --i) {
|
||||
void *inner_slot = *(void **)AT(ancestors[i], DN_VALUE);
|
||||
void *inner = (inner_slot != (void *)0) ? *(void **)inner_slot : (void *)0;
|
||||
if (inner != (void *)0) {
|
||||
void *ev = *(*(void ***)AT(vm, VM_STACK) - 1);
|
||||
dispatch_event_local_GC(vm, inner, ev, 1, type);
|
||||
if (ev_stopped(vm)) {
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* Target phase: ancestors[0]. */
|
||||
{
|
||||
void *inner_slot = *(void **)AT(ancestors[0], DN_VALUE);
|
||||
void *inner = (inner_slot != (void *)0) ? *(void **)inner_slot : (void *)0;
|
||||
if (inner != (void *)0) {
|
||||
void *ev = *(*(void ***)AT(vm, VM_STACK) - 1);
|
||||
*(uint8_t *)AT(ev, EV_PHASE) = 2;
|
||||
dispatch_event_local_GC(vm, inner, ev, 0, type);
|
||||
if (ev_stopped(vm)) {
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* Bubble phase: ancestors[1] outward, if the event bubbles. Unlike the
|
||||
* capture / target phases, the raw guards only on the slot then derefs it
|
||||
* unconditionally (durango 3355 / vita 642). */
|
||||
if (allow_bubble != 0) {
|
||||
*(uint8_t *)AT(*(*(void ***)AT(vm, VM_STACK) - 1), EV_PHASE) = 3;
|
||||
for (i = 1; i <= depth; ++i) {
|
||||
void *inner_slot = *(void **)AT(ancestors[i], DN_VALUE);
|
||||
if (inner_slot != (void *)0) {
|
||||
void *inner = *(void **)inner_slot;
|
||||
void *ev = *(*(void ***)AT(vm, VM_STACK) - 1);
|
||||
dispatch_event_local_GC(vm, inner, ev, 0, type);
|
||||
if (ev_stopped(vm)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
done:
|
||||
for (i = 0; i <= depth; ++i) {
|
||||
*(uint16_t *)AT(ancestors[i], DN_GEN) -= 1;
|
||||
}
|
||||
node = *(*(void ***)AT(vm, VM_STACK) - 1);
|
||||
def_prevented = *(uint8_t *)AT(node, EV_DEFPREV);
|
||||
ev_pop(vm);
|
||||
return def_prevented;
|
||||
}
|
||||
|
||||
/* Assemble a lazy event and propagate it capture -> target -> bubble down the
|
||||
* DisplayObject ancestor chain, gated by a per-ancestor "has capture listener"
|
||||
* flag array (raw:3428-3664 / vita:2066-2416). Sets *out_handled when any
|
||||
* listener participates. */
|
||||
static uintptr_t dispatch_lazy_event_GC(void *vm, void *scratch,
|
||||
void *dispatcher, void *node,
|
||||
int32_t *out_handled) {
|
||||
void *type = *(void **)AT(scratch, LZ_TYPE);
|
||||
void *ancestors[100];
|
||||
signed char capflag[100];
|
||||
int depth = 0;
|
||||
int captured = 0;
|
||||
int i;
|
||||
void *event;
|
||||
void *target;
|
||||
unsigned char def_prevented;
|
||||
|
||||
*out_handled = 0;
|
||||
if (node == (void *)0) {
|
||||
node = *(void **)AT(dispatcher, DISP_NODE);
|
||||
}
|
||||
if (dispatcher == (void *)0 && node != (void *)0 &&
|
||||
*(void **)AT(node, DN_VALUE) != (void *)0) {
|
||||
dispatcher = *(void **)(*(void **)AT(node, DN_VALUE));
|
||||
}
|
||||
|
||||
/* No ancestor chain: single-dispatcher target dispatch (raw:3467-3496). */
|
||||
if (node == (void *)0 ||
|
||||
(*(void **)AT(node, ND_PARENT) == (void *)0 &&
|
||||
(*(uint8_t *)AT(node, DN_FLAGS) & 8) == 0)) {
|
||||
if (dispatcher != (void *)0) {
|
||||
void *nd;
|
||||
for (nd = *(void **)AT(dispatcher, EV_DIRECTLIST);
|
||||
nd != (void *)0 && *(void **)AT(nd, ND_KEY) != type;
|
||||
nd = *(void **)AT(nd, ND_CHAINNEXT)) {
|
||||
}
|
||||
if (nd != (void *)0 && *(void **)AT(nd, ND_LISTBYCAP) != (void *)0) {
|
||||
*out_handled = 1;
|
||||
ev_push(vm, dispatcher);
|
||||
ev_push(vm, *(*(void ***)AT(vm, VM_STACK) - 2));
|
||||
event = as3vm_make_lazy_event_GC(vm, scratch);
|
||||
*(void ***)AT(vm, VM_STACK) = *(void ***)AT(vm, VM_STACK) - 2;
|
||||
setup_event(vm, event, 2, *(*(void ***)AT(vm, VM_STACK)));
|
||||
ev_push(vm, event);
|
||||
*(uint16_t *)AT(vm, VM_DEPTH) += 1;
|
||||
dispatch_loop_GC(vm, *(void **)AT(nd, ND_LISTBYCAP), nd, event,
|
||||
0xffffffffu);
|
||||
*(uint16_t *)AT(vm, VM_DEPTH) -= 1;
|
||||
ev_pop(vm);
|
||||
return (uintptr_t)*(uint8_t *)AT(*(*(void ***)AT(vm, VM_STACK)),
|
||||
EV_DEFPREV);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Build the ancestor array + capture-flag array. */
|
||||
for (;;) {
|
||||
void *inner_slot = *(void **)AT(node, DN_VALUE);
|
||||
void *inner = (inner_slot != (void *)0) ? *(void **)inner_slot : (void *)0;
|
||||
*(uint16_t *)AT(node, DN_GEN) += 1;
|
||||
ancestors[depth] = node;
|
||||
if (captured || inner == (void *)0) {
|
||||
capflag[depth] = 0;
|
||||
} else if (*(void **)AT(inner, EV_DIRECTLIST) == (void *)0 ||
|
||||
ev_has_capture_listener(vm, inner, type) == 0) {
|
||||
capflag[depth] = -1;
|
||||
} else {
|
||||
captured = 1;
|
||||
capflag[depth] = 1;
|
||||
}
|
||||
if ((node = *(void **)AT(node, ND_PARENT)) == (void *)0) {
|
||||
break;
|
||||
}
|
||||
++depth;
|
||||
if (depth >= 100) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!captured) {
|
||||
for (i = 0; i <= depth; ++i) {
|
||||
*(uint16_t *)AT(ancestors[i], DN_GEN) -= 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
*out_handled = 1;
|
||||
event = as3vm_make_lazy_event_GC(vm, scratch);
|
||||
if (*(void **)AT(vm, VM_EXCFLAG) != (void *)0) {
|
||||
return 1;
|
||||
}
|
||||
/* Drop a stale target box left over from a previous dispatch. */
|
||||
{
|
||||
void *slot0 = *(void **)AT(ancestors[0], DN_VALUE);
|
||||
if (slot0 != (void *)0 && *(void **)slot0 == (void *)7) {
|
||||
as3vm_pool_free(vm);
|
||||
*(void **)AT(ancestors[0], DN_VALUE) = (void *)0;
|
||||
}
|
||||
}
|
||||
ev_push(vm, event);
|
||||
*(uint16_t *)AT(vm, VM_DEPTH) += 1;
|
||||
if (*(void **)AT(ancestors[0], DN_VALUE) == (void *)0) {
|
||||
as3vm_get_movie_as3value_GC(*(void **)vm, ancestors[0]); /* durango 3590. */
|
||||
}
|
||||
target = *(void **)(*(void **)AT(ancestors[0], DN_VALUE));
|
||||
{
|
||||
void *ev = *(*(void ***)AT(vm, VM_STACK) - 1);
|
||||
*(uint8_t *)AT(ev, EV_PHASE) = 1;
|
||||
*(uint8_t *)AT(ev, EV_LAZYCLONE) = 1;
|
||||
as3vmcomp_set_value(vm, (char *)ev - 1, 0, target);
|
||||
as3vmcomp_set_value(vm, (char *)ev - 1, 1, target);
|
||||
}
|
||||
|
||||
if (!ev_stopped(vm)) {
|
||||
/* Capture phase. */
|
||||
for (i = depth; i > 0; --i) {
|
||||
void *inner_slot;
|
||||
void *inner;
|
||||
if (capflag[i] < 0) {
|
||||
continue;
|
||||
}
|
||||
inner_slot = *(void **)AT(ancestors[i], DN_VALUE);
|
||||
inner = (inner_slot != (void *)0) ? *(void **)inner_slot : (void *)0;
|
||||
if (inner != (void *)0) {
|
||||
void *ev = *(*(void ***)AT(vm, VM_STACK) - 1);
|
||||
dispatch_event_local_GC(vm, inner, ev, 1, type);
|
||||
if (ev_stopped(vm)) {
|
||||
goto lazy_done;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* Target phase. */
|
||||
if (capflag[0] >= 0) {
|
||||
void *inner_slot = *(void **)AT(ancestors[0], DN_VALUE);
|
||||
void *inner = (inner_slot != (void *)0) ? *(void **)inner_slot : (void *)0;
|
||||
if (inner != (void *)0) {
|
||||
void *ev = *(*(void ***)AT(vm, VM_STACK) - 1);
|
||||
*(uint8_t *)AT(ev, EV_PHASE) = 2;
|
||||
dispatch_event_local_GC(vm, inner, ev, 0, type);
|
||||
if (ev_stopped(vm)) {
|
||||
goto lazy_done;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* Bubble phase, if the lazy event bubbles. */
|
||||
if (*(char *)AT(scratch, LZ_CANCELABLE) != '\0') {
|
||||
*(uint8_t *)AT(*(*(void ***)AT(vm, VM_STACK) - 1), EV_PHASE) = 3;
|
||||
for (i = 1; i <= depth; ++i) {
|
||||
void *inner_slot;
|
||||
void *inner;
|
||||
if (capflag[i] < 0) {
|
||||
continue;
|
||||
}
|
||||
inner_slot = *(void **)AT(ancestors[i], DN_VALUE);
|
||||
inner = (inner_slot != (void *)0) ? *(void **)inner_slot : (void *)0;
|
||||
if (inner != (void *)0) {
|
||||
void *ev = *(*(void ***)AT(vm, VM_STACK) - 1);
|
||||
dispatch_event_local_GC(vm, inner, ev, 0, type);
|
||||
if (ev_stopped(vm)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
lazy_done:
|
||||
for (i = 0; i <= depth; ++i) {
|
||||
*(uint16_t *)AT(ancestors[i], DN_GEN) -= 1;
|
||||
}
|
||||
def_prevented = *(uint8_t *)AT(*(*(void ***)AT(vm, VM_STACK) - 1), EV_DEFPREV);
|
||||
*(uint16_t *)AT(vm, VM_DEPTH) -= 1;
|
||||
ev_pop(vm);
|
||||
return (uintptr_t)def_prevented;
|
||||
}
|
||||
|
||||
/* ---- Listener-table teardown --------------------------------------------- */
|
||||
|
||||
/* Free one node's capture + bubble listener entries through the GC pool/arena
|
||||
* and decrement its live count. */
|
||||
static void ev_free_node_entries(void *vm, void *node) {
|
||||
int which;
|
||||
for (which = 0; which < 2; ++which) {
|
||||
void *entry = *(void **)AT(node, which == 0 ? ND_LISTBYCAP : ND_LISTBYBUB);
|
||||
while (entry != (void *)0) {
|
||||
void *next = *(void **)AT(entry, LE_NEXT);
|
||||
if (*(void **)AT(entry, LE_HANDLE) != (void *)0) {
|
||||
as3vm_pool_free(vm);
|
||||
*(void **)AT(entry, LE_HANDLE) = (void *)0;
|
||||
}
|
||||
iggy_free_alloc(*(void **)vm, entry);
|
||||
*(int32_t *)AT(node, ND_COUNT) -= 1;
|
||||
entry = next;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Real: sweep the six per-phase listener tables, dropping dead entries and
|
||||
* compacting empty nodes (raw:2628-2757). */
|
||||
void as3vm_clean_listeners(void *vm) {
|
||||
int i;
|
||||
for (i = 0; i < 6; ++i) {
|
||||
void **slot = (void **)AT(vm, VM_LISTENER + (intptr_t)(i + 1) * (int)sizeof(void *));
|
||||
void *node = *slot;
|
||||
while (node != (void *)0) {
|
||||
void *next = *(void **)AT(node, ND_CHAINNEXT);
|
||||
ev_free_node_entries(vm, node);
|
||||
if (*(void **)AT(node, ND_LISTBYCAP) == (void *)0 &&
|
||||
*(void **)AT(node, ND_LISTBYBUB) == (void *)0) {
|
||||
*slot = next;
|
||||
if (*(void **)AT(node, ND_GROUP_ARENA) != (void *)0) {
|
||||
as3vm_pool_free(vm);
|
||||
*(void **)AT(node, ND_GROUP_ARENA) = (void *)0;
|
||||
}
|
||||
iggy_free_alloc(*(void **)vm, node);
|
||||
} else {
|
||||
slot = (void **)AT(node, ND_CHAINNEXT);
|
||||
}
|
||||
node = next;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Real: free every direct-listener node hung off the six phase tables
|
||||
* (raw:2763-2808). */
|
||||
void as3vm_clear_direct_listeners(void *vm) {
|
||||
int i;
|
||||
for (i = 0; i < 6; ++i) {
|
||||
void **slot = (void **)AT(vm, VM_LISTENER + (intptr_t)(i + 1) * (int)sizeof(void *));
|
||||
void *node = *slot;
|
||||
while (node != (void *)0) {
|
||||
void *next = *(void **)AT(node, ND_CHAINNEXT);
|
||||
ev_free_node_entries(vm, node);
|
||||
iggy_free_alloc(*(void **)vm, node);
|
||||
node = next;
|
||||
}
|
||||
*slot = (void *)0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,213 @@
|
||||
/*
|
||||
* swf_as3vm_flash_events_doevents.inc -- the do_*_event_GC engine entry points
|
||||
* (direct / displayobject / plain / timer / focus / keyboard / mouse). These
|
||||
* are the outer entries the runtime calls to raise a flash.event; each seeds a
|
||||
* lazy scratch (class, interned type name, bubbles/cancelable and the extended
|
||||
* input fields) and drives the file-static three-phase machinery in
|
||||
* swf_as3vm_flash_events_dispatch.inc. Reconstructed from the durango raw
|
||||
* (authoritative 64-bit) + vita/ps3 for the 32-bit scratch offsets, cross-
|
||||
* checked with object disassembly. Included by swf_as3vm_flash_events.c after
|
||||
* the dispatch machinery it depends on.
|
||||
*/
|
||||
|
||||
/* ---- do_*_event_GC engine entry points ----------------------------------- */
|
||||
|
||||
/* Real: dispatch a direct event to every registered node for the type index,
|
||||
* bumping the dispatch generation (raw:2835-2896). */
|
||||
void as3vm_do_direct_event_GC(void *vm, int index) {
|
||||
void *name;
|
||||
void *event;
|
||||
uint8_t scratch[sizeof(void *) * 16];
|
||||
void *node;
|
||||
uint16_t generation;
|
||||
if (*(void **)AT(vm, VM_LISTENER + (intptr_t)index * (int)sizeof(void *)) ==
|
||||
(void *)0) {
|
||||
return;
|
||||
}
|
||||
name = *(void **)AT(vm, VM_EVENTNAMES + (intptr_t)index * (int)sizeof(void *));
|
||||
memset(scratch, 0, LZ_BYTES);
|
||||
*(void **)AT(scratch, LZ_CLASS) = *(void **)AT(vm, VM_EVENTCLASS);
|
||||
*(void **)AT(scratch, LZ_TYPE) = as3vm_string_interned(vm, name);
|
||||
ev_push(vm, EV_TRUE_CELL);
|
||||
event = as3vm_make_lazy_event_GC(vm, scratch);
|
||||
*(uint16_t *)AT(vm, VM_DEPTH) = (uint16_t)(*(uint16_t *)AT(vm, VM_DEPTH) + 1);
|
||||
ev_pop(vm);
|
||||
generation = *(uint16_t *)AT(vm, VM_DEPTH);
|
||||
for (node = *(void **)AT(vm, VM_LISTENER + (intptr_t)index * (int)sizeof(void *));
|
||||
node != (void *)0; node = *(void **)AT(node, ND_CHAINNEXT)) {
|
||||
void *entry;
|
||||
for (entry = *(void **)AT(node, ND_LISTBYCAP); entry != (void *)0;
|
||||
entry = *(void **)AT(entry, LE_NEXT)) {
|
||||
void *handle = *(void **)AT(entry, LE_HANDLE);
|
||||
if (handle != (void *)0 && *(void **)handle != (void *)7) {
|
||||
*(uint16_t *)AT(entry, LE_PHASE) = generation;
|
||||
}
|
||||
}
|
||||
}
|
||||
ev_push(vm, event);
|
||||
for (node = *(void **)AT(vm, VM_LISTENER + (intptr_t)index * (int)sizeof(void *));
|
||||
node != (void *)0; node = *(void **)AT(node, ND_CHAINNEXT)) {
|
||||
void *chain = *(void **)AT(node, ND_LISTBYCAP);
|
||||
if (chain != (void *)0) {
|
||||
void *ev = *(*(void ***)AT(vm, VM_STACK) - 1);
|
||||
void *tgt = *(void **)(*(void **)AT(node, ND_GROUP_ARENA));
|
||||
/* Phase=2, lazy=1 written as two bytes (endian-safe on ps3; the durango
|
||||
* u16 0x102 store reverses on BE) -- vita 2566-2567. */
|
||||
*(uint8_t *)AT(ev, EV_PHASE) = 2;
|
||||
*(uint8_t *)AT(ev, EV_LAZYCLONE) = 1;
|
||||
as3vmcomp_set_value(vm, (char *)ev - 1, 0, tgt);
|
||||
as3vmcomp_set_value(vm, (char *)ev - 1, 1, tgt);
|
||||
dispatch_loop_GC(vm, chain, node, ev, generation);
|
||||
/* Clear the pending-exception flag each iteration -- dispatch_loop_GC does
|
||||
* not (vita 2573 param_1[0x5ba]=0; durango 2882-2891; objdump
|
||||
* do_direct+0x187 movq %r15,0x2908(%rbp)). */
|
||||
*(void **)AT(vm, VM_EXCFLAG) = (void *)0;
|
||||
}
|
||||
}
|
||||
ev_pop(vm);
|
||||
*(uint16_t *)AT(vm, VM_DEPTH) = (uint16_t)(*(uint16_t *)AT(vm, VM_DEPTH) - 1);
|
||||
}
|
||||
|
||||
/* Prepare a lazy scratch for the class/name pair and enter dispatch_lazy_event
|
||||
* (shared by do_event / do_displayobject_event). */
|
||||
static int ev_do_event_common(void *vm, void *obj, unsigned char index,
|
||||
unsigned char flag, void *cls, int as_target) {
|
||||
void *name =
|
||||
*(void **)AT(vm, VM_EVENTNAMES + (intptr_t)index * (int)sizeof(void *));
|
||||
uint8_t scratch[sizeof(void *) * 16];
|
||||
int32_t handled = 0;
|
||||
memset(scratch, 0, LZ_BYTES);
|
||||
*(void **)AT(scratch, LZ_CLASS) = cls;
|
||||
*(void **)AT(scratch, LZ_TYPE) = as3vm_string_interned(vm, name);
|
||||
*(uint8_t *)AT(scratch, LZ_DEFPREV) = 0;
|
||||
*(uint8_t *)AT(scratch, LZ_CANCELABLE) = flag;
|
||||
ev_push(vm, EV_TRUE_CELL);
|
||||
if (as_target) {
|
||||
dispatch_lazy_event_GC(vm, scratch, (void *)0, obj, &handled);
|
||||
} else {
|
||||
dispatch_lazy_event_GC(vm, scratch, obj, (void *)0, &handled);
|
||||
}
|
||||
ev_pop(vm);
|
||||
return handled;
|
||||
}
|
||||
|
||||
/* Real: dispatch a DisplayObject event (raw:2901-2926). */
|
||||
int as3vm_do_displayobject_event_GC(void *vm, void *obj, unsigned char index,
|
||||
unsigned char flag) {
|
||||
return ev_do_event_common(vm, obj, index, flag,
|
||||
*(void **)AT(vm, VM_EVENTCLASS), 1);
|
||||
}
|
||||
|
||||
/* Real: dispatch a plain event (raw:2932-2954). */
|
||||
int as3vm_do_event_GC(void *vm, void *obj, unsigned char index,
|
||||
unsigned char flag) {
|
||||
return ev_do_event_common(vm, obj, index, flag,
|
||||
*(void **)AT(vm, VM_EVENTCLASS), 0);
|
||||
}
|
||||
|
||||
/* Real: dispatch a TimerEvent (raw:2960-2980). */
|
||||
void as3vm_do_event_timer_GC(void *vm, void *obj, int which) {
|
||||
void *name = *(void **)AT(vm, VM_TIMERNAMES +
|
||||
(intptr_t)(which != 0) * (int)sizeof(void *));
|
||||
uint8_t scratch[sizeof(void *) * 16];
|
||||
int32_t handled = 0;
|
||||
memset(scratch, 0, LZ_BYTES);
|
||||
*(void **)AT(scratch, LZ_CLASS) = *(void **)AT(vm, VM_TIMEREVCLASS);
|
||||
*(void **)AT(scratch, LZ_TYPE) = as3vm_string_interned(vm, name);
|
||||
ev_push(vm, EV_TRUE_CELL);
|
||||
dispatch_lazy_event_GC(vm, scratch, obj, (void *)0, &handled);
|
||||
ev_pop(vm);
|
||||
}
|
||||
|
||||
/* Real: dispatch a FocusEvent, resolving the related object, seeding bubbles and
|
||||
* the keyCode field (raw:2986-3020 / vita:2694-2742). */
|
||||
void as3vm_do_focus_event_GC(void *vm, void *obj, uintptr_t index,
|
||||
void *related, int32_t param, unsigned char flag) {
|
||||
void *name = *(void **)AT(vm, VM_EVENTNAMES +
|
||||
(intptr_t)(index & 0xff) * (int)sizeof(void *));
|
||||
void *rel;
|
||||
uint8_t scratch[sizeof(void *) * 16];
|
||||
int32_t handled = 0;
|
||||
if (related == (void *)0) {
|
||||
rel = EV_TRUE_CELL;
|
||||
} else {
|
||||
as3vm_get_movie_as3value_GC(*(void **)vm, related);
|
||||
rel = **(void ***)AT(related, MV_VALUESLOT);
|
||||
}
|
||||
memset(scratch, 0, LZ_BYTES);
|
||||
*(void **)AT(scratch, LZ_CLASS) = *(void **)AT(vm, VM_FOCUSCLASS);
|
||||
*(void **)AT(scratch, LZ_TYPE) = as3vm_string_interned(vm, name);
|
||||
*(uint8_t *)AT(scratch, LZ_CANCELABLE) = 1; /* bubbles (durango 3016). */
|
||||
*(uint8_t *)AT(scratch, LZ_DEFPREV) = flag;
|
||||
ev_push(vm, rel);
|
||||
*(int32_t *)AT(scratch, SC_KEYCODE) = param; /* keyCode (durango 3015). */
|
||||
dispatch_lazy_event_GC(vm, scratch, (void *)0, obj, &handled);
|
||||
ev_pop(vm);
|
||||
}
|
||||
|
||||
/* Real: dispatch a KeyboardEvent, selecting the KEY_DOWN vs other class, seeding
|
||||
* bubbles/defaultPrevented and the keyCode/charCode/keyLocation fields
|
||||
* (raw:3026-3062 / vita:2746-2805). */
|
||||
void as3vm_do_keyboard_event_GC(void *vm, void *obj, unsigned char index,
|
||||
int32_t a, int32_t b, unsigned char flag) {
|
||||
void *name =
|
||||
*(void **)AT(vm, VM_EVENTNAMES + (intptr_t)index * (int)sizeof(void *));
|
||||
uint8_t scratch[sizeof(void *) * 16];
|
||||
int32_t handled = 0;
|
||||
memset(scratch, 0, LZ_BYTES);
|
||||
*(void **)AT(scratch, LZ_CLASS) =
|
||||
*(void **)AT(vm, index == 0x37 ? VM_KBEVCLASS : VM_KBEVCLASS2);
|
||||
*(void **)AT(scratch, LZ_TYPE) = as3vm_string_interned(vm, name);
|
||||
ev_push(vm, EV_TRUE_CELL);
|
||||
*(uint8_t *)AT(scratch, LZ_CANCELABLE) = 1; /* bubbles. */
|
||||
*(uint8_t *)AT(scratch, LZ_DEFPREV) = (uint8_t)(index == 0x37);
|
||||
*(int32_t *)AT(scratch, SC_KEYCODE) = a;
|
||||
*(int32_t *)AT(scratch, SC_CHARCODE) = b;
|
||||
*(uint8_t *)AT(scratch, SC_KEYLOCATION) = flag;
|
||||
dispatch_lazy_event_GC(vm, scratch, (void *)0, obj, &handled);
|
||||
ev_pop(vm);
|
||||
}
|
||||
|
||||
/* Real: dispatch a MouseEvent -- resolve the related object, seed bubbles, the
|
||||
* modifier buttonDown, clickCount / delta off the point struct, and the local
|
||||
* coordinates (mapped through the target transform when present)
|
||||
* (raw:3071-3128 / vita:2626-2690). */
|
||||
void as3vm_do_mouse_event_GC(void *vm, void *point, void *node, uintptr_t index,
|
||||
void *related, unsigned char flag, void *extra) {
|
||||
void *name = *(void **)AT(vm, VM_EVENTNAMES +
|
||||
(intptr_t)(index & 0xff) * (int)sizeof(void *));
|
||||
void *rel;
|
||||
uint8_t scratch[sizeof(void *) * 16];
|
||||
int32_t handled = 0;
|
||||
(void)extra;
|
||||
if (related == (void *)0) {
|
||||
rel = EV_TRUE_CELL;
|
||||
} else {
|
||||
as3vm_get_movie_as3value_GC(*(void **)vm, related);
|
||||
rel = **(void ***)AT(related, MV_VALUESLOT); /* durango 3102 / vita 2661. */
|
||||
}
|
||||
memset(scratch, 0, LZ_BYTES);
|
||||
*(void **)AT(scratch, LZ_CLASS) = *(void **)AT(vm, VM_MOUSECLASS);
|
||||
*(void **)AT(scratch, LZ_TYPE) = as3vm_string_interned(vm, name);
|
||||
*(uint8_t *)AT(scratch, LZ_CANCELABLE) = flag; /* bubbles (durango 3108). */
|
||||
*(uint8_t *)AT(scratch, LZ_DEFPREV) = 0;
|
||||
ev_push(vm, rel);
|
||||
*(uint8_t *)AT(scratch, SC_BUTTONDOWN) =
|
||||
*(uint8_t *)AT(*(void **)vm, VM_MODKEYS + 4); /* modifier buttonDown. */
|
||||
*(uint16_t *)AT(scratch, SC_CLICKCOUNT) =
|
||||
*(uint16_t *)((char *)point + 8);
|
||||
*(uint16_t *)AT(scratch, SC_DELTA) =
|
||||
(uint16_t)(int16_t)*(char *)((char *)point + 10);
|
||||
*(uint8_t *)AT(scratch, SC_MOUSEFLAG) = 1;
|
||||
if (*(void **)AT(node, ND_PARENT) == (void *)0) {
|
||||
*(uint32_t *)AT(scratch, SC_LOCALX) = *(uint32_t *)point;
|
||||
*(uint32_t *)AT(scratch, SC_LOCALY) = *((uint32_t *)point + 1);
|
||||
} else {
|
||||
uint8_t xform[24];
|
||||
iggy_get_o2w(*(void **)vm, node, xform);
|
||||
iggy_inverse_transform(AT(scratch, SC_LOCALX), AT(scratch, SC_LOCALY), xform,
|
||||
*(int32_t *)point);
|
||||
}
|
||||
dispatch_lazy_event_GC(vm, scratch, (void *)0, node, &handled);
|
||||
ev_pop(vm);
|
||||
}
|
||||
@@ -0,0 +1,336 @@
|
||||
/*
|
||||
* swf_as3vm_flash_events_event.inc -- flash.events.Event plus the sibling
|
||||
* flash.ui.Keyboard and flash.display.LoaderInfo binding thunks.
|
||||
* Included by swf_as3vm_flash_events.c.
|
||||
*/
|
||||
|
||||
/* ---- flash.events.Event -------------------------------------------------- */
|
||||
|
||||
/* Real: box the bubbles flag byte through as3vm_makebool (raw:717/722). */
|
||||
void as3vm_Event_get_bubbles(void *frame) {
|
||||
store_ptr(frame, ev_makebool(*(uint8_t *)AT(THISOBJ(frame), EV_BUBBLES)));
|
||||
}
|
||||
|
||||
/* Real: box the cancelable flag byte (raw:730/735). */
|
||||
void as3vm_Event_get_cancelable(void *frame) {
|
||||
store_ptr(frame, ev_makebool(*(uint8_t *)AT(THISOBJ(frame), EV_CANCELABLE)));
|
||||
}
|
||||
|
||||
/* Real: box the defaultPrevented flag byte (raw:801/806). */
|
||||
void as3vm_Event_isDefaultPrevented(void *frame) {
|
||||
store_ptr(frame, ev_makebool(*(uint8_t *)AT(THISOBJ(frame), EV_DEFPREV)));
|
||||
}
|
||||
|
||||
/* Real: box eventPhase byte * 2 (the AS3 int tag) (raw:758-762). */
|
||||
void as3vm_Event_get_eventPhase(void *frame) {
|
||||
store_astag(frame, *(uint8_t *)AT(THISOBJ(frame), EV_PHASE));
|
||||
}
|
||||
|
||||
/* Real: the currentTarget AS3 slot value (slot idx at classrec+SLOT_TAB+2)
|
||||
* (raw:743-751). */
|
||||
void as3vm_Event_get_currentTarget(void *frame) {
|
||||
store_ptr(frame, ev_slot_value(THISOBJ(frame), 2));
|
||||
}
|
||||
|
||||
/* Real: the target AS3 slot value (slot idx at classrec+SLOT_TAB+0)
|
||||
* (raw:770-776). */
|
||||
void as3vm_Event_get_target(void *frame) {
|
||||
store_ptr(frame, ev_slot_value(THISOBJ(frame), 0));
|
||||
}
|
||||
|
||||
/* Real: the interned type pointer, or the vm+VM_TYPEFALLBACK default when unset
|
||||
* (raw:784-794). */
|
||||
void as3vm_Event_get_type(void *frame) {
|
||||
void *type = *(void **)AT(THISOBJ(frame), EV_TYPE);
|
||||
if (type == (void *)0) {
|
||||
type = (void *)AT(VM(frame), VM_TYPEFALLBACK);
|
||||
}
|
||||
store_ptr(frame, type);
|
||||
}
|
||||
|
||||
/* Real: defaultPrevented := 1 only when cancelable is set (raw:814-819). */
|
||||
void as3vm_Event_preventDefault(void *frame) {
|
||||
void *obj = THISOBJ(frame);
|
||||
if (*(char *)AT(obj, EV_CANCELABLE) != '\0') {
|
||||
*(uint8_t *)AT(obj, EV_DEFPREV) = 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* Real: OR the propagation-stop flag byte with 2 (raw:827-833). */
|
||||
void as3vm_Event_stopImmediatePropagation(void *frame) {
|
||||
uint8_t *flags = (uint8_t *)AT(THISOBJ(frame), EV_FLAGS);
|
||||
*flags = (uint8_t)(*flags | 2);
|
||||
}
|
||||
|
||||
/* Real: OR the propagation-stop flag byte with 1 (raw:841-847). */
|
||||
void as3vm_Event_stopPropagation(void *frame) {
|
||||
uint8_t *flags = (uint8_t *)AT(THISOBJ(frame), EV_FLAGS);
|
||||
*flags = (uint8_t)(*flags | 1);
|
||||
}
|
||||
|
||||
/* Real: parse (type, ?bubbles, ?cancelable); seed the Event base fields and set
|
||||
* flags := 0x200 (phase 2, no stop) (raw:479-502). On a parse failure raise
|
||||
* 0x78. The flag u16 is written as two bytes so the store is endian-correct on
|
||||
* big-endian ps3 (stop byte := 0, phase byte := 2). */
|
||||
void as3vm_Event__construct(void *frame) {
|
||||
void *type = (void *)0;
|
||||
int32_t bubbles = 0;
|
||||
int32_t cancelable = 0;
|
||||
void *obj;
|
||||
if (as3vm_component_parse_arguments_GC(frame, EVFMT_EVENT, &type, &bubbles,
|
||||
&cancelable) != 0) {
|
||||
as3vm_exception_GC(VM(frame), 0x78);
|
||||
return;
|
||||
}
|
||||
obj = THISOBJ(frame);
|
||||
*(uint8_t *)AT(obj, EV_BUBBLES) = (uint8_t)bubbles;
|
||||
*(uint8_t *)AT(obj, EV_CANCELABLE) = (uint8_t)cancelable;
|
||||
*(uint8_t *)AT(obj, EV_FLAGS) = 0;
|
||||
*(uint8_t *)AT(obj, EV_PHASE) = 2;
|
||||
*(void **)AT(obj, EV_TYPE) = type;
|
||||
*(uint8_t *)AT(obj, EV_DEFPREV) = 0;
|
||||
*(uint8_t *)AT(obj, EV_LAZYCLONE) = 0;
|
||||
}
|
||||
|
||||
/* Copy the extended-field region of an Event into a freshly allocated clone of
|
||||
* the same class, then clear the per-dispatch flags. Shared verbatim by
|
||||
* Event / FocusEvent / KeyboardEvent / TextEvent clone (raw:509-537). */
|
||||
static void ev_clone_into(void *frame) {
|
||||
void *vm = VM(frame);
|
||||
void *obj = THISOBJ(frame);
|
||||
void *clsrec = *(void **)AT(obj, OFF_CLSREC);
|
||||
void *newobj =
|
||||
as3vm_make_object_no_constructor_GC(vm, *(void **)AT(clsrec, CLS_CLONECLASS));
|
||||
as3vmcomp_set_value(vm, (char *)newobj - 1, 2, ev_slot_value(obj, 4));
|
||||
memcpy(AT(newobj, EV_KEYCODE), AT(obj, EV_KEYCODE),
|
||||
(__SIZE_TYPE__)(EV_TYPE + (int)sizeof(void *) - EV_KEYCODE));
|
||||
*(uint8_t *)AT(newobj, EV_DEFPREV) = 0;
|
||||
*(uint8_t *)AT(newobj, EV_FLAGS) = 0;
|
||||
*(uint8_t *)AT(newobj, EV_PHASE) = 0;
|
||||
*(uint8_t *)AT(newobj, EV_LAZYCLONE) = 0;
|
||||
store_ptr(frame, newobj);
|
||||
}
|
||||
|
||||
/* Real: clone this Event (raw:509-539). */
|
||||
void as3vm_Event_clone(void *frame) { ev_clone_into(frame); }
|
||||
|
||||
/* Real: Event.toString -- "[<Class> type=... bubbles=... ...]". Pushes the
|
||||
* property values onto the VM value stack and assembles the string via
|
||||
* as3vm_create_interleaved_string_GC. The class is branched on the cached
|
||||
* MouseEvent / FocusEvent class slots (raw:858-1017). DEFERRED structurally
|
||||
* (deep string assembly; not exercised by the runtime harness). */
|
||||
void as3vm_Event_toString(void *frame) {
|
||||
void *vm = VM(frame);
|
||||
void *obj = THISOBJ(frame);
|
||||
void *clsrec = *(void **)AT(obj, OFF_CLSREC);
|
||||
void *cls = *(void **)AT(clsrec, CLS_CLONECLASS);
|
||||
void *result;
|
||||
|
||||
if (cls == *(void **)AT(vm, VM_MOUSECLASS)) {
|
||||
uint32_t local_x = 0, local_y = 0;
|
||||
void *tgt = ev_slot_value(obj, 0);
|
||||
if (((uintptr_t)tgt & 3) == 1 && *(char *)((char *)tgt - 1) == '$') {
|
||||
uint8_t xform[24];
|
||||
iggy_get_o2w(*(void **)vm, *(void **)AT(tgt, EV_KEYCODE), xform);
|
||||
iggy_transform(&local_y, &local_x, xform, *(int32_t *)AT(obj, EV_LOCALX));
|
||||
} else if (rr_isnan_f(*(float *)AT(obj, EV_LOCALY)) == 0) {
|
||||
local_x = 0;
|
||||
local_y = 0;
|
||||
} else {
|
||||
float nan = as3vm_NaNf;
|
||||
memcpy(&local_x, &nan, sizeof(float));
|
||||
local_y = local_x;
|
||||
}
|
||||
ev_push(vm, *(void **)AT(obj, EV_TYPE));
|
||||
ev_push(vm, ev_makebool(*(uint8_t *)AT(obj, EV_BUBBLES)));
|
||||
ev_push(vm, ev_makebool(*(uint8_t *)AT(obj, EV_CANCELABLE)));
|
||||
ev_push(vm, (void *)(intptr_t)((uint32_t)*(uint8_t *)AT(obj, EV_PHASE) * 2u));
|
||||
ev_push(vm, as3vm_make_number_GC(vm, ev_float_to_double(*(float *)AT(obj, EV_LOCALX))));
|
||||
ev_push(vm, as3vm_make_number_GC(vm, ev_float_to_double(*(float *)AT(obj, EV_LOCALY))));
|
||||
{ float fx; memcpy(&fx, &local_x, sizeof(float));
|
||||
ev_push(vm, as3vm_make_number_GC(vm, ev_float_to_double(fx))); }
|
||||
{ float fy; memcpy(&fy, &local_y, sizeof(float));
|
||||
ev_push(vm, as3vm_make_number_GC(vm, ev_float_to_double(fy))); }
|
||||
ev_push(vm, ev_slot_value(obj, 4));
|
||||
ev_push(vm, ev_makebool(*(uint8_t *)AT(obj, EV_CONTROLKEY)));
|
||||
ev_push(vm, ev_makebool(*(uint8_t *)AT(obj, EV_ALTKEY)));
|
||||
ev_push(vm, ev_makebool(*(uint8_t *)AT(obj, EV_SHIFTKEY)));
|
||||
ev_push(vm, ev_makebool(*(uint8_t *)AT(obj, EV_BUTTONDOWN)));
|
||||
ev_push(vm, (void *)(intptr_t)(*(int16_t *)AT(obj, EV_DELTA) * 2));
|
||||
result = as3vm_create_interleaved_string_GC(vm, 0xf);
|
||||
} else if (cls == *(void **)AT(vm, VM_FOCUSCLASS)) {
|
||||
ev_push(vm, *(void **)AT(obj, EV_TYPE));
|
||||
ev_push(vm, ev_makebool(*(uint8_t *)AT(obj, EV_BUBBLES)));
|
||||
ev_push(vm, ev_makebool(*(uint8_t *)AT(obj, EV_CANCELABLE)));
|
||||
ev_push(vm, (void *)(intptr_t)((uint32_t)*(uint8_t *)AT(obj, EV_PHASE) * 2u));
|
||||
ev_push(vm, ev_slot_value(obj, 4));
|
||||
ev_push(vm, ev_makebool(*(uint8_t *)AT(obj, EV_SHIFTKEY)));
|
||||
ev_push(vm, (void *)(intptr_t)((uint32_t)*(int32_t *)AT(obj, EV_KEYCODE) * 2u));
|
||||
result = as3vm_create_interleaved_string_GC(vm, 8);
|
||||
} else {
|
||||
ev_push(vm, *(void **)AT(obj, EV_TYPE));
|
||||
ev_push(vm, ev_makebool(*(uint8_t *)AT(obj, EV_BUBBLES)));
|
||||
ev_push(vm, ev_makebool(*(uint8_t *)AT(obj, EV_CANCELABLE)));
|
||||
ev_push(vm, (void *)(intptr_t)((uint32_t)*(uint8_t *)AT(obj, EV_PHASE) * 2u));
|
||||
result = as3vm_create_interleaved_string_GC(vm, 5);
|
||||
}
|
||||
store_ptr(frame, result);
|
||||
}
|
||||
|
||||
/* Real: Event.formatToString(name, ...propNames) -- assemble
|
||||
* "[<name> prop=value ...]" from the requested public properties. ToString's
|
||||
* each argument, interns it, walks the properties, computes the UTF-16 length,
|
||||
* allocates the string buffer and memcpies each fragment (raw:549-711).
|
||||
* DEFERRED structurally (deep string assembly; not exercised). */
|
||||
void as3vm_Event_formatToString(void *frame) {
|
||||
void *vm = VM(frame);
|
||||
void *thisobj = *(void **)FR(frame)[3]; /* this-slot[0] = the event. */
|
||||
int argc = ARGC(frame);
|
||||
void **args = (void **)FR(frame)[3]; /* args[i] = i-th argument (1-based).*/
|
||||
void **saved_sp = *(void ***)AT(vm, VM_STACK);
|
||||
void **keys = saved_sp; /* keys[0]=className, keys[i]=field. */
|
||||
void **vals; /* vals[i-1] = field i value string. */
|
||||
signed char quote[100];
|
||||
int i;
|
||||
int total = 1; /* '[' */
|
||||
void *sd;
|
||||
uint16_t *out;
|
||||
|
||||
/* Loop 1: ToString + intern each argument (className + field names), pushing
|
||||
* the results; a failure raises 0x78 (raw:591-606). */
|
||||
for (i = 1; i <= argc; ++i) {
|
||||
void *s = as3vm_ToString_GC(vm, args[i]);
|
||||
void *interned;
|
||||
if (s == (void *)7) {
|
||||
as3vm_exception_GC(vm, 0x78);
|
||||
return;
|
||||
}
|
||||
interned = as3vm_string_interned_nocreate(vm, s);
|
||||
if (interned == (void *)7) {
|
||||
as3vm_exception_GC(vm, 0x78);
|
||||
return;
|
||||
}
|
||||
ev_push(vm, interned);
|
||||
}
|
||||
ev_push(vm, (void *)0); /* raw:608 */
|
||||
vals = *(void ***)AT(vm, VM_STACK);
|
||||
|
||||
/* Loop 2: fetch each field's value off `this`, ToString it, note whether it is
|
||||
* a String (so it gets quoted) and push it (raw:611-633). */
|
||||
for (i = 1; i < argc; ++i) {
|
||||
void *pub = as3vm_get_public_string_GC(vm, thisobj, (intptr_t)keys[i] - 1);
|
||||
void *v;
|
||||
if (pub == (void *)7 || pub == EV_UNDEF_CELL) {
|
||||
as3vm_exception_GC(vm, 0x78);
|
||||
return;
|
||||
}
|
||||
quote[i] = (signed char)(((uintptr_t)pub & 3) == 1 &&
|
||||
*(char *)((char *)pub - 1) == '\b');
|
||||
v = as3vm_ToString_GC(vm, pub);
|
||||
if (v == (void *)7) {
|
||||
as3vm_exception_GC(vm, 0x78);
|
||||
return;
|
||||
}
|
||||
ev_push(vm, v);
|
||||
}
|
||||
|
||||
/* Each pushed value boxes a string; its stringdata pointer lives at
|
||||
* value+STR_HDR, the char count at stringdata+STR_HDR and the UTF-16 chars at
|
||||
* stringdata+STR_DATA (raw:664-667 / durango length 641-654). */
|
||||
#define EVSD(value) (*(void **)AT((value), STR_HDR))
|
||||
|
||||
/* Length: '[' + className + for each field ' ' + name + '=' + [<value> or
|
||||
* "<value>"] + final ']' (raw:637-655). */
|
||||
total += *(int32_t *)AT(EVSD(keys[0]), STR_HDR);
|
||||
for (i = 1; i < argc; ++i) {
|
||||
total += 2; /* ' ' + '=' */
|
||||
total += *(int32_t *)AT(EVSD(keys[i]), STR_HDR);
|
||||
total += *(int32_t *)AT(EVSD(vals[i - 1]), STR_HDR);
|
||||
if (quote[i]) {
|
||||
total += 2; /* opening + closing '"' */
|
||||
}
|
||||
}
|
||||
total += 1; /* ']' */
|
||||
|
||||
/* Assemble the UTF-16 string: '[' at STR_DATA, className, then each
|
||||
* name=value fragment, closing ']' (raw:657-697). */
|
||||
sd = as3vm_make_stringdata_GC(vm, (void *)0, total);
|
||||
*(uint16_t *)AT(sd, STR_DATA) = 0x5b; /* '[' */
|
||||
out = (uint16_t *)AT(sd, STR_DATA + 2);
|
||||
{
|
||||
void *s = EVSD(keys[0]);
|
||||
int len = *(int32_t *)AT(s, STR_HDR);
|
||||
memcpy(out, AT(s, STR_DATA), (__SIZE_TYPE__)len * 2);
|
||||
out += len;
|
||||
}
|
||||
for (i = 1; i < argc; ++i) {
|
||||
void *s;
|
||||
int len;
|
||||
*out++ = 0x20; /* ' ' */
|
||||
s = EVSD(keys[i]);
|
||||
len = *(int32_t *)AT(s, STR_HDR);
|
||||
memcpy(out, AT(s, STR_DATA), (__SIZE_TYPE__)len * 2);
|
||||
out += len;
|
||||
*out++ = 0x3d; /* '=' */
|
||||
if (quote[i]) {
|
||||
*out++ = 0x22; /* '"' */
|
||||
}
|
||||
s = EVSD(vals[i - 1]);
|
||||
len = *(int32_t *)AT(s, STR_HDR);
|
||||
memcpy(out, AT(s, STR_DATA), (__SIZE_TYPE__)len * 2);
|
||||
out += len;
|
||||
if (quote[i]) {
|
||||
*out++ = 0x22; /* '"' */
|
||||
}
|
||||
}
|
||||
*out++ = 0x5d; /* ']' */
|
||||
#undef EVSD
|
||||
*(void ***)AT(vm, VM_STACK) = saved_sp;
|
||||
store_ptr(frame, as3vm_make_string_GC(vm, sd));
|
||||
}
|
||||
|
||||
/* ---- flash.ui.Keyboard --------------------------------------------------- */
|
||||
|
||||
/* Unsupported: raise 0x74 (raw:1615-1618). */
|
||||
void as3vm_Keyboard__construct(void *frame) {
|
||||
as3vm_exception_GC(VM(frame), 0x74);
|
||||
}
|
||||
|
||||
/* Real: capsLock is always false (raw:1626-1630). */
|
||||
void as3vm_Keyboard_get_capsLock(void *frame) { store_ptr(frame, EV_FALSE_CELL); }
|
||||
|
||||
/* Real: numLock is always false (raw:1637-1641). */
|
||||
void as3vm_Keyboard_get_numLock(void *frame) { store_ptr(frame, EV_FALSE_CELL); }
|
||||
|
||||
/* Real: isAccessible is always true (raw:1648-1652). */
|
||||
void as3vm_Keyboard_isAccessible(void *frame) { store_ptr(frame, EV_TRUE_CELL); }
|
||||
|
||||
/* ---- flash.display.LoaderInfo -------------------------------------------- */
|
||||
|
||||
/* Empty constructor (raw:1659-1662). */
|
||||
void as3vm_LoaderInfo__construct(void *frame) { (void)frame; }
|
||||
|
||||
/* Real: bytes is always the true cell placeholder (raw:1669-1673). */
|
||||
void as3vm_LoaderInfo_get_bytes(void *frame) { store_ptr(frame, EV_TRUE_CELL); }
|
||||
|
||||
/* Real: box (vm[0] engine field 0x70) * 2 as an AS3 int (raw:1681-1684). */
|
||||
void as3vm_LoaderInfo_get_bytesLoaded(void *frame) {
|
||||
store_word(frame, *(intptr_t *)AT(*(void **)VM(frame), 0x70) * 2);
|
||||
}
|
||||
|
||||
/* Real: bytesTotal mirrors bytesLoaded (raw:1691-1695). */
|
||||
void as3vm_LoaderInfo_get_bytesTotal(void *frame) {
|
||||
store_word(frame, *(intptr_t *)AT(*(void **)VM(frame), 0x70) * 2);
|
||||
}
|
||||
|
||||
/* Real: a bare object of the parameters class (raw:1702-1711). */
|
||||
void as3vm_LoaderInfo_get_parameters(void *frame) {
|
||||
store_ptr(frame,
|
||||
as3vm_make_object_no_constructor_GC(
|
||||
VM(frame), *(void **)AT(VM(frame), VM_LOADERPARAMS)));
|
||||
}
|
||||
|
||||
/* Real: the cached empty-string cell (raw:1718-1722). */
|
||||
void as3vm_LoaderInfo_get_url(void *frame) {
|
||||
store_ptr(frame, *(void **)AT(VM(frame), VM_EMPTYSTR));
|
||||
}
|
||||
@@ -0,0 +1,278 @@
|
||||
/*
|
||||
* swf_as3vm_flash_events_eventdispatcher.inc -- flash.events.EventDispatcher.
|
||||
* The reject paths (argc / parse-failure / unsupported) are pinned by the
|
||||
* runtime harness; the listener-table mechanics are reconstructed from the
|
||||
* durango raw (authoritative 64-bit) + object. Included by
|
||||
* swf_as3vm_flash_events.c.
|
||||
*/
|
||||
|
||||
/* The dispatcher's per-type phase byte and direct-listener head are the module
|
||||
* offsets EV_TYPEPHASE / EV_DIRECTLIST (see the width table). */
|
||||
#define TYPEKEY_PHASE EV_TYPEPHASE
|
||||
#define OBJ_DIRECTLIST EV_DIRECTLIST
|
||||
|
||||
/* Empty constructor (raw:6-9). */
|
||||
void as3vm_EventDispatcher__construct(void *frame) { (void)frame; }
|
||||
|
||||
/* Real: tear down every listener node hung off the dispatcher, freeing the
|
||||
* boxed handles through the GC pool and the node structs through the arena
|
||||
* (raw:16-64). */
|
||||
void as3vm_EventDispatcher__finalize(void *frame) {
|
||||
void *vm = VM(frame);
|
||||
void *obj = THISOBJ(frame);
|
||||
void *node;
|
||||
if (*(void **)AT(obj, 0x28) != (void *)0) {
|
||||
*(void **)AT(obj, 0x28) = (void *)1;
|
||||
}
|
||||
while ((node = *(void **)AT(obj, 0x30)) != (void *)0) {
|
||||
void *entry;
|
||||
for (entry = *(void **)AT(node, ND_LISTBYBUB); entry != (void *)0;) {
|
||||
void *next = *(void **)AT(entry, LE_NEXT);
|
||||
if (*(void **)AT(entry, LE_HANDLE) != (void *)0) {
|
||||
as3vm_pool_free(vm);
|
||||
*(void **)AT(entry, LE_HANDLE) = (void *)0;
|
||||
}
|
||||
iggy_free_alloc(*(void **)vm, entry);
|
||||
*(int32_t *)AT(node, ND_COUNT) -= 1;
|
||||
entry = next;
|
||||
}
|
||||
for (entry = *(void **)AT(node, ND_LISTBYCAP); entry != (void *)0;) {
|
||||
void *next = *(void **)AT(entry, LE_NEXT);
|
||||
if (*(void **)AT(entry, LE_HANDLE) != (void *)0) {
|
||||
as3vm_pool_free(vm);
|
||||
*(void **)AT(entry, LE_HANDLE) = (void *)0;
|
||||
}
|
||||
iggy_free_alloc(*(void **)vm, entry);
|
||||
*(int32_t *)AT(node, ND_COUNT) -= 1;
|
||||
entry = next;
|
||||
}
|
||||
*(void **)AT(obj, 0x30) = *(void **)AT(node, ND_CHAINNEXT);
|
||||
if (*(void **)AT(node, ND_CLEANNEXT) == (void *)0) {
|
||||
*(int32_t *)AT(node, 8) = 0;
|
||||
iggy_free_alloc(*(void **)vm, node);
|
||||
} else {
|
||||
*(uint8_t *)AT(node, ND_DEAD) = 1;
|
||||
*(void **)AT(node, ND_LISTBYCAP) = (void *)0;
|
||||
*(void **)AT(node, ND_LISTBYBUB) = (void *)0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Real: parse (type, ?useCapture, priority, useWeakReference, listener); find or
|
||||
* create the type node, allocate a listener entry and splice it into the
|
||||
* phase-appropriate list in priority order (raw:70-265). Only the parse-
|
||||
* failure reject (0x78) is pinned by the harness. */
|
||||
void as3vm_EventDispatcher_addEventListener(void *frame) {
|
||||
void *vm = VM(frame);
|
||||
void *obj = THISOBJ(frame);
|
||||
void *listener = (void *)0;
|
||||
int32_t use_capture = 0;
|
||||
int32_t priority = 0;
|
||||
int32_t use_weak = 0;
|
||||
void **slot;
|
||||
void *node;
|
||||
uint8_t phase;
|
||||
void *entry;
|
||||
void **list;
|
||||
if (as3vm_component_parse_arguments_GC(frame, EVFMT_KEYBOARD, &listener,
|
||||
&use_weak, &use_capture, &priority,
|
||||
&listener) != 0) {
|
||||
as3vm_exception_GC(vm, 0x78);
|
||||
return;
|
||||
}
|
||||
phase = *(uint8_t *)AT(listener, TYPEKEY_PHASE);
|
||||
if ((uint8_t)(phase - 1) < 5) {
|
||||
slot = (void **)AT(vm, VM_LISTENER + (intptr_t)phase * (int)sizeof(void *));
|
||||
} else {
|
||||
slot = (void **)AT(obj, OBJ_DIRECTLIST);
|
||||
}
|
||||
node = (void *)0;
|
||||
for (void *walk = *slot; walk != (void *)0;
|
||||
walk = *(void **)AT(walk, ND_CHAINNEXT)) {
|
||||
if (*(void **)AT(walk, ND_KEY) == listener) {
|
||||
node = walk;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (node == (void *)0) {
|
||||
node = iggy_malloc_fileline(*(void **)vm, 0, ND_ALLOC, 9,
|
||||
iggy_swf_as3vm_flash_events_source_path, 820);
|
||||
*(void **)AT(node, 0x20) = (void *)0;
|
||||
*(void **)AT(node, 0x18) = (void *)0;
|
||||
*(void **)AT(node, ND_CLEANNEXT) = (void *)0;
|
||||
*(uint8_t *)AT(node, ND_DEAD) = 0;
|
||||
*(void **)AT(node, ND_KEY) = listener;
|
||||
*(void **)AT(node, ND_GROUP_ARENA) = (void *)0;
|
||||
*(void **)AT(node, ND_CHAINNEXT) = *slot;
|
||||
*slot = node;
|
||||
}
|
||||
entry = iggy_malloc_fileline(*(void **)vm, 0, LE_ALLOC, 10,
|
||||
iggy_swf_as3vm_flash_events_source_path, 863);
|
||||
*(void **)AT(entry, LE_HANDLE) =
|
||||
as3vm_pool_alloc(vm, *(void **)AT(obj, 0x10), 1);
|
||||
*(void **)AT(entry, LE_SELF) = (void *)0;
|
||||
*(int32_t *)AT(entry, LE_PRIO) = priority;
|
||||
*(uint8_t *)AT(entry, LE_USECAP) = (uint8_t)use_capture;
|
||||
/* GC write barriers when the boxed listener / bound-this cross a generation
|
||||
* boundary into the freshly allocated entry (raw:231-246). */
|
||||
{
|
||||
void **this_slot = (void **)FR(frame)[3];
|
||||
void *keyval = this_slot[2];
|
||||
if (((uintptr_t)keyval & 3) == 1 &&
|
||||
(uint8_t)(~*(uint8_t *)keyval & *(uint8_t *)obj) > 0x17) {
|
||||
as3vm_write_barrier_slowpath(vm, (char *)obj - 1, (char *)keyval - 1);
|
||||
}
|
||||
if (((uintptr_t)this_slot[1] & 3) == 1 &&
|
||||
(uint8_t)(~*(uint8_t *)this_slot[1] & *(uint8_t *)obj) > 0x17) {
|
||||
*(void **)AT(entry, LE_SELF) = *(void **)AT(this_slot[1], 7);
|
||||
as3vm_write_barrier_slowpath(vm, (char *)obj - 1, (char *)keyval - 1);
|
||||
}
|
||||
}
|
||||
*(int32_t *)AT(node, ND_COUNT) += 1;
|
||||
list = (void **)AT(node, use_capture == 0 ? ND_LISTBYCAP : ND_LISTBYBUB);
|
||||
while (*list != (void *)0 && priority <= *(int32_t *)AT(*list, LE_PRIO)) {
|
||||
list = (void **)AT(*list, LE_NEXT);
|
||||
}
|
||||
*(void **)AT(entry, LE_NEXT) = *list;
|
||||
*list = entry;
|
||||
store_ptr(frame, EV_UNDEF_CELL);
|
||||
}
|
||||
|
||||
/* Real: dispatchEvent -- reject argc<1 or a non-Event argument with 0x78; clone
|
||||
* a lazy event, set currentTarget/target and enter the propagation dispatch
|
||||
* (raw:271-305). The runtime harness pins the argc<1 reject. */
|
||||
void as3vm_EventDispatcher_dispatchEvent(void *frame) {
|
||||
void *vm = VM(frame);
|
||||
void *this_slot = FR(frame)[3];
|
||||
void *event;
|
||||
void *dispatcher;
|
||||
uint8_t bubbles;
|
||||
void *type;
|
||||
if (ARGC(frame) < 1) {
|
||||
as3vm_exception_GC(vm, 0x78);
|
||||
return;
|
||||
}
|
||||
event = *(void **)AT(this_slot, (int)sizeof(void *));
|
||||
if (((uintptr_t)event & 3) != 1 ||
|
||||
*(uint8_t *)((char *)event - 1) < 0x20 ||
|
||||
as3vm_is_ofclass((char *)event - 1, *(void **)AT(vm, VM_EVENTCLASS)) == 0) {
|
||||
as3vm_exception_GC(vm, 0x78);
|
||||
return;
|
||||
}
|
||||
if (*(char *)AT(event, EV_LAZYCLONE) != '\0') {
|
||||
event = as3vm_clone_GC(vm, *(void **)this_slot);
|
||||
*(void **)AT(this_slot, (int)sizeof(void *)) = event;
|
||||
}
|
||||
as3vmcomp_set_value(vm, (char *)event - 1, 0, *(void **)this_slot);
|
||||
dispatcher = *(void **)this_slot;
|
||||
bubbles = *(uint8_t *)AT(event, EV_BUBBLES);
|
||||
type = as3vm_string_interned(vm, *(void **)AT(event, EV_TYPE));
|
||||
dispatch_event_GC(vm, dispatcher, event, type, bubbles);
|
||||
}
|
||||
|
||||
/* Real: hasEventListener -- parse the type, walk the listener node's entries and
|
||||
* return the true/false cell (raw:311-359). Parse-failure reject (0x78) is
|
||||
* pinned. */
|
||||
void as3vm_EventDispatcher_hasEventListener(void *frame) {
|
||||
void *vm = VM(frame);
|
||||
void *args[3];
|
||||
void **slot;
|
||||
void *node;
|
||||
void *entry;
|
||||
uint8_t phase;
|
||||
args[0] = (void *)0;
|
||||
if (as3vm_component_parse_arguments_GC(frame, EVFMT_INTERN, args) != 0) {
|
||||
as3vm_exception_GC(vm, 0x78);
|
||||
return;
|
||||
}
|
||||
phase = *(uint8_t *)AT(args[0], TYPEKEY_PHASE);
|
||||
if ((uint8_t)(phase - 1) < 5) {
|
||||
slot = (void **)AT(vm, VM_LISTENER + (intptr_t)phase * (int)sizeof(void *));
|
||||
} else {
|
||||
slot = (void **)AT(THISOBJ(frame), OBJ_DIRECTLIST);
|
||||
}
|
||||
for (node = *slot; node != (void *)0;
|
||||
node = *(void **)AT(node, ND_CHAINNEXT)) {
|
||||
if (*(void **)AT(node, ND_KEY) == args[0]) {
|
||||
for (entry = *(void **)AT(node, ND_LISTBYCAP); entry != (void *)0;
|
||||
entry = *(void **)AT(entry, LE_NEXT)) {
|
||||
void *handle = *(void **)AT(entry, LE_HANDLE);
|
||||
if (handle != (void *)0 && *(void **)handle != (void *)7) {
|
||||
store_ptr(frame, EV_TRUE_CELL);
|
||||
return;
|
||||
}
|
||||
}
|
||||
for (entry = *(void **)AT(node, ND_LISTBYBUB); entry != (void *)0;
|
||||
entry = *(void **)AT(entry, LE_NEXT)) {
|
||||
void *handle = *(void **)AT(entry, LE_HANDLE);
|
||||
if (handle != (void *)0 && *(void **)handle != (void *)7) {
|
||||
store_ptr(frame, EV_TRUE_CELL);
|
||||
return;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
store_ptr(frame, EV_FALSE_CELL);
|
||||
}
|
||||
|
||||
/* Real: removeEventListener -- parse (type, ?useCapture, listener); find the
|
||||
* matching entry, free its boxed handle and mark the node for cleanup
|
||||
* (raw:366-453). Parse-failure reject (0x78) is pinned. */
|
||||
void as3vm_EventDispatcher_removeEventListener(void *frame) {
|
||||
void *vm = VM(frame);
|
||||
void *obj = THISOBJ(frame);
|
||||
void *type_key = (void *)0;
|
||||
void *listener = (void *)0;
|
||||
int32_t use_capture = 0;
|
||||
void **slot;
|
||||
void *node;
|
||||
void *entry;
|
||||
uint8_t phase;
|
||||
if (as3vm_component_parse_arguments_GC(frame, EVFMT_INTERN_BOOL, &type_key,
|
||||
&listener, &use_capture) != 0) {
|
||||
as3vm_exception_GC(vm, 0x78);
|
||||
return;
|
||||
}
|
||||
phase = *(uint8_t *)AT(type_key, TYPEKEY_PHASE);
|
||||
if ((uint8_t)(phase - 1) < 5) {
|
||||
node = *(void **)AT(vm, VM_LISTENER + (intptr_t)phase * (int)sizeof(void *));
|
||||
} else {
|
||||
node = *(void **)AT(obj, OBJ_DIRECTLIST);
|
||||
}
|
||||
while (node != (void *)0 &&
|
||||
*(void **)AT(node, ND_KEY) != type_key) {
|
||||
node = *(void **)AT(node, ND_CHAINNEXT);
|
||||
}
|
||||
if (node == (void *)0) {
|
||||
return;
|
||||
}
|
||||
slot = (void **)AT(node, use_capture == 0 ? ND_LISTBYCAP : ND_LISTBYBUB);
|
||||
for (entry = *slot; entry != (void *)0;
|
||||
entry = *(void **)AT(entry, LE_NEXT)) {
|
||||
void *handle = *(void **)AT(entry, LE_HANDLE);
|
||||
if (handle != (void *)0 && *(void **)handle == listener) {
|
||||
as3vm_pool_free(*(void **)AT(entry, LE_HANDLE));
|
||||
*(void **)AT(entry, LE_HANDLE) = (void *)0;
|
||||
if (*(void **)AT(node, ND_CLEANNEXT) == (void *)0) {
|
||||
*(void **)AT(node, ND_CLEANNEXT) = *(void **)AT(vm, VM_CLEANLIST);
|
||||
*(void **)AT(vm, VM_CLEANLIST) = node;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Real: willTrigger is unsupported -- raise 0x74 on good args, 0x78 on a parse
|
||||
* failure (raw:459-473). Both branches are pinned by the harness. */
|
||||
void as3vm_EventDispatcher_willTrigger(void *frame) {
|
||||
uint8_t args[24];
|
||||
int code = 0x74;
|
||||
if (as3vm_component_parse_arguments_GC(frame, EVFMT_INTERN, args) != 0) {
|
||||
code = 0x78;
|
||||
}
|
||||
as3vm_exception_GC(VM(frame), code);
|
||||
}
|
||||
|
||||
#undef TYPEKEY_PHASE
|
||||
#undef OBJ_DIRECTLIST
|
||||
@@ -0,0 +1,518 @@
|
||||
/*
|
||||
* swf_as3vm_flash_events_inputevents.inc -- flash.events.FocusEvent,
|
||||
* KeyboardEvent, MouseEvent and TextEvent binding thunks.
|
||||
* Included by swf_as3vm_flash_events.c.
|
||||
*/
|
||||
|
||||
/* Seed the Event base fields shared by every input-event constructor; flags are
|
||||
* written byte-wise (endian-correct on ps3). */
|
||||
static void ev_init_base(void *obj, void *type, int bubbles, int cancelable) {
|
||||
*(void **)AT(obj, EV_TYPE) = type;
|
||||
*(uint8_t *)AT(obj, EV_BUBBLES) = (uint8_t)bubbles;
|
||||
*(uint8_t *)AT(obj, EV_CANCELABLE) = (uint8_t)cancelable;
|
||||
*(uint8_t *)AT(obj, EV_FLAGS) = 0;
|
||||
*(uint8_t *)AT(obj, EV_PHASE) = 2;
|
||||
*(uint8_t *)AT(obj, EV_DEFPREV) = 0;
|
||||
*(uint8_t *)AT(obj, EV_LAZYCLONE) = 0;
|
||||
}
|
||||
|
||||
/* ---- flash.events.FocusEvent --------------------------------------------- */
|
||||
|
||||
/* Real: parse (type,?bubbles,?cancelable,?relatedObject,?shiftKey,?keyCode) and
|
||||
* seed the base + focus fields (raw:1023-1062). */
|
||||
void as3vm_FocusEvent__construct(void *frame) {
|
||||
void *type = (void *)0, *related = EV_TRUE_CELL;
|
||||
int32_t bubbles = 1, cancelable = 0, shift = 0, key = 0;
|
||||
void *obj;
|
||||
if (as3vm_component_parse_arguments_GC(
|
||||
frame, EVFMT_FOCUS, &type, &bubbles, &cancelable,
|
||||
*(void **)AT(VM(frame), VM_DEFAULTOBJ), &related, &shift, &key) != 0) {
|
||||
as3vm_exception_GC(VM(frame), 0x78);
|
||||
return;
|
||||
}
|
||||
obj = THISOBJ(frame);
|
||||
ev_init_base(obj, type, bubbles, cancelable);
|
||||
as3vmcomp_set_value(VM(frame), (char *)obj - 1, 2, related);
|
||||
obj = THISOBJ(frame);
|
||||
*(uint8_t *)AT(obj, EV_SHIFTKEY) = (uint8_t)shift;
|
||||
*(int32_t *)AT(obj, EV_KEYCODE) = key;
|
||||
}
|
||||
|
||||
/* Real: clone (raw:1068-1097). */
|
||||
void as3vm_FocusEvent_clone(void *frame) { ev_clone_into(frame); }
|
||||
|
||||
/* Real: box keyCode int * 2 (raw:1104-1108). */
|
||||
void as3vm_FocusEvent_get_keyCode(void *frame) {
|
||||
store_astag(frame, *(int32_t *)AT(THISOBJ(frame), EV_KEYCODE));
|
||||
}
|
||||
|
||||
/* Real: the relatedObject AS3 slot value (raw:1116-1123). */
|
||||
void as3vm_FocusEvent_get_relatedObject(void *frame) {
|
||||
store_ptr(frame, ev_slot_value(THISOBJ(frame), 4));
|
||||
}
|
||||
|
||||
/* Real: box the shiftKey flag byte (raw:1131-1136). */
|
||||
void as3vm_FocusEvent_get_shiftKey(void *frame) {
|
||||
store_ptr(frame, ev_makebool(*(uint8_t *)AT(THISOBJ(frame), EV_SHIFTKEY)));
|
||||
}
|
||||
|
||||
/* Real: parse a uint, write keyCode (raw:1144-1156). */
|
||||
void as3vm_FocusEvent_set_keyCode(void *frame) {
|
||||
uint32_t v[6];
|
||||
if (as3vm_component_parse_arguments_GC(frame, EVFMT_UINT, v) != 0) {
|
||||
as3vm_exception_GC(VM(frame), 0x78);
|
||||
return;
|
||||
}
|
||||
*(int32_t *)AT(THISOBJ(frame), EV_KEYCODE) = (int32_t)v[0];
|
||||
}
|
||||
|
||||
/* Real: parse an object, assign the relatedObject slot (raw:1163-1176). */
|
||||
void as3vm_FocusEvent_set_relatedObject(void *frame) {
|
||||
void *value[4];
|
||||
if (as3vm_component_parse_arguments_GC(frame, EVFMT_OBJECT,
|
||||
*(void **)AT(VM(frame), VM_DEFAULTOBJ),
|
||||
value) != 0) {
|
||||
as3vm_exception_GC(VM(frame), 0x78);
|
||||
return;
|
||||
}
|
||||
as3vmcomp_set_value(VM(frame), (char *)THISOBJ(frame) - 1, 2, value[0]);
|
||||
}
|
||||
|
||||
/* Real: parse a bool, write shiftKey (raw:1183-1195). */
|
||||
void as3vm_FocusEvent_set_shiftKey(void *frame) {
|
||||
uint8_t v[24];
|
||||
if (as3vm_component_parse_arguments_GC(frame, EVFMT_BOOL, v) != 0) {
|
||||
as3vm_exception_GC(VM(frame), 0x78);
|
||||
return;
|
||||
}
|
||||
*(uint8_t *)AT(THISOBJ(frame), EV_SHIFTKEY) = v[0];
|
||||
}
|
||||
|
||||
/* ---- flash.events.KeyboardEvent ------------------------------------------ */
|
||||
|
||||
/* Real: parse the keyboard-event argument vector and seed all fields
|
||||
* (raw:1202-1252). */
|
||||
void as3vm_KeyboardEvent__construct(void *frame) {
|
||||
void *type = (void *)0;
|
||||
int32_t bubbles = 1, cancelable = 0, keycode = 0, charcode = 0;
|
||||
int32_t keyloc = 0, alt = 0, ctrl = 0, cmd = 0, shift = 0;
|
||||
void *obj;
|
||||
if (as3vm_component_parse_arguments_GC(
|
||||
frame, EVFMT_KEYBOARD, &type, &bubbles, &cancelable, &charcode,
|
||||
&keycode, &keyloc, &alt, &ctrl, &cmd, &shift) != 0) {
|
||||
as3vm_exception_GC(VM(frame), 0x78);
|
||||
return;
|
||||
}
|
||||
obj = THISOBJ(frame);
|
||||
ev_init_base(obj, type, bubbles, cancelable);
|
||||
obj = THISOBJ(frame);
|
||||
*(int32_t *)AT(obj, EV_KEYCODE) = keycode;
|
||||
*(int32_t *)AT(obj, EV_CHARCODE) = charcode;
|
||||
*(uint8_t *)AT(obj, EV_KEYLOCATION) = (uint8_t)keyloc;
|
||||
*(uint8_t *)AT(obj, EV_ALTKEY) = (uint8_t)alt;
|
||||
*(uint8_t *)AT(obj, EV_SHIFTKEY) = (uint8_t)shift;
|
||||
*(uint8_t *)AT(obj, EV_CONTROLKEY) = (uint8_t)ctrl;
|
||||
*(uint8_t *)AT(obj, EV_COMMANDKEY) = (uint8_t)cmd;
|
||||
}
|
||||
|
||||
/* Real: clone (raw:1258-1287). */
|
||||
void as3vm_KeyboardEvent_clone(void *frame) { ev_clone_into(frame); }
|
||||
|
||||
/* Real: box the altKey flag byte (raw:1294-1299). */
|
||||
void as3vm_KeyboardEvent_get_altKey(void *frame) {
|
||||
store_ptr(frame, ev_makebool(*(uint8_t *)AT(THISOBJ(frame), EV_ALTKEY)));
|
||||
}
|
||||
|
||||
/* Real: box charCode int * 2 (raw:1307-1311). */
|
||||
void as3vm_KeyboardEvent_get_charCode(void *frame) {
|
||||
store_astag(frame, *(int32_t *)AT(THISOBJ(frame), EV_CHARCODE));
|
||||
}
|
||||
|
||||
/* Real: box the commandKey flag byte (raw:1319-1324). */
|
||||
void as3vm_KeyboardEvent_get_commandKey(void *frame) {
|
||||
store_ptr(frame, ev_makebool(*(uint8_t *)AT(THISOBJ(frame), EV_COMMANDKEY)));
|
||||
}
|
||||
|
||||
/* Real: box the controlKey flag byte (raw:1332-1337). */
|
||||
void as3vm_KeyboardEvent_get_controlKey(void *frame) {
|
||||
store_ptr(frame, ev_makebool(*(uint8_t *)AT(THISOBJ(frame), EV_CONTROLKEY)));
|
||||
}
|
||||
|
||||
/* Real: ctrlKey is true iff controlKey OR commandKey is set (raw:1347-1357).
|
||||
* DEFERRED: the retail makebool[0]/[1] alias is reconstructed as the boolean
|
||||
* OR of the two byte fields (the object does not pin the alias cleanly). */
|
||||
void as3vm_KeyboardEvent_get_ctrlKey(void *frame) {
|
||||
void *obj = THISOBJ(frame);
|
||||
unsigned set = (*(char *)AT(obj, EV_CONTROLKEY) != '\0') ||
|
||||
(*(char *)AT(obj, EV_COMMANDKEY) != '\0');
|
||||
store_ptr(frame, ev_makebool(set));
|
||||
}
|
||||
|
||||
/* Real: box keyCode int * 2 (raw:1363-1367). */
|
||||
void as3vm_KeyboardEvent_get_keyCode(void *frame) {
|
||||
store_astag(frame, *(int32_t *)AT(THISOBJ(frame), EV_KEYCODE));
|
||||
}
|
||||
|
||||
/* Real: box keyLocation byte * 2 (raw:1375-1379). */
|
||||
void as3vm_KeyboardEvent_get_keyLocation(void *frame) {
|
||||
store_astag(frame, *(uint8_t *)AT(THISOBJ(frame), EV_KEYLOCATION));
|
||||
}
|
||||
|
||||
/* Real: box the shiftKey flag byte (raw:1387-1392). */
|
||||
void as3vm_KeyboardEvent_get_shiftKey(void *frame) {
|
||||
store_ptr(frame, ev_makebool(*(uint8_t *)AT(THISOBJ(frame), EV_SHIFTKEY)));
|
||||
}
|
||||
|
||||
/* Shared int/uint setter (parse then write a 4-byte field). */
|
||||
static void ev_set_u32(void *frame, int field, const char *fmt) {
|
||||
uint32_t v[6];
|
||||
if (as3vm_component_parse_arguments_GC(frame, fmt, v) != 0) {
|
||||
as3vm_exception_GC(VM(frame), 0x78);
|
||||
return;
|
||||
}
|
||||
*(int32_t *)AT(THISOBJ(frame), field) = (int32_t)v[0];
|
||||
}
|
||||
|
||||
/* Shared bool/byte setter (parse then write a 1-byte field). */
|
||||
static void ev_set_u8(void *frame, int field) {
|
||||
uint8_t v[24];
|
||||
if (as3vm_component_parse_arguments_GC(frame, EVFMT_BOOL, v) != 0) {
|
||||
as3vm_exception_GC(VM(frame), 0x78);
|
||||
return;
|
||||
}
|
||||
*(uint8_t *)AT(THISOBJ(frame), field) = v[0];
|
||||
}
|
||||
|
||||
/* Real: set_altKey (raw:1400-1412). */
|
||||
void as3vm_KeyboardEvent_set_altKey(void *frame) {
|
||||
ev_set_u8(frame, EV_ALTKEY);
|
||||
}
|
||||
|
||||
/* Real: set_charCode (raw:1419-1431). */
|
||||
void as3vm_KeyboardEvent_set_charCode(void *frame) {
|
||||
ev_set_u32(frame, EV_CHARCODE, EVFMT_UINT);
|
||||
}
|
||||
|
||||
/* Real: set_commandKey (raw:1438-1450). */
|
||||
void as3vm_KeyboardEvent_set_commandKey(void *frame) {
|
||||
ev_set_u8(frame, EV_COMMANDKEY);
|
||||
}
|
||||
|
||||
/* Real: set_controlKey (raw:1457-1469). */
|
||||
void as3vm_KeyboardEvent_set_controlKey(void *frame) {
|
||||
ev_set_u8(frame, EV_CONTROLKEY);
|
||||
}
|
||||
|
||||
/* Real: set_ctrlKey -- retail parses "b" twice, writing controlKey both times;
|
||||
* the first block's failure still falls through to the second (raw:1474-1496,
|
||||
* confirmed by object disassembly). */
|
||||
void as3vm_KeyboardEvent_set_ctrlKey(void *frame) {
|
||||
uint8_t v[24];
|
||||
if (as3vm_component_parse_arguments_GC(frame, EVFMT_BOOL, v) == 0) {
|
||||
*(uint8_t *)AT(THISOBJ(frame), EV_CONTROLKEY) = v[0];
|
||||
} else {
|
||||
as3vm_exception_GC(VM(frame), 0x78);
|
||||
}
|
||||
if (as3vm_component_parse_arguments_GC(frame, EVFMT_BOOL, v) != 0) {
|
||||
as3vm_exception_GC(VM(frame), 0x78);
|
||||
return;
|
||||
}
|
||||
*(uint8_t *)AT(THISOBJ(frame), EV_CONTROLKEY) = v[0];
|
||||
}
|
||||
|
||||
/* Real: set_keyCode (raw:1502-1514). */
|
||||
void as3vm_KeyboardEvent_set_keyCode(void *frame) {
|
||||
ev_set_u32(frame, EV_KEYCODE, EVFMT_UINT);
|
||||
}
|
||||
|
||||
/* Real: set_keyLocation (parse uint, write a byte) (raw:1521-1533). */
|
||||
void as3vm_KeyboardEvent_set_keyLocation(void *frame) {
|
||||
uint32_t v[6];
|
||||
if (as3vm_component_parse_arguments_GC(frame, EVFMT_UINT, v) != 0) {
|
||||
as3vm_exception_GC(VM(frame), 0x78);
|
||||
return;
|
||||
}
|
||||
*(uint8_t *)AT(THISOBJ(frame), EV_KEYLOCATION) = (uint8_t)v[0];
|
||||
}
|
||||
|
||||
/* Real: set_shiftKey (raw:1540-1552). */
|
||||
void as3vm_KeyboardEvent_set_shiftKey(void *frame) {
|
||||
ev_set_u8(frame, EV_SHIFTKEY);
|
||||
}
|
||||
|
||||
/* Real: KeyboardEvent.toString -- push the properties and assemble the string
|
||||
* (raw:1559-1599). DEFERRED structurally (deep string assembly). */
|
||||
void as3vm_KeyboardEvent_toString(void *frame) {
|
||||
void *vm = VM(frame);
|
||||
void *obj = THISOBJ(frame);
|
||||
ev_push(vm, *(void **)AT(obj, EV_TYPE));
|
||||
ev_push(vm, ev_makebool(*(uint8_t *)AT(obj, EV_BUBBLES)));
|
||||
ev_push(vm, ev_makebool(*(uint8_t *)AT(obj, EV_CANCELABLE)));
|
||||
ev_push(vm, (void *)(intptr_t)((uint32_t)*(uint8_t *)AT(obj, EV_PHASE) * 2u));
|
||||
ev_push(vm, (void *)(intptr_t)((uint32_t)*(int32_t *)AT(obj, EV_CHARCODE) * 2u));
|
||||
ev_push(vm, (void *)(intptr_t)((uint32_t)*(int32_t *)AT(obj, EV_KEYCODE) * 2u));
|
||||
ev_push(vm, (void *)(intptr_t)((uint32_t)*(uint8_t *)AT(obj, EV_KEYLOCATION) * 2u));
|
||||
ev_push(vm, ev_makebool(*(uint8_t *)AT(obj, EV_CONTROLKEY)));
|
||||
ev_push(vm, ev_makebool(*(uint8_t *)AT(obj, EV_ALTKEY)));
|
||||
ev_push(vm, ev_makebool(*(uint8_t *)AT(obj, EV_SHIFTKEY)));
|
||||
store_ptr(frame, as3vm_create_interleaved_string_GC(vm, 0xb));
|
||||
}
|
||||
|
||||
/* Empty (raw:1605-1608). */
|
||||
void as3vm_KeyboardEvent_updateAfterEvent(void *frame) { (void)frame; }
|
||||
|
||||
/* ---- flash.events.MouseEvent --------------------------------------------- */
|
||||
|
||||
/* Real: parse the mouse-event argument vector and seed all fields
|
||||
* (raw:1731-1791). */
|
||||
void as3vm_MouseEvent__construct(void *frame) {
|
||||
void *type = (void *)0, *related = EV_TRUE_CELL;
|
||||
int32_t bubbles = 1, cancelable = 0;
|
||||
uint32_t local_x, local_y;
|
||||
int32_t alt = 0, shift = 0, ctrl = 0, cmd = 0, button = 0;
|
||||
int32_t click = 0, delta = 0;
|
||||
float nan = as3vm_NaNf;
|
||||
void *obj;
|
||||
memcpy(&local_x, &nan, sizeof(float));
|
||||
memcpy(&local_y, &nan, sizeof(float));
|
||||
if (as3vm_component_parse_arguments_GC(
|
||||
frame, EVFMT_MOUSE, &type, &bubbles, &cancelable, &local_x, &local_y,
|
||||
*(void **)AT(VM(frame), VM_DEFAULTOBJ), &related, &shift, &alt, &ctrl,
|
||||
&button, &cmd, &delta, &click) != 0) {
|
||||
as3vm_exception_GC(VM(frame), 0x78);
|
||||
return;
|
||||
}
|
||||
obj = THISOBJ(frame);
|
||||
ev_init_base(obj, type, bubbles, cancelable);
|
||||
obj = THISOBJ(frame);
|
||||
*(uint32_t *)AT(obj, EV_LOCALX) = local_x;
|
||||
*(uint32_t *)AT(obj, EV_LOCALY) = local_y;
|
||||
as3vmcomp_set_value(VM(frame), (char *)obj - 1, 2, related);
|
||||
*(uint8_t *)AT(obj, EV_ALTKEY) = (uint8_t)alt;
|
||||
*(uint8_t *)AT(obj, EV_SHIFTKEY) = (uint8_t)shift;
|
||||
*(uint8_t *)AT(obj, EV_BUTTONDOWN) = (uint8_t)button;
|
||||
*(uint16_t *)AT(obj, EV_DELTA) = (uint16_t)delta;
|
||||
*(uint8_t *)AT(obj, EV_COMMANDKEY) = (uint8_t)cmd;
|
||||
*(uint8_t *)AT(obj, EV_CONTROLKEY) = (uint8_t)ctrl;
|
||||
*(uint16_t *)AT(obj, EV_CLICKCOUNT) = (uint16_t)click;
|
||||
}
|
||||
|
||||
/* Real: box the altKey flag byte (raw:1798-1803). */
|
||||
void as3vm_MouseEvent_get_altKey(void *frame) {
|
||||
store_ptr(frame, ev_makebool(*(uint8_t *)AT(THISOBJ(frame), EV_ALTKEY)));
|
||||
}
|
||||
|
||||
/* Real: box the buttonDown flag byte (raw:1811-1816). */
|
||||
void as3vm_MouseEvent_get_buttonDown(void *frame) {
|
||||
store_ptr(frame, ev_makebool(*(uint8_t *)AT(THISOBJ(frame), EV_BUTTONDOWN)));
|
||||
}
|
||||
|
||||
/* Real: box clickCount short * 2 (raw:1824-1827). */
|
||||
void as3vm_MouseEvent_get_clickCount(void *frame) {
|
||||
store_word(frame, (intptr_t)(*(int16_t *)AT(THISOBJ(frame), EV_CLICKCOUNT) * 2));
|
||||
}
|
||||
|
||||
/* Real: box the commandKey flag byte (raw:1835-1840). */
|
||||
void as3vm_MouseEvent_get_commandKey(void *frame) {
|
||||
store_ptr(frame, ev_makebool(*(uint8_t *)AT(THISOBJ(frame), EV_COMMANDKEY)));
|
||||
}
|
||||
|
||||
/* Real: box the controlKey flag byte (raw:1848-1853). */
|
||||
void as3vm_MouseEvent_get_controlKey(void *frame) {
|
||||
store_ptr(frame, ev_makebool(*(uint8_t *)AT(THISOBJ(frame), EV_CONTROLKEY)));
|
||||
}
|
||||
|
||||
/* Real: ctrlKey true iff controlKey OR commandKey is set (raw:1863-1873). */
|
||||
void as3vm_MouseEvent_get_ctrlKey(void *frame) {
|
||||
void *obj = THISOBJ(frame);
|
||||
unsigned set = (*(char *)AT(obj, EV_CONTROLKEY) != '\0') ||
|
||||
(*(char *)AT(obj, EV_COMMANDKEY) != '\0');
|
||||
store_ptr(frame, ev_makebool(set));
|
||||
}
|
||||
|
||||
/* Real: box delta short * 2 (raw:1879-1882). */
|
||||
void as3vm_MouseEvent_get_delta(void *frame) {
|
||||
store_word(frame, (intptr_t)(*(int16_t *)AT(THISOBJ(frame), EV_DELTA) * 2));
|
||||
}
|
||||
|
||||
/* Real: box the localX float as a Number (raw:1890-1898). */
|
||||
void as3vm_MouseEvent_get_localX(void *frame) {
|
||||
store_ptr(frame, as3vm_make_number_GC(
|
||||
VM(frame),
|
||||
ev_float_to_double(*(float *)AT(THISOBJ(frame), EV_LOCALX))));
|
||||
}
|
||||
|
||||
/* Real: box the localY float as a Number (raw:1906-1914). */
|
||||
void as3vm_MouseEvent_get_localY(void *frame) {
|
||||
store_ptr(frame, as3vm_make_number_GC(
|
||||
VM(frame),
|
||||
ev_float_to_double(*(float *)AT(THISOBJ(frame), EV_LOCALY))));
|
||||
}
|
||||
|
||||
/* Real: the relatedObject AS3 slot value (raw:1922-1929). */
|
||||
void as3vm_MouseEvent_get_relatedObject(void *frame) {
|
||||
store_ptr(frame, ev_slot_value(THISOBJ(frame), 4));
|
||||
}
|
||||
|
||||
/* Real: box the shiftKey flag byte (raw:1937-1942). */
|
||||
void as3vm_MouseEvent_get_shiftKey(void *frame) {
|
||||
store_ptr(frame, ev_makebool(*(uint8_t *)AT(THISOBJ(frame), EV_SHIFTKEY)));
|
||||
}
|
||||
|
||||
/* Map a MouseEvent local coordinate into stage space, or NaN/0 when there is no
|
||||
* live target transform. `pick_y` selects the stage-Y output lane (raw:1953-
|
||||
* 2042). DEFERRED structurally (target transform; not exercised). */
|
||||
static void ev_stage_coord(void *frame, int pick_y) {
|
||||
void *vm = VM(frame);
|
||||
void *obj = THISOBJ(frame);
|
||||
void *tgt = ev_slot_value(obj, 0);
|
||||
uint32_t sx, sy;
|
||||
float value;
|
||||
if (((uintptr_t)tgt & 3) == 1 && *(char *)((char *)tgt - 1) == '$') {
|
||||
uint8_t xform[24];
|
||||
iggy_get_o2w(*(void **)vm, *(void **)AT(tgt, EV_KEYCODE), xform);
|
||||
if (pick_y) {
|
||||
iggy_transform(&sy, &sx, xform, *(int32_t *)AT(obj, EV_LOCALX));
|
||||
} else {
|
||||
iggy_transform(&sx, &sy, xform, *(int32_t *)AT(obj, EV_LOCALX));
|
||||
}
|
||||
} else if (rr_isnan_f(*(float *)AT(obj, EV_LOCALY)) == 0) {
|
||||
sx = 0;
|
||||
sy = 0;
|
||||
} else {
|
||||
float nan = as3vm_NaNf;
|
||||
memcpy(&sx, &nan, sizeof(float));
|
||||
sy = sx;
|
||||
}
|
||||
memcpy(&value, &sx, sizeof(float));
|
||||
store_ptr(frame, as3vm_make_number_GC(vm, ev_float_to_double(value)));
|
||||
}
|
||||
|
||||
/* Real: stageX (raw:1953-1993). */
|
||||
void as3vm_MouseEvent_get_stageX(void *frame) { ev_stage_coord(frame, 0); }
|
||||
|
||||
/* Real: stageY (raw:2002-2042). */
|
||||
void as3vm_MouseEvent_get_stageY(void *frame) { ev_stage_coord(frame, 1); }
|
||||
|
||||
/* Real: set_altKey (raw:2048-2060). */
|
||||
void as3vm_MouseEvent_set_altKey(void *frame) { ev_set_u8(frame, EV_ALTKEY); }
|
||||
|
||||
/* Real: set_buttonDown (raw:2067-2079). */
|
||||
void as3vm_MouseEvent_set_buttonDown(void *frame) {
|
||||
ev_set_u8(frame, EV_BUTTONDOWN);
|
||||
}
|
||||
|
||||
/* Real: set_commandKey (raw:2086-2098). */
|
||||
void as3vm_MouseEvent_set_commandKey(void *frame) {
|
||||
ev_set_u8(frame, EV_COMMANDKEY);
|
||||
}
|
||||
|
||||
/* Real: set_controlKey (raw:2105-2117). */
|
||||
void as3vm_MouseEvent_set_controlKey(void *frame) {
|
||||
ev_set_u8(frame, EV_CONTROLKEY);
|
||||
}
|
||||
|
||||
/* Real: set_ctrlKey -- retail parses "b" twice; the first block writes
|
||||
* controlKey, the second writes commandKey (raw:2124-2143). */
|
||||
void as3vm_MouseEvent_set_ctrlKey(void *frame) {
|
||||
uint8_t v[24];
|
||||
if (as3vm_component_parse_arguments_GC(frame, EVFMT_BOOL, v) == 0) {
|
||||
*(uint8_t *)AT(THISOBJ(frame), EV_CONTROLKEY) = v[0];
|
||||
} else {
|
||||
as3vm_exception_GC(VM(frame), 0x78);
|
||||
}
|
||||
if (as3vm_component_parse_arguments_GC(frame, EVFMT_BOOL, v) != 0) {
|
||||
as3vm_exception_GC(VM(frame), 0x78);
|
||||
return;
|
||||
}
|
||||
*(uint8_t *)AT(THISOBJ(frame), EV_COMMANDKEY) = v[0];
|
||||
}
|
||||
|
||||
/* Real: parse an int, write the delta short (raw:2150-2162). */
|
||||
void as3vm_MouseEvent_set_delta(void *frame) {
|
||||
uint16_t v[12];
|
||||
if (as3vm_component_parse_arguments_GC(frame, EVFMT_INT, v) != 0) {
|
||||
as3vm_exception_GC(VM(frame), 0x78);
|
||||
return;
|
||||
}
|
||||
*(uint16_t *)AT(THISOBJ(frame), EV_DELTA) = v[0];
|
||||
}
|
||||
|
||||
/* Real: parse a float, write localX (raw:2169-2181). */
|
||||
void as3vm_MouseEvent_set_localX(void *frame) {
|
||||
ev_set_u32(frame, EV_LOCALX, EVFMT_FLOAT);
|
||||
}
|
||||
|
||||
/* Real: parse a float, write localY (raw:2188-2200). */
|
||||
void as3vm_MouseEvent_set_localY(void *frame) {
|
||||
ev_set_u32(frame, EV_LOCALY, EVFMT_FLOAT);
|
||||
}
|
||||
|
||||
/* Real: assign the relatedObject slot (raw:2207-2220). */
|
||||
void as3vm_MouseEvent_set_relatedObject(void *frame) {
|
||||
void *value[4];
|
||||
if (as3vm_component_parse_arguments_GC(frame, EVFMT_OBJECT,
|
||||
*(void **)AT(VM(frame), VM_DEFAULTOBJ),
|
||||
value) != 0) {
|
||||
as3vm_exception_GC(VM(frame), 0x78);
|
||||
return;
|
||||
}
|
||||
as3vmcomp_set_value(VM(frame), (char *)THISOBJ(frame) - 1, 2, value[0]);
|
||||
}
|
||||
|
||||
/* Real: set_shiftKey (raw:2227-2239). */
|
||||
void as3vm_MouseEvent_set_shiftKey(void *frame) {
|
||||
ev_set_u8(frame, EV_SHIFTKEY);
|
||||
}
|
||||
|
||||
/* Empty (raw:2246-2249). */
|
||||
void as3vm_MouseEvent_updateAfterEvent(void *frame) { (void)frame; }
|
||||
|
||||
/* ---- flash.events.TextEvent ---------------------------------------------- */
|
||||
|
||||
/* Real: parse (type,?bubbles,?cancelable,?text); seed base + text slot; text
|
||||
* defaults to the empty-string cell (raw:2256-2283). */
|
||||
void as3vm_TextEvent__construct(void *frame) {
|
||||
void *type = (void *)0;
|
||||
void *text = *(void **)AT(VM(frame), VM_EMPTYSTR);
|
||||
int32_t bubbles = 0, cancelable = 0;
|
||||
void *obj;
|
||||
if (as3vm_component_parse_arguments_GC(frame, EVFMT_TEXT, &type, &bubbles,
|
||||
&cancelable, &text) != 0) {
|
||||
as3vm_exception_GC(VM(frame), 0x78);
|
||||
return;
|
||||
}
|
||||
obj = THISOBJ(frame);
|
||||
ev_init_base(obj, type, bubbles, cancelable);
|
||||
as3vmcomp_set_value(VM(frame), (char *)THISOBJ(frame) - 1, 2, text);
|
||||
}
|
||||
|
||||
/* Real: clone (raw:2290-2319). */
|
||||
void as3vm_TextEvent_clone(void *frame) { ev_clone_into(frame); }
|
||||
|
||||
/* Real: the text AS3 slot value (raw:2326-2333). */
|
||||
void as3vm_TextEvent_get_text(void *frame) {
|
||||
store_ptr(frame, ev_slot_value(THISOBJ(frame), 4));
|
||||
}
|
||||
|
||||
/* Real: parse a string, assign the text slot (raw:2341-2353). */
|
||||
void as3vm_TextEvent_set_text(void *frame) {
|
||||
void *value[3];
|
||||
if (as3vm_component_parse_arguments_GC(frame, EVFMT_STRING, value) != 0) {
|
||||
as3vm_exception_GC(VM(frame), 0x78);
|
||||
return;
|
||||
}
|
||||
as3vmcomp_set_value(VM(frame), (char *)THISOBJ(frame) - 1, 2, value[0]);
|
||||
}
|
||||
|
||||
/* Real: TextEvent.toString -- push properties + assemble (raw:2360-2382).
|
||||
* DEFERRED structurally (deep string assembly). */
|
||||
void as3vm_TextEvent_toString(void *frame) {
|
||||
void *vm = VM(frame);
|
||||
void *obj = THISOBJ(frame);
|
||||
ev_push(vm, *(void **)AT(obj, EV_TYPE));
|
||||
ev_push(vm, ev_makebool(*(uint8_t *)AT(obj, EV_BUBBLES)));
|
||||
ev_push(vm, ev_makebool(*(uint8_t *)AT(obj, EV_CANCELABLE)));
|
||||
ev_push(vm, ev_slot_value(obj, 4));
|
||||
store_ptr(frame, as3vm_create_interleaved_string_GC(vm, 5));
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
/*
|
||||
* swf_as3vm_flash_events_timer.inc -- flash.utils.Timer and
|
||||
* flash.events.TimerEvent binding thunks.
|
||||
* Included by swf_as3vm_flash_events.c.
|
||||
*/
|
||||
|
||||
/* ---- flash.utils.Timer --------------------------------------------------- */
|
||||
|
||||
/* Real: parse (delay, ?repeatCount); reject a parse failure with 0x78 and a
|
||||
* negative delay with 0x75; else seed the timer fields, link the timer into the
|
||||
* VM active-timer list and return the undefined cell (raw:2448-2478). */
|
||||
void as3vm_Timer__construct(void *frame) {
|
||||
void *vm = VM(frame);
|
||||
double delay = 0.0;
|
||||
int32_t repeat = 0;
|
||||
void *obj;
|
||||
FR(frame)[4] = (void *)1;
|
||||
if (as3vm_component_parse_arguments_GC(frame, EVFMT_TIMER, &delay, &repeat) !=
|
||||
0) {
|
||||
as3vm_exception_GC(vm, 0x78);
|
||||
return;
|
||||
}
|
||||
if (delay < 0.0) {
|
||||
as3vm_exception_GC(vm, 0x75);
|
||||
return;
|
||||
}
|
||||
obj = THISOBJ(frame);
|
||||
*(double *)AT(obj, TM_ELAPSED) = 0.0;
|
||||
*(int32_t *)AT(obj, TM_CURRENTCOUNT) = 0;
|
||||
*(double *)AT(obj, TM_DELAY) = delay;
|
||||
*(int32_t *)AT(obj, TM_RUNNING) = 0;
|
||||
*(int32_t *)AT(obj, TM_REPEATCOUNT) = repeat;
|
||||
*(void **)AT(obj, TM_NEXT) = *(void **)AT(vm, VM_TIMERLIST);
|
||||
*(void **)AT(vm, VM_TIMERLIST) = obj;
|
||||
store_ptr(frame, EV_UNDEF_CELL);
|
||||
}
|
||||
|
||||
/* Real: box currentCount int * 2 (raw:2485-2488). */
|
||||
void as3vm_Timer_get_currentCount(void *frame) {
|
||||
store_astag(frame, *(int32_t *)AT(THISOBJ(frame), TM_CURRENTCOUNT));
|
||||
}
|
||||
|
||||
/* Real: box the delay double as a Number (raw:2496-2502). */
|
||||
void as3vm_Timer_get_delay(void *frame) {
|
||||
store_ptr(frame, as3vm_make_number_GC(
|
||||
VM(frame), *(double *)AT(THISOBJ(frame), TM_DELAY)));
|
||||
}
|
||||
|
||||
/* Real: box repeatCount int * 2 (raw:2510-2513). */
|
||||
void as3vm_Timer_get_repeatCount(void *frame) {
|
||||
store_astag(frame, *(int32_t *)AT(THISOBJ(frame), TM_REPEATCOUNT));
|
||||
}
|
||||
|
||||
/* Real: running is true iff the running flag is nonzero (raw:2521-2531). */
|
||||
void as3vm_Timer_get_running(void *frame) {
|
||||
store_ptr(frame, (*(int32_t *)AT(THISOBJ(frame), TM_RUNNING) == 0)
|
||||
? EV_FALSE_CELL
|
||||
: EV_TRUE_CELL);
|
||||
}
|
||||
|
||||
/* Real: reset running / currentCount / elapsed (raw:2538-2547). */
|
||||
void as3vm_Timer_reset(void *frame) {
|
||||
void *obj = THISOBJ(frame);
|
||||
*(int32_t *)AT(obj, TM_RUNNING) = 0;
|
||||
*(int32_t *)AT(obj, TM_CURRENTCOUNT) = 0;
|
||||
*(double *)AT(obj, TM_ELAPSED) = 0.0;
|
||||
}
|
||||
|
||||
/* Real: parse a Number; a valid non-negative delay writes delay and clears
|
||||
* elapsed, otherwise raise 0x78 (raw:2554-2569). */
|
||||
void as3vm_Timer_set_delay(void *frame) {
|
||||
double v[3];
|
||||
void *obj;
|
||||
if (as3vm_component_parse_arguments_GC(frame, EVFMT_NUMBER, v) == 0 &&
|
||||
0.0 <= v[0]) {
|
||||
obj = THISOBJ(frame);
|
||||
*(double *)AT(obj, TM_DELAY) = v[0];
|
||||
*(double *)AT(obj, TM_ELAPSED) = 0.0;
|
||||
return;
|
||||
}
|
||||
as3vm_exception_GC(VM(frame), 0x78);
|
||||
}
|
||||
|
||||
/* Real: parse an int, write repeatCount; if it is nonzero and already reached
|
||||
* by currentCount, stop the timer (raw:2576-2593). */
|
||||
void as3vm_Timer_set_repeatCount(void *frame) {
|
||||
int32_t v[6];
|
||||
void *obj;
|
||||
if (as3vm_component_parse_arguments_GC(frame, EVFMT_INT, v) != 0) {
|
||||
as3vm_exception_GC(VM(frame), 0x78);
|
||||
return;
|
||||
}
|
||||
obj = THISOBJ(frame);
|
||||
*(int32_t *)AT(obj, TM_REPEATCOUNT) = v[0];
|
||||
if (v[0] != 0 && v[0] <= *(int32_t *)AT(obj, TM_CURRENTCOUNT)) {
|
||||
*(int32_t *)AT(obj, TM_RUNNING) = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Real: start -- running := 1 (raw:2600-2604). */
|
||||
void as3vm_Timer_start(void *frame) {
|
||||
*(int32_t *)AT(THISOBJ(frame), TM_RUNNING) = 1;
|
||||
}
|
||||
|
||||
/* Real: stop -- running := 0; clamp elapsed down to delay (raw:2611-2621). */
|
||||
void as3vm_Timer_stop(void *frame) {
|
||||
void *obj = THISOBJ(frame);
|
||||
*(int32_t *)AT(obj, TM_RUNNING) = 0;
|
||||
if (*(double *)AT(obj, TM_DELAY) <= *(double *)AT(obj, TM_ELAPSED)) {
|
||||
*(double *)AT(obj, TM_ELAPSED) = *(double *)AT(obj, TM_DELAY);
|
||||
}
|
||||
}
|
||||
|
||||
/* ---- flash.events.TimerEvent --------------------------------------------- */
|
||||
|
||||
/* Real: mark the frame's timer flag and delegate to Event.__construct
|
||||
* (raw:2389-2394). */
|
||||
void as3vm_TimerEvent__construct(void *frame) {
|
||||
FR(frame)[4] = (void *)1;
|
||||
as3vm_Event__construct(frame);
|
||||
}
|
||||
|
||||
/* Real: mark the frame's timer flag and delegate to Event.clone (raw:2401-
|
||||
* 2406). */
|
||||
void as3vm_TimerEvent_clone(void *frame) {
|
||||
FR(frame)[4] = (void *)1;
|
||||
as3vm_Event_clone(frame);
|
||||
}
|
||||
|
||||
/* Real: TimerEvent.toString -- push type/bubbles/cancelable + assemble
|
||||
* (raw:2413-2431). DEFERRED structurally (deep string assembly). */
|
||||
void as3vm_TimerEvent_toString(void *frame) {
|
||||
void *vm = VM(frame);
|
||||
void *obj = THISOBJ(frame);
|
||||
ev_push(vm, *(void **)AT(obj, EV_TYPE));
|
||||
ev_push(vm, ev_makebool(*(uint8_t *)AT(obj, EV_BUBBLES)));
|
||||
ev_push(vm, ev_makebool(*(uint8_t *)AT(obj, EV_CANCELABLE)));
|
||||
store_ptr(frame, as3vm_create_interleaved_string_GC(vm, 4));
|
||||
}
|
||||
|
||||
/* Empty (raw:2438-2441). */
|
||||
void as3vm_TimerEvent_updateAfterEvent(void *frame) { (void)frame; }
|
||||
448
tests/support/swf_as3vm_flash_events_test_support.c
Normal file
448
tests/support/swf_as3vm_flash_events_test_support.c
Normal file
@@ -0,0 +1,448 @@
|
||||
/*
|
||||
* Host harness for the reconstructed swf_as3vm_flash_events translation unit.
|
||||
*
|
||||
* swf_as3vm_flash_events is Iggy's AVM2 flash.events binding layer: the Event,
|
||||
* EventDispatcher, FocusEvent, KeyboardEvent, Keyboard, LoaderInfo, MouseEvent,
|
||||
* TextEvent, TimerEvent and Timer classes plus the lazy-event / dispatch / clone
|
||||
* helpers (as3vm_make_lazy_event_GC, as3vm_clone_GC, as3vm_do_*_event_GC,
|
||||
* as3vm_ev_setbool, as3vm_needs_cleaning, ...). It exports EXACTLY 118 entry
|
||||
* points on all four platforms (durango / orbis / ps3 / vita); the per-platform
|
||||
* source_functions count (recovered file-static dispatch_event_GC /
|
||||
* dispatch_loop_GC helpers) is 123 durango / 121 orbis / 120 ps3 / 122 vita.
|
||||
*
|
||||
* OBJECT MODEL (durango 64-bit -- the runtime test builds ONLY the durango dylib
|
||||
* so the 64-bit layout is authoritative):
|
||||
* frame[0]=vm, frame[1]=&result slot (a getter writes its box to *frame[1]),
|
||||
* frame[2]=argc, frame[3]=&this-slot (holds the RAW object pointer).
|
||||
* obj = *(this_slot) -- the Event / Timer native object itself.
|
||||
* Unlike swf_as3_textfield (obj -> handle -> info), the flash.events classes
|
||||
* store their native fields DIRECTLY in the object. Event base fields:
|
||||
* bubbles byte @ obj+0x35 (raw durango:496/722)
|
||||
* cancelable byte @ obj+0x36 (raw durango:497/735)
|
||||
* defaultPrevented byte @ obj+0x37 (raw durango:500/806/818)
|
||||
* flags/prop-stop u16 @ obj+0x38 (0x200 fresh; |1 stop, |2 stopImmed)
|
||||
* eventPhase byte @ obj+0x39 (raw durango:762)
|
||||
* lazy/clone flag byte @ obj+0x3a (raw durango:501/536)
|
||||
* type (interned) ptr @ obj+0x57 (raw durango:499/789)
|
||||
* FocusEvent/KeyboardEvent/MouseEvent/Timer add fields at obj+0x27..0x4f
|
||||
* (keyCode int@0x27, charCode int@0x2b, keyLocation byte@0x2f, altKey byte@0x30,
|
||||
* commandKey byte@0x31, controlKey byte@0x32, shiftKey byte@0x33; mouse
|
||||
* clickCount short@0x43, delta short@0x45, buttonDown byte@0x47; timer delay
|
||||
* double@0x37, elapsed double@0x3f, currentCount int@0x47, repeatCount int@0x4b,
|
||||
* running int@0x4f). Boolean getters index as3vm_makebool[byte]; small-int
|
||||
* getters store value*2 (AS3 int tag) directly into *frame[1].
|
||||
*
|
||||
* (32-bit ps3 / vita differ: frame stride 4, result @ frame+4, this-slot @
|
||||
* frame+0xc; makebool entries 4 bytes; Event fields shift down -- bubbles@0x25,
|
||||
* cancelable@0x26, defaultPrevented@0x27, flags@0x29, type@0x43 -- flagged
|
||||
* structural, NOT exercised by the durango-only runtime test.)
|
||||
*
|
||||
* The symbols supplied below are exactly the genuine nm ' U ' imports of the
|
||||
* retail object, modelled here as recording / controllable stubs so the durango
|
||||
* dylib links and the real bodies actually run. DATA imports (as3vm_makebool,
|
||||
* as3vm_NaNf, as3vm_truefalse_storage, as3vm_nullundef_storage) are defined as
|
||||
* real storage. libc (memcpy / memset) resolves from libSystem at load time.
|
||||
*/
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
/* ---- Recording counters. ---- */
|
||||
static size_t exception_count;
|
||||
static size_t parse_count;
|
||||
static size_t make_number_count;
|
||||
static size_t make_object_count;
|
||||
static size_t make_string_count;
|
||||
static size_t make_string_wc_count;
|
||||
static size_t make_stringdata_count;
|
||||
static size_t set_value_count;
|
||||
static size_t string_interned_count;
|
||||
static size_t interleaved_count;
|
||||
static size_t is_ofclass_count;
|
||||
static size_t write_barrier_count;
|
||||
static size_t pool_alloc_count;
|
||||
static size_t pool_free_count;
|
||||
static size_t free_count;
|
||||
static size_t malloc_fileline_count;
|
||||
static size_t method_call_count;
|
||||
|
||||
static int32_t last_exception_code;
|
||||
static double last_number_arg;
|
||||
static void *last_object;
|
||||
static void *last_object_class;
|
||||
static void *last_set_value_obj;
|
||||
static int last_set_value_kind;
|
||||
static void *last_set_value_value;
|
||||
static const char *last_parse_fmt;
|
||||
|
||||
/* ---- Controls. ---- */
|
||||
static int parse_ret;
|
||||
static int parse_writes_out;
|
||||
static const uint8_t *parse_out_bytes;
|
||||
static size_t parse_out_len;
|
||||
static uint8_t parse_out_store[64];
|
||||
static int is_ofclass_ret;
|
||||
|
||||
/* ---- Owned-by-sibling DATA the module indexes into. ---- */
|
||||
void *as3vm_makebool[64];
|
||||
float as3vm_NaNf;
|
||||
uint8_t as3vm_truefalse_storage[64];
|
||||
uint8_t as3vm_nullundef_storage[64];
|
||||
|
||||
/* ---- Bump pool backing the object-allocator fakes. ---- */
|
||||
static uint8_t fake_pool[1 << 20];
|
||||
static size_t fake_used;
|
||||
|
||||
static void *pool_bump(size_t size) {
|
||||
size_t base = (fake_used + 15u) & ~(size_t)15u;
|
||||
size_t rounded = (size + 15u) & ~(size_t)15u;
|
||||
if (rounded == 0u) {
|
||||
rounded = 16u;
|
||||
}
|
||||
if (base + rounded > sizeof(fake_pool)) {
|
||||
return 0;
|
||||
}
|
||||
fake_used = base + rounded;
|
||||
memset(fake_pool + base, 0, rounded);
|
||||
return fake_pool + base;
|
||||
}
|
||||
|
||||
void swf_as3vm_flash_events_test_reset(void) {
|
||||
exception_count = 0;
|
||||
parse_count = 0;
|
||||
make_number_count = 0;
|
||||
make_object_count = 0;
|
||||
make_string_count = 0;
|
||||
make_string_wc_count = 0;
|
||||
make_stringdata_count = 0;
|
||||
set_value_count = 0;
|
||||
string_interned_count = 0;
|
||||
interleaved_count = 0;
|
||||
is_ofclass_count = 0;
|
||||
write_barrier_count = 0;
|
||||
pool_alloc_count = 0;
|
||||
pool_free_count = 0;
|
||||
free_count = 0;
|
||||
malloc_fileline_count = 0;
|
||||
method_call_count = 0;
|
||||
last_exception_code = 0;
|
||||
last_number_arg = 0.0;
|
||||
last_object = 0;
|
||||
last_object_class = 0;
|
||||
last_set_value_obj = 0;
|
||||
last_set_value_kind = 0;
|
||||
last_set_value_value = 0;
|
||||
last_parse_fmt = 0;
|
||||
parse_ret = 0;
|
||||
parse_writes_out = 0;
|
||||
parse_out_bytes = 0;
|
||||
parse_out_len = 0;
|
||||
is_ofclass_ret = 0;
|
||||
fake_used = 0;
|
||||
memset(parse_out_store, 0, sizeof(parse_out_store));
|
||||
memset(as3vm_makebool, 0, sizeof(as3vm_makebool));
|
||||
memset(as3vm_truefalse_storage, 0, sizeof(as3vm_truefalse_storage));
|
||||
memset(as3vm_nullundef_storage, 0, sizeof(as3vm_nullundef_storage));
|
||||
as3vm_NaNf = 0.0f;
|
||||
}
|
||||
|
||||
/* ---- Count / last-value accessors. ---- */
|
||||
size_t swf_as3vm_flash_events_test_exception_count(void) {
|
||||
return exception_count;
|
||||
}
|
||||
size_t swf_as3vm_flash_events_test_parse_count(void) { return parse_count; }
|
||||
size_t swf_as3vm_flash_events_test_make_number_count(void) {
|
||||
return make_number_count;
|
||||
}
|
||||
size_t swf_as3vm_flash_events_test_make_object_count(void) {
|
||||
return make_object_count;
|
||||
}
|
||||
size_t swf_as3vm_flash_events_test_make_string_count(void) {
|
||||
return make_string_count;
|
||||
}
|
||||
size_t swf_as3vm_flash_events_test_make_string_wc_count(void) {
|
||||
return make_string_wc_count;
|
||||
}
|
||||
size_t swf_as3vm_flash_events_test_make_stringdata_count(void) {
|
||||
return make_stringdata_count;
|
||||
}
|
||||
size_t swf_as3vm_flash_events_test_set_value_count(void) {
|
||||
return set_value_count;
|
||||
}
|
||||
size_t swf_as3vm_flash_events_test_string_interned_count(void) {
|
||||
return string_interned_count;
|
||||
}
|
||||
size_t swf_as3vm_flash_events_test_interleaved_count(void) {
|
||||
return interleaved_count;
|
||||
}
|
||||
size_t swf_as3vm_flash_events_test_is_ofclass_count(void) {
|
||||
return is_ofclass_count;
|
||||
}
|
||||
size_t swf_as3vm_flash_events_test_write_barrier_count(void) {
|
||||
return write_barrier_count;
|
||||
}
|
||||
size_t swf_as3vm_flash_events_test_pool_alloc_count(void) {
|
||||
return pool_alloc_count;
|
||||
}
|
||||
size_t swf_as3vm_flash_events_test_pool_free_count(void) {
|
||||
return pool_free_count;
|
||||
}
|
||||
size_t swf_as3vm_flash_events_test_free_count(void) { return free_count; }
|
||||
size_t swf_as3vm_flash_events_test_method_call_count(void) {
|
||||
return method_call_count;
|
||||
}
|
||||
|
||||
int32_t swf_as3vm_flash_events_test_last_exception_code(void) {
|
||||
return last_exception_code;
|
||||
}
|
||||
double swf_as3vm_flash_events_test_last_number_arg(void) {
|
||||
return last_number_arg;
|
||||
}
|
||||
void *swf_as3vm_flash_events_test_last_object(void) { return last_object; }
|
||||
void *swf_as3vm_flash_events_test_last_object_class(void) {
|
||||
return last_object_class;
|
||||
}
|
||||
void *swf_as3vm_flash_events_test_last_set_value_obj(void) {
|
||||
return last_set_value_obj;
|
||||
}
|
||||
int swf_as3vm_flash_events_test_last_set_value_kind(void) {
|
||||
return last_set_value_kind;
|
||||
}
|
||||
void *swf_as3vm_flash_events_test_last_set_value_value(void) {
|
||||
return last_set_value_value;
|
||||
}
|
||||
void *swf_as3vm_flash_events_test_makebool_base(void) { return as3vm_makebool; }
|
||||
void *swf_as3vm_flash_events_test_truefalse_base(void) {
|
||||
return as3vm_truefalse_storage;
|
||||
}
|
||||
void *swf_as3vm_flash_events_test_nullundef_base(void) {
|
||||
return as3vm_nullundef_storage;
|
||||
}
|
||||
|
||||
/* ---- Controls. ---- */
|
||||
void swf_as3vm_flash_events_test_set_parse_ret(int value) { parse_ret = value; }
|
||||
void swf_as3vm_flash_events_test_set_parse_out(const void *bytes, size_t len) {
|
||||
if (len > sizeof(parse_out_store)) {
|
||||
len = sizeof(parse_out_store);
|
||||
}
|
||||
memcpy(parse_out_store, bytes, len);
|
||||
parse_out_bytes = parse_out_store;
|
||||
parse_out_len = len;
|
||||
parse_writes_out = 1;
|
||||
}
|
||||
void swf_as3vm_flash_events_test_set_is_ofclass_ret(int value) {
|
||||
is_ofclass_ret = value;
|
||||
}
|
||||
void swf_as3vm_flash_events_test_set_makebool(int index, void *value) {
|
||||
if (index >= 0 && index < 64) {
|
||||
as3vm_makebool[index] = value;
|
||||
}
|
||||
}
|
||||
|
||||
/* ---- Imports (recording / controllable stubs). ---- */
|
||||
|
||||
/* as3vm_interpreter (DONE). */
|
||||
void as3vm_exception_GC(void *vm, int code) {
|
||||
(void)vm;
|
||||
last_exception_code = code;
|
||||
++exception_count;
|
||||
}
|
||||
|
||||
/* as3_component_helpers (DONE). Variadic across callers ("s", "s_u", "s_b",
|
||||
* "s_f", "s_d", "s_I", "s_Ic_b", "s_Ic_bdb", ...). When armed, copies
|
||||
* parse_out_bytes into the FIRST pointer argument so the callers' out slot
|
||||
* resolves to controllable data. */
|
||||
int as3vm_component_parse_arguments_GC(void *frame, const char *fmt, ...) {
|
||||
(void)frame;
|
||||
++parse_count;
|
||||
last_parse_fmt = fmt;
|
||||
if (parse_writes_out) {
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
void *out = va_arg(ap, void *);
|
||||
if (out && parse_out_bytes) {
|
||||
memcpy(out, parse_out_bytes, parse_out_len);
|
||||
}
|
||||
va_end(ap);
|
||||
}
|
||||
return parse_ret;
|
||||
}
|
||||
|
||||
/* as3_component_helpers slot writer (DONE). */
|
||||
void as3vmcomp_set_value(void *vm, void *obj, int kind, ...) {
|
||||
(void)vm;
|
||||
++set_value_count;
|
||||
last_set_value_obj = obj;
|
||||
last_set_value_kind = kind;
|
||||
va_list ap;
|
||||
va_start(ap, kind);
|
||||
last_set_value_value = va_arg(ap, void *);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
/* as3vm_create / as3vm_interpreter factories (DONE). */
|
||||
void *as3vm_make_object_no_constructor_GC(void *vm, void *cls) {
|
||||
(void)vm;
|
||||
++make_object_count;
|
||||
last_object_class = cls;
|
||||
last_object = pool_bump(0x100u);
|
||||
return last_object;
|
||||
}
|
||||
void *as3vm_make_number_GC(void *vm, double value) {
|
||||
(void)vm;
|
||||
++make_number_count;
|
||||
last_number_arg = value;
|
||||
return pool_bump(0x10u);
|
||||
}
|
||||
void *as3vm_make_string_GC(void *vm, void *text) {
|
||||
(void)vm;
|
||||
(void)text;
|
||||
++make_string_count;
|
||||
return pool_bump(0x10u);
|
||||
}
|
||||
void *as3vm_make_string_wc_GC(void *vm, void *text, int len) {
|
||||
(void)vm;
|
||||
(void)text;
|
||||
(void)len;
|
||||
++make_string_wc_count;
|
||||
return pool_bump(0x10u);
|
||||
}
|
||||
void *as3vm_make_stringdata_GC(void *vm, void *text, int len) {
|
||||
(void)vm;
|
||||
(void)text;
|
||||
(void)len;
|
||||
++make_stringdata_count;
|
||||
return pool_bump(0x20u);
|
||||
}
|
||||
void *as3vm_create_interleaved_string_GC(void *vm, int count, ...) {
|
||||
(void)vm;
|
||||
(void)count;
|
||||
++interleaved_count;
|
||||
return pool_bump(0x20u);
|
||||
}
|
||||
void *as3vm_ToString_GC(void *vm, void *value) {
|
||||
(void)vm;
|
||||
(void)value;
|
||||
return pool_bump(0x10u);
|
||||
}
|
||||
void *as3vm_get_public_string_GC(void *vm, void *obj, int64_t index) {
|
||||
(void)vm;
|
||||
(void)obj;
|
||||
(void)index;
|
||||
return pool_bump(0x10u);
|
||||
}
|
||||
void *as3vm_get_movie_as3value_GC(void *vm, void *movie) {
|
||||
(void)vm;
|
||||
(void)movie;
|
||||
return pool_bump(0x10u);
|
||||
}
|
||||
void *as3vm_string_interned(void *vm, void *text) {
|
||||
(void)vm;
|
||||
(void)text;
|
||||
++string_interned_count;
|
||||
return pool_bump(0x10u);
|
||||
}
|
||||
void *as3vm_string_interned_nocreate(void *vm, void *text) {
|
||||
(void)vm;
|
||||
(void)text;
|
||||
++string_interned_count;
|
||||
return pool_bump(0x10u);
|
||||
}
|
||||
|
||||
/* as3vm_class type test (DONE). */
|
||||
int as3vm_is_ofclass(void *obj, void *cls) {
|
||||
(void)obj;
|
||||
(void)cls;
|
||||
++is_ofclass_count;
|
||||
return is_ofclass_ret;
|
||||
}
|
||||
|
||||
/* as3vm_interpreter dispatch (DONE). */
|
||||
void as3vm_do_method_call_GC(void *vm, void *a, void *b, void *c, void *d) {
|
||||
(void)vm;
|
||||
(void)a;
|
||||
(void)b;
|
||||
(void)c;
|
||||
(void)d;
|
||||
++method_call_count;
|
||||
}
|
||||
void as3vm_do_func_call_vmc_GC(void *vm, void *a, void *b, void *c) {
|
||||
(void)vm;
|
||||
(void)a;
|
||||
(void)b;
|
||||
(void)c;
|
||||
++method_call_count;
|
||||
}
|
||||
void as3vm_do_func_call_vv_GC(void *vm, void *a, void *b) {
|
||||
(void)vm;
|
||||
(void)a;
|
||||
(void)b;
|
||||
++method_call_count;
|
||||
}
|
||||
|
||||
/* as3vm_interpreter GC write barrier (DONE). */
|
||||
void as3vm_write_barrier_slowpath(void *vm, void *obj, void *value) {
|
||||
(void)vm;
|
||||
(void)obj;
|
||||
(void)value;
|
||||
++write_barrier_count;
|
||||
}
|
||||
|
||||
/* as3vm_gc pool (DONE). */
|
||||
void *as3vm_pool_alloc(void *vm, void *arena, int size) {
|
||||
(void)vm;
|
||||
(void)arena;
|
||||
++pool_alloc_count;
|
||||
return pool_bump(size ? (size_t)size : 16u);
|
||||
}
|
||||
void as3vm_pool_free(void *ptr) {
|
||||
(void)ptr;
|
||||
++pool_free_count;
|
||||
}
|
||||
|
||||
/* iggy arena (DONE). */
|
||||
void iggy_free_alloc(void *arena, void *ptr) {
|
||||
(void)arena;
|
||||
(void)ptr;
|
||||
++free_count;
|
||||
}
|
||||
void *iggy_malloc_fileline(void *arena, int flags, size_t size,
|
||||
int tag, const char *file, int line) {
|
||||
(void)arena;
|
||||
(void)flags;
|
||||
(void)tag;
|
||||
(void)file;
|
||||
(void)line;
|
||||
++malloc_fileline_count;
|
||||
return pool_bump(size ? size : 16u);
|
||||
}
|
||||
|
||||
/* iggy transform stack (DONE). */
|
||||
void iggy_get_o2w(void *movie, void *node, void *out) {
|
||||
(void)movie;
|
||||
(void)node;
|
||||
(void)out;
|
||||
}
|
||||
void iggy_transform(void *out_x, void *out_y, void *matrix, int value) {
|
||||
(void)out_x;
|
||||
(void)out_y;
|
||||
(void)matrix;
|
||||
(void)value;
|
||||
}
|
||||
void iggy_inverse_transform(void *out_x, void *out_y, void *matrix, int value) {
|
||||
(void)out_x;
|
||||
(void)out_y;
|
||||
(void)matrix;
|
||||
(void)value;
|
||||
}
|
||||
|
||||
/* iggy diagnostics (DONE). */
|
||||
void iggy_uncaught_exception_warning(void *vm, void *info) {
|
||||
(void)vm;
|
||||
(void)info;
|
||||
}
|
||||
|
||||
/* rrmath NaN classifier (DONE). */
|
||||
int rr_isnan_f(float value) { return value != value; }
|
||||
728
tests/test_reconstructed_swf_as3vm_flash_events.py
Normal file
728
tests/test_reconstructed_swf_as3vm_flash_events.py
Normal file
@@ -0,0 +1,728 @@
|
||||
"""Runtime tests for the reconstructed swf_as3vm_flash_events translation unit.
|
||||
|
||||
RED STATE: swf_as3vm_flash_events.c / swf_as3vm_flash_events.h do not exist yet,
|
||||
so setUpClass raises "missing swf_as3vm_flash_events runtime inputs". Every
|
||||
assertion below is grounded in a specific line of
|
||||
iggy-decompiled/raw/durango/swf_as3vm_flash_events.c (cited inline) so a faithful
|
||||
DURANGO reconstruction turns these green.
|
||||
|
||||
swf_as3vm_flash_events is Iggy's AVM2 flash.events binding layer: the Event,
|
||||
EventDispatcher, FocusEvent, KeyboardEvent, Keyboard, LoaderInfo, MouseEvent,
|
||||
TextEvent, TimerEvent and Timer classes plus the lazy-event / dispatch / clone
|
||||
helpers (as3vm_make_lazy_event_GC, as3vm_clone_GC, as3vm_do_*_event_GC,
|
||||
as3vm_ev_setbool, as3vm_needs_cleaning, ...). It exports EXACTLY 118 entry points
|
||||
on all four platforms.
|
||||
|
||||
OBJECT MODEL (durango 64-bit -- the runtime test builds ONLY the durango dylib so
|
||||
the 64-bit layout is authoritative):
|
||||
frame[0]=vm, frame[1]=&result slot (a getter writes its box to *frame[1]),
|
||||
frame[2]=argc, frame[3]=&this-slot (holds the RAW object pointer).
|
||||
obj = *(this_slot)
|
||||
Unlike swf_as3_textfield (obj -> handle -> info), the flash.events classes store
|
||||
their native fields DIRECTLY in the object. Event base fields:
|
||||
bubbles byte@0x35, cancelable byte@0x36, defaultPrevented byte@0x37,
|
||||
flags/prop-stop u16@0x38, eventPhase byte@0x39, lazy/clone byte@0x3a,
|
||||
type ptr@0x57. Boolean getters index as3vm_makebool[byte]; small-int getters
|
||||
store value*2 (the AS3 int tag) directly into *frame[1].
|
||||
|
||||
WHAT IS PINNED (real, deterministic DURANGO behavior, raw line cites inline):
|
||||
Event flag getters index as3vm_makebool by the field byte (raw:717/730/801);
|
||||
get_eventPhase stores byte@0x39 * 2 (raw:758-762); get_type stores ptr@0x57 or
|
||||
the vm+0x27a1 fallback (raw:784-794). preventDefault gates on cancelable
|
||||
(raw:814-819); stop*Propagation OR the flag byte@0x38 (raw:827-847).
|
||||
Event__construct writes the base fields + 0x38:=0x200 and reject-0x78 on a parse
|
||||
failure (raw:490-502). FocusEvent / KeyboardEvent / MouseEvent getters and
|
||||
setters read / write the extended int / byte fields (raw:1104-1194, 1294-1450,
|
||||
1811-1890). Timer getters / setters read the delay double / count ints
|
||||
(raw:2483-2586); Timer__construct rejects a negative delay with 0x75, a parse
|
||||
failure with 0x78 (raw:2454-2469). EventDispatcher.dispatchEvent rejects
|
||||
argc<1 with 0x78 (raw:281-284); willTrigger raises 0x74 on good args and 0x78 on
|
||||
bad args (raw:466-471); addEventListener / hasEventListener / removeEventListener
|
||||
reject a parse failure with 0x78 (raw:104/320/381). ev_setbool parses "b" then
|
||||
writes the byte at obj-1+field (raw:3146-3157); needs_cleaning links a node into
|
||||
the vm+0xd20 cleanup list iff node+0x40 is empty (raw:3206-3212); end_lazy_event
|
||||
pops the vm+0x6b18 value stack by 8 (raw:3135-3138). Event_clone copies the base
|
||||
fields into a fresh object and clears the flags (raw:509-537).
|
||||
|
||||
DEFERRED (flagged structural, NOT exercised): the addEventListener /
|
||||
removeEventListener / dispatchEvent happy-path list insertion / dispatch_loop_GC
|
||||
walk (needs the vm+0xf0.. listener tables and pool allocation); the deep toString /
|
||||
formatToString string assembly; make_lazy_event_GC (needs the vm+0x6b18 value stack
|
||||
and a live class at vm[0x4d5]); the do_*_event_GC engine entry points;
|
||||
KeyboardEvent/MouseEvent get_ctrlKey (a Ghidra makebool[0]/[1] alias the object
|
||||
does not pin cleanly); the MouseEvent localX/localY/stageX/stageY float transforms;
|
||||
the 32-bit ps3 / vita layout (frame stride 4, Event fields bubbles@0x25 /
|
||||
cancelable@0x26 / defaultPrevented@0x27 / flags@0x29 / type@0x43, makebool stride 4).
|
||||
|
||||
Full-suite runs use python3.12 (the machine python3 is 3.14, which SEGFAULTs at
|
||||
teardown on the full suite via an unrelated CPython ctypes-GC bug -- exit 139 AFTER
|
||||
the last "ok" with 0 fail/err is a teardown artifact, not a failure).
|
||||
"""
|
||||
|
||||
import ctypes
|
||||
import shutil
|
||||
import struct
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
RECONSTRUCTED = ROOT / "iggy-decompiled/src/reconstructed"
|
||||
SOURCE = RECONSTRUCTED / "swf_as3vm_flash_events.c"
|
||||
HEADER = RECONSTRUCTED / "swf_as3vm_flash_events.h"
|
||||
SUPPORT = ROOT / "tests/support/swf_as3vm_flash_events_test_support.c"
|
||||
|
||||
MASK64 = (1 << 64) - 1
|
||||
|
||||
# 64-bit DURANGO object-model field offsets (cited per test).
|
||||
OFF_BUBBLES = 0x35 # Event bubbles byte (raw:496/722).
|
||||
OFF_CANCELABLE = 0x36 # Event cancelable byte (raw:497/735).
|
||||
OFF_DEFAULTPREVENTED = 0x37 # Event defaultPrevented byte (raw:500/806).
|
||||
OFF_FLAGS = 0x38 # Event flags / prop-stop u16 (raw:498/833/847).
|
||||
OFF_EVENTPHASE = 0x39 # Event eventPhase byte (raw:762).
|
||||
OFF_LAZYCLONE = 0x3A # Event lazy / clone byte (raw:501/536).
|
||||
OFF_TYPE = 0x57 # Event type interned pointer (raw:499/789).
|
||||
# 32-bit ps3 / vita counterparts (comments for the implementer -- NOT exercised):
|
||||
# bubbles@0x25, cancelable@0x26, defaultPrevented@0x27, flags@0x29, type@0x43
|
||||
# (raw ps3:851-863, vita Event__construct:box @ 0x25/0x26/0x29/0x43).
|
||||
|
||||
OFF_KEYCODE = 0x27 # Focus/Keyboard keyCode int (raw:1108/1367/1155).
|
||||
OFF_CHARCODE = 0x2B # KeyboardEvent charCode int (raw:1311/1430).
|
||||
OFF_KEYLOCATION = 0x2F # KeyboardEvent keyLocation byte (raw:1379).
|
||||
OFF_ALTKEY = 0x30 # Keyboard/Mouse altKey byte (raw:1299/1411).
|
||||
OFF_COMMANDKEY = 0x31 # commandKey byte (raw:1324/1449).
|
||||
OFF_CONTROLKEY = 0x32 # controlKey byte (raw:1337).
|
||||
OFF_SHIFTKEY = 0x33 # Focus/Keyboard shiftKey byte (raw:1136/1392/1194).
|
||||
OFF_MOUSE_CLICKCOUNT = 0x43 # MouseEvent clickCount short (raw:1824+).
|
||||
OFF_MOUSE_DELTA = 0x45 # MouseEvent delta short (raw:1879+).
|
||||
OFF_MOUSE_BUTTONDOWN = 0x47 # MouseEvent buttonDown byte (raw:1811+).
|
||||
|
||||
OFF_TIMER_DELAY = 0x37 # Timer delay double (raw:2470/2493).
|
||||
OFF_TIMER_ELAPSED = 0x3F # Timer elapsed double (raw:2467).
|
||||
OFF_TIMER_CURRENTCOUNT = 0x47 # Timer currentCount int (raw:2483).
|
||||
OFF_TIMER_REPEATCOUNT = 0x4B # Timer repeatCount int (raw:2508/2588).
|
||||
OFF_TIMER_RUNNING = 0x4F # Timer running int (raw:2517/2591).
|
||||
|
||||
OFF_VM_TYPE_FALLBACK = 0x27A1 # vm -> default type string base (raw:791).
|
||||
OFF_VM_CLEANLIST = 0xD20 # vm -> cleanup-list head (raw:3210).
|
||||
OFF_VALUE_STACK = 0x6B18 # vm -> value-stack pointer (raw:3138).
|
||||
OFF_NODE_CLEANNEXT = 0x40 # listener node -> cleanup-next (raw:3209).
|
||||
|
||||
|
||||
class ReconstructedSwfAs3vmFlashEventsTests(unittest.TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
missing = [str(path) for path in (SOURCE, HEADER, SUPPORT)
|
||||
if not path.exists()]
|
||||
if missing:
|
||||
raise AssertionError(
|
||||
"missing swf_as3vm_flash_events runtime inputs: "
|
||||
+ ", ".join(missing))
|
||||
cls.temp = tempfile.TemporaryDirectory()
|
||||
cls.base = Path(cls.temp.name) / "swf_as3vm_flash_events.dylib"
|
||||
build = subprocess.run([
|
||||
"clang", "-dynamiclib", "-std=c11", "-O2", "-Wall", "-Wextra",
|
||||
"-Werror", "-Wl,-undefined,dynamic_lookup",
|
||||
"-DIGGY_RECONSTRUCT_SWF_AS3VM_FLASH_EVENTS_DURANGO=1",
|
||||
"-I", str(RECONSTRUCTED),
|
||||
str(SOURCE), str(SUPPORT), "-o", str(cls.base),
|
||||
], capture_output=True, text=True)
|
||||
if build.returncode:
|
||||
raise AssertionError(build.stdout + build.stderr)
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
cls.temp.cleanup()
|
||||
|
||||
def setUp(self):
|
||||
unique = (Path(self.temp.name) /
|
||||
f"swf_as3vm_flash_events_{self._testMethodName}.dylib")
|
||||
shutil.copyfile(self.base, unique)
|
||||
self.lib = ctypes.CDLL(str(unique))
|
||||
self.lib.swf_as3vm_flash_events_test_reset()
|
||||
self._keep = []
|
||||
|
||||
# --- harness accessors -------------------------------------------- #
|
||||
|
||||
def _count(self, name):
|
||||
fn = getattr(self.lib, f"swf_as3vm_flash_events_test_{name}_count")
|
||||
fn.restype = ctypes.c_size_t
|
||||
fn.argtypes = []
|
||||
return fn()
|
||||
|
||||
def _last_exc(self):
|
||||
self.lib.swf_as3vm_flash_events_test_last_exception_code.restype = \
|
||||
ctypes.c_int32
|
||||
return self.lib.swf_as3vm_flash_events_test_last_exception_code()
|
||||
|
||||
def _last_number(self):
|
||||
self.lib.swf_as3vm_flash_events_test_last_number_arg.restype = \
|
||||
ctypes.c_double
|
||||
return self.lib.swf_as3vm_flash_events_test_last_number_arg()
|
||||
|
||||
def _ptr(self, name):
|
||||
fn = getattr(self.lib, f"swf_as3vm_flash_events_test_{name}")
|
||||
fn.restype = ctypes.c_void_p
|
||||
fn.argtypes = []
|
||||
return fn() or 0
|
||||
|
||||
def _set_parse_ret(self, value):
|
||||
self.lib.swf_as3vm_flash_events_test_set_parse_ret.argtypes = [
|
||||
ctypes.c_int]
|
||||
self.lib.swf_as3vm_flash_events_test_set_parse_ret(value)
|
||||
|
||||
def _set_parse_out(self, data):
|
||||
self.lib.swf_as3vm_flash_events_test_set_parse_out.argtypes = [
|
||||
ctypes.c_void_p, ctypes.c_size_t]
|
||||
buf = (ctypes.c_uint8 * len(data)).from_buffer_copy(data)
|
||||
self._keep.append(buf)
|
||||
self.lib.swf_as3vm_flash_events_test_set_parse_out(
|
||||
ctypes.c_void_p(ctypes.addressof(buf)), len(data))
|
||||
|
||||
def _set_makebool(self, index, value):
|
||||
self.lib.swf_as3vm_flash_events_test_set_makebool.argtypes = [
|
||||
ctypes.c_int, ctypes.c_void_p]
|
||||
self.lib.swf_as3vm_flash_events_test_set_makebool(
|
||||
index, ctypes.c_void_p(value))
|
||||
|
||||
# --- buffer helpers ----------------------------------------------- #
|
||||
|
||||
def _buf(self, size):
|
||||
buf = (ctypes.c_uint8 * size)()
|
||||
self._keep.append(buf)
|
||||
return buf
|
||||
|
||||
def _addr(self, buf):
|
||||
return ctypes.addressof(buf)
|
||||
|
||||
def _poke_u64(self, buf, offset, value):
|
||||
ctypes.c_uint64.from_buffer(buf, offset).value = value & MASK64
|
||||
|
||||
def _peek_u64(self, buf, offset):
|
||||
return ctypes.c_uint64.from_buffer(buf, offset).value
|
||||
|
||||
def _poke_u32(self, buf, offset, value):
|
||||
ctypes.c_uint32.from_buffer(buf, offset).value = value & 0xFFFFFFFF
|
||||
|
||||
def _peek_u32(self, buf, offset):
|
||||
return ctypes.c_uint32.from_buffer(buf, offset).value
|
||||
|
||||
def _poke_u16(self, buf, offset, value):
|
||||
ctypes.c_uint16.from_buffer(buf, offset).value = value & 0xFFFF
|
||||
|
||||
def _peek_u16(self, buf, offset):
|
||||
return ctypes.c_uint16.from_buffer(buf, offset).value
|
||||
|
||||
def _poke_u8(self, buf, offset, value):
|
||||
ctypes.c_uint8.from_buffer(buf, offset).value = value & 0xFF
|
||||
|
||||
def _peek_u8(self, buf, offset):
|
||||
return ctypes.c_uint8.from_buffer(buf, offset).value
|
||||
|
||||
def _frame(self, vm=0, result=0, this_slot=0, argc=0, extra=0):
|
||||
frame = self._buf(0x30)
|
||||
self._poke_u64(frame, 0x00, vm)
|
||||
self._poke_u64(frame, 0x08, result)
|
||||
ctypes.c_int32.from_buffer(frame, 0x10).value = argc
|
||||
self._poke_u64(frame, 0x18, this_slot)
|
||||
self._poke_u64(frame, 0x20, extra)
|
||||
return frame
|
||||
|
||||
def _this_slot(self, obj_addr):
|
||||
slot = self._buf(8)
|
||||
self._poke_u64(slot, 0, obj_addr)
|
||||
return slot
|
||||
|
||||
def _vm(self, size=0x7000):
|
||||
return self._buf(size)
|
||||
|
||||
def _object(self):
|
||||
# The flash.events object holds its native fields directly.
|
||||
return self._buf(0x100)
|
||||
|
||||
def _obj_frame(self, obj, vm=None, result=None, argc=0):
|
||||
this_slot = self._this_slot(self._addr(obj))
|
||||
return self._frame(
|
||||
vm=self._addr(vm) if vm is not None else 0,
|
||||
result=self._addr(result) if result is not None else 0,
|
||||
this_slot=self._addr(this_slot), argc=argc)
|
||||
|
||||
def _call_frame(self, name, frame):
|
||||
fn = getattr(self.lib, name)
|
||||
fn.restype = None
|
||||
fn.argtypes = [ctypes.c_void_p]
|
||||
fn(ctypes.c_void_p(self._addr(frame)))
|
||||
|
||||
def _reset(self):
|
||||
self.lib.swf_as3vm_flash_events_test_reset()
|
||||
|
||||
# ------------------------------------------------------------------ #
|
||||
# Event flag getters -- index as3vm_makebool by the field byte.
|
||||
# ------------------------------------------------------------------ #
|
||||
|
||||
def _bool_getter(self, name, offset):
|
||||
self._reset()
|
||||
obj = self._object()
|
||||
self._set_makebool(0, 0xFA15E)
|
||||
self._set_makebool(1, 0x712)
|
||||
result = self._buf(8)
|
||||
# byte value 1 selects makebool[1] (true).
|
||||
self._poke_u8(obj, offset, 1)
|
||||
frame = self._obj_frame(obj, result=result)
|
||||
self._call_frame(name, frame)
|
||||
self.assertEqual(self._peek_u64(result, 0), 0x712, name)
|
||||
# byte value 0 selects makebool[0] (false).
|
||||
self._reset()
|
||||
obj = self._object()
|
||||
self._set_makebool(0, 0xFA15E)
|
||||
self._set_makebool(1, 0x712)
|
||||
self._poke_u8(obj, offset, 0)
|
||||
result = self._buf(8)
|
||||
frame = self._obj_frame(obj, result=result)
|
||||
self._call_frame(name, frame)
|
||||
self.assertEqual(self._peek_u64(result, 0), 0xFA15E, name)
|
||||
|
||||
def test_event_bool_getters_index_makebool(self):
|
||||
# raw:717-723 / 730-736 / 801-806 makebool[ byte@0x35 / 0x36 / 0x37 ].
|
||||
self._bool_getter("as3vm_Event_get_bubbles", OFF_BUBBLES)
|
||||
self._bool_getter("as3vm_Event_get_cancelable", OFF_CANCELABLE)
|
||||
self._bool_getter("as3vm_Event_isDefaultPrevented",
|
||||
OFF_DEFAULTPREVENTED)
|
||||
|
||||
def test_focus_and_keyboard_bool_getters_index_makebool(self):
|
||||
# raw:1131-1136 / 1294-1299 / 1319-1324 / 1332-1337 / 1385-1392.
|
||||
self._bool_getter("as3vm_FocusEvent_get_shiftKey", OFF_SHIFTKEY)
|
||||
self._bool_getter("as3vm_KeyboardEvent_get_altKey", OFF_ALTKEY)
|
||||
self._bool_getter("as3vm_KeyboardEvent_get_commandKey", OFF_COMMANDKEY)
|
||||
self._bool_getter("as3vm_KeyboardEvent_get_controlKey", OFF_CONTROLKEY)
|
||||
self._bool_getter("as3vm_KeyboardEvent_get_shiftKey", OFF_SHIFTKEY)
|
||||
|
||||
def test_mouse_bool_getters_index_makebool(self):
|
||||
# raw:1811-1817 (buttonDown@0x47) / 1867-1873 (commandKey@0x31).
|
||||
self._bool_getter("as3vm_MouseEvent_get_buttonDown",
|
||||
OFF_MOUSE_BUTTONDOWN)
|
||||
self._bool_getter("as3vm_MouseEvent_get_commandKey", OFF_COMMANDKEY)
|
||||
|
||||
# ------------------------------------------------------------------ #
|
||||
# Small-int getters -- store field * 2 (the AS3 int tag) into *frame[1].
|
||||
# ------------------------------------------------------------------ #
|
||||
|
||||
def _int_getter(self, name, offset, value, width="i"):
|
||||
self._reset()
|
||||
obj = self._object()
|
||||
if width == "i":
|
||||
ctypes.c_int32.from_buffer(obj, offset).value = value
|
||||
elif width == "h":
|
||||
ctypes.c_int16.from_buffer(obj, offset).value = value
|
||||
else:
|
||||
self._poke_u8(obj, offset, value)
|
||||
result = self._buf(8)
|
||||
frame = self._obj_frame(obj, result=result)
|
||||
self._call_frame(name, frame)
|
||||
self.assertEqual(self._peek_u64(result, 0), (value * 2) & MASK64, name)
|
||||
|
||||
def test_int_getters_store_field_times_two(self):
|
||||
# raw:1108 (keyCode int@0x27), 1311 (charCode int@0x2b),
|
||||
# 758-762 (eventPhase byte@0x39), 1375-1379 (keyLocation byte@0x2f),
|
||||
# 1824 (clickCount short@0x43), 1879 (delta short@0x45),
|
||||
# 2483 (currentCount int@0x47), 2508 (repeatCount int@0x4b).
|
||||
self._int_getter("as3vm_FocusEvent_get_keyCode", OFF_KEYCODE, 21)
|
||||
self._int_getter("as3vm_KeyboardEvent_get_keyCode", OFF_KEYCODE, 65)
|
||||
self._int_getter("as3vm_KeyboardEvent_get_charCode", OFF_CHARCODE, 97)
|
||||
self._int_getter("as3vm_Event_get_eventPhase", OFF_EVENTPHASE, 2,
|
||||
width="b")
|
||||
self._int_getter("as3vm_KeyboardEvent_get_keyLocation",
|
||||
OFF_KEYLOCATION, 1, width="b")
|
||||
self._int_getter("as3vm_MouseEvent_get_clickCount",
|
||||
OFF_MOUSE_CLICKCOUNT, 3, width="h")
|
||||
self._int_getter("as3vm_MouseEvent_get_delta", OFF_MOUSE_DELTA, 5,
|
||||
width="h")
|
||||
self._int_getter("as3vm_Timer_get_currentCount",
|
||||
OFF_TIMER_CURRENTCOUNT, 9)
|
||||
self._int_getter("as3vm_Timer_get_repeatCount", OFF_TIMER_REPEATCOUNT,
|
||||
4)
|
||||
|
||||
# ------------------------------------------------------------------ #
|
||||
# Event get_type -- ptr@0x57 or the vm+0x27a1 fallback.
|
||||
# ------------------------------------------------------------------ #
|
||||
|
||||
def test_get_type_selects_field_or_vm_fallback(self):
|
||||
# raw:784-794 ptr@0x57 if set else vm+0x27a1.
|
||||
vm = self._vm()
|
||||
obj = self._object()
|
||||
self._poke_u64(obj, OFF_TYPE, 0xDEADBEEF)
|
||||
result = self._buf(8)
|
||||
frame = self._obj_frame(obj, vm=vm, result=result)
|
||||
self._call_frame("as3vm_Event_get_type", frame)
|
||||
self.assertEqual(self._peek_u64(result, 0), 0xDEADBEEF)
|
||||
|
||||
self._reset()
|
||||
obj2 = self._object() # type slot zero -> vm+0x27a1 fallback.
|
||||
result2 = self._buf(8)
|
||||
frame2 = self._obj_frame(obj2, vm=vm, result=result2)
|
||||
self._call_frame("as3vm_Event_get_type", frame2)
|
||||
self.assertEqual(self._peek_u64(result2, 0),
|
||||
(self._addr(vm) + OFF_VM_TYPE_FALLBACK) & MASK64)
|
||||
|
||||
# ------------------------------------------------------------------ #
|
||||
# Event flag mutators.
|
||||
# ------------------------------------------------------------------ #
|
||||
|
||||
def test_prevent_default_gates_on_cancelable(self):
|
||||
# raw:814-819 defaultPrevented@0x37 := 1 only when cancelable@0x36 set.
|
||||
obj = self._object()
|
||||
self._poke_u8(obj, OFF_CANCELABLE, 1)
|
||||
frame = self._obj_frame(obj)
|
||||
self._call_frame("as3vm_Event_preventDefault", frame)
|
||||
self.assertEqual(self._peek_u8(obj, OFF_DEFAULTPREVENTED), 1)
|
||||
|
||||
self._reset()
|
||||
obj2 = self._object() # cancelable clear -> no write.
|
||||
frame2 = self._obj_frame(obj2)
|
||||
self._call_frame("as3vm_Event_preventDefault", frame2)
|
||||
self.assertEqual(self._peek_u8(obj2, OFF_DEFAULTPREVENTED), 0)
|
||||
|
||||
def test_stop_propagation_flags_or_the_flag_byte(self):
|
||||
# raw:841-847 flag@0x38 |= 1 ; raw:827-833 flag@0x38 |= 2.
|
||||
obj = self._object()
|
||||
self._poke_u16(obj, OFF_FLAGS, 0x10)
|
||||
frame = self._obj_frame(obj)
|
||||
self._call_frame("as3vm_Event_stopPropagation", frame)
|
||||
self.assertEqual(self._peek_u8(obj, OFF_FLAGS), 0x11)
|
||||
|
||||
self._reset()
|
||||
obj2 = self._object()
|
||||
self._poke_u16(obj2, OFF_FLAGS, 0x10)
|
||||
frame2 = self._obj_frame(obj2)
|
||||
self._call_frame("as3vm_Event_stopImmediatePropagation", frame2)
|
||||
self.assertEqual(self._peek_u8(obj2, OFF_FLAGS), 0x12)
|
||||
|
||||
# ------------------------------------------------------------------ #
|
||||
# Event__construct -- writes the base fields + 0x38:=0x200.
|
||||
# ------------------------------------------------------------------ #
|
||||
|
||||
def test_event_construct_writes_base_fields(self):
|
||||
# raw:490-502 parse "s_bb"; type@0x57 := parsed string; 0x38:=0x200,
|
||||
# 0x37:=0, 0x3a:=0. (The harness controls only the first out arg = type;
|
||||
# bubbles / cancelable default to their pre-parse zero.)
|
||||
vm = self._vm()
|
||||
obj = self._object()
|
||||
self._poke_u8(obj, OFF_DEFAULTPREVENTED, 0xFF) # must be cleared.
|
||||
self._poke_u8(obj, OFF_LAZYCLONE, 0xFF)
|
||||
self._set_parse_out(struct.pack("<Q", 0xABCDEF12))
|
||||
frame = self._obj_frame(obj, vm=vm)
|
||||
self._call_frame("as3vm_Event__construct", frame)
|
||||
self.assertEqual(self._peek_u64(obj, OFF_TYPE), 0xABCDEF12)
|
||||
self.assertEqual(self._peek_u16(obj, OFF_FLAGS), 0x200)
|
||||
self.assertEqual(self._peek_u8(obj, OFF_DEFAULTPREVENTED), 0)
|
||||
self.assertEqual(self._peek_u8(obj, OFF_LAZYCLONE), 0)
|
||||
self.assertEqual(self._count("exception"), 0)
|
||||
|
||||
def test_event_construct_bad_args_raise_0x78(self):
|
||||
# raw:491-493 a nonzero parse result raises 0x78.
|
||||
self._set_parse_ret(1)
|
||||
vm = self._vm()
|
||||
obj = self._object()
|
||||
frame = self._obj_frame(obj, vm=vm)
|
||||
self._call_frame("as3vm_Event__construct", frame)
|
||||
self.assertEqual(self._count("exception"), 1)
|
||||
self.assertEqual(self._last_exc(), 0x78)
|
||||
|
||||
# ------------------------------------------------------------------ #
|
||||
# FocusEvent / KeyboardEvent / Timer setters -- parse then write a field.
|
||||
# ------------------------------------------------------------------ #
|
||||
|
||||
def _int_setter(self, name, offset, pack, expect):
|
||||
self._reset()
|
||||
vm = self._vm()
|
||||
obj = self._object()
|
||||
self._set_parse_out(pack)
|
||||
frame = self._obj_frame(obj, vm=vm)
|
||||
self._call_frame(name, frame)
|
||||
self.assertEqual(self._peek_u32(obj, offset), expect & 0xFFFFFFFF, name)
|
||||
self.assertEqual(self._count("exception"), 0, name)
|
||||
|
||||
def test_int_setters_write_the_parsed_field(self):
|
||||
# raw:1155 (Focus keyCode@0x27), 1430 (Keyboard charCode@0x2b),
|
||||
# 1502-1521 (Keyboard keyCode@0x27), 2588 (Timer repeatCount@0x4b).
|
||||
self._int_setter("as3vm_FocusEvent_set_keyCode", OFF_KEYCODE,
|
||||
struct.pack("<I", 0x33), 0x33)
|
||||
self._int_setter("as3vm_KeyboardEvent_set_charCode", OFF_CHARCODE,
|
||||
struct.pack("<I", 0x61), 0x61)
|
||||
self._int_setter("as3vm_KeyboardEvent_set_keyCode", OFF_KEYCODE,
|
||||
struct.pack("<I", 0x41), 0x41)
|
||||
self._int_setter("as3vm_Timer_set_repeatCount", OFF_TIMER_REPEATCOUNT,
|
||||
struct.pack("<i", 7), 7)
|
||||
|
||||
def _byte_setter(self, name, offset):
|
||||
self._reset()
|
||||
vm = self._vm()
|
||||
obj = self._object()
|
||||
self._set_parse_out(bytes([1]))
|
||||
frame = self._obj_frame(obj, vm=vm)
|
||||
self._call_frame(name, frame)
|
||||
self.assertEqual(self._peek_u8(obj, offset), 1, name)
|
||||
self.assertEqual(self._count("exception"), 0, name)
|
||||
|
||||
def test_byte_setters_write_the_parsed_field(self):
|
||||
# raw:1194 (Focus shiftKey@0x33), 1411 (Keyboard altKey@0x30),
|
||||
# 1449 (Keyboard commandKey@0x31).
|
||||
self._byte_setter("as3vm_FocusEvent_set_shiftKey", OFF_SHIFTKEY)
|
||||
self._byte_setter("as3vm_KeyboardEvent_set_altKey", OFF_ALTKEY)
|
||||
self._byte_setter("as3vm_KeyboardEvent_set_commandKey", OFF_COMMANDKEY)
|
||||
|
||||
def test_setter_bad_args_raise_0x78(self):
|
||||
# raw:1151/1407 a nonzero parse result raises 0x78 and writes no field.
|
||||
for name in ("as3vm_FocusEvent_set_keyCode",
|
||||
"as3vm_FocusEvent_set_shiftKey",
|
||||
"as3vm_KeyboardEvent_set_altKey"):
|
||||
self._reset()
|
||||
self._set_parse_ret(1)
|
||||
vm = self._vm()
|
||||
obj = self._object()
|
||||
frame = self._obj_frame(obj, vm=vm)
|
||||
self._call_frame(name, frame)
|
||||
self.assertEqual(self._count("exception"), 1, name)
|
||||
self.assertEqual(self._last_exc(), 0x78, name)
|
||||
|
||||
# ------------------------------------------------------------------ #
|
||||
# Timer -- delay double + reject paths + running flag.
|
||||
# ------------------------------------------------------------------ #
|
||||
|
||||
def test_timer_get_delay_boxes_the_double(self):
|
||||
# raw:2493-2496 make_number(vm, *(double*)(obj+0x37)) -> *frame[1].
|
||||
vm = self._vm()
|
||||
obj = self._object()
|
||||
ctypes.c_double.from_buffer(obj, OFF_TIMER_DELAY).value = 250.0
|
||||
result = self._buf(8)
|
||||
frame = self._obj_frame(obj, vm=vm, result=result)
|
||||
self._call_frame("as3vm_Timer_get_delay", frame)
|
||||
self.assertEqual(self._count("make_number"), 1)
|
||||
self.assertEqual(self._last_number(), 250.0)
|
||||
|
||||
def test_timer_set_delay_writes_double_and_rejects_negative(self):
|
||||
# raw:2565-2575 parse "f"; delay@0x37 := value, elapsed@0x3f := 0;
|
||||
# a negative delay raises 0x78.
|
||||
vm = self._vm()
|
||||
obj = self._object()
|
||||
ctypes.c_double.from_buffer(obj, OFF_TIMER_ELAPSED).value = 5.0
|
||||
self._set_parse_out(struct.pack("<d", 500.0))
|
||||
frame = self._obj_frame(obj, vm=vm)
|
||||
self._call_frame("as3vm_Timer_set_delay", frame)
|
||||
self.assertEqual(
|
||||
ctypes.c_double.from_buffer(obj, OFF_TIMER_DELAY).value, 500.0)
|
||||
self.assertEqual(
|
||||
ctypes.c_double.from_buffer(obj, OFF_TIMER_ELAPSED).value, 0.0)
|
||||
self.assertEqual(self._count("exception"), 0)
|
||||
|
||||
self._reset()
|
||||
obj2 = self._object()
|
||||
self._set_parse_out(struct.pack("<d", -1.0))
|
||||
frame2 = self._obj_frame(obj2, vm=vm)
|
||||
self._call_frame("as3vm_Timer_set_delay", frame2)
|
||||
self.assertEqual(self._count("exception"), 1)
|
||||
self.assertEqual(self._last_exc(), 0x78)
|
||||
|
||||
def test_timer_construct_rejects_negative_delay_with_0x75(self):
|
||||
# raw:2465-2469 Timer__construct raises 0x75 on a negative delay
|
||||
# (distinct from the 0x78 parse-failure path).
|
||||
vm = self._vm()
|
||||
obj = self._object()
|
||||
self._set_parse_out(struct.pack("<d", -3.0))
|
||||
frame = self._obj_frame(obj, vm=vm)
|
||||
self._call_frame("as3vm_Timer__construct", frame)
|
||||
self.assertEqual(self._count("exception"), 1)
|
||||
self.assertEqual(self._last_exc(), 0x75)
|
||||
|
||||
def test_timer_construct_bad_args_raise_0x78(self):
|
||||
# raw:2458-2461 a nonzero parse result raises 0x78.
|
||||
self._set_parse_ret(1)
|
||||
vm = self._vm()
|
||||
obj = self._object()
|
||||
frame = self._obj_frame(obj, vm=vm)
|
||||
self._call_frame("as3vm_Timer__construct", frame)
|
||||
self.assertEqual(self._count("exception"), 1)
|
||||
self.assertEqual(self._last_exc(), 0x78)
|
||||
|
||||
def test_timer_start_and_stop_toggle_running(self):
|
||||
# raw:2591 (start: running@0x4f := 1) / 2600 (stop: running@0x4f := 0).
|
||||
obj = self._object()
|
||||
frame = self._obj_frame(obj)
|
||||
self._call_frame("as3vm_Timer_start", frame)
|
||||
self.assertEqual(self._peek_u32(obj, OFF_TIMER_RUNNING), 1)
|
||||
|
||||
self._reset()
|
||||
obj2 = self._object()
|
||||
self._poke_u32(obj2, OFF_TIMER_RUNNING, 1)
|
||||
frame2 = self._obj_frame(obj2)
|
||||
self._call_frame("as3vm_Timer_stop", frame2)
|
||||
self.assertEqual(self._peek_u32(obj2, OFF_TIMER_RUNNING), 0)
|
||||
|
||||
def test_timer_reset_clears_counters(self):
|
||||
# raw:2532-2537 running@0x4f := 0, currentCount@0x47 := 0,
|
||||
# elapsed@0x3f := 0.
|
||||
obj = self._object()
|
||||
self._poke_u32(obj, OFF_TIMER_RUNNING, 1)
|
||||
self._poke_u32(obj, OFF_TIMER_CURRENTCOUNT, 9)
|
||||
ctypes.c_double.from_buffer(obj, OFF_TIMER_ELAPSED).value = 42.0
|
||||
frame = self._obj_frame(obj)
|
||||
self._call_frame("as3vm_Timer_reset", frame)
|
||||
self.assertEqual(self._peek_u32(obj, OFF_TIMER_RUNNING), 0)
|
||||
self.assertEqual(self._peek_u32(obj, OFF_TIMER_CURRENTCOUNT), 0)
|
||||
self.assertEqual(
|
||||
ctypes.c_double.from_buffer(obj, OFF_TIMER_ELAPSED).value, 0.0)
|
||||
|
||||
# ------------------------------------------------------------------ #
|
||||
# EventDispatcher reject paths + willTrigger dual-exception.
|
||||
# ------------------------------------------------------------------ #
|
||||
|
||||
def test_dispatch_event_rejects_empty_argc(self):
|
||||
# raw:281-284 argc < 1 -> exception 0x78.
|
||||
vm = self._vm()
|
||||
obj = self._object()
|
||||
frame = self._obj_frame(obj, vm=vm, argc=0)
|
||||
self._call_frame("as3vm_EventDispatcher_dispatchEvent", frame)
|
||||
self.assertEqual(self._count("exception"), 1)
|
||||
self.assertEqual(self._last_exc(), 0x78)
|
||||
|
||||
def test_dispatcher_parse_failures_raise_0x78(self):
|
||||
# raw:104-106 / 320-323 / 381-384 parse failure -> exception 0x78.
|
||||
for name in ("as3vm_EventDispatcher_addEventListener",
|
||||
"as3vm_EventDispatcher_hasEventListener",
|
||||
"as3vm_EventDispatcher_removeEventListener"):
|
||||
self._reset()
|
||||
self._set_parse_ret(1)
|
||||
vm = self._vm()
|
||||
obj = self._object()
|
||||
frame = self._obj_frame(obj, vm=vm, argc=1)
|
||||
self._call_frame(name, frame)
|
||||
self.assertEqual(self._count("exception"), 1, name)
|
||||
self.assertEqual(self._last_exc(), 0x78, name)
|
||||
|
||||
def test_will_trigger_is_unsupported_dual_exception(self):
|
||||
# raw:466-471 willTrigger raises 0x74 on good args, 0x78 on bad args.
|
||||
vm = self._vm()
|
||||
obj = self._object()
|
||||
frame = self._obj_frame(obj, vm=vm, argc=1)
|
||||
self._call_frame("as3vm_EventDispatcher_willTrigger", frame)
|
||||
self.assertEqual(self._count("exception"), 1)
|
||||
self.assertEqual(self._last_exc(), 0x74)
|
||||
|
||||
self._reset()
|
||||
self._set_parse_ret(1)
|
||||
obj2 = self._object()
|
||||
frame2 = self._obj_frame(obj2, vm=vm, argc=1)
|
||||
self._call_frame("as3vm_EventDispatcher_willTrigger", frame2)
|
||||
self.assertEqual(self._count("exception"), 1)
|
||||
self.assertEqual(self._last_exc(), 0x78)
|
||||
|
||||
# ------------------------------------------------------------------ #
|
||||
# Shared helpers -- ev_setbool, needs_cleaning, end_lazy_event.
|
||||
# ------------------------------------------------------------------ #
|
||||
|
||||
def test_ev_setbool_writes_byte_at_obj_minus_one_plus_field(self):
|
||||
# raw:3146-3157 parse "b" then obj-1+field := bool byte.
|
||||
vm = self._vm()
|
||||
obj = self._object()
|
||||
self._set_parse_out(bytes([1]))
|
||||
this_slot = self._this_slot(self._addr(obj))
|
||||
frame = self._frame(vm=self._addr(vm),
|
||||
this_slot=self._addr(this_slot))
|
||||
fn = self.lib.as3vm_ev_setbool
|
||||
fn.restype = None
|
||||
fn.argtypes = [ctypes.c_void_p, ctypes.c_int]
|
||||
fn(ctypes.c_void_p(self._addr(frame)), 0x34) # writes obj + 0x34 - 1.
|
||||
self.assertEqual(self._peek_u8(obj, 0x33), 1)
|
||||
self.assertEqual(self._count("exception"), 0)
|
||||
|
||||
def test_ev_setbool_bad_args_raise_0x78(self):
|
||||
# raw:3153-3155 a nonzero parse result raises 0x78.
|
||||
self._set_parse_ret(1)
|
||||
vm = self._vm()
|
||||
obj = self._object()
|
||||
this_slot = self._this_slot(self._addr(obj))
|
||||
frame = self._frame(vm=self._addr(vm),
|
||||
this_slot=self._addr(this_slot))
|
||||
fn = self.lib.as3vm_ev_setbool
|
||||
fn.restype = None
|
||||
fn.argtypes = [ctypes.c_void_p, ctypes.c_int]
|
||||
fn(ctypes.c_void_p(self._addr(frame)), 0x34)
|
||||
self.assertEqual(self._count("exception"), 1)
|
||||
self.assertEqual(self._last_exc(), 0x78)
|
||||
|
||||
def test_needs_cleaning_links_node_when_empty(self):
|
||||
# raw:3206-3212 if node+0x40 == 0: node+0x40 := vm+0xd20; vm+0xd20 := node.
|
||||
vm = self._vm()
|
||||
node = self._buf(0x80)
|
||||
self._poke_u64(vm, OFF_VM_CLEANLIST, 0xC0FFEE)
|
||||
fn = self.lib.as3vm_needs_cleaning
|
||||
fn.restype = None
|
||||
fn.argtypes = [ctypes.c_void_p, ctypes.c_void_p]
|
||||
fn(ctypes.c_void_p(self._addr(vm)), ctypes.c_void_p(self._addr(node)))
|
||||
self.assertEqual(self._peek_u64(node, OFF_NODE_CLEANNEXT), 0xC0FFEE)
|
||||
self.assertEqual(self._peek_u64(vm, OFF_VM_CLEANLIST),
|
||||
self._addr(node) & MASK64)
|
||||
|
||||
def test_needs_cleaning_skips_node_when_already_linked(self):
|
||||
# raw:3209 a node whose cleanup-next is set is left untouched.
|
||||
vm = self._vm()
|
||||
node = self._buf(0x80)
|
||||
self._poke_u64(vm, OFF_VM_CLEANLIST, 0xC0FFEE)
|
||||
self._poke_u64(node, OFF_NODE_CLEANNEXT, 0x1234)
|
||||
fn = self.lib.as3vm_needs_cleaning
|
||||
fn.restype = None
|
||||
fn.argtypes = [ctypes.c_void_p, ctypes.c_void_p]
|
||||
fn(ctypes.c_void_p(self._addr(vm)), ctypes.c_void_p(self._addr(node)))
|
||||
self.assertEqual(self._peek_u64(node, OFF_NODE_CLEANNEXT), 0x1234)
|
||||
self.assertEqual(self._peek_u64(vm, OFF_VM_CLEANLIST), 0xC0FFEE)
|
||||
|
||||
def test_end_lazy_event_pops_value_stack(self):
|
||||
# raw:3135-3138 vm+0x6b18 -= 8.
|
||||
vm = self._vm()
|
||||
self._poke_u64(vm, OFF_VALUE_STACK, 0x9000)
|
||||
fn = self.lib.as3vm_end_lazy_event
|
||||
fn.restype = None
|
||||
fn.argtypes = [ctypes.c_void_p]
|
||||
fn(ctypes.c_void_p(self._addr(vm)))
|
||||
self.assertEqual(self._peek_u64(vm, OFF_VALUE_STACK), 0x9000 - 8)
|
||||
|
||||
# ------------------------------------------------------------------ #
|
||||
# Event_clone -- fresh object with the base fields copied + flags cleared.
|
||||
# ------------------------------------------------------------------ #
|
||||
|
||||
def test_event_clone_copies_fields_into_fresh_object(self):
|
||||
# raw:509-537 make_object(class @ *(*(obj+7)+0x20)); copy 0x27..0x57;
|
||||
# new+0x38 := 0, new+0x37 := 0, new+0x3a := 0; *frame[1] := new.
|
||||
vm = self._vm()
|
||||
clsrec = self._buf(0x80)
|
||||
slotdesc = self._buf(0x40)
|
||||
self._poke_u64(clsrec, 0x20, 0xC1A55) # class pointer.
|
||||
self._poke_u64(clsrec, 0x58, self._addr(slotdesc))
|
||||
self._poke_u16(slotdesc, 0x04, 2) # slot index (u16).
|
||||
obj = self._object()
|
||||
self._poke_u64(obj, 0x07, self._addr(clsrec)) # obj -> class record.
|
||||
self._poke_u64(obj, OFF_TYPE, 0xFEEDFACE)
|
||||
self._poke_u16(obj, OFF_FLAGS, 0x200)
|
||||
self._poke_u8(obj, OFF_DEFAULTPREVENTED, 1)
|
||||
self._poke_u8(obj, OFF_LAZYCLONE, 1)
|
||||
result = self._buf(8)
|
||||
frame = self._obj_frame(obj, vm=vm, result=result)
|
||||
self._call_frame("as3vm_Event_clone", frame)
|
||||
self.assertEqual(self._count("make_object"), 1)
|
||||
self.assertEqual(self._ptr("last_object_class"), 0xC1A55)
|
||||
new_obj = self._ptr("last_object")
|
||||
self.assertEqual(self._peek_u64(result, 0), new_obj & MASK64)
|
||||
self.assertEqual(ctypes.c_uint64.from_address(new_obj + OFF_TYPE).value,
|
||||
0xFEEDFACE)
|
||||
self.assertEqual(
|
||||
ctypes.c_uint16.from_address(new_obj + OFF_FLAGS).value, 0)
|
||||
self.assertEqual(
|
||||
ctypes.c_uint8.from_address(new_obj + OFF_DEFAULTPREVENTED).value, 0)
|
||||
self.assertEqual(
|
||||
ctypes.c_uint8.from_address(new_obj + OFF_LAZYCLONE).value, 0)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
492
tests/test_reconstructed_swf_as3vm_flash_events_cross.py
Normal file
492
tests/test_reconstructed_swf_as3vm_flash_events_cross.py
Normal file
@@ -0,0 +1,492 @@
|
||||
"""Cross-platform contract tests for the reconstructed swf_as3vm_flash_events module.
|
||||
|
||||
Mirrors tests/test_reconstructed_swf_as3_textfield_cross.py (the direct analog in
|
||||
the same AS3 / AVM2 VM binding cluster). RED until swf_as3vm_flash_events.c /
|
||||
swf_as3vm_flash_events.h (and their CMake / modules.tsv rows) exist; the
|
||||
retail-evidence assertions (exports, no-owned-global, imports, provenance and the
|
||||
inventory) run NOW against the four .obj and prove the nm / strings parsing.
|
||||
|
||||
swf_as3vm_flash_events is Iggy's AVM2 flash.events binding layer: the Event,
|
||||
EventDispatcher, FocusEvent, KeyboardEvent, Keyboard, LoaderInfo, MouseEvent,
|
||||
TextEvent, TimerEvent, Timer classes plus the object factory /
|
||||
lazy-event / dispatch / clone helpers (as3vm_make_lazy_event_GC, as3vm_clone_GC,
|
||||
as3vm_do_*_event_GC, as3vm_ev_setbool, as3vm_needs_cleaning, ...). It exports a
|
||||
fixed 118 entry points on every platform. The per-platform source_functions count
|
||||
(recovered file-static helpers such as dispatch_event_GC / dispatch_loop_GC) is
|
||||
123 durango / 121 orbis / 120 ps3 / 122 vita; the exported ABI is 118 everywhere.
|
||||
|
||||
How EXPECTED_* were derived (all four .obj under
|
||||
work/iggy-native-decomp/<platform>-objects/swf_as3vm_flash_events.obj, verified
|
||||
with /opt/homebrew/opt/llvm/bin/llvm-nm and `nm -g`):
|
||||
|
||||
EXPECTED_FUNCTIONS = `llvm-nm --extern-only --defined-only <obj>` T-tagged
|
||||
names, leading '.' stripped on ps3. IDENTICAL 118-name
|
||||
set on durango / orbis / ps3 / vita. The ps3 .opd
|
||||
descriptors surface each export a second time as 'D';
|
||||
those normalize to the exported names and are NOT globals.
|
||||
|
||||
EXPECTED_GLOBALS = EMPTY. This module owns NO externally named data global.
|
||||
The forty-two durango 'R' COMDATs are ??_C@ string literals
|
||||
(the "s"/"s_u"/"Ic_bdb"/... arg-format specs, the property
|
||||
name fragments " bubbles=" / " keyCode=" / ... , the
|
||||
"[Event type=\"" toString prefixes and the provenance path)
|
||||
-- MSVC read-only ARTIFACTS, local (.L.str) on the other
|
||||
three platforms. as3vm_makebool and the value-cell
|
||||
singletons are IMPORTS owned elsewhere.
|
||||
|
||||
EXPECTED_IMPORTS = the genuine non-scaffolding references present on ALL FOUR
|
||||
retail objects (INVARIANT -- 32 symbols).
|
||||
|
||||
PLATFORM_IMPORTS = the per-platform libc the retail optimizer emitted (Event
|
||||
toString / dispatcher struct copies): durango / ps3 / vita
|
||||
{memcpy, memset}; orbis {memcpy} (memset inlined).
|
||||
|
||||
RUNTIME_ALLOWLISTS = pure toolchain scaffolding, verified against retail
|
||||
`llvm-nm --undefined-only`:
|
||||
durango {_fltused, __chkstk, __report_rangecheckfailure,
|
||||
__GSHandlerCheck, __security_check_cookie,
|
||||
__security_cookie
|
||||
(+ __ImageBase a fresh MSVC compile may emit)}
|
||||
orbis {_GLOBAL_OFFSET_TABLE_}
|
||||
ps3 {}
|
||||
vita {__aeabi_unwind_cpp_pr0/_pr1, __stack_chk_fail,
|
||||
__stack_chk_guard}
|
||||
|
||||
PROVENANCE = every platform embeds __FILE__ via iggy_malloc_fileline, so
|
||||
the canonical c:\\projects\\g\\src\\flash\\swf_as3vm_flash_events.c
|
||||
is present on ALL FOUR; durango ALSO carries its build .obj
|
||||
path.
|
||||
|
||||
Run the full suite with python3.12 (`python3.12 -m unittest discover -s tests`):
|
||||
the machine python3 is 3.14, which SEGFAULTs at teardown on the full suite via an
|
||||
unrelated CPython ctypes-GC bug. This cross test's cross-compile / nm logic is
|
||||
python-version-independent.
|
||||
"""
|
||||
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
RECONSTRUCTED = ROOT / "iggy-decompiled/src/reconstructed"
|
||||
SOURCE = RECONSTRUCTED / "swf_as3vm_flash_events.c"
|
||||
HEADER = RECONSTRUCTED / "swf_as3vm_flash_events.h"
|
||||
LLVM_NM = Path("/opt/homebrew/opt/llvm/bin/llvm-nm")
|
||||
VARIANTS = {
|
||||
"durango": ("clang", "x86_64-pc-windows-msvc"),
|
||||
"orbis": ("clang", "x86_64-unknown-freebsd"),
|
||||
"vita": ("clang", "armv7a-unknown-linux-gnueabihf"),
|
||||
}
|
||||
PS3_CLANG = Path("/opt/homebrew/opt/llvm/bin/clang")
|
||||
if PS3_CLANG.exists():
|
||||
VARIANTS["ps3"] = (str(PS3_CLANG), "powerpc-unknown-linux-gnu")
|
||||
|
||||
# Invariant 118-name exported ABI (leading '.' stripped on ps3).
|
||||
EXPECTED_FUNCTIONS = {
|
||||
"as3vm_EventDispatcher__construct",
|
||||
"as3vm_EventDispatcher__finalize",
|
||||
"as3vm_EventDispatcher_addEventListener",
|
||||
"as3vm_EventDispatcher_dispatchEvent",
|
||||
"as3vm_EventDispatcher_hasEventListener",
|
||||
"as3vm_EventDispatcher_removeEventListener",
|
||||
"as3vm_EventDispatcher_willTrigger",
|
||||
"as3vm_Event__construct",
|
||||
"as3vm_Event_clone",
|
||||
"as3vm_Event_formatToString",
|
||||
"as3vm_Event_get_bubbles",
|
||||
"as3vm_Event_get_cancelable",
|
||||
"as3vm_Event_get_currentTarget",
|
||||
"as3vm_Event_get_eventPhase",
|
||||
"as3vm_Event_get_target",
|
||||
"as3vm_Event_get_type",
|
||||
"as3vm_Event_isDefaultPrevented",
|
||||
"as3vm_Event_preventDefault",
|
||||
"as3vm_Event_stopImmediatePropagation",
|
||||
"as3vm_Event_stopPropagation",
|
||||
"as3vm_Event_toString",
|
||||
"as3vm_FocusEvent__construct",
|
||||
"as3vm_FocusEvent_clone",
|
||||
"as3vm_FocusEvent_get_keyCode",
|
||||
"as3vm_FocusEvent_get_relatedObject",
|
||||
"as3vm_FocusEvent_get_shiftKey",
|
||||
"as3vm_FocusEvent_set_keyCode",
|
||||
"as3vm_FocusEvent_set_relatedObject",
|
||||
"as3vm_FocusEvent_set_shiftKey",
|
||||
"as3vm_KeyboardEvent__construct",
|
||||
"as3vm_KeyboardEvent_clone",
|
||||
"as3vm_KeyboardEvent_get_altKey",
|
||||
"as3vm_KeyboardEvent_get_charCode",
|
||||
"as3vm_KeyboardEvent_get_commandKey",
|
||||
"as3vm_KeyboardEvent_get_controlKey",
|
||||
"as3vm_KeyboardEvent_get_ctrlKey",
|
||||
"as3vm_KeyboardEvent_get_keyCode",
|
||||
"as3vm_KeyboardEvent_get_keyLocation",
|
||||
"as3vm_KeyboardEvent_get_shiftKey",
|
||||
"as3vm_KeyboardEvent_set_altKey",
|
||||
"as3vm_KeyboardEvent_set_charCode",
|
||||
"as3vm_KeyboardEvent_set_commandKey",
|
||||
"as3vm_KeyboardEvent_set_controlKey",
|
||||
"as3vm_KeyboardEvent_set_ctrlKey",
|
||||
"as3vm_KeyboardEvent_set_keyCode",
|
||||
"as3vm_KeyboardEvent_set_keyLocation",
|
||||
"as3vm_KeyboardEvent_set_shiftKey",
|
||||
"as3vm_KeyboardEvent_toString",
|
||||
"as3vm_KeyboardEvent_updateAfterEvent",
|
||||
"as3vm_Keyboard__construct",
|
||||
"as3vm_Keyboard_get_capsLock",
|
||||
"as3vm_Keyboard_get_numLock",
|
||||
"as3vm_Keyboard_isAccessible",
|
||||
"as3vm_LoaderInfo__construct",
|
||||
"as3vm_LoaderInfo_get_bytes",
|
||||
"as3vm_LoaderInfo_get_bytesLoaded",
|
||||
"as3vm_LoaderInfo_get_bytesTotal",
|
||||
"as3vm_LoaderInfo_get_parameters",
|
||||
"as3vm_LoaderInfo_get_url",
|
||||
"as3vm_MouseEvent__construct",
|
||||
"as3vm_MouseEvent_get_altKey",
|
||||
"as3vm_MouseEvent_get_buttonDown",
|
||||
"as3vm_MouseEvent_get_clickCount",
|
||||
"as3vm_MouseEvent_get_commandKey",
|
||||
"as3vm_MouseEvent_get_controlKey",
|
||||
"as3vm_MouseEvent_get_ctrlKey",
|
||||
"as3vm_MouseEvent_get_delta",
|
||||
"as3vm_MouseEvent_get_localX",
|
||||
"as3vm_MouseEvent_get_localY",
|
||||
"as3vm_MouseEvent_get_relatedObject",
|
||||
"as3vm_MouseEvent_get_shiftKey",
|
||||
"as3vm_MouseEvent_get_stageX",
|
||||
"as3vm_MouseEvent_get_stageY",
|
||||
"as3vm_MouseEvent_set_altKey",
|
||||
"as3vm_MouseEvent_set_buttonDown",
|
||||
"as3vm_MouseEvent_set_commandKey",
|
||||
"as3vm_MouseEvent_set_controlKey",
|
||||
"as3vm_MouseEvent_set_ctrlKey",
|
||||
"as3vm_MouseEvent_set_delta",
|
||||
"as3vm_MouseEvent_set_localX",
|
||||
"as3vm_MouseEvent_set_localY",
|
||||
"as3vm_MouseEvent_set_relatedObject",
|
||||
"as3vm_MouseEvent_set_shiftKey",
|
||||
"as3vm_MouseEvent_updateAfterEvent",
|
||||
"as3vm_TextEvent__construct",
|
||||
"as3vm_TextEvent_clone",
|
||||
"as3vm_TextEvent_get_text",
|
||||
"as3vm_TextEvent_set_text",
|
||||
"as3vm_TextEvent_toString",
|
||||
"as3vm_TimerEvent__construct",
|
||||
"as3vm_TimerEvent_clone",
|
||||
"as3vm_TimerEvent_toString",
|
||||
"as3vm_TimerEvent_updateAfterEvent",
|
||||
"as3vm_Timer__construct",
|
||||
"as3vm_Timer_get_currentCount",
|
||||
"as3vm_Timer_get_delay",
|
||||
"as3vm_Timer_get_repeatCount",
|
||||
"as3vm_Timer_get_running",
|
||||
"as3vm_Timer_reset",
|
||||
"as3vm_Timer_set_delay",
|
||||
"as3vm_Timer_set_repeatCount",
|
||||
"as3vm_Timer_start",
|
||||
"as3vm_Timer_stop",
|
||||
"as3vm_clean_listeners",
|
||||
"as3vm_clear_direct_listeners",
|
||||
"as3vm_clone_GC",
|
||||
"as3vm_do_direct_event_GC",
|
||||
"as3vm_do_displayobject_event_GC",
|
||||
"as3vm_do_event_GC",
|
||||
"as3vm_do_event_timer_GC",
|
||||
"as3vm_do_focus_event_GC",
|
||||
"as3vm_do_keyboard_event_GC",
|
||||
"as3vm_do_mouse_event_GC",
|
||||
"as3vm_end_lazy_event",
|
||||
"as3vm_ev_setbool",
|
||||
"as3vm_make_lazy_event_GC",
|
||||
"as3vm_needs_cleaning",
|
||||
"as3vm_prep_lazy_event",
|
||||
}
|
||||
# swf_as3vm_flash_events owns NO externally named data global.
|
||||
EXPECTED_GLOBALS = set()
|
||||
|
||||
# Genuine non-scaffolding imports present on all four retail objects (invariant).
|
||||
EXPECTED_IMPORTS = {
|
||||
"as3vm_NaNf", # as3vm_interpreter DATA (DONE).
|
||||
"as3vm_ToString_GC", # as3vm_convert (DONE).
|
||||
"as3vm_component_parse_arguments_GC", # as3_component_helpers (DONE).
|
||||
"as3vm_create_interleaved_string_GC", # as3vm_interpreter (DONE).
|
||||
"as3vm_do_func_call_vmc_GC", # as3vm_interpreter dispatch (DONE).
|
||||
"as3vm_do_func_call_vv_GC", # as3vm_interpreter dispatch (DONE).
|
||||
"as3vm_do_method_call_GC", # as3vm_interpreter dispatch (DONE).
|
||||
"as3vm_exception_GC", # as3vm_interpreter (DONE).
|
||||
"as3vm_get_movie_as3value_GC", # as3vm binding glue (DONE).
|
||||
"as3vm_get_public_string_GC", # as3vm_interpreter (DONE).
|
||||
"as3vm_is_ofclass", # as3vm_class (DONE).
|
||||
"as3vm_make_number_GC", # as3vm_interpreter (DONE).
|
||||
"as3vm_make_object_no_constructor_GC", # as3vm_create (DONE).
|
||||
"as3vm_make_string_GC", # as3vm_interpreter (DONE).
|
||||
"as3vm_make_string_wc_GC", # as3vm_interpreter (DONE).
|
||||
"as3vm_make_stringdata_GC", # as3vm_interpreter (DONE).
|
||||
"as3vm_makebool", # as3vm_interpreter DATA table (DONE).
|
||||
"as3vm_nullundef_storage", # as3vm_interpreter DATA (DONE).
|
||||
"as3vm_pool_alloc", # as3vm_gc pool (DONE).
|
||||
"as3vm_pool_free", # as3vm_gc pool (DONE).
|
||||
"as3vm_string_interned", # as3vm_interpreter (DONE).
|
||||
"as3vm_string_interned_nocreate", # as3vm_interpreter (DONE).
|
||||
"as3vm_truefalse_storage", # as3vm_interpreter DATA (DONE).
|
||||
"as3vm_write_barrier_slowpath", # as3vm_interpreter (DONE).
|
||||
"as3vmcomp_set_value", # as3_component_helpers (DONE).
|
||||
"iggy_free_alloc", # iggy arena (DONE).
|
||||
"iggy_get_o2w", # iggy transform stack (DONE).
|
||||
"iggy_inverse_transform", # iggy transform stack (DONE).
|
||||
"iggy_malloc_fileline", # iggy arena (DONE).
|
||||
"iggy_transform", # iggy transform stack (DONE).
|
||||
"iggy_uncaught_exception_warning", # iggy diagnostics (DONE).
|
||||
"rr_isnan_f", # rrmath (DONE).
|
||||
}
|
||||
# Per-platform libc symbols the retail optimizer emitted (Event / MouseEvent
|
||||
# toString buffers, dispatcher struct copies). memset is inlined on orbis.
|
||||
PLATFORM_IMPORTS = {
|
||||
"durango": {"memcpy", "memset"},
|
||||
"orbis": {"memcpy"},
|
||||
"ps3": {"memcpy", "memset"},
|
||||
"vita": {"memcpy", "memset"},
|
||||
}
|
||||
RUNTIME_ALLOWLISTS = {
|
||||
"durango": {"_fltused", "__chkstk", "__report_rangecheckfailure",
|
||||
"__ImageBase", "__GSHandlerCheck",
|
||||
"__security_check_cookie", "__security_cookie"},
|
||||
"orbis": {"_GLOBAL_OFFSET_TABLE_"},
|
||||
"ps3": set(),
|
||||
"vita": {"__aeabi_unwind_cpp_pr0", "__aeabi_unwind_cpp_pr1",
|
||||
"__stack_chk_fail", "__stack_chk_guard"},
|
||||
}
|
||||
# libc the fresh cross-compile may emit or inline differently than retail; not part
|
||||
# of the cross-module ABI contract, so tolerated in the reconstruction import check
|
||||
# (the retail check pins the exact per-platform set instead).
|
||||
LIBM_LIBC = {"memcpy", "memset", "memmove", "ceil", "ceilf", "sqrt", "sqrtf"}
|
||||
|
||||
# Every platform embeds __FILE__ via iggy_malloc_fileline, so the canonical path is
|
||||
# present everywhere; durango additionally carries its build .obj path.
|
||||
CANONICAL_PROVENANCE = r"c:\projects\g\src\flash\swf_as3vm_flash_events.c"
|
||||
DURANGO_OBJ_PROVENANCE = (
|
||||
r"c:\projects\g\build\release\temps\libdu\iggy_durango"
|
||||
r"\swf_as3vm_flash_events.obj")
|
||||
# (source_functions, raw line count) per platform. Exports (118) are invariant;
|
||||
# source_functions differs (recovered file-static dispatch helpers). From
|
||||
# iggy_<platform>.modules.tsv column 3 and `wc -l` on raw.
|
||||
RETAIL_INVENTORY = {
|
||||
"durango": (123, 3728),
|
||||
"orbis": (121, 3467),
|
||||
"ps3": (120, 4018),
|
||||
"vita": (122, 4432),
|
||||
}
|
||||
|
||||
|
||||
def normalized_symbol(name):
|
||||
name = name.removeprefix(".")
|
||||
name = name.removeprefix("__imp_")
|
||||
if name == "_setjmp":
|
||||
return "setjmp"
|
||||
return name
|
||||
|
||||
|
||||
class ReconstructedSwfAs3vmFlashEventsCrossTests(unittest.TestCase):
|
||||
def _obj(self, platform):
|
||||
return ROOT / (
|
||||
f"work/iggy-native-decomp/{platform}-objects"
|
||||
f"/swf_as3vm_flash_events.obj")
|
||||
|
||||
def test_ability_inventory_is_one_hundred_eighteen_exports(self):
|
||||
# Documentary: 118 exports and 32 genuine cross-module imports.
|
||||
self.assertEqual(len(EXPECTED_FUNCTIONS), 118)
|
||||
self.assertEqual(len(EXPECTED_IMPORTS), 32)
|
||||
# The nine public classes each contribute a constructor.
|
||||
for ctor in ("as3vm_Event__construct",
|
||||
"as3vm_EventDispatcher__construct",
|
||||
"as3vm_FocusEvent__construct",
|
||||
"as3vm_KeyboardEvent__construct",
|
||||
"as3vm_MouseEvent__construct",
|
||||
"as3vm_TextEvent__construct",
|
||||
"as3vm_TimerEvent__construct",
|
||||
"as3vm_Timer__construct",
|
||||
"as3vm_Keyboard__construct"):
|
||||
self.assertIn(ctor, EXPECTED_FUNCTIONS)
|
||||
|
||||
def test_native_provenance_counts_source_path_and_inventory(self):
|
||||
# Retail evidence -- runs NOW. Exports present in nm, source_functions /
|
||||
# line counts in the symbols inventory, and provenance string embedded.
|
||||
for platform, (functions, lines) in RETAIL_INVENTORY.items():
|
||||
modules = ROOT / (
|
||||
f"iggy-decompiled/symbols/iggy_{platform}.modules.tsv")
|
||||
row = next(
|
||||
line for line in modules.read_text(encoding="utf-8").splitlines()
|
||||
if line.startswith("swf_as3vm_flash_events\t"))
|
||||
self.assertEqual(int(row.split("\t")[2]), functions, platform)
|
||||
raw = ROOT / f"iggy-decompiled/raw/{platform}/swf_as3vm_flash_events.c"
|
||||
self.assertEqual(
|
||||
len(raw.read_text(encoding="utf-8").splitlines()),
|
||||
lines, platform)
|
||||
obj = self._obj(platform)
|
||||
symbols = subprocess.run(
|
||||
["nm", "-g", str(obj)], capture_output=True, text=True)
|
||||
self.assertEqual(symbols.returncode, 0, (platform, symbols.stderr))
|
||||
normalized = symbols.stdout.replace(" .", " ")
|
||||
for symbol in EXPECTED_FUNCTIONS:
|
||||
self.assertIn(symbol, normalized, (platform, symbol))
|
||||
strings = subprocess.run(
|
||||
["strings", str(obj)], capture_output=True, text=True)
|
||||
self.assertIn(CANONICAL_PROVENANCE, strings.stdout, platform)
|
||||
durango_strings = subprocess.run(
|
||||
["strings", str(self._obj("durango"))],
|
||||
capture_output=True, text=True)
|
||||
self.assertIn(DURANGO_OBJ_PROVENANCE, durango_strings.stdout)
|
||||
|
||||
if SOURCE.exists():
|
||||
cmake = (RECONSTRUCTED / "CMakeLists.txt").read_text(
|
||||
encoding="utf-8")
|
||||
self.assertIn(
|
||||
"iggy_reconstructed_swf_as3vm_flash_events_${platform}", cmake)
|
||||
self.assertIn(
|
||||
"add_library(${target} STATIC swf_as3vm_flash_events.c)", cmake)
|
||||
self.assertIn(
|
||||
"IGGY_RECONSTRUCT_SWF_AS3VM_FLASH_EVENTS_${platform_upper}",
|
||||
cmake)
|
||||
inventory = (RECONSTRUCTED / "modules.tsv").read_text(
|
||||
encoding="utf-8")
|
||||
# Exports (118) invariant; source_functions is per-platform.
|
||||
for platform, (functions, _lines) in RETAIL_INVENTORY.items():
|
||||
self.assertIn(
|
||||
f"swf_as3vm_flash_events\t{functions}\t118\t{platform}"
|
||||
f"\tcomplete",
|
||||
inventory)
|
||||
|
||||
def test_retail_object_owns_no_data_global_and_classifies_comdats(self):
|
||||
# Retail evidence -- runs NOW. No B/C-tagged externally named data
|
||||
# global; the durango ??_C@ symbols are R rodata artifacts, not owned data.
|
||||
if not LLVM_NM.exists():
|
||||
self.skipTest("llvm-nm unavailable")
|
||||
for platform in ("durango", "orbis", "ps3", "vita"):
|
||||
defined = subprocess.run(
|
||||
[str(LLVM_NM), "--extern-only", "--defined-only",
|
||||
str(self._obj(platform))],
|
||||
capture_output=True, text=True)
|
||||
self.assertEqual(defined.returncode, 0, platform)
|
||||
owned_data = set()
|
||||
for line in defined.stdout.splitlines():
|
||||
parts = line.split()
|
||||
if len(parts) < 2:
|
||||
continue
|
||||
tag, name = parts[-2].upper(), normalized_symbol(parts[-1])
|
||||
# A genuinely-owned data global would be B/C AND not just a ps3
|
||||
# .opd descriptor of an exported function.
|
||||
if tag in {"B", "C"} and name not in EXPECTED_FUNCTIONS:
|
||||
owned_data.add(name)
|
||||
# ??_C@ format literals must never surface as extern data.
|
||||
if name.startswith("??_C@"):
|
||||
self.assertEqual(tag, "R", (platform, name))
|
||||
self.assertEqual(owned_data, EXPECTED_GLOBALS, platform)
|
||||
|
||||
def test_retail_object_import_contract(self):
|
||||
# Retail evidence -- runs NOW. The genuine 32-symbol import set is present
|
||||
# and, after subtracting the toolchain allowlist, only the per-platform
|
||||
# libc symbols remain.
|
||||
if not LLVM_NM.exists():
|
||||
self.skipTest("llvm-nm unavailable")
|
||||
for platform in ("durango", "orbis", "ps3", "vita"):
|
||||
undefined = subprocess.run(
|
||||
[str(LLVM_NM), "--undefined-only", str(self._obj(platform))],
|
||||
capture_output=True, text=True)
|
||||
self.assertEqual(undefined.returncode, 0, platform)
|
||||
imports = {normalized_symbol(line.split()[-1])
|
||||
for line in undefined.stdout.splitlines()
|
||||
if line.split()}
|
||||
self.assertTrue(
|
||||
EXPECTED_IMPORTS <= imports,
|
||||
(platform, EXPECTED_IMPORTS - imports))
|
||||
self.assertEqual(
|
||||
imports - EXPECTED_IMPORTS - RUNTIME_ALLOWLISTS[platform],
|
||||
PLATFORM_IMPORTS[platform], (platform, sorted(imports)))
|
||||
|
||||
def test_exact_exports_globals_normalized_imports_and_c_cpp_abi(self):
|
||||
# RED until the reconstruction exists; then the fresh cross-compile must
|
||||
# reproduce the exact export set, no owned global, and the invariant
|
||||
# cross-module import set on all four targets.
|
||||
self.assertTrue(SOURCE.exists(), f"missing {SOURCE}")
|
||||
self.assertTrue(HEADER.exists(), f"missing {HEADER}")
|
||||
self.assertIn(r"c:\\projects\\g\\src\\flash\\swf_as3vm_flash_events.c",
|
||||
SOURCE.read_text(encoding="utf-8"))
|
||||
|
||||
function_pointers = "".join(
|
||||
f" (GenericFn)&{name},\n" for name in sorted(EXPECTED_FUNCTIONS))
|
||||
probe_text = (
|
||||
'#include <stdint.h>\n#include "swf_as3vm_flash_events.h"\n'
|
||||
'typedef void (*GenericFn)(void);\n'
|
||||
'static GenericFn flash_events_abis[] = {\n'
|
||||
+ function_pointers + '};\n'
|
||||
'int use_abis(void) {\n'
|
||||
' for (unsigned i = 0; '
|
||||
'i < sizeof(flash_events_abis) / sizeof(flash_events_abis[0]); '
|
||||
'++i) {\n'
|
||||
' if (!flash_events_abis[i]) return 0;\n'
|
||||
' }\n'
|
||||
' return 1;\n'
|
||||
'}\n')
|
||||
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
temporary = Path(directory)
|
||||
for platform, (compiler, target) in VARIANTS.items():
|
||||
extra = ["-mthumb"] if platform == "vita" else []
|
||||
output = temporary / f"swf_as3vm_flash_events_{platform}.o"
|
||||
build = subprocess.run([
|
||||
compiler, "-target", target, "-ffreestanding",
|
||||
"-fno-builtin",
|
||||
"-c", "-std=c11", "-O2", "-Wall", "-Wextra", "-Werror",
|
||||
*extra,
|
||||
f"-DIGGY_RECONSTRUCT_SWF_AS3VM_FLASH_EVENTS_"
|
||||
f"{platform.upper()}=1",
|
||||
"-I", str(RECONSTRUCTED), str(SOURCE), "-o", str(output),
|
||||
], capture_output=True, text=True)
|
||||
self.assertEqual(build.returncode, 0, (platform, build.stderr))
|
||||
if LLVM_NM.exists():
|
||||
defined = subprocess.run([
|
||||
str(LLVM_NM), "--extern-only", "--defined-only",
|
||||
str(output),
|
||||
], capture_output=True, text=True)
|
||||
undefined = subprocess.run([
|
||||
str(LLVM_NM), "--undefined-only", str(output),
|
||||
], capture_output=True, text=True)
|
||||
names = {normalized_symbol(parts[-1])
|
||||
for line in defined.stdout.splitlines()
|
||||
if len(parts := line.split()) >= 2 and
|
||||
parts[-2].upper() in {"T", "D", "B", "C"}}
|
||||
imports = {normalized_symbol(line.split()[-1])
|
||||
for line in undefined.stdout.splitlines()
|
||||
if line.split()}
|
||||
self.assertEqual(
|
||||
names, EXPECTED_FUNCTIONS | EXPECTED_GLOBALS, platform)
|
||||
# The cross-module import contract is exactly EXPECTED_IMPORTS
|
||||
# once toolchain scaffolding and optimizer-chosen libc are
|
||||
# removed.
|
||||
residual = (imports - RUNTIME_ALLOWLISTS[platform]
|
||||
- LIBM_LIBC)
|
||||
self.assertEqual(residual, EXPECTED_IMPORTS,
|
||||
(platform, sorted(imports)))
|
||||
|
||||
for language, standard in (("c", "c11"), ("c++", "c++17")):
|
||||
suffix = "c" if language == "c" else "cpp"
|
||||
probe = (temporary /
|
||||
f"swf_as3vm_flash_events_abi_{platform}.{suffix}")
|
||||
probe.write_text(probe_text, encoding="utf-8")
|
||||
syntax = subprocess.run([
|
||||
compiler, "-target", target, "-ffreestanding",
|
||||
"-fsyntax-only", f"-std={standard}",
|
||||
"-Wall", "-Wextra", "-Werror", *extra,
|
||||
f"-DIGGY_RECONSTRUCT_SWF_AS3VM_FLASH_EVENTS_"
|
||||
f"{platform.upper()}=1",
|
||||
"-I", str(RECONSTRUCTED), str(probe),
|
||||
], capture_output=True, text=True)
|
||||
self.assertEqual(syntax.returncode, 0,
|
||||
(platform, language, syntax.stderr))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user