hackedteam/vector-edk

View on GitHub
vector-uefi/fd/tool/chipsec/hal/spi_uefi.py

Summary

Maintainability
D
2 days
Test Coverage

Function parse_uefi_section has a Cognitive Complexity of 46 (exceeds 5 allowed). Consider refactoring.
Open

def parse_uefi_section( _uefi, data, Size, offset, polarity, parent_offset, parent_path, decode_log_path ):
   sec_offset, next_sec_offset, SecName, SecType, SecBody, SecHeaderSize = NextFwFileSection(data, Size, offset, polarity)
   secn = 0
   ui_string = None
   efi_file = None
Severity: Minor
Found in vector-uefi/fd/tool/chipsec/hal/spi_uefi.py - About 7 hrs to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function parse_uefi_region has a Cognitive Complexity of 37 (exceeds 5 allowed). Consider refactoring.
Open

def parse_uefi_region( _uefi, data, uefi_region_path ):
    voln = 0
    FvOffset, FsGuid, FvLength, FvAttributes, FvHeaderLength, FvChecksum, ExtHeaderOffset, FvImage, CalcSum = NextFwVolume(data)
    while FvOffset != None:
        decode_log_path = os.path.join(uefi_region_path, "efi_firmware_volumes.log")
Severity: Minor
Found in vector-uefi/fd/tool/chipsec/hal/spi_uefi.py - About 5 hrs to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function save_file_info has 9 arguments (exceeds 4 allowed). Consider refactoring.
Open

def save_file_info( cur_offset, Name, Type, Attributes, State, Checksum, Size, file_path, fCalcSum ):
Severity: Major
Found in vector-uefi/fd/tool/chipsec/hal/spi_uefi.py - About 1 hr to fix

    Function save_vol_info has 9 arguments (exceeds 4 allowed). Consider refactoring.
    Open

    def save_vol_info( FvOffset, FsGuid, FvLength, FvAttributes, FvHeaderLength, FvChecksum, ExtHeaderOffset, file_path, CalcSum ):
    Severity: Major
    Found in vector-uefi/fd/tool/chipsec/hal/spi_uefi.py - About 1 hr to fix

      Function parse_uefi_section has 8 arguments (exceeds 4 allowed). Consider refactoring.
      Open

      def parse_uefi_section( _uefi, data, Size, offset, polarity, parent_offset, parent_path, decode_log_path ):
      Severity: Major
      Found in vector-uefi/fd/tool/chipsec/hal/spi_uefi.py - About 1 hr to fix

        Avoid deeply nested control flow statements.
        Open

                       if (sguid == EFI_CRC32_GUIDED_SECTION_EXTRACTION_PROTOCOL_GUID):
                          parse_uefi_section(_uefi, SecBody[DataOffset:], Size - DataOffset, 0, polarity, 0, section_dir_path, decode_log_path)
                       #else:
                       #   write_file( os.path.join(section_dir_path, "%s-%04X" % (sguid, Attributes)), SecBody[DataOffset:] )
                       pass
        Severity: Major
        Found in vector-uefi/fd/tool/chipsec/hal/spi_uefi.py - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                         if decompressed:
                            parse_uefi_section(_uefi, decompressed, len(decompressed), 0, polarity, 0, section_dir_path, decode_log_path)
                            pass
                      elif (SecType == EFI_SECTION_GUID_DEFINED):
          Severity: Major
          Found in vector-uefi/fd/tool/chipsec/hal/spi_uefi.py - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                             if os.path.exists( file_path ):
                                file_path = file_path + ("_%08X" % cur_offset)
                             write_file( file_path, FileImage )
            Severity: Major
            Found in vector-uefi/fd/tool/chipsec/hal/spi_uefi.py - About 45 mins to fix

              Avoid deeply nested control flow statements.
              Open

                               if Type in FILE_TYPE_NAMES.keys():
                                  file_type_str = FILE_TYPE_NAMES[Type]
                               file_path = os.path.join( volume_path, "%s.%s-%02X" % (Name, file_type_str, Type))
              Severity: Major
              Found in vector-uefi/fd/tool/chipsec/hal/spi_uefi.py - About 45 mins to fix

                Avoid deeply nested control flow statements.
                Open

                               if (ui_string[-4:] != '.efi'): ui_string = "%s.efi" % ui_string
                               #print ui_string
                Severity: Major
                Found in vector-uefi/fd/tool/chipsec/hal/spi_uefi.py - About 45 mins to fix

                  Avoid deeply nested control flow statements.
                  Open

                                 if efi_file != None:
                                    os.rename(os.path.join(parent_path, efi_file), os.path.join(parent_path, ui_string))
                                    efi_file = None
                           if (SecType in (EFI_SECTION_COMPRESSION, EFI_SECTION_GUID_DEFINED, EFI_SECTION_FIRMWARE_VOLUME_IMAGE)):
                  Severity: Major
                  Found in vector-uefi/fd/tool/chipsec/hal/spi_uefi.py - About 45 mins to fix

                    Avoid deeply nested control flow statements.
                    Open

                                     if (Type not in (EFI_FV_FILETYPE_ALL, EFI_FV_FILETYPE_RAW, EFI_FV_FILETYPE_FFS_PAD)):
                                        os.makedirs( file_dir_path )
                                        parse_uefi_section(_uefi, FileImage, Size, HeaderSize, polarity, FvOffset + cur_offset, file_dir_path, decode_log_path)
                                     elif (Type == EFI_FV_FILETYPE_RAW):
                                        if ((Name == NVAR_NVRAM_FS_FILE) and UD):
                    Severity: Major
                    Found in vector-uefi/fd/tool/chipsec/hal/spi_uefi.py - About 45 mins to fix

                      There are no issues that match your filters.

                      Category
                      Status