mirror of
https://github.com/Grasscutters/Cultivation.git
synced 2025-12-14 08:04:52 +01:00
Key replacement
This commit is contained in:
1
src-tauri/keys/dispatchKey.txt
Normal file
1
src-tauri/keys/dispatchKey.txt
Normal file
@@ -0,0 +1 @@
|
||||
<RSAKeyValue><Modulus>AMW28dptX3h8q0O4z/vJrQxf6cmC6yVilgHRL98GazrYzmc3ixj87JpHIJ3IKEYV+HU/tYrUjEfY/ZtPzsLB9lKBelN9i8QjkFkA9QDICGYwJCXibxU67Z/HzENe9NQpG2i01SI0TJU8PJDV7zQPwPVGraIg5ouExRupq8UymaSHEyJ7zxKZCtgO0LKdROLJBSvI5srMu7kYTGmB7T07Ab8T9M595YSgd1vh06qZ3nsF1h4wg3y+zW28vdY28+RCj2V1i7oVyL0dQruLYq7qK8FycZl2j9R0GaJ8rRAjVP1Dsz+hjS3atHhQxOG9OFo6d/euedRvfWIhT9p6h1SeTjE=</Modulus><Exponent>AQAB</Exponent></RSAKeyValue>
|
||||
7
src-tauri/keys/passwordKey.txt
Normal file
7
src-tauri/keys/passwordKey.txt
Normal file
@@ -0,0 +1,7 @@
|
||||
<RSAKeyValue>
|
||||
<Exponent>AQAB</Exponent>
|
||||
<Modulus>yytg/H9lz7Lm0XcA8LMqIyXPVNApYTcSepT4VDLB4qqqFC3s
|
||||
/Huv8vN7zA/P4uoREIu8KMenADFk7uwrZSxoMWwJgn6A7sbAt1cqAaUXB
|
||||
9J4NzhL0x3AFTiHEQbw86hRvm2VGkbA5sWnr0NZw8SGBBY+EODwNIt51G
|
||||
dBA7eoUQU=</Modulus>
|
||||
</RSAKeyValue>
|
||||
@@ -1,18 +1,21 @@
|
||||
use core::ffi::c_void;
|
||||
use std::fs::File;
|
||||
use std::io::Read;
|
||||
use std::io::Write;
|
||||
use libloading::os::windows::Library;
|
||||
use libloading::os::windows::Symbol;
|
||||
use regex::Regex;
|
||||
use std::fs::File;
|
||||
use std::io::Read;
|
||||
use std::io::Write;
|
||||
|
||||
fn dll_decrypt_global_metadata(data : *mut u8, size : u64) -> Result<*const c_void, Box<dyn std::error::Error>> {
|
||||
fn dll_decrypt_global_metadata(
|
||||
data: *mut u8,
|
||||
size: u64,
|
||||
) -> Result<*const c_void, Box<dyn std::error::Error>> {
|
||||
unsafe {
|
||||
// Load DLL
|
||||
let lib = Library::new("mhycrypto.dll")?;
|
||||
|
||||
// Load function and call it
|
||||
let func : Symbol<unsafe extern fn(*mut u8, u64) -> *const c_void> = lib.get_ordinal(0x1)?;
|
||||
let func: Symbol<unsafe extern "C" fn(*mut u8, u64) -> *const c_void> = lib.get_ordinal(0x1)?;
|
||||
let decrypted_data = func(data, size);
|
||||
|
||||
// Close DLL and return result
|
||||
@@ -21,13 +24,16 @@ fn dll_decrypt_global_metadata(data : *mut u8, size : u64) -> Result<*const c_vo
|
||||
}
|
||||
}
|
||||
|
||||
fn dll_encrypt_global_metadata(data : *mut u8, size : u64) -> Result<*const c_void, Box<dyn std::error::Error>> {
|
||||
fn dll_encrypt_global_metadata(
|
||||
data: *mut u8,
|
||||
size: u64,
|
||||
) -> Result<*const c_void, Box<dyn std::error::Error>> {
|
||||
unsafe {
|
||||
// Load DLL
|
||||
let lib = Library::new("mhycrypto.dll")?;
|
||||
|
||||
// Load function and call it
|
||||
let func : Symbol<unsafe extern fn(*mut u8, u64) -> *const c_void> = lib.get_ordinal(0x2)?;
|
||||
let func: Symbol<unsafe extern "C" fn(*mut u8, u64) -> *const c_void> = lib.get_ordinal(0x2)?;
|
||||
let encrypted_data = func(data, size);
|
||||
|
||||
// Close DLL and return result
|
||||
@@ -40,22 +46,16 @@ fn dll_encrypt_global_metadata(data : *mut u8, size : u64) -> Result<*const c_vo
|
||||
pub fn patch_metadata(metadata_folder: &str) {
|
||||
let metadata_file = &(metadata_folder.to_owned() + "\\global-metadata.dat");
|
||||
println!("Patching metadata file: {}", metadata_file);
|
||||
let decrypted : Vec<u8> = decrypt_metadata(metadata_file);
|
||||
let decrypted: Vec<u8> = decrypt_metadata(metadata_file);
|
||||
|
||||
//write decrypted to file
|
||||
let mut file = File::create(&(metadata_folder.to_owned() + "\\decrypted-metadata.dat")).unwrap();
|
||||
file.write_all(&decrypted).unwrap();
|
||||
let modified = replace_keys(&decrypted);
|
||||
|
||||
replace_rsa_key(&decrypted);
|
||||
|
||||
/*if decrypted != Vec::new() {
|
||||
|
||||
} else {
|
||||
// error
|
||||
}*/
|
||||
//write modfied to file
|
||||
let mut file = File::create(&(metadata_folder.to_owned() + "\\modified-metadata.dat")).unwrap();
|
||||
file.write_all(&modified).unwrap();
|
||||
}
|
||||
|
||||
fn decrypt_metadata(file_path: &str) -> Vec<u8>{
|
||||
fn decrypt_metadata(file_path: &str) -> Vec<u8> {
|
||||
let mut file = match File::open(file_path) {
|
||||
Ok(file) => file,
|
||||
Err(e) => {
|
||||
@@ -84,7 +84,9 @@ fn decrypt_metadata(file_path: &str) -> Vec<u8>{
|
||||
}
|
||||
}
|
||||
|
||||
fn replace_rsa_key(data: &Vec<u8>) {
|
||||
fn replace_keys(data: &Vec<u8>) -> Vec<u8> {
|
||||
let mut new_data = String::new();
|
||||
|
||||
unsafe {
|
||||
let data_str = String::from_utf8_unchecked(data.to_vec());
|
||||
|
||||
@@ -94,36 +96,54 @@ fn replace_rsa_key(data: &Vec<u8>) {
|
||||
// dispatch key is index 3
|
||||
// password key is index 2
|
||||
|
||||
//println!("Found {} RSA Key(s)", matches.count());
|
||||
for (i, rmatch) in matches.enumerate() {
|
||||
let key = rmatch.as_str();
|
||||
|
||||
println!("{} - RSA Key {}", i, key);
|
||||
println!("\n");
|
||||
if i == 2 {
|
||||
println!("Replacing password key");
|
||||
new_data = replace_rsa_key(&data_str, &key, "passwordKey.txt");
|
||||
} else if i == 3 {
|
||||
println!("Replacing dispatch key");
|
||||
new_data = replace_rsa_key(&new_data, &key, "dispatchKey.txt");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return new_data.as_bytes().to_vec();
|
||||
}
|
||||
|
||||
/*if matches.count() < 1 {
|
||||
println!("No RSA keys found");
|
||||
return Vec::new();
|
||||
}*/
|
||||
fn replace_rsa_key(old_data: &str, to_replace: &str, file_name: &str) -> String {
|
||||
// Read dispatch key file
|
||||
unsafe {
|
||||
let mut new_key_file = match File::open(&("keys/".to_owned() + file_name)) {
|
||||
Ok(file) => file,
|
||||
Err(e) => {
|
||||
println!("Failed to open keys/{}: {}", file_name, e);
|
||||
return String::new();
|
||||
}
|
||||
};
|
||||
let mut key_data = Vec::new();
|
||||
new_key_file.read_to_end(&mut key_data).unwrap();
|
||||
let new_key = String::from_utf8_unchecked(key_data.to_vec());
|
||||
|
||||
// Replace old key with new key
|
||||
return old_data.replace(to_replace, &new_key);
|
||||
}
|
||||
}
|
||||
|
||||
/*let mut file = match OpenOptions::new().write(true).create(true).open(&(file_location.to_owned() + "\\decrypted_metadata.dat")) {
|
||||
Ok(file) => file,
|
||||
Err(e) => {
|
||||
println!("Failed to open file: {}", e);
|
||||
return;
|
||||
}
|
||||
};
|
||||
match file.write_all(&data) {
|
||||
Ok(_) => {
|
||||
println!("Successfully decrypted metadata");
|
||||
}
|
||||
Err(e) => {
|
||||
println!("Failed to write to file: {}", e);
|
||||
return;
|
||||
}
|
||||
}*/
|
||||
Ok(file) => file,
|
||||
Err(e) => {
|
||||
println!("Failed to open file: {}", e);
|
||||
return;
|
||||
}
|
||||
};
|
||||
match file.write_all(&data) {
|
||||
Ok(_) => {
|
||||
println!("Successfully decrypted metadata");
|
||||
}
|
||||
Err(e) => {
|
||||
println!("Failed to write to file: {}", e);
|
||||
return;
|
||||
}
|
||||
}*/
|
||||
|
||||
@@ -56,6 +56,7 @@
|
||||
},
|
||||
"resources": [
|
||||
"lang/*.json",
|
||||
"keys/*",
|
||||
"./mhycrypto.dll"
|
||||
],
|
||||
"targets": "all",
|
||||
|
||||
Reference in New Issue
Block a user