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

Method _format_lines

python/lineformatter.py:145–205  ·  view source on GitHub ↗
(
            self, ctxt, in_lines, in_count: int, settings: core.BNLineFormatterSettingsHandle,
            out_count: ctypes.POINTER(ctypes.c_ulonglong)
    )

Source from the content-addressed store, hash-verified

143 self.__class__._registered_formatters.append(self)
144
145 def _format_lines(
146 self, ctxt, in_lines, in_count: int, settings: core.BNLineFormatterSettingsHandle,
147 out_count: ctypes.POINTER(ctypes.c_ulonglong)
148 ):
149 try:
150 settings = settings[0]
151 if len(settings.languageName) == 0:
152 language_name = None
153 else:
154 language_name = settings.languageName
155 hlil = highlevelil.HighLevelILFunction(handle=core.BNNewHighLevelILFunctionReference(settings.highLevelIL))
156 settings = LineFormatterSettings(
157 hlil, settings.desiredLineLength, settings.minimumContentLength, settings.tabWidth, language_name,
158 settings.commentStartString, settings.commentEndString,
159 settings.annotationStartString, settings.annotationEndString
160 )
161
162 lines = []
163 if in_lines is not None:
164 for i in range(0, in_count):
165 addr = in_lines[i].addr
166 if in_lines[i].instrIndex != 0xffffffffffffffff:
167 il_instr = hlil[in_lines[i].instrIndex] # type: ignore
168 else:
169 il_instr = None
170 color = highlight.HighlightColor._from_core_struct(in_lines[i].highlight)
171 tokens = function.InstructionTextToken._from_core_struct(in_lines[i].tokens, in_lines[i].count)
172 lines.append(function.DisassemblyTextLine(tokens, addr, il_instr, color))
173
174 lines = self.format_lines(lines, settings)
175
176 out_count[0] = len(lines)
177 self.line_buf = (core.BNDisassemblyTextLine * len(lines))()
178 for i in range(len(lines)):
179 line = lines[i]
180 color = line.highlight
181 if not isinstance(color, HighlightStandardColor) and not isinstance(color, highlight.HighlightColor):
182 raise ValueError("Specified color is not one of HighlightStandardColor, highlight.HighlightColor")
183 if isinstance(color, HighlightStandardColor):
184 color = highlight.HighlightColor(color)
185 self.line_buf[i].highlight = color._to_core_struct()
186 if line.address is None:
187 if len(line.tokens) > 0:
188 self.line_buf[i].addr = line.tokens[0].address
189 else:
190 self.line_buf[i].addr = 0
191 else:
192 self.line_buf[i].addr = line.address
193 if line.il_instruction is not None:
194 self.line_buf[i].instrIndex = line.il_instruction.instr_index
195 else:
196 self.line_buf[i].instrIndex = 0xffffffffffffffff
197
198 self.line_buf[i].count = len(line.tokens)
199 self.line_buf[i].tokens = function.InstructionTextToken._get_core_struct(line.tokens)
200
201 return ctypes.cast(self.line_buf, ctypes.c_void_p).value
202 except:

Callers

nothing calls this directly

Calls 9

format_linesMethod · 0.95
_to_core_structMethod · 0.95
log_errorFunction · 0.85
HighLevelILFunctionMethod · 0.80
DisassemblyTextLineMethod · 0.80
_get_core_structMethod · 0.80
_from_core_structMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected