Skip to content

Commit 9cafb77

Browse files
committed
Add dtk extab clean & config.yml clean_extab
It was discovered that certain extab actions contain uninitalized data from the compiler. This provides a way to zero out uninitialized data in DOL or object files. Usage: `dtk extab clean input.dol output.dol` A `clean_extab` setting was added to config.yml, so projects can link the cleaned objects and target the cleaned DOL hash.
1 parent 20e877c commit 9cafb77

File tree

12 files changed

+331
-138
lines changed

12 files changed

+331
-138
lines changed

Cargo.lock

Lines changed: 46 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "decomp-toolkit"
33
description = "Yet another GameCube/Wii decompilation toolkit."
44
authors = ["Luke Street <[email protected]>"]
55
license = "MIT OR Apache-2.0"
6-
version = "1.5.2"
6+
version = "1.6.0"
77
edition = "2021"
88
publish = false
99
repository = "https://github.com/encounter/decomp-toolkit"
@@ -37,7 +37,7 @@ typed-path = "0.9"
3737
cbc = "0.1"
3838
crossterm = "0.28"
3939
cwdemangle = "1.0"
40-
cwextab = "1.0"
40+
cwextab = "1.1"
4141
dyn-clone = "1.0"
4242
enable-ansi-support = "0.2"
4343
filetime = "0.2"

src/cmd/dol.rs

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ use crate::{
4747
diff::{calc_diff_ranges, print_diff, process_code},
4848
dol::process_dol,
4949
elf::{process_elf, write_elf},
50+
extab::clean_extab,
5051
file::{
5152
buf_copy_with_hash, buf_writer, check_hash_str, touch, verify_hash, FileIterator,
5253
FileReadInfo,
@@ -293,6 +294,9 @@ pub struct ModuleConfig {
293294
pub block_relocations: Vec<BlockRelocationConfig>,
294295
#[serde(default, skip_serializing_if = "Vec::is_empty")]
295296
pub add_relocations: Vec<AddRelocationConfig>,
297+
/// Process exception tables and zero out uninitialized data.
298+
#[serde(default, skip_serializing_if = "Option::is_none")]
299+
pub clean_extab: Option<bool>,
296300
}
297301

298302
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
@@ -818,17 +822,29 @@ struct AnalyzeResult {
818822
splits_cache: Option<FileReadInfo>,
819823
}
820824

821-
fn load_analyze_dol(config: &ProjectConfig, object_base: &ObjectBase) -> Result<AnalyzeResult> {
822-
let object_path = object_base.join(&config.base.object);
825+
fn load_dol_module(
826+
config: &ModuleConfig,
827+
object_base: &ObjectBase,
828+
) -> Result<(ObjInfo, Utf8NativePathBuf)> {
829+
let object_path = object_base.join(&config.object);
823830
log::debug!("Loading {}", object_path);
824831
let mut obj = {
825-
let mut file = object_base.open(&config.base.object)?;
832+
let mut file = object_base.open(&config.object)?;
826833
let data = file.map()?;
827-
if let Some(hash_str) = &config.base.hash {
834+
if let Some(hash_str) = &config.hash {
828835
verify_hash(data, hash_str)?;
829836
}
830-
process_dol(data, config.base.name())?
837+
process_dol(data, config.name())?
831838
};
839+
if config.clean_extab.unwrap_or(false) {
840+
log::debug!("Cleaning extab for {}", config.name());
841+
clean_extab(&mut obj)?;
842+
}
843+
Ok((obj, object_path))
844+
}
845+
846+
fn load_analyze_dol(config: &ProjectConfig, object_base: &ObjectBase) -> Result<AnalyzeResult> {
847+
let (mut obj, object_path) = load_dol_module(&config.base, object_base)?;
832848
let mut dep = vec![object_path];
833849

834850
if let Some(comment_version) = config.mw_comment_version {
@@ -1658,15 +1674,7 @@ fn diff(args: DiffArgs) -> Result<()> {
16581674
let config: ProjectConfig = serde_yaml::from_reader(config_file.as_mut())?;
16591675
let object_base = find_object_base(&config)?;
16601676

1661-
log::info!("Loading {}", object_base.join(&config.base.object));
1662-
let mut obj = {
1663-
let mut file = object_base.open(&config.base.object)?;
1664-
let data = file.map()?;
1665-
if let Some(hash_str) = &config.base.hash {
1666-
verify_hash(data, hash_str)?;
1667-
}
1668-
process_dol(data, config.base.name())?
1669-
};
1677+
let (mut obj, _object_path) = load_dol_module(&config.base, &object_base)?;
16701678

16711679
if let Some(symbols_path) = &config.base.symbols {
16721680
apply_symbols_file(&symbols_path.with_encoding(), &mut obj)?;
@@ -1882,15 +1890,7 @@ fn apply(args: ApplyArgs) -> Result<()> {
18821890
let config: ProjectConfig = serde_yaml::from_reader(config_file.as_mut())?;
18831891
let object_base = find_object_base(&config)?;
18841892

1885-
log::info!("Loading {}", object_base.join(&config.base.object));
1886-
let mut obj = {
1887-
let mut file = object_base.open(&config.base.object)?;
1888-
let data = file.map()?;
1889-
if let Some(hash_str) = &config.base.hash {
1890-
verify_hash(data, hash_str)?;
1891-
}
1892-
process_dol(data, config.base.name())?
1893-
};
1893+
let (mut obj, _object_path) = load_dol_module(&config.base, &object_base)?;
18941894

18951895
let Some(symbols_path) = &config.base.symbols else {
18961896
bail!("No symbols file specified in config");

0 commit comments

Comments
 (0)