Skip to content

Commit

Permalink
refactor parser location
Browse files Browse the repository at this point in the history
  • Loading branch information
clearbluejar committed Sep 11, 2023
1 parent 90d3f04 commit 8e6672b
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 39 deletions.
4 changes: 2 additions & 2 deletions ghidriff/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
from .version_tracking_diff import VersionTrackingDiff
from .simple_diff import SimpleDiff
from .structural_graph_diff import StructualGraphDiff
from .__main__ import get_parser, get_engine_classes
from .parser import get_parser,get_engine_classes

__all__ = [
"GhidraDiffEngine", "SimpleDiff", "StructualGraphDiff", "VersionTrackingDiff", "get_parser", "get_engine_classes"
"GhidraDiffEngine", "SimpleDiff", "StructualGraphDiff", "VersionTrackingDiff", "get_parser","get_engine_classes"
]
40 changes: 3 additions & 37 deletions ghidriff/__main__.py
Original file line number Diff line number Diff line change
@@ -1,50 +1,16 @@
import argparse
from argparse import ArgumentParser
from pathlib import Path
import json
import inspect

import ghidriff
from ghidriff import GhidraDiffEngine


def get_engine_classes() -> dict:
engines = {}

for name, klass in inspect.getmembers(ghidriff, inspect.isclass):
if name.endswith('Diff'):
engines[name] = klass

return engines

def get_parser() -> argparse.ArgumentParser:
"""
Build main ghidriff parser
"""

parser = argparse.ArgumentParser(description='ghidriff - A Command Line Ghidra Binary Diffing Engine',
formatter_class=argparse.ArgumentDefaultsHelpFormatter)

parser.add_argument('old', nargs=1, help="Path to old version of binary '/somewhere/bin.old'")
parser.add_argument('new', action='append', nargs='+',
help="Path to new version of binary '/somewhere/bin.new'. (For multiple new binaries add oldest to newest)")

# setup Engine class options
engines = get_engine_classes()
parser.add_argument('--engine', help='The diff implementation to use.',
default='VersionTrackingDiff', choices=engines.keys())

parser.add_argument('-o', '--output-path', help='Output path for resulting diffs', default='ghidriffs')
parser.add_argument('--summary', help='Add a summary diff if more than two bins are provided', default=False)

return parser

from .parser import get_parser,get_engine_classes

def main():
"""
ghidriff - GhidraDiffEngine module main function
"""

parser = get_parser()
parser : ArgumentParser = get_parser()

GhidraDiffEngine.add_ghidra_args_to_parser(parser)

Expand Down
35 changes: 35 additions & 0 deletions ghidriff/parser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import inspect
import argparse
import ghidriff


def get_engine_classes() -> dict:
engines = {}

for name, klass in inspect.getmembers(ghidriff, inspect.isclass):
if name.endswith('Diff'):
engines[name] = klass

return engines

def get_parser() -> argparse.ArgumentParser:
"""
Build main ghidriff parser
"""

parser = argparse.ArgumentParser(description='ghidriff - A Command Line Ghidra Binary Diffing Engine',
formatter_class=argparse.ArgumentDefaultsHelpFormatter)

parser.add_argument('old', nargs=1, help="Path to old version of binary '/somewhere/bin.old'")
parser.add_argument('new', action='append', nargs='+',
help="Path to new version of binary '/somewhere/bin.new'. (For multiple new binaries add oldest to newest)")

# setup Engine class options
engines = get_engine_classes()
parser.add_argument('--engine', help='The diff implementation to use.',
default='VersionTrackingDiff', choices=engines.keys())

parser.add_argument('-o', '--output-path', help='Output path for resulting diffs', default='ghidriffs')
parser.add_argument('--summary', help='Add a summary diff if more than two bins are provided', default=False)

return parser

0 comments on commit 8e6672b

Please sign in to comment.