Skip to content

Sourcery refactored master branch#1

Open
sourcery-ai[bot] wants to merge 1 commit intomasterfrom
sourcery/master
Open

Sourcery refactored master branch#1
sourcery-ai[bot] wants to merge 1 commit intomasterfrom
sourcery/master

Conversation

@sourcery-ai
Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot commented Oct 10, 2023

Branch master refactored by Sourcery.

If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.

See our documentation here.

Run Sourcery locally

Reduce the feedback loop during development by using the Sourcery editor plugin:

Review changes via command line

To manually merge these changes, make sure you're on the master branch, then run:

git fetch origin sourcery/master
git merge --ff-only FETCH_HEAD
git reset HEAD^

Help us improve this pull request!

@sourcery-ai sourcery-ai Bot requested a review from ChairGraveyard October 10, 2023 15:49
Copy link
Copy Markdown
Author

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Due to GitHub API limits, only the first 60 comments can be shown.

Comment thread modules/install.py
Comment on lines -14 to +32
print ("Usage: %s <IDA install path> [--install | --remove]" % sys.argv[0])
print(f"Usage: {sys.argv[0]} <IDA install path> [--install | --remove]")
sys.exit(1)

source_path = os.path.dirname(os.path.realpath(__file__))

if install:
print ("Installing python modules from %s to %s..." % (source_path, py_module_path))
print(f"Installing python modules from {source_path} to {py_module_path}...")
else:
print ("Removing python modules from %s..." % py_module_path)
print(f"Removing python modules from {py_module_path}...")

for py_module in next(os.walk('.'))[1]:
src = os.path.join(source_path, py_module, py_module + '.py')
dst = os.path.join(py_module_path, py_module + '.py')
src = os.path.join(source_path, py_module, f'{py_module}.py')
dst = os.path.join(py_module_path, f'{py_module}.py')

if install:
print ("Installing %s..." % py_module)
print(f"Installing {py_module}...")
shutil.copyfile(src, dst)
else:
print ("Removing %s..." % py_module)
print(f"Removing {py_module}...")
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 14-32 refactored with the following changes:

Comment thread plugins/install.py
Comment on lines -20 to +24
plugins = []
for plugin in os.listdir(source_path):
if not os.path.isdir(os.path.join(source_path, plugin)):
continue
plugins.append(plugin)
return plugins
return [
plugin
for plugin in os.listdir(source_path)
if os.path.isdir(os.path.join(source_path, plugin))
]
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function get_plugin_directories refactored with the following changes:

Comment thread plugins/install.py
Comment on lines -37 to +52
print("Installing plugins from %s to %s..." % (source_path, install_path))
print(f"Installing plugins from {source_path} to {install_path}...")

plugins = get_plugin_directories(source_path)
for plugin in plugins:
print("Installing %s..." % plugin, end=''),
(print(f"Installing {plugin}...", end=''), )
if 'shims' in plugin:
shims_dir = os.path.join(install_path, 'shims')
try:
os.mkdir(shims_dir)
except OSError:
pass
src = os.path.join(source_path, plugin, 'ida_' + plugin + '.py')
dst = os.path.join(shims_dir, 'ida_' + plugin + '.py')
src = os.path.join(source_path, plugin, f'ida_{plugin}.py')
dst = os.path.join(shims_dir, f'ida_{plugin}.py')
open(os.path.join(shims_dir, '__init__.py'), 'a').close()
else:
src = os.path.join(source_path, plugin, plugin + '.py')
dst = os.path.join(install_path, plugin + '.py')
src = os.path.join(source_path, plugin, f'{plugin}.py')
dst = os.path.join(install_path, f'{plugin}.py')
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function install_plugins refactored with the following changes:

Comment thread plugins/install.py
Comment on lines -68 to +81
print("Removing plugins from %s..." % install_path)
print(f"Removing plugins from {install_path}...")

plugins = get_plugin_directories(source_path)
for plugin in plugins:
print("Removing %s..." % plugin, end='')
print(f"Removing {plugin}...", end='')
try:
if 'shims' in plugin:
dst = os.path.join(install_path, 'shims', 'ida_' +
plugin + '.py')
shutil.rmtree(os.path.dirname(dst))
else:
dst = os.path.join(install_path, plugin + '.py')
dst = os.path.join(install_path, f'{plugin}.py')
os.remove(dst)
except OSError:
print('%s was not installed' % plugin)
print(f'{plugin} was not installed')
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function remove_plugins refactored with the following changes:

Comment thread plugins/install.py
Comment on lines -95 to +100

parser.add_argument('-d', '--directory', help='IDA installation directory.')

args = parser.parse_args()

if not os.path.exists(args.directory):
raise Exception('IDA installation, %s, does not exist.' %
args.directory)
raise Exception(f'IDA installation, {args.directory}, does not exist.')
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 95-102 refactored with the following changes:

Comment on lines -269 to +265
if self.history_index < 0:
self.history_index = 0
self.history_index = max(self.history_index, 0)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function AlleyCatGraphHistory.undo refactored with the following changes:

Comment on lines -319 to +321
else:
self.cmd_undo = self.AddCommand("Undo", "")
self.cmd_redo = self.AddCommand("Redo", "")
self.cmd_reset = self.AddCommand("Reset graph", "")
self.cmd_exclude = self.AddCommand("Exclude node", "")
self.cmd_include = self.AddCommand("Include node", "")
self.cmd_unhighlight = self.AddCommand(
"Temporarily un-highlight all paths", "")
return True
self.cmd_undo = self.AddCommand("Undo", "")
self.cmd_redo = self.AddCommand("Redo", "")
self.cmd_reset = self.AddCommand("Reset graph", "")
self.cmd_exclude = self.AddCommand("Exclude node", "")
self.cmd_include = self.AddCommand("Include node", "")
self.cmd_unhighlight = self.AddCommand(
"Temporarily un-highlight all paths", "")
return True
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function AlleyCatGraph.Show refactored with the following changes:

Comment on lines -457 to +460
for xref in idautils.XrefsTo(edge_node_ea):
# Is the specified node_id the source of this xref?
if self.match_xref_source(xref, node_ea):
xref_locations.append((xref.frm, edge_node_ea))

xref_locations.extend(
(xref.frm, edge_node_ea)
for xref in idautils.XrefsTo(edge_node_ea)
if self.match_xref_source(xref, node_ea)
)
if xref_locations:
xref_locations.sort()

print("")
print("Path Xrefs from %s:" % self[node_id])
print(f"Path Xrefs from {self[node_id]}:")
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function AlleyCatGraph.OnDblClick refactored with the following changes:

This removes the following comments ( why? ):

# Is the specified node_id the source of this xref?

Comment on lines -532 to +527
if not name:
name = "0x%X" % ea
if not name:
name = "0x%X" % ea
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function AlleyCatGraph.get_name_by_ea refactored with the following changes:

Comment on lines -537 to +531
# Colorizes an entire code block
func = idaapi.get_func(ea)
if func:
if func := idaapi.get_func(ea):
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function AlleyCatGraph.colorize_node refactored with the following changes:

This removes the following comments ( why? ):

# Colorizes an entire code block

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants