OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

IDA Pro change color of variables in pseudocode

  • Thread starter Thread starter Roman Toasov
  • Start date Start date
R

Roman Toasov

Guest
Very basic Ida Pro plugin that changes color of MyVar123 inside pseudocode window.

Problem is this approach is limited to using ida_lines.SCOLOR_... constants for color and i want to define my own text color e.g. #00FF00, how to do so?

Code:
import idaapi, ida_kernwin, ida_lines

class ColorizeVariable(ida_kernwin.action_handler_t):

    def __init__(self):
        ida_kernwin.action_handler_t.__init__(self)

    def activate(self, ctx):

        if ida_kernwin.get_widget_type(ctx.widget) == ida_kernwin.BWN_PSEUDOCODE:
            vu = idaapi.get_widget_vdui(ctx.widget)
            pc = vu.cfunc.get_pseudocode()


            find = "MyVar123"

            vu.refresh_view(False)

            for sl in pc:
                sl.line = sl.line.replace(find, ida_lines.COLSTR(find, ida_lines.SCOLOR_ASMDIR))

        return 0

    def update(self, ctx):
        return ida_kernwin.AST_ENABLE_ALWAYS




class ida_plugin_container(idaapi.plugin_t):

    flags         = idaapi.PLUGIN_UNL
    comment       = 'plugin comment'
    help          = 'help message'
    wanted_name   = "myPlugin"
    wanted_hotkey = 'Shift-Q'

    def init(self):

        action_desc = idaapi.action_desc_t(
            'myPlugin',
            'Colorize Variable',
            ColorizeVariable(),
            'Ctrl+H',
            'Colorize Variable in Pseudocode',
            10)

        idaapi.register_action(action_desc)

        idaapi.attach_action_to_toolbar("SearchToolBar", 'myPlugin')

        return idaapi.PLUGIN_OK


    def run(self, arg):
        pass


    def term(self):
        pass

def PLUGIN_ENTRY():
    return ida_plugin_container()
<p>Very basic Ida Pro plugin that changes color of <code>MyVar123</code> inside pseudocode window.</p>
<p>Problem is this approach is limited to using <a href="https://hex-rays.com/products/ida/support/sdkdoc/group___s_c_o_l_o_r__.html" rel="nofollow noreferrer">ida_lines.SCOLOR_...</a> constants for color and i want to define my own text color e.g. #00FF00, how to do so?</p>
<pre><code>import idaapi, ida_kernwin, ida_lines

class ColorizeVariable(ida_kernwin.action_handler_t):

def __init__(self):
ida_kernwin.action_handler_t.__init__(self)

def activate(self, ctx):

if ida_kernwin.get_widget_type(ctx.widget) == ida_kernwin.BWN_PSEUDOCODE:
vu = idaapi.get_widget_vdui(ctx.widget)
pc = vu.cfunc.get_pseudocode()


find = "MyVar123"

vu.refresh_view(False)

for sl in pc:
sl.line = sl.line.replace(find, ida_lines.COLSTR(find, ida_lines.SCOLOR_ASMDIR))

return 0

def update(self, ctx):
return ida_kernwin.AST_ENABLE_ALWAYS




class ida_plugin_container(idaapi.plugin_t):

flags = idaapi.PLUGIN_UNL
comment = 'plugin comment'
help = 'help message'
wanted_name = "myPlugin"
wanted_hotkey = 'Shift-Q'

def init(self):

action_desc = idaapi.action_desc_t(
'myPlugin',
'Colorize Variable',
ColorizeVariable(),
'Ctrl+H',
'Colorize Variable in Pseudocode',
10)

idaapi.register_action(action_desc)

idaapi.attach_action_to_toolbar("SearchToolBar", 'myPlugin')

return idaapi.PLUGIN_OK


def run(self, arg):
pass


def term(self):
pass

def PLUGIN_ENTRY():
return ida_plugin_container()
</code></pre>
 
Top