Skip to content
This repository was archived by the owner on May 23, 2026. It is now read-only.
david-wm-sandersPublic archive

About

Async RwR code patching tool using Frida and Trio

Resources

Stars

3 stars

Watchers

2 watching

Forks

Latest commit

 

History

3 Commits

Folders and files

Repository files navigation

FRIDRWR

A Trio-based async wrapper around Frida that can inject memory patches (currently just "reduce fog density") into RWR and exposes a Quart web interface.

What?

FRIDRWR is a live memory-patcher for Running With Rifles (rwr_game.exe), a 32-bit PC game. It uses Frida to attach to the running game process, inject JavaScript agents, and rewrite specific machine-code bytes to change the game's behavior. A Quart-Trio webserver runs alongside it on 127.0.0.1:5000 so the user can (eventually) see status / control patches from a browser.

How?

Entrypoint - fridrwr.py

  • Runs under trio.run (no asyncio anywhere).
  • Opens one top-level nursery with two long-lived tasks (fridrwr.py:100-102):
    1. fridrwr_setup - polls every 15 s for rwr_game.exe; when it finds it, attaches Frida and applies patches.
    2. hypercorn.trio.serve(app, …) - the Quart-Trio webserver.
  • On Ctrl-C, trio.Cancelled propagates down and patches get unapplied so the game doesn't segfault on now-dangling code-cave addresses it was jumping into (fridrwr.py:86-95).

The one concrete patch: "anti-fog" (fridrwr.py:27-62)

  • Searches the game for a specific x87 FPU byte pattern (D9 44 24 08 D9 59 4C D9 44 24 04 D9 59 50) - four floating-point loads/stores that configure the game's fog range/offset.
  • Rewrites them to load 600.0 (range) and -100.0 (offset) from Frida-allocated memory instead of whatever the game would normally compute. Effect: reduce the fog density globally.

fridare/ - the library

  • fridare/__init__.py - constructs the singleton FridAsync instance (fa) and the Quart-Trio app (app); wires Pint / db / routes / filters.
  • fridare/routes.py - two read-only web views: / (index) and /fridrwr (shows the RWR session status).
  • fridare/fridasync/ - the heart of it. A thin async wrapper around Frida's sync Python API:
    • fridasync.py - FridAsync keeps a dict[target_name → FAsyncSession] and does frida.attach off-thread via trio.to_thread.run_sync.
    • session.py - wraps frida.core.Session; on init, loads _fridasync.js (utility RPCs: arch, pid, heap size, module lookup, Memory.scanSync, etc.) and caches target process info.
    • script.py / patcher.py - FAsyncScript wraps frida.core.Script; FAsyncPatcherScript adds apply()/clear() that call into the injected JS's rpc.exports.
    • patcher.py:61-105 - PatchBuilder renders two Jinja JS templates (jmp_patch.js, nop_patch.js) into per-patch script sources with the user's target pattern, vars, and custom code-writer function stitched in.

The Frida-JS side - fridajs_templates/

  • patch.js - base Patch class: scans the target module's memory for target_pattern, enforces it matches exactly once, snapshots original bytes, allocates memory for patch-local variables.
  • jmp_patch.js - JmpPatch subclass: allocates RWX scratch memory, runs the caller-supplied cw_patch_func to fill it with replacement code via Frida's X86Writer, appends a jmp back to the target, then overwrites the match site with a 5-byte jmp + NOP sled so the game's original flow detours through your code. clear() restores the original bytes.
  • nop_patch.js - NopPatch: simpler variant that just NOPs nop_length bytes at nop_offset into the match; clear() restores.

About

Async RwR code patching tool using Frida and Trio

Resources

Stars

3 stars

Watchers

2 watching

Forks

Releases

Packages

Contributors

Languages