| 85 | |
| 86 | |
| 87 | class FlowGraphNode: |
| 88 | def __init__(self, graph=None, handle=None): |
| 89 | _handle = handle |
| 90 | if _handle is None: |
| 91 | if graph is None: |
| 92 | raise ValueError("flow graph node must be associated with a graph") |
| 93 | _handle = core.BNCreateFlowGraphNode(graph.handle) |
| 94 | assert _handle is not None |
| 95 | self.handle = _handle |
| 96 | self._graph = graph |
| 97 | if self._graph is None: |
| 98 | self._graph = FlowGraph(handle=core.BNGetFlowGraphNodeOwner(self.handle)) |
| 99 | |
| 100 | def __del__(self): |
| 101 | if core is not None: |
| 102 | core.BNFreeFlowGraphNode(self.handle) |
| 103 | |
| 104 | def __repr__(self): |
| 105 | block = self.basic_block |
| 106 | if block: |
| 107 | arch = block.arch |
| 108 | if arch: |
| 109 | return "<graph node: %s@%#x-%#x>" % (arch.name, block.start, block.end) |
| 110 | else: |
| 111 | return "<graph node: %#x-%#x>" % (block.start, block.end) |
| 112 | return "<graph node>" |
| 113 | |
| 114 | def __eq__(self, other): |
| 115 | if not isinstance(other, self.__class__): |
| 116 | return NotImplemented |
| 117 | return ctypes.addressof(self.handle.contents) == ctypes.addressof(other.handle.contents) |
| 118 | |
| 119 | def __ne__(self, other): |
| 120 | if not isinstance(other, self.__class__): |
| 121 | return NotImplemented |
| 122 | return not (self == other) |
| 123 | |
| 124 | def __hash__(self): |
| 125 | return hash(ctypes.addressof(self.handle.contents)) |
| 126 | |
| 127 | def __iter__(self): |
| 128 | count = ctypes.c_ulonglong() |
| 129 | lines = core.BNGetFlowGraphNodeLines(self.handle, count) |
| 130 | assert lines is not None, "core.BNGetFlowGraphNodeLines returned None" |
| 131 | block = self.basic_block |
| 132 | try: |
| 133 | for i in range(0, count.value): |
| 134 | addr = lines[i].addr |
| 135 | if (lines[i].instrIndex != 0xffffffffffffffff) and (block |
| 136 | is not None) and hasattr(block, 'il_function'): |
| 137 | il_instr = block.il_function[lines[i].instrIndex] |
| 138 | else: |
| 139 | il_instr = None |
| 140 | tokens = function.InstructionTextToken._from_core_struct(lines[i].tokens, lines[i].count) |
| 141 | yield function.DisassemblyTextLine(tokens, addr, il_instr) |
| 142 | finally: |
| 143 | core.BNFreeDisassemblyTextLines(lines, count.value) |
| 144 |
no outgoing calls
no test coverage detected