SNES - Playable-Quotes/QuoteKit GitHub Wiki

How do we launch Retroarch and attach Frida to it?

Find the current frida version with this command:

$ frida --version 16.2.1

Next, download corresponding gadget from the compiled releases on the frida github project: https://github.com/frida/frida/releases/

We want the file that looks like this “frida-gadget-{version}-macos-universal.dylib.xz”. Download and unzip this file to recover the .dylib file.

Now, launch RetroArch with the frida gadget injected:

$ DYLD_INSERT_LIBRARIES=frida-gadget-16.2.1-macos-universal.dylib /Applications/RetroArch.app/Contents/MacOS/RetroArch -L snes9x_libretro /Users/adam/Downloads/Super\ Mario\ World\ (USA).sfc

[Frida INFO] Listening on 127.0.0.1 TCP port 27042

The RetroArch window will not display as frida has halted the app’s start up to give you a chance to attach frida first.

In another terminal window, launch frida with the “-R” flag to have it connect to a remote process (using localhost:27024 as the default remote configuration).

$ frida -R Gadget


. . . . Connected to Local Socket (id=socket)

The moment frida connects, RetroArch should finish launching!

How do we hook into the emulator's main loop?

Intercept calls to retro_run

const  funcAddr  =  DebugSymbol.fromName("retro_run").address;
Interceptor.attach(funcAddr, function () {
  ...
});

How fast (Hz) does the main loop typically run?

60.6 Hz (on Tony's Macbook Air M2 2022)

What does it cost to create a savestate?

TODO: Measure the actual time spend saving the state (now that we know it is small enough not to disrupt the main loop much).

How do we replay user-input events over time?

TODO We should respect sub-tick time granularity if needed on that platform.

How do we get a pointer to the emulated system's main memory buffer and determine the size of the buffer?

We can call retro_get_memory_data"to get a pointer to the base and retro_get_memory_size to find the length.

For memory-like mass storage, how do we find out which blocks have been accessed since the last tick?

Can we just use Frida's MemoryAccessMonitor?

  • Seems like MemoryAccessMonitor isn't fully implemented. There are mixed results with using it on windows, but with mixed results, so avoid it instead.

For the various mass storage systems, how much state changes between ticks on average?