From a3e4645b52241e913e01af4b2020bcaafeb662f6 Mon Sep 17 00:00:00 2001 From: Mauri Mustonen Date: Mon, 1 Apr 2024 16:23:35 +0300 Subject: [PATCH] more fixes --- ocgraph/__main__.py | 4 +-- ocgraph/configuration/configuration.py | 29 ++++++++----------- .../configuration/disassembler/gdb_default.py | 3 +- ocgraph/configuration/logger.py | 1 - ocgraph/interface/analyzer.py | 4 +-- 5 files changed, 17 insertions(+), 24 deletions(-) mode change 100755 => 100644 ocgraph/configuration/logger.py diff --git a/ocgraph/__main__.py b/ocgraph/__main__.py index b53afcb..fee92c2 100755 --- a/ocgraph/__main__.py +++ b/ocgraph/__main__.py @@ -64,9 +64,7 @@ def main(): args = parser.parse_args() # Create configuration - config = OcGraphConfiguration( - disassembler=args.diss, arch=args.arch, logging_preset=args.logger - ) + config = OcGraphConfiguration(disassembler=args.diss, arch=args.arch, preset=args.logger) lines = read_lines(args.file) diff --git a/ocgraph/configuration/configuration.py b/ocgraph/configuration/configuration.py index b01c9d3..34630ef 100755 --- a/ocgraph/configuration/configuration.py +++ b/ocgraph/configuration/configuration.py @@ -2,7 +2,7 @@ # SPDX-License-Identifier: GTDGmbH """Module for configuration of the ocgraph package.""" -from .logger import OcctreLogger, preset_logging +from .logger import OCGraphLogger, logging_preset from .architecture.architecture import Architecture from .architecture.x86 import X86Architecture @@ -51,21 +51,25 @@ "architecture": PpcArchitecture(), }, } - # fmt: on class OcGraphConfiguration: """Implement configuration presets for the ASM2CFG tool.""" - def __init__( - self, arch: str = "sparc", disassembler: str = "OBJDUMP", logging_preset="default" - ): + logger: OCGraphLogger + """Logging mechanism for module""" + architecture: Architecture + """Target architecture instance""" + disassembler: Disassembler + """Target disassembler tool like OBJDump, GDB, ...""" + + def __init__(self, arch: str = "sparc", disassembler: str = "OBJDUMP", preset="default"): if architecture_option.get(arch) is None: raise NotImplementedError("Architecture option not supported!") if disassembler_option.get(disassembler) is None: raise NotImplementedError("Disassembler option not supported!") - if preset_logging.get(logging_preset) is None: + if logging_preset.get(preset) is None: raise NotImplementedError("Logging preset not supported!") # load module preset @@ -74,7 +78,7 @@ def __init__( self.__dict__ = _preset # configure logging - self.logger = OCGraphLogger("OcGraph", logging_preset, "asm2cfg.log") + self.logger = OCGraphLogger("OcGraph", preset, "asm2cfg.log") @staticmethod def architectures(): @@ -89,13 +93,4 @@ def disassemblers(): @staticmethod def loggers(): """Return all available disassemblers options""" - return preset_logging.keys() - - logger: logging.Logger = logging.Logger("OcGraph") - """Logging mechanism for module""" - - architecture: Architecture - """Target architecture instance""" - - disassembler: Disassembler - """Target disassembler tool like OBJDump, GDB, ...""" + return logging_preset.keys() diff --git a/ocgraph/configuration/disassembler/gdb_default.py b/ocgraph/configuration/disassembler/gdb_default.py index 7d54096..beecbbf 100755 --- a/ocgraph/configuration/disassembler/gdb_default.py +++ b/ocgraph/configuration/disassembler/gdb_default.py @@ -214,4 +214,5 @@ def parse_line(self, line: str, lineno, function_name: str) -> Instruction | Non ) def parse_jump_target(self, str_input: str) -> int | None: - return int(re.search(rf"{HEX_LONG_PATTERN}", str_input)[0], 16) + # TODO: Fix str_input indexing because it's a list. + return int(re.search(rf"{HEX_LONG_PATTERN}", str_input[0])[0], 16) diff --git a/ocgraph/configuration/logger.py b/ocgraph/configuration/logger.py old mode 100755 new mode 100644 index b68874b..badab2a --- a/ocgraph/configuration/logger.py +++ b/ocgraph/configuration/logger.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python # SPDX-License-Identifier: GTDGmbH # Copyright 2024 by GTD GmbH. """Class configuring the OCGraph logging.""" diff --git a/ocgraph/interface/analyzer.py b/ocgraph/interface/analyzer.py index 7d436b7..2427109 100755 --- a/ocgraph/interface/analyzer.py +++ b/ocgraph/interface/analyzer.py @@ -125,11 +125,11 @@ def _create_basic_blocks(self) -> None: prev_branch_block: BasicBlock | None = None # block completion flag (introduced for SPARC pipeline) - block_completion: int = 0 + block_completion: int | None = 0 for instruction in self.instructions: # if block completion is in progress - if block_completion > 0: + if block_completion is not None and block_completion > 0: block_completion -= 1 if block_completion > 0: self.basic_blocks[curr_basic_block.key].add_instruction(instruction)