Fix ICF decoding bugs (again)

This commit is contained in:
beerpiss 2024-03-23 16:54:11 +07:00
parent 9cf8803035
commit d2a276923c

View File

@ -181,14 +181,15 @@ pub fn decode_icf(data: &mut [u8]) -> Result<Vec<IcfData>> {
let data: IcfData = match container_type { let data: IcfData = match container_type {
0x0000 | 0x0001 | 0x0002 => { 0x0000 | 0x0001 | 0x0002 => {
let (version, datetime, required_system_version) =
decode_icf_container_data(&mut rd)?;
for _ in 0..2 { for _ in 0..2 {
if rd.read_u64()? != 0 { if rd.read_u64()? != 0 {
return Err(anyhow!("Padding error. Expected 16 NULL bytes.")); return Err(anyhow!("Padding error. Expected 16 NULL bytes."));
} }
} }
let (version, datetime, required_system_version) = decode_icf_container_data(&mut rd)?;
match container_type { match container_type {
0x0000 => IcfData::System(IcfInnerData { 0x0000 => IcfData::System(IcfInnerData {
id: platform_id.clone(), id: platform_id.clone(),
@ -224,14 +225,15 @@ pub fn decode_icf(data: &mut [u8]) -> Result<Vec<IcfData>> {
} }
let (target_version, target_datetime, _) = decode_icf_container_data(&mut rd)?; let (target_version, target_datetime, _) = decode_icf_container_data(&mut rd)?;
let (source_version, _, source_required_system_version) = decode_icf_container_data(&mut rd)?; let (source_version, _, source_required_system_version) =
decode_icf_container_data(&mut rd)?;
IcfData::Patch(IcfPatchData { IcfData::Patch(IcfPatchData {
id: app_id.clone(), id: app_id.clone(),
source_version, source_version,
target_version, target_version,
required_system_version: source_required_system_version, required_system_version: source_required_system_version,
datetime: target_datetime, datetime: target_datetime,
}) })
} }
}; };