use std::env; use std::fs::File; use std::io::Read; use std::path::Path; use enemize::PatchSet; use enemize::asar; use enemize::rom::RomData; fn main() -> Result<(), anyhow::Error> { let mut args = env::args(); let output_path = args.next_back().expect("No output file"); let symbols_path = args.next_back().expect("No symbols file"); let patch_path = args.next_back().expect("No patch file"); let rom_path = args.next_back().expect("No ROM file"); let mut rom_bytes = vec![]; let mut rom_file = File::open(&rom_path)?; rom_file.read_to_end(&mut rom_bytes)?; rom_bytes = if rom_bytes.len() % 1024 == 512 { rom_bytes.into_iter().skip(512).collect() } else { rom_bytes }; let expected = [ 0x03, 0xa6, 0x39, 0x45, 0x39, 0x81, 0x91, 0x33, 0x7e, 0x89, 0x6e, 0x57, 0x71, 0xf7, 0x71, 0x73, ]; let actual: [u8; 16] = md5::compute(&rom_bytes).into(); assert_eq!(expected, actual, "Invalid rom file"); println!("Applying Patch to rom"); rom_bytes.resize(4 * 1024 * 1024, 0); let symbols = asar::load_symbols(Path::new(&symbols_path))?; let mut rom = RomData::new(symbols, rom_bytes); let mut patches = PatchSet::load(Path::new(&patch_path))?; patches.patch_rom(&mut rom); rom.move_room_headers(); let rom_patches = rom.generate_patch(); patches.add_patches(rom_patches); println!("Writing output file {}", output_path); let out_file = File::create(&output_path)?; serde_json::to_writer(out_file, &patches)?; Ok(()) }