cea-sec/miasm

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

Summary

Maintainability
F
5 days
Test Coverage

File pe.py has 643 lines of code (exceeds 250 allowed). Consider refactoring.
Open

from builtins import map
import os
import struct
import logging
from collections import defaultdict
Severity: Major
Found in miasm/jitter/loader/pe.py - About 1 day to fix

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

        def add_export_lib(self, e, name):
            if name in self.created_redirected_imports:
                log.error("%r has previously been created due to redirect\
                imports due to %r. Change the loading order.",
                          name, self.created_redirected_imports[name])
    Severity: Minor
    Found in miasm/jitter/loader/pe.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 vm_load_pe_and_dependencies has a Cognitive Complexity of 34 (exceeds 5 allowed). Consider refactoring.
    Open

    def vm_load_pe_and_dependencies(vm, fname, name2module, runtime_lib,
                                    lib_path_base, **kwargs):
        """Load a binary and all its dependencies. Returns a dictionary containing
        the association between binaries names and it's pe object
    
    
    Severity: Minor
    Found in miasm/jitter/loader/pe.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 vm_load_pe has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring.
    Open

    def vm_load_pe(vm, fdata, align_s=True, load_hdr=True, name="", winobjs=None, **kargs):
        """Load a PE in memory (@vm) from a data buffer @fdata
        @vm: VmMngr instance
        @fdata: data buffer to parse
        @align_s: (optional) If False, keep gaps between section
    Severity: Minor
    Found in miasm/jitter/loader/pe.py - About 4 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 vm2pe has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
    Open

    def vm2pe(myjit, fname, libs=None, e_orig=None,
              min_addr=None, max_addr=None,
              min_section_offset=0x1000, img_base=None,
              added_funcs=None, **kwargs):
        if e_orig:
    Severity: Minor
    Found in miasm/jitter/loader/pe.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 gen_new_lib has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
    Open

        def gen_new_lib(self, target_pe, filter_import=lambda peobj, ad: True, **kwargs):
            """Gen a new DirImport description
            @target_pe: PE instance
            @filter_import: (boolean f(pe, address)) restrict addresses to keep
            """
    Severity: Minor
    Found in miasm/jitter/loader/pe.py - About 2 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 transition has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

        def transition(self, data):
            if self.state == self.STATE_SEARCH:
                if data in self.func_addrs:
                    self.state = self.STATE_FUNC_FOUND
                    func_addr = struct.unpack(self.ptrtype, data)[0]
    Severity: Minor
    Found in miasm/jitter/loader/pe.py - About 1 hr 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 recover_import has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

        def recover_import(self, update_libs=True, align_hypothesis=False):
            """
            Launch the import recovery routine.
            @update_libs: if set (default), update `libs` object with founded addresses
            @align_hypothesis: if not set (default), do not consider import
    Severity: Minor
    Found in miasm/jitter/loader/pe.py - About 1 hr 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 vm2pe has 10 arguments (exceeds 4 allowed). Consider refactoring.
    Open

    def vm2pe(myjit, fname, libs=None, e_orig=None,
    Severity: Major
    Found in miasm/jitter/loader/pe.py - About 1 hr to fix

      Function vm_load_pe has 7 arguments (exceeds 4 allowed). Consider refactoring.
      Open

      def vm_load_pe(vm, fdata, align_s=True, load_hdr=True, name="", winobjs=None, **kargs):
      Severity: Major
      Found in miasm/jitter/loader/pe.py - About 50 mins to fix

        Function get_pe_dependencies has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

        def get_pe_dependencies(pe_obj):
            """Collect the shared libraries upon which this PE depends.
        
            @pe_obj: pe object
            Returns a set of strings of DLL names.
        Severity: Minor
        Found in miasm/jitter/loader/pe.py - About 45 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 get_import_address_pe has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

        def get_import_address_pe(e):
            """Compute the addresses of imported symbols.
            @e: pe object
            Returns a dict mapping from tuple (dll name string, symbol name string) to set of virtual addresses.
        
        
        Severity: Minor
        Found in miasm/jitter/loader/pe.py - About 45 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_pe_and_dependencies has 6 arguments (exceeds 4 allowed). Consider refactoring.
        Open

        def vm_load_pe_and_dependencies(vm, fname, name2module, runtime_lib,
        Severity: Minor
        Found in miasm/jitter/loader/pe.py - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                                  for tmp_func, tmp_addr in ads:
                                      if tmp_func == exp_fname:
                                          found = tmp_addr
                                  assert found is not None
          Severity: Major
          Found in miasm/jitter/loader/pe.py - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                                    if not exp_dname in self.name2off:
                                        self.created_redirected_imports.setdefault(
                                            exp_dname, set()).add(name)
            
                                    # Ensure import entry is created
            Severity: Major
            Found in miasm/jitter/loader/pe.py - About 45 mins to fix

              Avoid deeply nested control flow statements.
              Open

                                      if isinstance(exp_fname, str):
                                          exp_fname = bytes(ord(c) for c in exp_fname)
                                      found = None
              Severity: Major
              Found in miasm/jitter/loader/pe.py - About 45 mins to fix

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

                def vm_fix_imports_pe_libs(lib_imgs, libs, lib_path_base,
                Severity: Minor
                Found in miasm/jitter/loader/pe.py - About 35 mins to fix

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

                  def vm_load_pe_lib(vm, fname_in, libs, lib_path_base, **kargs):
                  Severity: Minor
                  Found in miasm/jitter/loader/pe.py - About 35 mins to fix

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

                    def vm_load_pe_libs(vm, libs_name, libs, lib_path_base, **kargs):
                    Severity: Minor
                    Found in miasm/jitter/loader/pe.py - About 35 mins to fix

                      Function preload_pe has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                      Open

                      def preload_pe(vm, e, runtime_lib, patch_vm_imp=True):
                          fa = get_import_address_pe(e)
                          dyn_funcs = {}
                          # log.debug('imported funcs: %s' % fa)
                          for (libname, libfunc), ads in viewitems(fa):
                      Severity: Minor
                      Found in miasm/jitter/loader/pe.py - About 25 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

                      There are no issues that match your filters.

                      Category
                      Status