File asmblock.py
has 1109 lines of code (exceeds 250 allowed). Consider refactoring. Open
#-*- coding:utf-8 -*-
from builtins import map
from builtins import range
import logging
Function _dis_block
has a Cognitive Complexity of 60 (exceeds 5 allowed). Consider refactoring. Open
def _dis_block(self, offset, job_done=None):
"""Disassemble the block at offset @offset
@job_done: a set of already disassembled addresses
Return the created AsmBlock and future offsets to disassemble
"""
- Read upRead up
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_splitting
has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring. Open
def apply_splitting(self, blocks):
"""Consider @blocks' bto destinations and split block in @blocks if one
of these destinations jumps in the middle of this block. In order to
work, they must be only one block in @self per loc_key in
- Read upRead up
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 guess_blocks_size
has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring. Open
def guess_blocks_size(self, mnemo):
"""Asm and compute max block size
Add a 'size' and 'max_size' attribute on each block
@mnemo: metamn instance"""
for block in self.blocks:
- Read upRead up
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 asmblock_final
has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring. Open
def asmblock_final(mnemo, asmcfg, blockChains, conservative=False):
"""Resolve and assemble @blockChains until fixed point is
reached"""
log_asmblock.debug("asmbloc_final")
- Read upRead up
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
AsmCFG
has 27 functions (exceeds 20 allowed). Consider refactoring. Open
class AsmCFG(DiGraph):
"""Directed graph standing for a ASM Control Flow Graph with:
- nodes: AsmBlock
- edges: constraints between blocks, synchronized with AsmBlock's "bto"
Function assemble_block
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
def assemble_block(mnemo, block, conservative=False):
"""Assemble a @block
@conservative: (optional) use original bytes when possible
"""
offset_i = 0
- Read upRead up
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 rebuild_edges
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
def rebuild_edges(self):
"""Consider blocks '.bto' and rebuild edges according to them, ie:
- update constraint type
- add missing edge
- remove no more used edge
- Read upRead up
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_block_loc_keys
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
def get_block_loc_keys(block):
"""Extract loc_keys used by @block"""
symbols = set()
for instr in block.lines:
if isinstance(instr, AsmRaw):
- Read upRead up
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 group_constrained_blocks
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
def group_constrained_blocks(asmcfg):
"""
Return the BlockChains list built from grouped blocks in asmcfg linked by
asm_constraint_next
@asmcfg: an AsmCfg instance
- Read upRead up
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 _merge_blocks
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
def _merge_blocks(dg, graph):
"""Graph simplification merging AsmBlock with one and only one son with this
son if this son has one and only one parent"""
# Blocks to ignore, because they have been removed from the graph
- Read upRead up
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 resolve_symbol
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
def resolve_symbol(blockChains, loc_db, dst_interval=None):
"""Place @blockChains in the @dst_interval"""
log_asmblock.info('resolve_symbol')
if dst_interval is None:
- Read upRead up
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_bad_blocks_predecessors
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
def get_bad_blocks_predecessors(self, strict=False):
"""Iterator on loc_keys with an AsmBlockBad destination
@strict: (optional) if set, return loc_key with only bad
successors
"""
- Read upRead up
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 dis_multiblock
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def dis_multiblock(self, offset, blocks=None, job_done=None):
"""Disassemble every block reachable from @offset regarding
specific disasmEngine conditions
Return an AsmCFG instance containing disassembled blocks
@offset: starting offset
- Read upRead up
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 asm_resolve_final
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def asm_resolve_final(mnemo, asmcfg, dst_interval=None):
"""Resolve and assemble @asmcfg into interval
@dst_interval"""
asmcfg.sanity_check()
- Read upRead up
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 conservative_asm
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def conservative_asm(mnemo, instr, symbols, conservative):
"""
Asm instruction;
Try to keep original instruction bytes if it exists
"""
- Read upRead up
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 sanity_check
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def sanity_check(self):
"""Do sanity checks on blocks' constraints:
* no pendings
* no multiple next constraint to same block
* no next constraint to self
- Read upRead up
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 add_block
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def add_block(self, block):
"""
Add the block @block to the current instance, if it is not already in
@block: AsmBlock instance
- Read upRead up
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
Avoid deeply nested control flow statements. Open
if len(instr.raw) == 0:
l = 0
else:
l = (instr.raw[0].size // 8) * len(instr.raw)
elif isinstance(instr.raw, str):
Function __init__
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
def __init__(self, loc_db, loc_key=None, alignment=1, errno=ERROR_UNKNOWN, *args, **kwargs):
Function to_string
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def to_string(self):
out = []
out.append(self.loc_db.pretty_str(self.loc_key))
for instr in self.lines:
- Read upRead up
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 __init__
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def __init__(self, arch, attrib, bin_stream, loc_db, **kwargs):
Function get_flow_instr
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def get_flow_instr(self):
if not self.lines:
return None
for i in range(-1, -1 - self.lines[0].delayslot - 1, -1):
if not 0 <= i < len(self.lines):
- Read upRead up
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 node2lines
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def node2lines(self, node):
loc_key_name = self.loc_db.pretty_str(node)
yield self.DotCellDescription(text=loc_key_name,
attr={'align': 'center',
'colspan': 2,
- Read upRead up
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 _set_pinned_block_idx
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def _set_pinned_block_idx(self):
self.pinned_block_idx = None
for i, block in enumerate(self.blocks):
loc_key = block.loc_key
if self.loc_db.get_location_offset(loc_key) is not None:
- Read upRead up
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
Similar blocks of code found in 2 locations. Consider refactoring. Open
if self.blocs_wd is not None and bloc_cpt > self.blocs_wd:
log_asmblock.debug("blocks watchdog reached at %X", int(offset))
break
- Read upRead up
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 40.
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
if self.lines_wd is not None and lines_cpt > self.lines_wd:
log_asmblock.debug("lines watchdog reached at %X", int(offset))
break
- Read upRead up
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 40.
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76