0

I want to have utility functions shared between all databases, for example:

from idautils import *
from idaapi import *
from idc import *
from ida_name import *

def FindFunctionImpl(FunctionNameToFind):
    for SegmentAddress in Segments():
        for FunctionAddress in Functions(SegmentAddress, get_segm_end(SegmentAddress)):
            FunctionName = get_func_name(FunctionAddress)
            DemangledName = get_long_name(FunctionAddress)
            if DemangledName.find(FunctionNameToFind) != -1:
                print(f"0x{FunctionAddress:x}:{DemangledName}")

class ExamplePlugin(idaapi.plugin_t):
    flags = idaapi.PLUGIN_DRAW
    comment = ""
    help = ""
    wanted_name = "Example"

    def init(self):
        print("ExamplePlugin initialized")
        global FindFunction = FindFunctionImpl
        return idaapi.PLUGIN_KEEP # On garde le plugin chargé en mémoire

    def run(self, arg):
        return

    def term(self):
        pass

def PLUGIN_ENTRY():
    return ExamplePlugin()

But it doesn't want to let me use neither FindFunction nor FindFunctionImpl from the console. Says "name isn't defined" in the console. It prints in the console that the plugin is initialized.

2
  • 2
    Put your function definitions inside the idapythonrc.py file that IDAPython executes on startup. This is one of the installation methods of the minsc plugin that I maintain which is a library that provides something similar to what you're starting to do (arizvisa.github.io/ida-minsc/…). The idapythonrc.py method for initiailzing the Python interpreter is also documented at the Hex-Rays blog (hex-rays.com/blog/…). Nov 29, 2023 at 17:28
  • @AliRizvi-Santiago please add this as an answer
    – Igor Skochinsky
    Dec 2, 2023 at 22:25

2 Answers 2

2
  1. Separate out FindFunctionImpl into its own .py file, say FuncUtil.py.
  2. Put the directory containing that file into your system's $PYTHONPATH.
  3. Invoke it from the IDAPython console as FuncUtil.FindFunctionImpl.
1

You can add a path to your plugin script in one of the plugins.list files, this will tell IDA to load the plugin everytime you open an IDB. You can run plugins from Edit/Plugins menu.

It's a shame HexRays haven't put up any docs on that to this day, but you can find a decent explanation in Sark's reference.

1
  • 1
    plugins.list is not used by IDA but seems to be a Sark feature.
    – Igor Skochinsky
    Dec 2, 2023 at 22:24

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.