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)

You can also use Sark:

import sark
code_block = sark.CodeBlock(some_ea)
code_block.color = 0x00ff0000

You can use SetColor API ether.
You should call SetColor on every lines of the block, as it colors only one instruction line at a time.

Here is my IDAPython code example:

class ColoringBB(): 
    flowchart = False 
    tgt_ea = 0 
    startea = 0 
    endea = 0 
    addr_fc = 0

    def __init__(self, addr_fc):

    def _set_fc_address(self, addr_fc):
        self.addr_fc = addr_fc 

    def _set_flowchart(self):
        f = idaapi.get_func(self.addr_fc)
        self.flowchart = idaapi.FlowChart(f)

    def coloring_bb(self, addr):
        for addr in range(self.startea, self.endea):
            idc.SetColor(addr, idc.CIC_ITEM, 0x8f8080) # olive

    def _set_bb_range(self, addr):
        for block in self.flowchart:
            if block.startEA <= addr and block.endEA > addr:
                self.startea, self.endea = block.startEA, block.endEA

Set the flowchart information before coloring the block.

addr_fc = 0x8040DCF4 # set flow chart address
cb = ColoringBB(addr_fc)

cb.coloring_bb(0x8040DD40) # color the block containing those address
cb.coloring_bb(0x8040DD34) # color the block containing those address

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.