MCPcopy Create free account
hub / github.com/Vector35/binaryninja-api / format_lines

Method format_lines

python/lineformatter.py:238–281  ·  view source on GitHub ↗
(
            self, in_lines: List['function.DisassemblyTextLine'], settings: 'LineFormatterSettings'
    )

Source from the content-addressed store, hash-verified

236 _formatter_cache[ctypes.addressof(handle.contents)] = self
237
238 def format_lines(
239 self, in_lines: List['function.DisassemblyTextLine'], settings: 'LineFormatterSettings'
240 ) -> List['function.DisassemblyTextLine']:
241 line_buf = (core.BNDisassemblyTextLine * len(in_lines))()
242 for i in range(len(in_lines)):
243 line = in_lines[i]
244 color = line.highlight
245 if not isinstance(color, HighlightStandardColor) and not isinstance(color, highlight.HighlightColor):
246 raise ValueError("Specified color is not one of HighlightStandardColor, highlight.HighlightColor")
247 if isinstance(color, HighlightStandardColor):
248 color = highlight.HighlightColor(color)
249 line_buf[i].highlight = color._to_core_struct()
250 if line.address is None:
251 if len(line.tokens) > 0:
252 line_buf[i].addr = line.tokens[0].address
253 else:
254 line_buf[i].addr = 0
255 else:
256 line_buf[i].addr = line.address
257 if line.il_instruction is not None:
258 line_buf[i].instrIndex = line.il_instruction.instr_index
259 else:
260 line_buf[i].instrIndex = 0xffffffffffffffff
261
262 line_buf[i].count = len(line.tokens)
263 line_buf[i].tokens = function.InstructionTextToken._get_core_struct(line.tokens)
264
265 count = ctypes.c_ulonglong()
266 lines = core.BNFormatLines(self.handle, line_buf, len(in_lines), settings._to_core_struct(), count)
267
268 result = []
269 if lines is not None:
270 result = []
271 for i in range(0, count.value):
272 addr = lines[i].addr
273 if lines[i].instrIndex != 0xffffffffffffffff:
274 il_instr = settings.hlil[lines[i].instrIndex] # type: ignore
275 else:
276 il_instr = None
277 color = highlight.HighlightColor._from_core_struct(lines[i].highlight)
278 tokens = function.InstructionTextToken._from_core_struct(lines[i].tokens, lines[i].count)
279 result.append(function.DisassemblyTextLine(tokens, addr, il_instr, color))
280 core.BNFreeDisassemblyTextLines(lines, count.value)
281 return result
282
283 @classmethod
284 def _from_cache(cls, handle) -> 'LineFormatter':

Callers

nothing calls this directly

Calls 6

_to_core_structMethod · 0.95
_get_core_structMethod · 0.80
DisassemblyTextLineMethod · 0.80
_to_core_structMethod · 0.45
_from_core_structMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected