mirror of
https://github.com/Grasscutters/Cultivation.git
synced 2025-12-13 15:44:35 +01:00
Re-encrypt Metadata
We in the end game now bois (Time for UI, refactoring, and better functionality)
This commit is contained in:
@@ -19,7 +19,7 @@ mod downloader;
|
|||||||
mod lang;
|
mod lang;
|
||||||
mod proxy;
|
mod proxy;
|
||||||
mod web;
|
mod web;
|
||||||
mod metadata;
|
mod metadata_patcher;
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
static ref WATCH_GAME_PROCESS: Mutex<String> = {
|
static ref WATCH_GAME_PROCESS: Mutex<String> = {
|
||||||
@@ -64,7 +64,7 @@ fn main() {
|
|||||||
lang::get_lang,
|
lang::get_lang,
|
||||||
lang::get_languages,
|
lang::get_languages,
|
||||||
web::valid_url,
|
web::valid_url,
|
||||||
metadata::patch_metadata
|
metadata_patcher::patch_metadata
|
||||||
])
|
])
|
||||||
.run(tauri::generate_context!())
|
.run(tauri::generate_context!())
|
||||||
.expect("error while running tauri application");
|
.expect("error while running tauri application");
|
||||||
|
|||||||
@@ -6,10 +6,7 @@ use std::fs::File;
|
|||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
|
|
||||||
fn dll_decrypt_global_metadata(
|
fn dll_decrypt_global_metadata(data: *mut u8, size: u64) -> Result<*const c_void, Box<dyn std::error::Error>> {
|
||||||
data: *mut u8,
|
|
||||||
size: u64,
|
|
||||||
) -> Result<*const c_void, Box<dyn std::error::Error>> {
|
|
||||||
unsafe {
|
unsafe {
|
||||||
// Load DLL
|
// Load DLL
|
||||||
let lib = Library::new("mhycrypto.dll")?;
|
let lib = Library::new("mhycrypto.dll")?;
|
||||||
@@ -24,10 +21,7 @@ fn dll_decrypt_global_metadata(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dll_encrypt_global_metadata(
|
fn dll_encrypt_global_metadata(data: *mut u8, size: u64) -> Result<*const c_void, Box<dyn std::error::Error>> {
|
||||||
data: *mut u8,
|
|
||||||
size: u64,
|
|
||||||
) -> Result<*const c_void, Box<dyn std::error::Error>> {
|
|
||||||
unsafe {
|
unsafe {
|
||||||
// Load DLL
|
// Load DLL
|
||||||
let lib = Library::new("mhycrypto.dll")?;
|
let lib = Library::new("mhycrypto.dll")?;
|
||||||
@@ -46,13 +40,13 @@ fn dll_encrypt_global_metadata(
|
|||||||
pub fn patch_metadata(metadata_folder: &str) {
|
pub fn patch_metadata(metadata_folder: &str) {
|
||||||
let metadata_file = &(metadata_folder.to_owned() + "\\global-metadata.dat");
|
let metadata_file = &(metadata_folder.to_owned() + "\\global-metadata.dat");
|
||||||
println!("Patching metadata file: {}", metadata_file);
|
println!("Patching metadata file: {}", metadata_file);
|
||||||
let decrypted: Vec<u8> = decrypt_metadata(metadata_file);
|
let decrypted = decrypt_metadata(metadata_file);
|
||||||
|
|
||||||
let modified = replace_keys(&decrypted);
|
let modified = replace_keys(&decrypted);
|
||||||
|
let encrypted = encrypt_metadata(&modified);
|
||||||
|
|
||||||
//write modfied to file
|
//write encrypted to file
|
||||||
let mut file = File::create(&(metadata_folder.to_owned() + "\\modified-metadata.dat")).unwrap();
|
let mut file = File::create(&(metadata_folder.to_owned() + "\\encrypted-metadata.dat")).unwrap();
|
||||||
file.write_all(&modified).unwrap();
|
file.write_all(&encrypted).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn decrypt_metadata(file_path: &str) -> Vec<u8> {
|
fn decrypt_metadata(file_path: &str) -> Vec<u8> {
|
||||||
@@ -131,19 +125,16 @@ fn replace_rsa_key(old_data: &str, to_replace: &str, file_name: &str) -> String
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*let mut file = match OpenOptions::new().write(true).create(true).open(&(file_location.to_owned() + "\\decrypted_metadata.dat")) {
|
fn encrypt_metadata(old_data: &Vec<u8>) -> Vec<u8> {
|
||||||
Ok(file) => file,
|
let mut data = old_data.to_vec();
|
||||||
Err(e) => {
|
match dll_encrypt_global_metadata(data.as_mut_ptr(), data.len().try_into().unwrap()) {
|
||||||
println!("Failed to open file: {}", e);
|
Ok(_) => {
|
||||||
return;
|
println!("Successfully encrypted global-metadata");
|
||||||
}
|
return data;
|
||||||
};
|
}
|
||||||
match file.write_all(&data) {
|
Err(e) => {
|
||||||
Ok(_) => {
|
println!("Failed to encrypt global-metadata: {}", e);
|
||||||
println!("Successfully decrypted metadata");
|
return Vec::new();
|
||||||
}
|
}
|
||||||
Err(e) => {
|
};
|
||||||
println!("Failed to write to file: {}", e);
|
}
|
||||||
return;
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
Reference in New Issue
Block a user