Esempio n. 1
0
    def decode_rom(self):
        _uefi = UEFI(self.cs)
        self.logger.log(
            "[CHIPSEC] Decoding SPI ROM image from a file '{}'".format(
                self._rom))
        f = read_file(self._rom)
        if not f:
            return False
        (fd_off, fd) = 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 '{}'".
                format(self._rom))
            self.logger.log_information(
                "To decode an image without a flash decriptor try chipsec_util uefi decode"
            )
            return False

        self.logger.log(
            "[CHIPSEC] Found SPI Flash descriptor at offset 0x{:X} in the binary '{}'"
            .format(fd_off, self._rom))
        rom = f[fd_off:]

        # Decoding SPI Flash Regions
        flregs = get_spi_regions(fd)
        if flregs is None:
            self.logger.error("SPI Flash descriptor region is not valid")
            self.logger.log_information(
                "To decode an image with an invalid flash decriptor try chipsec_util uefi decode"
            )
            return False

        _orig_logname = self.logger.LOG_FILE_NAME

        pth = os.path.join(self.cs.helper.getcwd(), self._rom + ".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}_{}.bin'.format(idx, base, limit, name))
                write_file(fname, region_data)
                if FLASH_DESCRIPTOR == idx:
                    # Decoding Flash Descriptor
                    self.logger.set_log_file(os.path.join(pth, fname + '.log'))
                    parse_spi_flash_descriptor(self.cs, region_data)
                elif BIOS == idx:
                    # Decoding EFI Firmware Volumes
                    self.logger.set_log_file(os.path.join(pth, fname + '.log'))
                    decode_uefi_region(_uefi, pth, fname, self._fwtype)

        self.logger.set_log_file(_orig_logname)
Esempio n. 2
0
    def decode(self):
        if not os.path.exists( self.filename ):
            self.logger.error( "Could not find file '{}'".format(self.filename) )
            return

        self.logger.log( "[CHIPSEC] Parsing EFI volumes from '{}'..".format(self.filename) )
        _orig_logname = self.logger.LOG_FILE_NAME
        self.logger.set_log_file( self.filename + '.UEFI.lst' )
        cur_dir = self.cs.helper.getcwd()
        ftypes = []
        inv_filetypes = {v : k for k, v in FILE_TYPE_NAMES.items()}
        if self.filetypes:
            for mtype in self.filetypes:
                if mtype in inv_filetypes.keys():
                    if inv_filetypes[mtype] not in ftypes:
                        ftypes.append(inv_filetypes[mtype])
                    break
        decode_uefi_region(self._uefi, cur_dir, self.filename, self.fwtype, ftypes)
        self.logger.set_log_file( _orig_logname )
Esempio n. 3
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) )
Esempio n. 4
0
def decode(argv):

    if 3 > len(argv):
        print usage
        return

    rom_file = argv[2]

    fwtype = ''
    if 4 == len(argv):
        fwtype = argv[3]

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

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

    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
    #logger().LOG_COMPLETE_FILE_NAME = os.path.join( pth, 'flash_descriptor.log' )
    #parse_spi_flash_descriptor( 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:
        logger().error( "SPI Flash descriptor region is not valid" )
        return False

    _orig_logname = logger().LOG_FILE_NAME

    pth = os.path.join( _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) )
            chipsec.file.write_file( fname, region_data )
            if spi.FLASH_DESCRIPTOR == idx:
                # Decoding Flash Descriptor
                logger().set_log_file( os.path.join( pth, fname + '.log' ) )
                spi_descriptor.parse_spi_flash_descriptor( region_data )
            elif spi.BIOS == idx:
                # Decoding EFI Firmware Volumes
                logger().set_log_file( os.path.join( pth, fname + '.log' ) )
                spi_uefi.decode_uefi_region(_uefi, pth, fname, fwtype)

    logger().set_log_file( _orig_logname )
    logger().log( "[CHIPSEC] (decode) time elapsed %.3f" % (time.time()-t) )
Esempio n. 5
0
def decode(argv):

    if 3 > len(argv):
        print usage
        return

    rom_file = argv[2]

    fwtype = ''
    if 4 == len(argv):
        fwtype = argv[3]

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

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

    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
    #logger().LOG_COMPLETE_FILE_NAME = os.path.join( pth, 'flash_descriptor.log' )
    #parse_spi_flash_descriptor( 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:
        logger().error("SPI Flash descriptor region is not valid")
        return False

    _orig_logname = logger().LOG_FILE_NAME

    pth = os.path.join(chipsec_util._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))
            chipsec.file.write_file(fname, region_data)
            if spi.FLASH_DESCRIPTOR == idx:
                # Decoding Flash Descriptor
                logger().set_log_file(os.path.join(pth, fname + '.log'))
                spi_descriptor.parse_spi_flash_descriptor(region_data)
            elif spi.BIOS == idx:
                # Decoding EFI Firmware Volumes
                logger().set_log_file(os.path.join(pth, fname + '.log'))
                spi_uefi.decode_uefi_region(_uefi, pth, fname, fwtype)

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