-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
63 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,57 @@ | ||
use std::fs; | ||
use std::path::PathBuf; | ||
use std::time::Instant; | ||
|
||
use clap::Parser; | ||
use winreg::{enums::HKEY_CLASSES_ROOT, RegKey}; | ||
|
||
const SIGNATURE: &[u8] = &[ | ||
0x41, 0x80, 0xbe, 0x50, 0x01, 0x00, 0x00, 0x00, 0x74, 0x05, 0xe8, | ||
]; | ||
|
||
const PATCH: &[u8] = &[ | ||
0x41, 0x80, 0xbe, 0x50, 0x01, 0x00, 0x00, 0x00, 0x90, 0x90, 0xe8, | ||
]; | ||
|
||
#[derive(Parser)] | ||
#[command(author, version, about, long_about = None)] | ||
struct Cli { | ||
input: Option<PathBuf>, | ||
output: Option<PathBuf>, | ||
} | ||
|
||
fn patch(input: &PathBuf, output: &PathBuf) { | ||
let mut binary = fs::read(input).expect("Could not read input file."); | ||
|
||
let offset = binary | ||
.windows(SIGNATURE.len()) | ||
.position(|window| window == SIGNATURE) | ||
.expect("Could not find signature."); | ||
|
||
binary[offset..offset + PATCH.len()].copy_from_slice(PATCH); | ||
fs::write(output, binary).expect("Could not write output file."); | ||
} | ||
|
||
fn main() { | ||
println!("Hello, world!"); | ||
let Cli { input, output } = Cli::parse(); | ||
|
||
#[rustfmt::skip] | ||
let input = input.unwrap_or_else(|| { | ||
let path: String = RegKey::predef(HKEY_CLASSES_ROOT) | ||
.open_subkey("roblox-studio").unwrap() | ||
.open_subkey("DefaultIcon").unwrap() | ||
.get_value("").unwrap(); | ||
|
||
PathBuf::from(path) | ||
}); | ||
|
||
let output = if cfg!(debug_assertions) { | ||
output.unwrap_or_else(|| input.with_file_name("RobloxStudioBeta_INTERNAL.exe")) | ||
} else { | ||
output.unwrap_or_else(|| input.clone()) // TODO: Is convenience really worth it? | ||
}; | ||
|
||
let now = Instant::now(); | ||
patch(&input, &output); | ||
println!("Patched in {:?}.", now.elapsed()); | ||
} |