Python pygments.lexers.CppLexer() Examples

The following are 5 code examples of pygments.lexers.CppLexer(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module pygments.lexers , or try the search function .
Example #1
Source File: diaphora_ida.py    From maltindex with GNU General Public License v2.0 6 votes vote down vote up
def show_pseudo(self, item, primary):
    cur = self.db_cursor()
    if primary:
      db = "main"
    else:
      db = "diff"
    ea = str(int(item[1], 16))
    sql = "select prototype, pseudocode, name from %s.functions where address = ?"
    sql = sql % db
    cur.execute(sql, (str(ea), ))
    row = cur.fetchone()
    if row is None or row["prototype"] is None or row["pseudocode"] is None:
      Warning("Sorry, there is no pseudo-code available for the selected function.")
    else:
      fmt = HtmlFormatter()
      fmt.noclasses = True
      fmt.linenos = True
      func = "%s\n%s" % (row["prototype"], row["pseudocode"])
      src = highlight(func, CppLexer(), fmt)
      title = "Pseudo-code for %s" % row["name"]
      cdiffer = CHtmlViewer()
      cdiffer.Show(src, title)
    cur.close() 
Example #2
Source File: diaphora_ida.py    From diaphora with GNU Affero General Public License v3.0 6 votes vote down vote up
def show_pseudo(self, item, primary):
    cur = self.db_cursor()
    if primary:
      db = "main"
    else:
      db = "diff"
    ea = str(int(item[1], 16))
    sql = "select prototype, pseudocode, name from %s.functions where address = ?"
    sql = sql % db
    cur.execute(sql, (str(ea), ))
    row = cur.fetchone()
    if row is None or row["prototype"] is None or row["pseudocode"] is None:
      warning("Sorry, there is no pseudo-code available for the selected function.")
    else:
      fmt = HtmlFormatter()
      fmt.noclasses = True
      fmt.linenos = True
      func = "%s\n%s" % (row["prototype"], row["pseudocode"])
      src = highlight(func, CppLexer(), fmt)
      title = "Pseudo-code for %s" % row["name"]
      cdiffer = CHtmlViewer()
      cdiffer.Show(src, title)
    cur.close() 
Example #3
Source File: test_completion_lexer.py    From Computable with MIT License 5 votes vote down vote up
def testC(self):
        """ Does the CompletionLexer work for C/C++?
        """
        lexer = CompletionLexer(CLexer())
        self.assertEqual(lexer.get_context("foo.bar"), [ "foo", "bar" ])
        self.assertEqual(lexer.get_context("foo->bar"), [ "foo", "bar" ])

        lexer = CompletionLexer(CppLexer())
        self.assertEqual(lexer.get_context("Foo::Bar"), [ "Foo", "Bar" ]) 
Example #4
Source File: test_cpp.py    From pygments with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def lexer():
    yield CppLexer() 
Example #5
Source File: diaphora_ida.py    From diaphora with GNU Affero General Public License v3.0 4 votes vote down vote up
def show_pseudo_diff(self, item, html = True):
    cur = self.db_cursor()
    sql = """select *
               from (
             select prototype, pseudocode, name, 1
               from functions
              where address = ?
                and pseudocode is not null
       union select prototype, pseudocode, name, 2
               from diff.functions
              where address = ?
                and pseudocode is not null)
              order by 4 asc"""
    ea1 = str(int(item[1], 16))
    ea2 = str(int(item[3], 16))
    cur.execute(sql, (ea1, ea2))
    rows = cur.fetchall()
    if len(rows) != 2:
      warning("Sorry, there is no pseudo-code available for either the first or the second database.")
    else:
      row1 = rows[0]
      row2 = rows[1]

      html_diff = CHtmlDiff()
      proto1 = self.decompile_and_get(int(ea1))
      if proto1:
        buf1 = proto1 + "\n" + "\n".join(self.pseudo[int(ea1)])
      else:
        log("warning: cannot retrieve the current pseudo-code for the function, using the previously saved one...")
        buf1 = row1["prototype"] + "\n" + row1["pseudocode"]
      buf2 = row2["prototype"] + "\n" + row2["pseudocode"]

      if buf1 == buf2:
        warning("Both pseudo-codes are equal.")
        return

      fmt = HtmlFormatter()
      fmt.noclasses = True
      fmt.linenos = False
      fmt.nobackground = True
      if not html:
        uni_diff = difflib.unified_diff(buf1.split("\n"), buf2.split("\n"))
        tmp = []
        for line in uni_diff:
          tmp.append(line.strip("\n"))
        tmp = tmp[2:]
        buf = "\n".join(tmp)
        
        src = highlight(buf, DiffLexer(), fmt)
      else:
        src = html_diff.make_file(buf1.split("\n"), buf2.split("\n"), fmt, CppLexer())

      title = "Diff pseudo-code %s - %s" % (row1["name"], row2["name"])
      cdiffer = CHtmlViewer()
      cdiffer.Show(src, title)

    cur.close()