4 releases

new 0.2.0-beta.7 Jan 29, 2025
0.2.0-beta.4 Jan 27, 2025

#1390 in Web programming

Download history 164/week @ 2025-01-22

164 downloads per month

LGPL-3.0

37KB
671 lines

A library for modding Electron apps in-memory, without modifying any program files.

This library was made for improving the modding experience for Discord, but it can be used for any Electron app.

Features

  • asar: Enables the ASAR archive builder. (enabled by default)
  • uuid: Enables the use of random UUIDs for ASAR archive names. (enabled by default)

Examples

electron-hook maps the original app.asar to _app.asar, so keep this in mind if you need to call the original file anywhere, as shown in this example.

use electron_hook::asar::Asar;

let mod_dir = mod_artifact_dir("moonlight");

let _download_url = "https://github.com/moonlight-mod/moonlight/releases/latest/download/dist.tar.gz";
// extract and save `_download_url` into `mod_dir`

let mod_entrypoint = mod_dir.join("injector.js");

let template = r#"
    console.log("Mod injected!!!");
    let asar = require("path").resolve(__dirname, "../_app.asar");
    require("$ENTRYPOINT").inject(asar);
"#;

// Create the asar file
let asar = Asar::new()
    .with_id("moonlight")
    .with_template(template)
    .with_mod_entrypoint(mod_dir)
    .create()
    .unwrap();

electron_hook::launch(
    "/path/to/executable/Discord",
    asar.path().to_str().unwrap(),
    vec!["--pass-arguments-here"],
    None, // Optional profile directory
    true, // Detach the process
);

Dependencies

~10–21MB
~303K SLoC