Hex-Rays decompiler plug-in load delay on Home version

Foreground:
In forking Gepetto AI plugin and working on a lazy init/loading fix, I ran into an issue where this Python plugin does a bunch of initialization in it’s def init(self): plugin handler.
Apparently in the “Pro” et al versions, the Hex-Rays decompiler plugin is either already loaded and/or it will load when ida_hexrays.init_hexrays_plugin() is called.

This is not so with the “Home” version (and probably any other version that uses the cloud vs the local) it’s not loaded yet and init_hexrays_plugin() will return False.

The way I fix it is to lazy init this call on the first plugin action. It’s typically at this time when it needs to access Hex-rays decompiled data to prompt AI with.

Question:
Is this intended/known behavior or is it a bug? Should the Hex-Rays plugin be initialized first?
To me more of a conundrum since its a built-in plugin, it should probably be one of the, if not the first to be initialized rather than later.

Hi,
Could you provide the exact steps to reproduce this issue?
There shouldn’t be differences between IDA Pro and Home in that aspect.
Thank you!

Sure, make a mostly empty do nothing Python plugin, but in the init() do:

import ida_hexrays
ok = ida_hexrays.init_hexrays_plugin()
print(“init_hexrays_plugin() ->”, ok)

More than likely you will see from the log it’s False on the home version (I suspect any cloud version) and then try it on IDA Pro where it will be True.

And then to be complete, I’d say add the same code to the run() where you should see with any version it’s loaded by then (on hotkey activation).

Should be obvious too because you will probably see the init_hexrays_plugin() -> False log line before the Hex-Rays plugin load message ones.

What’s the name of your plugin? Please take into account that plugins are loaded in the alphabetical order (ensured by the file system)

Hey ilfak nice to chat with you again.

Okay, got to do the work for this.
Simple plugin based on the IDA hello world example:

import idaapi
import ida_hexrays

class load_test_t(idaapi.plugin_t):
flags = 0 # Same as Gepetto’s
comment = “comment”
help = “help”
wanted_name = “* Decomp load order test *”
wanted_hotkey = “Alt-F8”

def init(self):      
    print("*Test: init() init_hexrays_plugin() ->", ida_hexrays.init_hexrays_plugin())
    return idaapi.PLUGIN_KEEP
    
def run(self, arg):     
    print("*Test: run() init_hexrays_plugin() ->", ida_hexrays.init_hexrays_plugin())        
    return 0       

def PLUGIN_ENTRY():
print(“*Test: PLUGIN_ENTRY() hotkey Alt-F8.”)
return load_test_t()

The test is have a filename that should load first vs a filename that should load last vs the decompiler plugin load order.

As plugin named “aaaa_decomp_load_test.py” so it’s the first:
IDA Home 9.2: “hexcx64.dll”
*Test: PLUGIN_ENTRY() hotkey Alt-F8.
*Test: init() init_hexrays_plugin() → False
Hex-Rays Cloud Decompiler plugin has been loaded (v9.2.0.250908)
..
*Test: run() init_hexrays_plugin() → True

Okay just as you say “alphabetical order”. We see our Python script init() before Hex-Rays done as evident by log lines. ‘A’ is before ‘H”. At least assuming the Qt log line events came in order.

Now lets rename the plugin to “zzzz_decomp_load_test.py” so that it should be the last to load:
IDA Home 9.2: “hexcx64.dll”
Hex-Rays Cloud Decompiler plugin has been loaded (v9.2.0.250908)
*Test: PLUGIN_ENTRY() hotkey Alt-F8.
*Test: init() init_hexrays_plugin() → True
..
*Test: run() init_hexrays_plugin() → True

Also what you say as ‘H’ comes before ‘Z’.

I only have an IDA 9.2 license for home currently, but tested it on IDA Pro 8.4 and I get the same exact results.
Okay I don’t see it documented in the IDA API docs any place, but it makes sense.
We find out, normally you don’t want to call “init_hexrays_plugin()” inside of a plugin’s init().
In Gepetto it’s used there there to both initialize the Hex-Rays for plugin use, and also to see if it even exists.
Which IS kind of unnecessary because if someone is silly enough to install a plugin that requires the decompiler, but then doesn’t have it, they have bigger problems. And decompiler API functions are not called until later, long after init(), it would just throw some exception in the code.

But strange thing is that still, it apparently doesn’t happening in IDA Pro 9.2. I’m the first person to bring up this issue with the plugin and it’s very popular. Can you guys try this script on IDA Pro 9.2 for Windows and Linux and see if the behavior is different?

I’ll ask the author of the plugin to try it too.

Now I see a potential solution in the IDA SDK example ““decompile_entry_points.py”".
The cloud version names would have to be added to the list though, with additional logic as they are not in that example.
That is, call ida_loader.load_plugin(decompiler) from init(), before the ida_hexrays.init_hexrays_plugin() call.

1 Like

Yes, this is a very good solution, but you need to know what plugin to load, it depends on the processor.