Allow specifying replacement bytes in dtk extab clean (#103)

* Allow specifying replacement bytes in dtk extab clean

* Simplify extab padding replacement

* Reword log message

* clippy has bad taste

* Don't specify revision number for cwextab

---------

Co-authored-by: Amber Brault <celestialamber1@gmail.com>
This commit is contained in:
cadmic
2025-06-04 20:01:05 -07:00
committed by GitHub
parent 9cafb77d3f
commit 5e33fea49f
4 changed files with 31 additions and 16 deletions

View File

@@ -838,7 +838,7 @@ fn load_dol_module(
};
if config.clean_extab.unwrap_or(false) {
log::debug!("Cleaning extab for {}", config.name());
clean_extab(&mut obj)?;
clean_extab(&mut obj, std::iter::empty())?;
}
Ok((obj, object_path))
}

View File

@@ -30,15 +30,18 @@ enum SubCommand {
}
#[derive(FromArgs, PartialEq, Eq, Debug)]
/// Rewrites extab data in a DOL or ELF file, zeroing out any uninitialized padding bytes.
/// Rewrites extab data in a DOL or ELF file, replacing any uninitialized padding bytes.
#[argp(subcommand, name = "clean")]
pub struct CleanArgs {
#[argp(positional, from_str_fn(native_path))]
/// path to input file
/// Path to input file
input: Utf8NativePathBuf,
#[argp(positional, from_str_fn(native_path))]
/// path to output file
/// Path to output file
output: Utf8NativePathBuf,
#[argp(option, short = 'p')]
/// Data to replace padding bytes with, encoded as a hexadecimal string. If not specified, padding bytes will be zeroed instead.
padding: Option<String>,
}
pub fn run(args: Args) -> Result<()> {
@@ -56,7 +59,13 @@ fn clean_extab(args: CleanArgs) -> Result<()> {
let name = args.input.file_stem().unwrap_or_default();
process_dol(file.map()?, name)?
};
let num_cleaned = util::extab::clean_extab(&mut obj)?;
let padding: Vec<u8> = match args.padding {
None => Vec::new(),
Some(padding_str) => {
hex::decode(padding_str).context("Failed to decode padding bytes from hex")?
}
};
let num_cleaned = util::extab::clean_extab(&mut obj, padding.iter().copied())?;
tracing::debug!("Cleaned {num_cleaned} extab symbols");
let mut out = buf_writer(&args.output)?;
if is_elf {