cea-sec/miasm

View on GitHub
miasm/jitter/loader/elf.py

Summary

Maintainability
D
2 days
Test Coverage

Function fill_loc_db_with_symbols has a Cognitive Complexity of 58 (exceeds 5 allowed). Consider refactoring.
Open

def fill_loc_db_with_symbols(elf, loc_db, base_addr=0):
    """Parse the miasm.loader's ELF @elf to extract symbols, and fill the LocationDB
    instance @loc_db with parsed symbols.

    The ELF is considered mapped at @base_addr
Severity: Minor
Found in miasm/jitter/loader/elf.py - About 1 day 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 vm_load_elf has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
Open

def vm_load_elf(vm, fdata, name="", base_addr=0, loc_db=None, apply_reloc=False,
                **kargs):
    """
    Very dirty elf loader
    TODO XXX: implement real loader
Severity: Minor
Found in miasm/jitter/loader/elf.py - About 3 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 apply_reloc_x86 has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
Open

def apply_reloc_x86(elf, vm, section, base_addr, loc_db):
    """Apply relocation for x86 ELF contained in the section @section
    @elf: miasm.loader's ELF instance
    @vm: VmMngr instance
    @section: elf's section containing relocation to perform
Severity: Minor
Found in miasm/jitter/loader/elf.py - About 3 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

File elf.py has 270 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import struct
from collections import defaultdict

from future.utils import viewitems

Severity: Minor
Found in miasm/jitter/loader/elf.py - About 2 hrs to fix

    Function preload_elf has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

    def preload_elf(vm, e, runtime_lib, patch_vm_imp=True, loc_db=None):
        # XXX quick hack
        fa = get_import_address_elf(e)
        dyn_funcs = {}
        for (libname, libfunc), ads in viewitems(fa):
    Severity: Minor
    Found in miasm/jitter/loader/elf.py - About 55 mins 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 vm_load_elf has 7 arguments (exceeds 4 allowed). Consider refactoring.
    Open

    def vm_load_elf(vm, fdata, name="", base_addr=0, loc_db=None, apply_reloc=False,
    Severity: Major
    Found in miasm/jitter/loader/elf.py - About 50 mins to fix

      Function preload_elf has 5 arguments (exceeds 4 allowed). Consider refactoring.
      Open

      def preload_elf(vm, e, runtime_lib, patch_vm_imp=True, loc_db=None):
      Severity: Minor
      Found in miasm/jitter/loader/elf.py - About 35 mins to fix

        Function apply_reloc_x86 has 5 arguments (exceeds 4 allowed). Consider refactoring.
        Open

        def apply_reloc_x86(elf, vm, section, base_addr, loc_db):
        Severity: Minor
        Found in miasm/jitter/loader/elf.py - About 35 mins to fix

          Similar blocks of code found in 2 locations. Consider refactoring.
          Open

                  if (elf.size, reloc.type) in [
                          (64, elf_csts.R_X86_64_RELATIVE),
                          (64, elf_csts.R_X86_64_IRELATIVE),
                          (32, elf_csts.R_386_RELATIVE),
                          (32, elf_csts.R_386_IRELATIVE),
          Severity: Major
          Found in miasm/jitter/loader/elf.py and 1 other location - About 1 hr to fix
          miasm/jitter/loader/elf.py on lines 228..232

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 39.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Similar blocks of code found in 2 locations. Consider refactoring.
          Open

                  elif (elf.size, reloc.type) in [
                          (64, elf_csts.R_X86_64_GLOB_DAT),
                          (64, elf_csts.R_X86_64_JUMP_SLOT),
                          (32, elf_csts.R_386_JMP_SLOT),
                          (32, elf_csts.R_386_GLOB_DAT),
          Severity: Major
          Found in miasm/jitter/loader/elf.py and 1 other location - About 1 hr to fix
          miasm/jitter/loader/elf.py on lines 203..207

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 39.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          There are no issues that match your filters.

          Category
          Status