2

Is it possible to remotely debug IDAPyhton scripts using VSCode and ptvsd? I found a few tutorials on the net, but no one is working. In the past, using the same protocol I was able to connect to Maya from VSCode and to remotely debug Pymel scripts. So, from IDA python console I entered:

ptvsd.enable_attach(address=('localhost', 5678), redirect_output=True)

and eventually:

ptvsd.wait_for_attach(60)

A Python MsgBox appears telling a script is running... Now in VSCode I started the script to be debugged using the standard json configuration file for attaching to a remote debugger, but the connection is always refused. I tried to change the port (3528, 3000), the address (0.0.0.0) and to remove the redirect_output flag. No matter what, I wasn't able to connect. I tried also:

ptvsd.break_into_debugger()

But again, no luck.

As a second question, is there a way to make the import statement recognize IDAPython modules (idaapi, idc, idc_bytes and so on) or to use autocompletion? I know IDAPython is bundled with IDA and not installed in site-packages, but I wonder if is there a solution (not to execute the script outside of IDA, but to have the modules and keywords recognized).

1
  • Worth noting break_into_debugger only works if the debugger is already attached. First I took it to do what wait_for_attach is doing.
    – Trass3r
    Oct 6, 2020 at 13:50

2 Answers 2

1

Something this should work for ptvsd:

        {
            "name": "Python: Remote Attach",
            "type": "python",
            "request": "attach",
            "debugServer": 5678,
            "showReturnValue": true,
            "internalConsoleOptions": "openOnSessionStart",
            "redirectOutput": true,
        }

You may need to insert an explicit breakpoint() in the code.

For IntelliSense in VSCode there's PYTHONPATH or

    "python.autoComplete.extraPaths": [
        "..."
    ],
    "python.analysis.extraPaths": [
        "..."
    ],
0

idacode offers a wonderful integration between VSCode and idapython.

The github repo is the best place to find the IDA plugin, and there is a VSCode extension under the same name available in the extension repository.

If your IDA installation is not in the default location, see the readme in the github repo.

Once installed, you enable a local listening server within IDA from the plugin menu, and then in VSCode you open a workspace in the directory containing your python code. Using the command list (ctrl+shift+P), type 'IDA' and choose one of the options to connect with or without a debugger. Then each time you save the python script, it will be executed in IDA.

If you wish to use vscodium instead of vscode, you will need to select "install from *.vsix" in the extension manager menu and choose the vsix which you can download here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.