mirror of
https://github.com/italicsjenga/agb.git
synced 2024-12-23 08:11:33 +11:00
Use a different footer to announce the file type
This commit is contained in:
parent
5366fc252b
commit
b3e18d130f
|
@ -13,19 +13,29 @@ pub fn load_dwarf(
|
||||||
return load_from_object(&object);
|
return load_from_object(&object);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// the file might have been padded, so ensure we skip any padding before continuing
|
||||||
|
let last_non_zero_byte = file_content
|
||||||
|
.iter()
|
||||||
|
.rposition(|&b| b != 0)
|
||||||
|
.ok_or_else(|| anyhow::anyhow!("Gba file is empty"))?;
|
||||||
|
|
||||||
|
let file_content = &file_content[..last_non_zero_byte + 1];
|
||||||
|
|
||||||
let last_8_bytes = &file_content[file_content.len() - 8..];
|
let last_8_bytes = &file_content[file_content.len() - 8..];
|
||||||
let len = u32::from_le_bytes(last_8_bytes[0..4].try_into()?) as usize;
|
let len = u32::from_le_bytes(last_8_bytes[0..4].try_into()?) as usize;
|
||||||
let version = u32::from_le_bytes(last_8_bytes[4..].try_into()?) as usize;
|
let version = &last_8_bytes[4..];
|
||||||
|
|
||||||
if version != 1 {
|
if version != b"agb1" {
|
||||||
bail!("Only version 1 of the debug info is supported");
|
bail!("Failed to load debug information from ROM file, it might not have been included?");
|
||||||
}
|
}
|
||||||
|
|
||||||
let compressed_debug_data = &file_content[file_content.len() - len - 8..file_content.len() - 8];
|
let compressed_debug_data = &file_content[file_content.len() - len - 8..file_content.len() - 8];
|
||||||
|
|
||||||
let decompressing_reader =
|
let decompressing_reader =
|
||||||
lz4_flex::frame::FrameDecoder::new(Cursor::new(compressed_debug_data));
|
lz4_flex::frame::FrameDecoder::new(Cursor::new(compressed_debug_data));
|
||||||
let debug_info: HashMap<String, Vec<u8>> = rmp_serde::decode::from_read(decompressing_reader)?;
|
let debug_info: HashMap<String, Vec<u8>> =
|
||||||
|
rmp_serde::decode::from_read(decompressing_reader)
|
||||||
|
.map_err(|e| anyhow::anyhow!("Failed to load debug information: {e}"))?;
|
||||||
|
|
||||||
let dwarf = gimli::Dwarf::load(|id| {
|
let dwarf = gimli::Dwarf::load(|id| {
|
||||||
let data = debug_info
|
let data = debug_info
|
||||||
|
|
|
@ -173,7 +173,7 @@ fn write_debug<W: Write>(
|
||||||
|
|
||||||
output.write_all(&debug_data)?;
|
output.write_all(&debug_data)?;
|
||||||
output.write_all(&(debug_data.len() as u32).to_le_bytes())?;
|
output.write_all(&(debug_data.len() as u32).to_le_bytes())?;
|
||||||
output.write_all(&(1u32).to_le_bytes())?;
|
output.write_all(b"agb1")?;
|
||||||
|
|
||||||
Ok(debug_data.len() as u64 + 4)
|
Ok(debug_data.len() as u64 + 4)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue