@@ -62,6 +62,7 @@ use crate::variable::DataVariable;
6262use crate :: { Endianness , BN_FULL_CONFIDENCE } ;
6363use std:: collections:: HashMap ;
6464use std:: ffi:: { c_char, c_void, CString } ;
65+ use std:: fmt:: { Display , Formatter } ;
6566use std:: ops:: Range ;
6667use std:: path:: Path ;
6768use std:: ptr:: NonNull ;
@@ -187,11 +188,57 @@ pub struct AnalysisInfo {
187188 pub active_info : Vec < ActiveAnalysisInfo > ,
188189}
189190
190- #[ derive( Debug , Clone ) ]
191- pub struct AnalysisProgress {
192- pub state : AnalysisState ,
193- pub count : usize ,
194- pub total : usize ,
191+ #[ derive( Debug , Clone , Ord , PartialOrd , Eq , PartialEq ) ]
192+ pub enum AnalysisProgress {
193+ Initial ,
194+ Hold ,
195+ Idle ,
196+ Discovery ,
197+ Disassembling ( usize , usize ) ,
198+ Analyzing ( usize , usize ) ,
199+ ExtendedAnalysis ,
200+ }
201+
202+ impl Display for AnalysisProgress {
203+ fn fmt ( & self , f : & mut Formatter < ' _ > ) -> std:: fmt:: Result {
204+ match self {
205+ AnalysisProgress :: Initial => {
206+ write ! ( f, "Initial" )
207+ }
208+ AnalysisProgress :: Hold => {
209+ write ! ( f, "Hold" )
210+ }
211+ AnalysisProgress :: Idle => {
212+ write ! ( f, "Idle" )
213+ }
214+ AnalysisProgress :: Discovery => {
215+ write ! ( f, "Discovery" )
216+ }
217+ AnalysisProgress :: Disassembling ( count, total) => {
218+ write ! ( f, "Disassembling ({count}/{total})" )
219+ }
220+ AnalysisProgress :: Analyzing ( count, total) => {
221+ write ! ( f, "Analyzing ({count}/{total})" )
222+ }
223+ AnalysisProgress :: ExtendedAnalysis => {
224+ write ! ( f, "Extended Analysis" )
225+ }
226+ }
227+ }
228+ }
229+
230+ impl From < BNAnalysisProgress > for AnalysisProgress {
231+ fn from ( value : BNAnalysisProgress ) -> Self {
232+ match value. state {
233+ BNAnalysisState :: InitialState => Self :: Initial ,
234+ BNAnalysisState :: HoldState => Self :: Hold ,
235+ BNAnalysisState :: IdleState => Self :: Idle ,
236+ BNAnalysisState :: DiscoveryState => Self :: Discovery ,
237+ BNAnalysisState :: DisassembleState => Self :: Disassembling ( value. count , value. total ) ,
238+ BNAnalysisState :: AnalyzeState => Self :: Analyzing ( value. count , value. total ) ,
239+ BNAnalysisState :: ExtendedAnalyzeState => Self :: ExtendedAnalysis ,
240+ }
241+ }
195242}
196243
197244pub trait BinaryViewExt : BinaryViewBase {
@@ -604,12 +651,8 @@ pub trait BinaryViewExt: BinaryViewBase {
604651 }
605652
606653 fn analysis_progress ( & self ) -> AnalysisProgress {
607- let progress = unsafe { BNGetAnalysisProgress ( self . as_ref ( ) . handle ) } ;
608- AnalysisProgress {
609- state : progress. state ,
610- count : progress. count ,
611- total : progress. total ,
612- }
654+ let progress_raw = unsafe { BNGetAnalysisProgress ( self . as_ref ( ) . handle ) } ;
655+ AnalysisProgress :: from ( progress_raw)
613656 }
614657
615658 fn default_arch ( & self ) -> Option < CoreArchitecture > {
0 commit comments