Esempio n. 1
0
def parse_efivar_file( fname, var=None ):
    if not var:
        var = read_file( fname )
    #path, var_name = os.path.split( fname )
    #var_name, ext = os.path.splitext( var_name )
    var_path = fname + '.dir'
    if not os.path.exists( var_path ):
        os.makedirs( var_path )

    parse_db( var, var_path )
Esempio n. 2
0
    def run(self):
        if len(self.argv) < 3:
            print SPIDescCommand.__doc__
            return

        fd_file = self.argv[2]
        self.logger.log( "[CHIPSEC] Parsing SPI Flash Descriptor from file '%s'\n" % fd_file )

        t = time.time()
        fd = read_file( fd_file )
        if type(fd) == str: parse_spi_flash_descriptor( fd )
        self.logger.log( "\n[CHIPSEC] (spidesc) time elapsed %.3f" % (time.time()-t) )
Esempio n. 3
0
    def run(self):
        if len(self.argv) < 3:
            print UCodeCommand.__doc__
            return

        ucode_op = self.argv[2]
        t = time.time()

        if ( 'load' == ucode_op ):
            if (4 == len(self.argv)):
                ucode_filename = self.argv[3]
                self.logger.log( "[CHIPSEC] Loading Microcode update on all cores from '%s'" % ucode_filename )
                self.cs.ucode.update_ucode_all_cpus( ucode_filename )
            elif (5 == len(self.argv)):
                ucode_filename = self.argv[3]
                cpu_thread_id = int(self.argv[4],16)
                self.logger.log( "[CHIPSEC] Loading Microcode update on CPU%d from '%s'" % (cpu_thread_id, ucode_filename) )
                self.cs.ucode.update_ucode( cpu_thread_id, ucode_filename )
            else:
                print UCodeCommand.__doc__
                return
        elif ( 'decode' == ucode_op ):
            if (4 == len(self.argv)):
                ucode_filename = self.argv[3]
                if (not ucode_filename.endswith('.pdb')):
                    self.logger.log( "[CHIPSEC] Ucode update file is not PDB file: '%s'" % ucode_filename )
                    return
                pdb_ucode_buffer = read_file( ucode_filename )
                self.logger.log( "[CHIPSEC] Decoding Microcode Update header of PDB file: '%s'" % ucode_filename )
                dump_ucode_update_header( pdb_ucode_buffer )
        elif ( 'id' == ucode_op ):
            if (3 == len(self.argv)):
                for tid in range(self.cs.msr.get_cpu_thread_count()):
                    ucode_update_id = self.cs.ucode.ucode_update_id( tid )
                    self.logger.log( "[CHIPSEC] CPU%d: Microcode update ID = 0x%08X" % (tid, ucode_update_id) )
            elif (4 == len(self.argv)):
                cpu_thread_id = int(self.argv[3],16)
                ucode_update_id = self.cs.ucode.ucode_update_id( cpu_thread_id )
                self.logger.log( "[CHIPSEC] CPU%d: Microcode update ID = 0x%08X" % (cpu_thread_id, ucode_update_id) )
        else:
            self.logger.error( "unknown command-line option '%.32s'" % ucode_op )
            print UCodeCommand.__doc__
            return

        self.logger.log( "[CHIPSEC] (ucode) time elapsed %.3f" % (time.time()-t) )
Esempio n. 4
0
def DecompressSection(CompressedFileName, OutputFileName, CompressionType):
    from subprocess import call
    from chipsec.file import read_file
    decompressed = None
    edk2path = os.path.join('..','..','tools','edk2','win')
    exe = None
    try:
        if   (CompressionType == 1):
            exe = os.path.join(edk2path,'TianoCompress.exe')
        elif (CompressionType == 2):
            exe = os.path.join(edk2path,'LzmaCompress.exe')
        else:
            pass
        if exe:
            call('%s -d -o %s %s' % (exe, OutputFileName, CompressedFileName))
        decompressed = read_file( OutputFileName )
    except:
        pass
    return decompressed
Esempio n. 5
0
    def run(self):
        if len(self.argv) < 3:
            print DecodeCommand.__doc__
            return
        
        _uefi = uefi.UEFI( self.cs )
        if self.argv[2] == "types":
            print "\n<fw_type> should be in [ %s ]\n" % ( " | ".join( ["%s" % t for t in uefi.uefi_platform.fw_types] ) )
            return
            
        rom_file = self.argv[2]
        fwtype   = self.argv[3] if len(self.argv) == 4 else None      

        self.logger.log( "[CHIPSEC] Decoding SPI ROM image from a file '%s'" % rom_file )
        t = time.time()

        f = read_file( rom_file )
        (fd_off, fd) = spi_descriptor.get_spi_flash_descriptor( f )
        if (-1 == fd_off) or (fd is None):
            self.logger.error( "Could not find SPI Flash descriptor in the binary '%s'" % rom_file )
            return False

        self.logger.log( "[CHIPSEC] Found SPI Flash descriptor at offset 0x%x in the binary '%s'" % (fd_off, rom_file) )
        rom = f[fd_off:]
        # Decoding Flash Descriptor
        #self.logger.LOG_COMPLETE_FILE_NAME = os.path.join( pth, 'flash_descriptor.log' )
        #parse_spi_flash_descriptor( self.cs, fd )

        # Decoding SPI Flash Regions
        # flregs[r] = (r,SPI_REGION_NAMES[r],flreg,base,limit,notused)
        flregs = spi_descriptor.get_spi_regions( fd )
        if flregs is None:
            self.logger.error( "SPI Flash descriptor region is not valid" )
            return False

        _orig_logname = self.logger.LOG_FILE_NAME

        pth = os.path.join( self.cs.helper.getcwd(), rom_file + ".dir" )
        if not os.path.exists( pth ):
            os.makedirs( pth )

        for r in flregs:
            idx     = r[0]
            name    = r[1]
            base    = r[3]
            limit   = r[4]
            notused = r[5]
            if not notused:
                region_data = rom[base:limit+1]
                fname = os.path.join( pth, '%d_%04X-%04X_%s.bin' % (idx, base, limit, name) )
                write_file( fname, region_data )
                if spi.FLASH_DESCRIPTOR == idx:
                    # Decoding Flash Descriptor
                    self.logger.set_log_file( os.path.join( pth, fname + '.log' ) )
                    spi_descriptor.parse_spi_flash_descriptor( self.cs, region_data )
                elif spi.BIOS == idx:
                    # Decoding EFI Firmware Volumes
                    self.logger.set_log_file( os.path.join( pth, fname + '.log' ) )
                    spi_uefi.decode_uefi_region(_uefi, pth, fname, fwtype)

        self.logger.set_log_file( _orig_logname )
        self.logger.log( "[CHIPSEC] (decode) time elapsed %.3f" % (time.time()-t) )