How can I change color of node (or block?) with idapython? I know about SetColor, but this function does not work with blocks/nodes.

enter image description here

EDIT: Solved, see the code snippet below.

def get_bb_id(graph, ea):
    for block in graph:
        if block.startEA <= ea and block.endEA > ea:
            return block.id

start_ea = 0x15f9ad6
base_block_ea = 0x15f9a60

f = get_func(start_ea)
g = FlowChart(f, flags=FC_PREDS) #???
bb_id = get_bb_id(g, start_ea)

p = idaapi.node_info_t()
p.bg_color = 0x00ff00 # green

print idaapi.set_node_info2(base_block_ea, bb_id, p, 
                            idaapi.NIF_BG_COLOR | idaapi.NIF_FRAME_COLOR)
  • Probably best if you enter the solution as an answer and mark it as correct. – tmr232 Oct 21 '15 at 8:18

Look over following functions and around (found in idaapi.py):

def SetNodeInfo(self, node_index, node_info, flags):
    Set the properties for the given node.

    Example usage (set second nodes's bg color to red):
      inst = ...
      p = idaapi.node_info_t()
      p.bg_color = 0x00ff0000
      inst.SetNodeInfo(1, p, idaapi.NIF_BG_COLOR)

    @param node_index: The node index.
    @param node_info: An idaapi.node_info_t instance.
    @param flags: An OR'ed value of NIF_* values.
    _idaapi.pygc_set_node_info(self, node_index, node_info, flags)

def SetNodesInfos(self, values):
    Set the properties for the given nodes.

    Example usage (set first three nodes's bg color to purple):
      inst = ...
      p = idaapi.node_info_t()
      p.bg_color = 0x00ff00ff
      inst.SetNodesInfos({0 : p, 1 : p, 2 : p})

    @param values: A dictionary of 'int -> node_info_t' objects.
    _idaapi.pygc_set_nodes_infos(self, values)
| improve this answer | |

You can also use Sark:

import sark
code_block = sark.CodeBlock(some_ea)
code_block.color = 0x00ff0000
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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