-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement main logic and patches
- Loading branch information
1 parent
2bc8685
commit 6613e0a
Showing
2 changed files
with
117 additions
and
2 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,45 @@ | ||
fn main() { | ||
println!("Hello, world!"); | ||
use std::error::Error; | ||
use std::fs; | ||
use std::path::Path; | ||
|
||
use clap::Parser; | ||
|
||
use patches::apply_patches; | ||
|
||
mod patches; | ||
|
||
#[derive(Parser, Debug)] | ||
#[command(version, about)] | ||
struct Args { | ||
#[arg(short, long, default_value = r"C:\Program Files\AMD\RyzenMaster\bin\AMD Ryzen Master.exe")] | ||
path: String, | ||
#[arg(short, long, default_value = r"C:\Program Files\AMD\RyzenMaster\bin\Patched AMD Ryzen Master.exe")] | ||
output: String, | ||
} | ||
|
||
fn main() -> Result<(), Box<dyn Error>> { | ||
let args = Args::parse(); | ||
let exe_path = Path::new(&args.path); | ||
|
||
if !exe_path.exists() { | ||
eprintln!("File not found: {:?}", exe_path); | ||
return Ok(()); | ||
} | ||
|
||
println!("Patching: {:?}", exe_path); | ||
|
||
let mut exe_data = fs::read(exe_path)?; | ||
|
||
let some_patches_applied = | ||
apply_patches(&mut exe_data); | ||
|
||
if !some_patches_applied { | ||
println!("Nothing to patch"); | ||
return Ok(()); | ||
} | ||
|
||
println!("Writing patched file: {:?}", args.output); | ||
fs::write(&args.output, &exe_data)?; | ||
|
||
Ok(()) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,73 @@ | ||
use std::error::Error; | ||
|
||
pub struct Patch<'a> { | ||
pub desc: &'static str, | ||
search: &'a [u8], | ||
replace: &'a [u8], | ||
} | ||
|
||
impl<'a> Patch<'a> { | ||
pub fn apply(&self, data: &mut [u8]) -> Result<(), Box<dyn Error>> { | ||
let mut positions = data | ||
.windows(self.search.len()) | ||
.enumerate() | ||
.filter_map(|(i, window)| if window == self.search { Some(i) } else { None }); | ||
|
||
match (positions.next(), positions.next()) { | ||
(Some(_), Some(_)) => Err("Duplicate found".into()), | ||
(Some(y), None) => { | ||
data[y..y + self.replace.len()].copy_from_slice(self.replace); | ||
Ok(()) | ||
} | ||
_ => Err("Not found".into()) | ||
} | ||
} | ||
} | ||
|
||
pub static PATTERNS: &[Patch] = &[ | ||
Patch { | ||
desc: "Ryzen Master (v.1.5 -> v2.2)", | ||
search: &[0x44, 0x39, 0x6D, 0xA8, 0x0F, 0x84, 0xF7], | ||
replace: &[0x44, 0x39, 0x6D, 0xA8, 0x90, 0xe9, 0xf7], | ||
}, | ||
Patch { | ||
desc: "Ryzen Master (v2.3 -> 2.6.0)", | ||
search: &[0x44, 0x39, 0xad, 0xf8, 0, 0, 0, 0x0f, 0x84], | ||
replace: &[0x44, 0x39, 0xad, 0xf8, 0, 0, 0, 0x90, 0xe9], | ||
}, | ||
Patch { | ||
desc: "Ryzen Master (v2.6.2 -> ?)", | ||
search: &[0x8D, 0x48, 0xFA, 0x83, 0xF9, 0x01, 0x0F, 0x87], | ||
// mov edi, eax | ||
// lea ecx, [rax-6] | ||
// cmp ecx, 1 | ||
// ja loc_14001BF3A | ||
replace: &[0x8D, 0x48, 0xFA, 0x83, 0xF9, 0x01, 0x90, 0xe9], | ||
// mov edi, eax | ||
// lea ecx, [rax-6] | ||
// cmp ecx, 1 | ||
// nop | ||
// jmp loc_14001BF3A | ||
}, | ||
Patch { | ||
desc: "Ryzen Master (? -> v2.13.0 -> ?)", | ||
search: &[0xc3, 0xcc, 0x40, 0x55, 0x53, 0x56, 0x57, 0x41], | ||
replace: &[0xc3, 0xcc, 0xb8, 0x00, 0x00, 0x00, 0x00, 0xc3], | ||
// mov EAX, 0x0 | ||
// ret | ||
}, | ||
]; | ||
|
||
pub fn apply_patches(data: &mut [u8]) -> bool { | ||
let mut found = false; | ||
for patch in PATTERNS { | ||
let r = patch.apply(data); | ||
if r.is_ok() { | ||
println!("[+] Patched: {}", patch.desc); | ||
found = true; | ||
} else if let Err(e) = r { | ||
eprintln!("[-] {}: {}", e, patch.desc); | ||
} | ||
} | ||
found | ||
} |