File tree Expand file tree Collapse file tree 1 file changed +12
-6
lines changed
Expand file tree Collapse file tree 1 file changed +12
-6
lines changed Original file line number Diff line number Diff line change @@ -35,6 +35,17 @@ pub struct CPDHeader {
3535 // _10: u32,
3636}
3737
38+ impl CPDHeader {
39+ pub fn name ( & self ) -> String {
40+ let n = self . part_name ;
41+ match std:: str:: from_utf8 ( & n) {
42+ // some names are shorter than 4 bytes and padded with 0x0
43+ Ok ( n) => n. trim_end_matches ( '\0' ) . to_string ( ) ,
44+ Err ( _) => format ! ( "{:02x?}" , n) ,
45+ }
46+ }
47+ }
48+
3849const HEADER_SIZE : usize = core:: mem:: size_of :: < CPDHeader > ( ) ;
3950
4051// See <https://github.com/corna/me_cleaner> `check_and_remove_modules_gen3()`
@@ -141,12 +152,7 @@ impl CodePartitionDirectory {
141152 let Ok ( ( header, _) ) = CPDHeader :: read_from_prefix ( & data) else {
142153 return Err ( "could not parse CPD header" . to_string ( ) ) ;
143154 } ;
144- let n = header. part_name ;
145- let name = match std:: str:: from_utf8 ( & n) {
146- // some names are shorter than 4 bytes and padded with 0x0
147- Ok ( n) => n. trim_end_matches ( '\0' ) . to_string ( ) ,
148- Err ( _) => format ! ( "{:02x?}" , n) ,
149- } ;
155+ let name = header. name ( ) ;
150156 let header_size = if header. version_or_checksum == 0x00140102 {
151157 HEADER_SIZE + 4
152158 } else {
You can’t perform that action at this time.
0 commit comments