From e3dbffec44315e957112d4c4a0c5a548f3c6b0dc Mon Sep 17 00:00:00 2001 From: TheAlternateDoctor Date: Sun, 10 Mar 2024 23:29:17 +0100 Subject: [PATCH] Fixed an issue with non-null terminated blocks --- src/main.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index 587a284..7795f97 100644 --- a/src/main.rs +++ b/src/main.rs @@ -71,7 +71,9 @@ fn extract_msbt(args: Args) -> ::msbt::Result<()> { for string in strings { let mut parsed_string = ::msbt::structs::TXT2::parse_binary(string.string, msbt.endianness); - parsed_string.truncate(parsed_string.len() - 1); + if parsed_string.ends_with('\0'){ + parsed_string.truncate(parsed_string.len() - 1); + } output_map.insert(string.label, parsed_string); } let order = match msbt.endianness { @@ -171,7 +173,7 @@ fn diff_msbt(args: Args) -> ::msbt::Result<()> { if !added_strings.is_empty() || !deleted_strings.is_empty() || !edited_strings.is_empty(){ let output_path = if args.output.is_some(){args.output.unwrap()} else {filepath.join(filename.to_owned() + ".msbd.txt").into_os_string().into_string().unwrap()}; let mut diff_file = File::create(output_path)?; - + //Writing file let _ = diff_file.write((filename.to_owned()+"\n").as_bytes()); let _ = diff_file.write((filename.to_owned()+"\n").as_bytes()); @@ -185,7 +187,9 @@ fn diff_msbt(args: Args) -> ::msbt::Result<()> { let label = "+".to_owned()+&string.label+"\n"; let _ = diff_file.write(label.as_bytes()); let mut parsed_string = ::msbt::structs::TXT2::parse_binary(string.string, endianness); - parsed_string.truncate(parsed_string.len() - 1); + if parsed_string.ends_with('\0'){ + parsed_string.truncate(parsed_string.len() - 1); + } parsed_string = parsed_string.replace('\n', "\n>"); let _ = diff_file.write((">".to_owned()+&parsed_string+"\n").as_bytes()); let _ = diff_file.write("\n".as_bytes()); @@ -203,7 +207,9 @@ fn diff_msbt(args: Args) -> ::msbt::Result<()> { let label = "~".to_owned()+&string.label+"\n"; let _ = diff_file.write(label.as_bytes()); let mut parsed_string = ::msbt::structs::TXT2::parse_binary(string.string, endianness); - parsed_string.truncate(parsed_string.len() - 1); + if parsed_string.ends_with('\0'){ + parsed_string.truncate(parsed_string.len() - 1); + } parsed_string = parsed_string.replace('\n', "\n>"); let _ = diff_file.write((">".to_owned()+&parsed_string+"\n").as_bytes()); let _ = diff_file.write("\n".as_bytes());