Skip to content
This repository has been archived by the owner on Feb 19, 2021. It is now read-only.

Commit

Permalink
Check code style w/ flake8
Browse files Browse the repository at this point in the history
  • Loading branch information
NeatMonster committed Aug 31, 2018
1 parent 7dad355 commit 62102bc
Show file tree
Hide file tree
Showing 23 changed files with 772 additions and 739 deletions.
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ language: python
python:
- "3.6"
install:
- pip install black
- pip install black flake8 flake8-import-order pep8-naming
script:
- black -l 79 --check idarling_plugin.py idarling_server.py idarling/**/*.py
- black -l 79 --check **/*.py
- flake8 --ignore=W503 **/*.py --import-order-style=google
122 changes: 61 additions & 61 deletions easy_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,89 +20,89 @@
import ida_loader

# Allow the user to override the download URL
if 'URL' not in locals():
URL = 'https://github.com/IDArlingTeam/IDArling/archive/master.zip'
if "URL" not in locals():
URL = "https://github.com/IDArlingTeam/IDArling/archive/master.zip"

print('[*] Installing IDArling...')
if os.name == 'nt':
print("[*] Installing IDArling...")
if os.name == "nt":
# Install into the user directory on Windows
userDir = ida_diskio.get_user_idadir()
if not os.path.exists(userDir):
os.makedirs(userDir, 0755)
destDir = os.path.join(userDir, 'idarling')
if not os.path.exists(destDir):
os.makedirs(destDir, 0755)
user_dir = ida_diskio.get_user_idadir()
if not os.path.exists(user_dir):
os.makedirs(user_dir, 493) # 0755
dest_dir = os.path.join(user_dir, "idarling")
if not os.path.exists(dest_dir):
os.makedirs(dest_dir, 493) # 0755
else:
# Install into the plugins directory on Linux
destDir = os.path.join(ida_diskio.idadir(None), 'plugins')
dest_dir = os.path.join(ida_diskio.idadir(None), "plugins")

print('[*] Downloading master.zip archive...')
archivePath = os.path.join(destDir, 'master.zip')
if os.path.exists(archivePath):
os.remove(archivePath)
with open(archivePath, 'wb') as f:
print("[*] Downloading master.zip archive...")
archive_path = os.path.join(dest_dir, "master.zip")
if os.path.exists(archive_path):
os.remove(archive_path)
with open(archive_path, "wb") as f:
f.write(urllib2.urlopen(URL).read())

print('[*] Unzipping master.zip archive...')
archiveDir = os.path.join(destDir, 'IDArling-master')
if os.path.exists(archiveDir):
shutil.rmtree(archiveDir)
with zipfile.ZipFile(archivePath, 'r') as zip:
for zipfile in zip.namelist():
if zipfile.startswith(os.path.basename(archiveDir)):
zip.extract(zipfile, destDir)
print("[*] Unzipping master.zip archive...")
archive_dir = os.path.join(dest_dir, "IDArling-master")
if os.path.exists(archive_dir):
shutil.rmtree(archive_dir)
with zipfile.ZipFile(archive_path, "r") as zip:
for zip_file in zip.namelist():
if zip_file.startswith(os.path.basename(archive_dir)):
zip.extract(zip_file, dest_dir)

print('[*] Moving the IDArling files...')
srcPath = os.path.join(archiveDir, 'idarling_plugin.py')
dstPath = os.path.join(destDir, os.path.basename(srcPath))
if os.path.exists(dstPath):
os.remove(dstPath)
shutil.move(srcPath, dstPath)
srcDir = os.path.join(archiveDir, 'idarling')
dstDir = os.path.join(destDir, os.path.basename(srcDir))
if os.path.exists(dstDir):
shutil.rmtree(dstDir)
shutil.move(srcDir, dstDir)
print("[*] Moving the IDArling files...")
src_path = os.path.join(archive_dir, "idarling_plugin.py")
dst_path = os.path.join(dest_dir, os.path.basename(src_path))
if os.path.exists(dst_path):
os.remove(dst_path)
shutil.move(src_path, dst_path)
src_dir = os.path.join(archive_dir, "idarling")
dst_dir = os.path.join(dest_dir, os.path.basename(src_dir))
if os.path.exists(dst_dir):
shutil.rmtree(dst_dir)
shutil.move(src_dir, dst_dir)

print('[*] Removing master.zip archive...')
if os.path.exists(archivePath):
os.remove(archivePath)
if os.path.exists(archiveDir):
shutil.rmtree(archiveDir)
print("[*] Removing master.zip archive...")
if os.path.exists(archive_path):
os.remove(archive_path)
if os.path.exists(archive_dir):
shutil.rmtree(archive_dir)

print('[*] Loading IDArling into IDA Pro...')
if os.name == 'nt':
content = '''
print("[*] Loading IDArling into IDA Pro...")
if os.name == "nt":
content = """
#-----BEGIN IDARLING-----
import os
import ida_diskio
import ida_kernwin
import ida_loader
def load():
userDir = ida_diskio.get_user_idadir()
pluginDir = os.path.join(userDir, 'idarling')
pluginPath = os.path.join(pluginDir, 'idarling_plugin.py')
ida_loader.load_plugin(pluginPath)
user_dir = ida_diskio.get_user_idadir()
plugin_dir = os.path.join(user_dir, 'idarling')
plugin_path = os.path.join(plugin_dir, 'idarling_plugin.py')
ida_loader.load_plugin(plugin_path)
ida_kernwin.register_timer(0, load)
#-----END IDARLING-----
'''
sys.path.append(destDir)
"""
sys.path.append(dest_dir)
exec(content)

print('[*] Editing idapythonrc.py file...')
userDir = ida_diskio.get_user_idadir()
idapyrcPath = os.path.join(userDir, 'idapythonrc.py')
idapyrcContent = ''
if os.path.exists(idapyrcPath):
with open(idapyrcPath, 'r') as f:
idapyrcContent = f.read()
print("[*] Editing idapythonrc.py file...")
user_dir = ida_diskio.get_user_idadir()
idapyrc_path = os.path.join(user_dir, "idapythonrc.py")
idapyrc_content = ""
if os.path.exists(idapyrc_path):
with open(idapyrc_path, "r") as f:
idapyrc_content = f.read()

if content.split('\n')[1] not in idapyrcContent:
with open(idapyrcPath, 'a') as f:
if content.split("\n")[1] not in idapyrc_content:
with open(idapyrc_path, "a") as f:
f.write(content)
else:
pluginPath = os.path.join(destDir, 'idarling_plugin.py')
ida_loader.load_plugin(pluginPath)
plugin_path = os.path.join(dest_dir, "idarling_plugin.py")
ida_loader.load_plugin(plugin_path)

print('[*] IDArling installed successfully!')
print("[*] IDArling installed successfully!")
59 changes: 29 additions & 30 deletions idarling/core/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@
import ida_kernwin
import ida_netnode

from .hooks import HexRaysHooks, Hooks, IDBHooks, IDPHooks, UIHooks, ViewHooks
from ..module import Module
from ..shared.commands import Subscribe, Unsubscribe

from .hooks import Hooks, IDBHooks, IDPHooks, HexRaysHooks, ViewHooks, UIHooks

logger = logging.getLogger("IDArling.Core")


Expand All @@ -35,14 +34,14 @@ def __init__(self, plugin):
super(Core, self).__init__(plugin)
self._hooked = False

self._idbHooks = None
self._idpHooks = None
self._hxeHooks = None
self._viewHooks = None
self._uiHooks = None
self._idb_hooks = None
self._idp_hooks = None
self._hxe_hooks = None
self._view_hooks = None
self._ui_hooks = None

self._uiHooksCore = None
self._idbHooksCore = None
self._ui_hooks_core = None
self._idb_hooks_core = None

# Database members
self._repo = None
Expand All @@ -53,11 +52,11 @@ def _install(self):
logger.debug("Installing hooks")
core = self

self._idbHooks = IDBHooks(self._plugin)
self._idpHooks = IDPHooks(self._plugin)
self._hxeHooks = HexRaysHooks(self._plugin)
self._viewHooks = ViewHooks(self._plugin)
self._uiHooks = UIHooks(self._plugin)
self._idb_hooks = IDBHooks(self._plugin)
self._idp_hooks = IDPHooks(self._plugin)
self._hxe_hooks = HexRaysHooks(self._plugin)
self._view_hooks = ViewHooks(self._plugin)
self._ui_hooks = UIHooks(self._plugin)

class UIHooksCore(Hooks, ida_kernwin.UI_Hooks):
"""
Expand Down Expand Up @@ -85,8 +84,8 @@ def ready_to_run(self, *_):
)
core.hook_all()

self._uiHooksCore = UIHooksCore(self._plugin)
self._uiHooksCore.hook()
self._ui_hooks_core = UIHooksCore(self._plugin)
self._ui_hooks_core.hook()

class IDBHooksCore(Hooks, ida_idp.IDB_Hooks):
"""
Expand All @@ -106,14 +105,14 @@ def closebase(self):
core.ticks = 0
return 0

self._idbHooksCore = IDBHooksCore(self._plugin)
self._idbHooksCore.hook()
self._idb_hooks_core = IDBHooksCore(self._plugin)
self._idb_hooks_core.hook()
return True

def _uninstall(self):
logger.debug("Uninstalling hooks")
self._idbHooksCore.unhook()
self._uiHooksCore.unhook()
self._idb_hooks_core.unhook()
self._ui_hooks_core.unhook()
self.unhook_all()
return True

Expand All @@ -123,11 +122,11 @@ def hook_all(self):
"""
if self._hooked:
return
self._idbHooks.hook()
self._idpHooks.hook()
self._hxeHooks.hook()
self._viewHooks.hook()
self._uiHooks.hook()
self._idb_hooks.hook()
self._idp_hooks.hook()
self._hxe_hooks.hook()
self._view_hooks.hook()
self._ui_hooks.hook()
self._hooked = True

def unhook_all(self):
Expand All @@ -136,11 +135,11 @@ def unhook_all(self):
"""
if not self._hooked:
return
self._idbHooks.unhook()
self._idpHooks.unhook()
self._hxeHooks.unhook()
self._viewHooks.unhook()
self._uiHooks.unhook()
self._idb_hooks.unhook()
self._idp_hooks.unhook()
self._hxe_hooks.unhook()
self._view_hooks.unhook()
self._ui_hooks.unhook()
self._hooked = False

@property
Expand Down
7 changes: 6 additions & 1 deletion idarling/core/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import logging
import sys

import ida_bytes
import ida_enum
Expand All @@ -29,6 +30,10 @@

from ..shared.packets import DefaultEvent

if sys.version_info > (3,):
unicode = str


logger = logging.getLogger("IDArling.Core")


Expand Down Expand Up @@ -383,7 +388,7 @@ def __call__(self):
if self.op == "struct":
path_len = len(self.extra["spath"])
path = ida_pro.tid_array(path_len)
for i in xrange(path_len):
for i in range(path_len):
sname = Event.encode(self.extra["spath"][i])
path[i] = ida_struct.get_struc_id(sname)
insn = ida_ua.insn_t()
Expand Down
Loading

0 comments on commit 62102bc

Please sign in to comment.