Есть такой код // Dependencies use terminalmenu::{run, menu, label, scroll, string,…
- User
Есть такой код // Dependencies use terminal_menu::{run, menu, label, scroll, string, submenu, back_button, button, mut_menu, list}; use zip_extensions::zip_create_from_directory; use std::{path::PathBuf, fs::{self, File}, io::{Cursor, Write}}; use platform_dirs::AppDirs; use crx_dl::{ChromeCRXQuery, crx_to_zip};
// Constants const PROXIES_URL: &str = "https://raw.githubusercontent.com/Stefanuk12/RoProPatcher/master/proxies.txt";
/// Fetches each proxy. fn get_proxies() -> Vec { reqwest::blocking::Client::new() .get(PROXIES_URL) .send() .expect("unable to grab proxies") .text() .expect("invalid proxies") .lines() .map(|x| x.to_string()) .collect() }
/// Performs the entire patching process. fn patch(path: PathBuf, proxy: String) { // The regex replace thing. We don't want to proxy everything, only the stuff that needs verification let re = regex::Regex::new(r#"(https://api\.)ropro\.io/(validateUser\.php|getServerInfo\.php|getServerConnectionScore\.php|getServerAge\.php|getSubscription\.php)"#).unwrap(); let rep = format!("https://{}/${{2}}///api", proxy);
// Patching the background file let background = path.join("background.js"); let background_contents = fs::read_to_string(&background).expect("Unable to open file (background.js)"); let new_background_contents = re.replace_all(&background_contents, &rep).to_string(); fs::write(&background, new_background_contents.clone()).expect("Unable to write file contents (background.js)"); // Checking if they changed if background_contents == new_background_contents { println!("warning: nothing changed while patching `background.js` (and possibly others within js/page) - already patched?"); } // Patching each file in js/page let jspage = path.join("js/page"); for dir_entry in fs::read_dir(jspage).unwrap() { // Get the file path let file = dir_entry.unwrap(); let file_name = format!("js/page/{}", file.file_name().to_str().unwrap()); let file_path = file.path(); // Patch the file let file_data = fs::read_to_string(file_path.clone()).unwrap_or_else(|_| panic!("Unable to open file ({})", file_name)); let new_file_data = re.replace_all(&file_data, &rep).to_string(); fs::write(file_path.clone(), new_file_data.clone()).unwrap_or_else(|_| panic!("Unable to write file contents ({})", file_name)); }}
/// Downloads RoPro source. fn download_extension() -> Vec { // Download the extension let mut crx_query = ChromeCRXQuery::default(); crx_query.x = "adbacgifemdbhdkfppmeilbgppmhaobf"; let extension_crx = crx_query.download_blocking().unwrap();
// Convert it to .zip let crx_zip = crx_to_zip(extension_crx, None).unwrap(); // Done crx_zip - Assistant