编辑:已解决,请参见下面的代码片段。
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)
#1 楼
查看以下功能以及相关功能(可在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)
#2 楼
您也可以使用Sark:import sark
code_block = sark.CodeBlock(some_ea)
code_block.color = 0x00ff0000
#3 楼
您可以使用SetColor
API ether。您应该在该块的每一行上调用
SetColor
,因为它一次只能着色一条指令行。这是我的IDAPython代码示例: br />为块着色之前设置流程图信息。
class ColoringBB():
flowchart = False
tgt_ea = 0
startea = 0
endea = 0
addr_fc = 0
def __init__(self, addr_fc):
self._set_fc_address(addr_fc)
self._set_flowchart()
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):
self._set_bb_range(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
break
评论
如果您输入解决方案作为答案并将其标记为正确,那可能是最好的。