<s> '''<STR_LIT>''' <EOL> import uefi <EOL> import pfs <EOL> import me <EOL> import flash <EOL> from misc import checker <EOL> from base import FirmwareObject <EOL> from utils import search_firmware_volumes <EOL> class AutoParser ( object ) : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self , data , search = True ) : <EOL> '''<STR_LIT>''' <EOL> self . data = data <EOL> self . data_type = '<STR_LIT>' <EOL> self . constructor = None <EOL> self . firmware = None <EOL> header = data [ : <NUM_LIT:100> ] <EOL> for tester in checker . TESTERS : <EOL> if tester ( ) . match ( header ) : <EOL> self . data_type = tester ( ) . name <EOL> self . constructor = tester ( ) . parser <EOL> def type ( self ) : <EOL> '''<STR_LIT>''' <EOL> return self . data_type <EOL> def parse ( self ) : <EOL> '''<STR_LIT>''' <EOL> if self . constructor is None : <EOL> return None <EOL> if self . firmware is not None : <EOL> return self . firmware <EOL> self . firmware = self . constructor ( self . data ) <EOL> if not self . firmware . process ( ) : <EOL> self . firmware = None <EOL> return None <EOL> if self . constructor is uefi . FirmwareVolume : <EOL> mfc = MultiVolumeContainer ( self . data [ self . firmware . size : ] ) <EOL> if mfc . has_indexes ( ) : <EOL> if mfc . process ( ) : <EOL> mfc . append_base ( self . firmware ) <EOL> self . firmware = mfc <EOL> return self . firmware <EOL> class MultiVolumeContainer ( FirmwareObject ) : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self , data ) : <EOL> '''<STR_LIT>''' <EOL> self . data = data <EOL> self . indexes = search_firmware_volumes ( data ) <EOL> self . volumes = [ ] <EOL> def has_indexes ( self ) : <EOL> '''<STR_LIT>''' <EOL> return self . indexes > <NUM_LIT:0> <EOL> def append_base ( self , volume ) : <EOL> '''<STR_LIT>''' <EOL> self . volumes = [ volume ] + self . volumes <EOL> def process ( self ) : <EOL> for index in self . indexes : <EOL> volume = uefi . FirmwareVolume ( self . data [ index - <NUM_LIT> : ] , index ) <EOL> if volume . process ( ) : <EOL> self . volumes . append ( volume ) <EOL> return len ( self . volumes ) > <NUM_LIT:0> <EOL> @ property <EOL> def objects ( self ) : <EOL> return self . volumes <EOL> def showinfo ( self , ts = '<STR_LIT>' , index = None ) : <EOL> '''<STR_LIT>''' <EOL> for volume in self . volumes : <EOL> volume . showinfo ( ts , index ) <EOL> def dump ( self , parent , index = None ) : <EOL> '''<STR_LIT>''' <EOL> for i in range ( self . volumes ) : <EOL> path = os . path . join ( parent , "<STR_LIT>" % i ) <EOL> self . volumes [ i ] . dump ( path ) <EOL> __title__ = "<STR_LIT>" <EOL> __version__ = "<STR_LIT>" <EOL> __author__ = "<STR_LIT>" <EOL> __license__ = "<STR_LIT>" </s>
