How to check if idapythonrc.py is running in IDA Pro or idalib?

I’ve found that idapythonrc.py is loaded both by IDA Pro (the user interface) and idalib. However, there’s some configuration that I only want applied when running within IDA Pro (the user interface), such as pre-configuring logging, formatting, etc.

What is the supported way to recognize when idapythonrc.py is being loaded by IDA Pro (the user interface) versus idalib?

I’ve found IDAPYTHON_OWNING_INTERPRETER which seems to be set to True in IDA Pro and False in idalib (and not present outside of the IDA ecosystem). However, its not documented. Can I rely on it being present?

You can see how I would use it here: https://github.com/williballenthin/dotfiles/blob/8f0d6f6fddddd2ec91bfa24e0c5767d17fc6e26c/.idapro/idapythonrc.py#L1-L5

if globals().get("IDAPYTHON_OWNING_INTERPRETER"):
    # when running within IDA Pro...
    # 
    # this is a magic symbol that seems to be set when
    # IDAPython is hosted within IDA Pro (and not idalib).

    import logging
    logging.basicConfig(level=logging.INFO)

for now you can use os.environ.get("IDA_IS_INTERACTIVE")=="1".

1 Like