@@ -114,7 +114,6 @@ pub struct TranslatesIDBType<'a> {
114114
115115pub struct TranslateIDBTypes < ' a , F > {
116116 pub arch : CoreArchitecture ,
117- pub total : usize ,
118117 pub progress : F ,
119118 // key til addr and type idx
120119 pub types_by_idx : HashMap < ( usize , usize ) , usize > ,
@@ -129,19 +128,16 @@ where
129128 F : Fn ( usize , usize ) -> Result < ( ) , ( ) > ,
130129{
131130 pub fn from_types ( arch : CoreArchitecture , tils : & ' a [ TILSection ] , progress : F ) -> Result < Self > {
132- let total = tils
133- . iter ( )
134- . map ( |til| til. symbols . len ( ) + til. types . len ( ) )
135- . sum ( ) ;
136- let mut types = Vec :: with_capacity ( total) ;
137- let mut types_by_idx = HashMap :: with_capacity ( total) ;
138- let mut types_by_ord = HashMap :: with_capacity ( total) ;
139- let mut types_by_name = HashMap :: with_capacity ( total) ;
140131 let all_types = tils. iter ( ) . flat_map ( |til| {
141132 core:: iter:: repeat ( til) . zip ( til. types . iter ( ) . enumerate ( ) . zip ( core:: iter:: repeat ( false ) ) )
142133 // TODO: it's unclear how the demangle symbols and types names/ord, for now only parse types
143134 //.chain(til.symbols.iter().zip(core::iter::repeat(true)))
144135 } ) ;
136+ let total = all_types. clone ( ) . count ( ) ;
137+ let mut types = Vec :: with_capacity ( total) ;
138+ let mut types_by_idx = HashMap :: with_capacity ( total) ;
139+ let mut types_by_ord = HashMap :: with_capacity ( total) ;
140+ let mut types_by_name = HashMap :: with_capacity ( total) ;
145141 for ( i, ( til, ( ( ty_idx, ty) , is_symbol) ) ) in all_types. enumerate ( ) {
146142 // TODO sanitized the input
147143 // TODO find out how the namespaces used by TIL works
@@ -189,7 +185,6 @@ where
189185 }
190186
191187 Ok ( TranslateIDBTypes {
192- total,
193188 arch,
194189 progress,
195190 tils,
@@ -201,7 +196,7 @@ where
201196 }
202197
203198 fn resolve ( & mut self ) -> Result < ( ) > {
204- if ( self . progress ) ( 0 , self . total ) . is_err ( ) {
199+ if ( self . progress ) ( 0 , self . types . len ( ) ) . is_err ( ) {
205200 return Err ( anyhow ! ( "IDB import aborted" ) ) ;
206201 }
207202
@@ -238,14 +233,15 @@ where
238233 }
239234
240235 // count the number of finished types
241- if let TranslateTypeResult :: Translated ( _) = & self . types [ i] . ty {
242- num_translated += 1
236+ let was_translated =
237+ matches ! ( & self . types[ i] . ty, TranslateTypeResult :: Translated ( _) ) ;
238+ if was_translated {
239+ num_translated += 1 ;
243240 }
244-
245- all_done &= matches ! ( & self . types[ i] . ty, TranslateTypeResult :: Translated ( _) ) ;
241+ all_done &= was_translated;
246242 }
247243
248- if ( self . progress ) ( num_translated, self . total ) . is_err ( ) {
244+ if ( self . progress ) ( num_translated, self . types . len ( ) ) . is_err ( ) {
249245 // error means the user aborted the progress
250246 return Err ( anyhow ! ( "User aborted during processing" ) ) ;
251247 }
@@ -770,7 +766,6 @@ pub fn translate_ephemeral_type(debug_file: &BinaryView, ty: &TILType) -> Transl
770766 macros : None ,
771767 } ] ,
772768 types : vec ! [ ] ,
773- total : 0 ,
774769 types_by_idx : HashMap :: new ( ) ,
775770 types_by_ord : HashMap :: new ( ) ,
776771 types_by_name : HashMap :: new ( ) ,
@@ -779,14 +774,6 @@ pub fn translate_ephemeral_type(debug_file: &BinaryView, ty: &TILType) -> Transl
779774 translator. translate_type ( & translator. tils [ 0 ] , ty)
780775}
781776
782- pub fn translate_tils_types (
783- arch : CoreArchitecture ,
784- tils : & [ TILSection ] ,
785- progress : impl Fn ( usize , usize ) -> Result < ( ) , ( ) > ,
786- ) -> Result < Vec < TranslatesIDBType < ' _ > > > {
787- translate_til_types ( arch, tils, progress)
788- }
789-
790777pub fn translate_til_types (
791778 arch : CoreArchitecture ,
792779 tils : & [ TILSection ] ,
0 commit comments