Skip to content

Commit

Permalink
more fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Kazhuu committed Apr 1, 2024
1 parent c555976 commit a3e4645
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 24 deletions.
4 changes: 1 addition & 3 deletions ocgraph/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
29 changes: 12 additions & 17 deletions ocgraph/configuration/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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():
Expand All @@ -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()
3 changes: 2 additions & 1 deletion ocgraph/configuration/disassembler/gdb_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
1 change: 0 additions & 1 deletion ocgraph/configuration/logger.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python
# SPDX-License-Identifier: GTDGmbH
# Copyright 2024 by GTD GmbH.
"""Class configuring the OCGraph logging."""
Expand Down
4 changes: 2 additions & 2 deletions ocgraph/interface/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit a3e4645

Please sign in to comment.