Пример #1
0
    def list_EFI_variables(self):   
                
        off = 0
        buf = list()
        hdr = 0
        attr = 0
        variables = dict()

        status_dict = { 0:"EFI_SUCCESS", 1:"EFI_LOAD_ERROR", 2:"EFI_INVALID_PARAMETER", 3:"EFI_UNSUPPORTED", 4:"EFI_BAD_BUFFER_SIZE", 5:"EFI_BUFFER_TOO_SMALL", 6:"EFI_NOT_READY", 7:"EFI_DEVICE_ERROR", 8:"EFI_WRITE_PROTECTED", 9:"EFI_OUT_OF_RESOURCES", 14:"EFI_NOT_FOUND", 26:"EFI_SECURITY_VIOLATION" }
        
        name = '\0'*200
        
        randguid = uuid.uuid4()
        
        (status, name, size, guidbytes) = edk2.GetNextVariableName(200, unicode(name), randguid.bytes)     
        
        if status == 5:
            if logger().VERBOSE: logger().log("size was too small increasing to %d" % size)
            name = '\0'*size
            (status, name, size, guidbytes) = edk2.GetNextVariableName(size, unicode(name), randguid.bytes)

        
#        while status != 14:
        while status == 0:
            guid =  uuid.UUID(bytes=guidbytes)  
            name = name.encode('ascii','ignore')
            (status, data, attr) = self.get_EFI_variable_full(name, guid.hex)
            
            if logger().VERBOSE: logger().log("%d: Found variable %s" % (len(variables), name))

            var = (off, buf, hdr, data, guid, attr)
            if name in variables: 
                if logger().VERBOSE: logger().log("WARNING: found a second instance of name %s." % name)

            else: variables[name] = []
            if data != "" or guid != 0 or attr != 0:
                variables[name].append(var)

            (status, name, size, guidbytes) = edk2.GetNextVariableName(200, unicode(name), guid.bytes)
            if logger().VERBOSE: logger().log("returned %s. status is %s" % (name, status_dict[status]))

            if status == 5:
                if logger().VERBOSE: logger().log("size was too small increasing to %d" % size)
                (status, name, size, guidbytes) = edk2.GetNextVariableName(size, unicode(name), guid.bytes)
        return variables        
Пример #2
0
    def list_EFI_variables(self):

        off = 0
        buf = list()
        hdr = 0
        attr = 0
        var_list = list()
        variables = dict()

        status_dict = {
            0: "EFI_SUCCESS",
            1: "EFI_LOAD_ERROR",
            2: "EFI_INVALID_PARAMETER",
            3: "EFI_UNSUPPORTED",
            4: "EFI_BAD_BUFFER_SIZE",
            5: "EFI_BUFFER_TOO_SMALL",
            6: "EFI_NOT_READY",
            7: "EFI_DEVICE_ERROR",
            8: "EFI_WRITE_PROTECTED",
            9: "EFI_OUT_OF_RESOURCES",
            14: "EFI_NOT_FOUND",
            26: "EFI_SECURITY_VIOLATION"
        }

        namestr = ''
        size = 200
        guidstr = str(uuid.uuid4())

        search_complete = False
        while not search_complete:
            namestr += '\x00'
            name = namestr.encode('utf-16-le')
            guid = uuid.UUID(guidstr).bytes_le
            (status, namestr, size,
             guidstr) = edk2.GetNextVariableName(size, name, guid)

            if status == 5:
                if logger().DEBUG:
                    logger().log(
                        "[helper] EFI Variable name size was too small increasing to {:d}"
                        .format(size))
                (status, namestr, size,
                 guidstr) = edk2.GetNextVariableName(size, name, guid)

            if logger().DEBUG:
                logger().log("[helper] Returned {}. Status is {}".format(
                    name, status_dict[status]))

            if status:
                search_complete = True
            else:
                if (namestr, guidstr) in var_list:
                    continue
                else:
                    var_list.append((namestr, guidstr))

                if logger().DEBUG:
                    logger().log("[helper] Found variable '{}' - [{}]".format(
                        name, guidstr))

        for (name, guidstr) in var_list:
            (status, data, attr) = self.get_EFI_variable_full(name, guidstr)

            if status:
                logger().verbose_log(
                    '[helper] Error reading variable {}.  Status = {:d} - {}'.
                    format(name, status, status_dict[status]))

            var_data = (off, buf, hdr, data, guidstr, attr)

            if name in variables:
                logger().verbose_log(
                    '[helper] Duplicate variable name {} - {}'.format(
                        name, guidstr))
                continue
            else:
                variables[name] = []

            if data != '' or guidstr != '' or attr != 0:
                variables[name].append(var_data)

        return variables