def run(self): self.assert_has_content() try: lexer = get_lexer_by_name(self.arguments[0]) except ValueError: # no lexer found - use the text one instead of an exception lexer = TextLexer() formatter = HtmlFormatter(noclasses=False) if 'linenos' in self.options: formatter.linenos = 2 # inline parsed = highlight('\n'.join(self.content), lexer, formatter) return [nodes.raw('', parsed, format='html')]
def run(self): self.assert_has_content() try: lexer = get_lexer_by_name(self.arguments[0]) except ValueError: # no lexer found - use the text one instead of an exception lexer = TextLexer() formatter = HtmlFormatter(noclasses=False) if 'linenos' in self.options: formatter.linenos = 2 # inline parsed = highlight(u'\n'.join(self.content), lexer, formatter) return [nodes.raw('', parsed, format='html')]
def OnCommand(self, n, cmd_id): if cmd_id == self.cmd_show_reasons: match = self.items[n] reasons = match[len(match) - 1] msg = "\n".join(reasons) info(msg) elif cmd_id == self.cmd_show_source: item = self.items[n] src_id = int(item[1]) cur = self.importer.db.cursor() sql = "select source from src.functions where id = ?" cur.execute(sql, (src_id, )) row = cur.fetchone() if row is not None: fmt = HtmlFormatter() fmt.noclasses = True fmt.linenos = True func = row["source"] src = highlight(func, CppLexer(), fmt) title = "Source code of %s" % repr(item[2]) cdiffer = CHtmlViewer() cdiffer.Show(src, title) cur.close() elif cmd_id == self.cmd_import_all: if askyn_c( 0, "HIDECANCEL\nDo you really want to import all matched functions as well as struct, union, enum and typedef definitions?" ) == 1: import_items = [] for item in self.items: src_id, src_name, bin_ea = int(item[1]), item[2], int( item[3], 16) import_items.append([src_id, src_name, bin_ea]) self.importer.import_items(import_items) elif cmd_id == self.cmd_import_selected: if len(self.selected_items) == 1 or askyn_c( 1, "HIDECANCEL\nDo you really want to import the selected functions?" ) == 1: import_items = [] for index in self.selected_items: item = self.items[index] src_id, src_name, bin_ea = int(item[1]), item[2], int( item[3], 16) import_items.append([src_id, src_name, bin_ea]) import_definitions = askyn_c( 0, "HIDECANCEL\nDo you also want to import all struct, union, enum and typedef definitions?" ) == 1 self.importer.import_items( import_items, import_definitions=import_definitions) elif cmd_id == self.cmd_diff_c: html_diff = CHtmlDiff() item = self.items[n] src_id = long(item[1]) cur = self.differ.db.cursor() sql = "select source from src.functions where id = ?" cur.execute(sql, (src_id, )) row = cur.fetchone() cur.close() if not row: Warning("Cannot find the source function.") return False ea = long(item[3], 16) proto = self.differ.decompile_and_get(ea) if not proto: Warning("Cannot decompile function 0x%08x" % ea) return False buf1 = indent_source(row[0].decode("utf-8", "ignore")) buf2 = proto buf2 += u"\n".join(self.differ.pseudo[ea]) new_buf = indent_source(buf2) src = html_diff.make_file(new_buf.split(u"\n"), buf1.split(u"\n")) title = "Diff pseudo-source %s - %s" % (item[2], item[4]) cdiffer = CHtmlViewer() cdiffer.Show(src, title)