├── LICENSE ├── README.md ├── autocompletion.png ├── docstring.png ├── paths.png ├── pycharm_wrapper.py └── template.png /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Lukasz Taczuk 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # IDAPython-pycharm-setup 2 | How to setup Pycharm to run scripts in IDA using the Run menu (or a keybind) 3 | 4 | This is just a placeholder Readme. FIXME: Improve me 5 | 6 | ## Running your code directly from PyCharm 7 | 8 | Note: you need to install and configure [IPyIDA](https://github.com/eset/ipyida) first. 9 | 10 | TL;DR: Set the pycharm_wrapper.py file as as Run/Debug Configuration template 11 | using the appropriate options and then just use Shift+F10 to (re-)run your 12 | python script in IDA while seeing the output in a separate terminal. 13 | 14 | ![](template.png) 15 | 16 | ## Configuring autocompletion 17 | 18 | Open the settings window, navigate to your interpreter and add IDAPython 19 | directory to the interpreter paths 20 | 21 | ![](paths.png) 22 | 23 | Autocompletion and docstrings in PyCharm should now be working! 24 | 25 | ![](autocompletion.png) 26 | 27 | ![](docstring.png) 28 | -------------------------------------------------------------------------------- /autocompletion.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/overfl0/IDAPython-pycharm-setup/fcb627c339070101c12eb2eca6bd958c2a047c2f/autocompletion.png -------------------------------------------------------------------------------- /docstring.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/overfl0/IDAPython-pycharm-setup/fcb627c339070101c12eb2eca6bd958c2a047c2f/docstring.png -------------------------------------------------------------------------------- /paths.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/overfl0/IDAPython-pycharm-setup/fcb627c339070101c12eb2eca6bd958c2a047c2f/paths.png -------------------------------------------------------------------------------- /pycharm_wrapper.py: -------------------------------------------------------------------------------- 1 | import argparse 2 | import textwrap 3 | 4 | import jupyter_client 5 | from jupyter_client.manager import KernelManager 6 | 7 | """ 8 | Set this file as "interpreter options" in your "Run/Debug configurations" 9 | template. This way, all your files you'll execute will be executed through 10 | the jupyter kernel, running in IPyIDA. 11 | 12 | To spawn a separate console to see the results, open cmd and run: 13 | 14 | ############################################################################################ 15 | python -m jupyter_console --existing --ZMQTerminalInteractiveShell.include_other_output=true 16 | ############################################################################################ 17 | """ 18 | 19 | parser = argparse.ArgumentParser(description='Execute a file inside a running ipython kernel') 20 | parser.add_argument('path', type=str, help='path to the file being executed') 21 | parser.add_argument('rest', nargs=argparse.REMAINDER) 22 | 23 | args = parser.parse_args() 24 | 25 | 26 | def escape_string(txt): 27 | """Poor man's escaping""" 28 | return txt.replace('\\', '\\\\').replace('"', '\\"') 29 | 30 | 31 | command = f'%run -G -e "{escape_string(args.path)}" ' + ' '.join(args.rest) 32 | print(f'Connecting to ipython\'s kernel and executing {command}...') 33 | 34 | connection_file = jupyter_client.connect.find_connection_file() 35 | manager = KernelManager(connection_file=connection_file) 36 | manager.load_connection_file() 37 | client = manager.client() 38 | client.execute_interactive(f'%reset -f --aggressive', store_history=False) 39 | 40 | # Check if we're calling the PyCharm debugger 41 | if 'helpers/pydev/pydevd.py' in args.path: 42 | # Remove the pydev module vendored in debugpy because it clashes with the 43 | # one from PyCharm and hope it doesn't break anything 44 | # Otherwise, we get: 45 | # ModuleNotFoundError: No module named '_pydevd_bundle.pydevd_collect_try_except_info' 46 | remove_debugpy_pydevd = textwrap.dedent("""\ 47 | import sys 48 | import os 49 | 50 | __blacklisted_path = f'{os.sep}debugpy{os.sep}_vendored{os.sep}' 51 | 52 | for name in sys.modules.copy(): 53 | if 'pydev' in name and __blacklisted_path in getattr(sys.modules[name], '__file__', ''): 54 | del sys.modules[name] 55 | """) 56 | client.execute_interactive(remove_debugpy_pydevd, store_history=True, allow_stdin=True) 57 | 58 | client.execute_interactive(command, store_history=True, allow_stdin=True) 59 | -------------------------------------------------------------------------------- /template.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/overfl0/IDAPython-pycharm-setup/fcb627c339070101c12eb2eca6bd958c2a047c2f/template.png --------------------------------------------------------------------------------