Generate correct 0 bytes

This commit is contained in:
Gwilym Inzani 2023-04-06 23:09:19 +01:00
parent a111a41deb
commit 07318256e0

View file

@ -19,7 +19,9 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut header = gbafix::GBAHeader::default(); let mut header = gbafix::GBAHeader::default();
let mut written_header = false; const GBA_START_ADDRESS: u64 = 0x8000000;
let mut address = GBA_START_ADDRESS;
for section_header in section_headers.iter() { for section_header in section_headers.iter() {
const SHT_NOBITS: u32 = 8; const SHT_NOBITS: u32 = 8;
const SHT_NULL: u32 = 0; const SHT_NULL: u32 = 0;
@ -31,12 +33,16 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
continue; continue;
} }
for _ in address..section_header.sh_addr {
output.write_all(&[0])?;
}
let (mut data, compression) = elf_file.section_data(&section_header)?; let (mut data, compression) = elf_file.section_data(&section_header)?;
if let Some(compression) = compression { if let Some(compression) = compression {
panic!("Cannot decompress elf content, but got compression header {compression:?}"); panic!("Cannot decompress elf content, but got compression header {compression:?}");
} }
if !written_header { if address == GBA_START_ADDRESS {
const GBA_HEADER_SIZE: usize = 192; const GBA_HEADER_SIZE: usize = 192;
assert!( assert!(
@ -51,10 +57,11 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
output.write_all(header_bytes)?; output.write_all(header_bytes)?;
data = &data[GBA_HEADER_SIZE..]; data = &data[GBA_HEADER_SIZE..];
written_header = true; address += GBA_HEADER_SIZE as u64;
} }
output.write_all(data)?; output.write_all(data)?;
address += data.len() as u64;
} }
output.flush()?; output.flush()?;