diff --git a/tbf-parser/src/types.rs b/tbf-parser/src/types.rs index 5f4dca45..66a0a9df 100644 --- a/tbf-parser/src/types.rs +++ b/tbf-parser/src/types.rs @@ -960,13 +960,9 @@ impl TbfHeader { match *self { TbfHeader::TbfHeaderV2(hd) => { if hd.program.is_some() { - hd.program.map_or(0, |p| { - (hd.base.header_size as u32) + p.protected_trailer_size - }) + hd.program.map_or(0, |p| p.protected_trailer_size) } else if hd.main.is_some() { - hd.main.map_or(0, |m| { - (hd.base.header_size as u32) + m.protected_trailer_size - }) + hd.main.map_or(0, |m| m.protected_trailer_size) } else { 0 } @@ -990,11 +986,9 @@ impl TbfHeader { match *self { TbfHeader::TbfHeaderV2(hd) => { if hd.program.is_some() { - hd.program - .map_or(0, |p| p.init_fn_offset + (hd.base.header_size as u32)) + hd.program.map_or(0, |p| p.init_fn_offset) } else if hd.main.is_some() { - hd.main - .map_or(0, |m| m.init_fn_offset + (hd.base.header_size as u32)) + hd.main.map_or(0, |m| m.init_fn_offset) } else { 0 } @@ -1175,6 +1169,14 @@ impl TbfHeader { } } + /// Return the TBF version + pub fn get_tbf_version(&self) -> u16 { + match self { + TbfHeader::TbfHeaderV2(hd) => hd.base.version, + _ => 0, + } + } + /// Return the fixed ShortId of the application if it was specified in the /// TBF header. pub fn get_fixed_short_id(&self) -> Option { diff --git a/tbf-parser/tests/parse.rs b/tbf-parser/tests/parse.rs index a9362c4c..f2b3826f 100644 --- a/tbf-parser/tests/parse.rs +++ b/tbf-parser/tests/parse.rs @@ -16,8 +16,8 @@ fn simple_tbf() { dbg!(&header); assert!(header.enabled()); assert_eq!(header.get_minimum_app_ram_size(), 4848); - assert_eq!(header.get_init_function_offset(), 41 + header_len as u32); - assert_eq!(header.get_protected_size(), header_len as u32); + assert_eq!(header.get_init_function_offset(), 41); + assert_eq!(header.get_protected_size(), 0); assert_eq!(header.get_package_name().unwrap(), "_heart"); assert_eq!(header.get_kernel_version().unwrap(), (2, 0)); } @@ -37,8 +37,8 @@ fn footer_sha256() { dbg!(&header); assert!(header.enabled()); assert_eq!(header.get_minimum_app_ram_size(), 4848); - assert_eq!(header.get_init_function_offset(), 41 + header_len as u32); - assert_eq!(header.get_protected_size(), header_len as u32); + assert_eq!(header.get_init_function_offset(), 41); + assert_eq!(header.get_protected_size(), 0); assert_eq!(header.get_package_name().unwrap(), "_heart"); assert_eq!(header.get_kernel_version().unwrap(), (2, 0)); let binary_offset = header.get_binary_end() as usize; @@ -87,8 +87,8 @@ fn footer_rsa4096() { dbg!(&header); assert!(header.enabled()); assert_eq!(header.get_minimum_app_ram_size(), 4612); - assert_eq!(header.get_init_function_offset(), 41 + header_len as u32); - assert_eq!(header.get_protected_size(), header_len as u32); + assert_eq!(header.get_init_function_offset(), 41); + assert_eq!(header.get_protected_size(), 0); assert_eq!(header.get_package_name().unwrap(), "c_hello"); assert_eq!(header.get_kernel_version().unwrap(), (2, 0)); let binary_offset = header.get_binary_end() as usize; diff --git a/tockloader-cli/src/display.rs b/tockloader-cli/src/display.rs index 356bd67b..14996f69 100644 --- a/tockloader-cli/src/display.rs +++ b/tockloader-cli/src/display.rs @@ -82,7 +82,7 @@ pub async fn print_info(app_details: &mut [AppAttributes], system_details: &mut println!( " {BOLD_GREEN} TBF version: {RESET}{}", - details.tbf_header.get_binary_version(), + details.tbf_header.get_tbf_version(), ); println!( @@ -111,7 +111,7 @@ pub async fn print_info(app_details: &mut [AppAttributes], system_details: &mut details.tbf_header.sticky(), ); - println!(" {BOLD_GREEN} TVL: Main (1){RESET}"); + println!(" {BOLD_GREEN} TLV: Main (1){RESET}"); println!( " {BOLD_GREEN} init_fn_offset: {RESET}{}", details.tbf_header.get_init_function_offset(), @@ -127,7 +127,7 @@ pub async fn print_info(app_details: &mut [AppAttributes], system_details: &mut details.tbf_header.get_minimum_app_ram_size(), ); - println!(" {BOLD_GREEN} TVL: Program (9){RESET}"); + println!(" {BOLD_GREEN} TLV: Program (9){RESET}"); println!( " {BOLD_GREEN} init_fn_offset: {RESET}{}", details.tbf_header.get_init_function_offset(), @@ -153,13 +153,13 @@ pub async fn print_info(app_details: &mut [AppAttributes], system_details: &mut details.tbf_header.get_binary_version(), ); - println!(" {BOLD_GREEN} TVL: Package Name (3){RESET}"); + println!(" {BOLD_GREEN} TLV: Package Name (3){RESET}"); println!( " {BOLD_GREEN} package_name: {RESET}{}", details.tbf_header.get_package_name().unwrap(), ); - println!(" {BOLD_GREEN} TVL: Kernel Version (8){RESET}"); + println!(" {BOLD_GREEN} TLV: Kernel Version (8){RESET}"); println!( " {BOLD_GREEN} kernel_major: {RESET}{}", details.tbf_header.get_kernel_version().unwrap().0, @@ -183,7 +183,7 @@ pub async fn print_info(app_details: &mut [AppAttributes], system_details: &mut println!(" {BOLD_GREEN} footer_size: {RESET}{total_footer_size}"); for (j, footer_details) in details.tbf_footers.iter().enumerate() { - println!(" {BOLD_GREEN} Footer [{j}] TVL: Credentials{RESET}"); + println!(" {BOLD_GREEN} Footer [{j}] TLV: Credentials{RESET}"); println!( " {BOLD_GREEN} Type: {RESET}{}",