Python pygments.lexers.NasmLexer() Examples

The following are 8 code examples of pygments.lexers.NasmLexer(). 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_asm(self, item, primary):
    cur = self.db_cursor()
    if primary:
      db = "main"
    else:
      db = "diff"
    ea = str(int(item[1], 16))
    sql = "select prototype, assembly, name from %s.functions where address = ?"
    sql = sql % db
    cur.execute(sql, (ea, ))
    row = cur.fetchone()
    if row is None:
      Warning("Sorry, there is no assembly available for the selected function.")
    else:
      fmt = HtmlFormatter()
      fmt.noclasses = True
      fmt.linenos = True
      asm = self.prettify_asm(row["assembly"])
      final_asm = "; %s\n%s proc near\n%s\n%s endp\n"
      final_asm = final_asm % (row["prototype"], row["name"], asm, row["name"])
      src = highlight(final_asm, NasmLexer(), fmt)
      title = "Assembly 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_asm(self, item, primary):
    cur = self.db_cursor()
    if primary:
      db = "main"
    else:
      db = "diff"
    ea = str(int(item[1], 16))
    sql = "select prototype, assembly, name from %s.functions where address = ?"
    sql = sql % db
    cur.execute(sql, (ea, ))
    row = cur.fetchone()
    if row is None:
      warning("Sorry, there is no assembly available for the selected function.")
    else:
      fmt = HtmlFormatter()
      fmt.noclasses = True
      fmt.linenos = True
      asm = self.prettify_asm(row["assembly"])
      final_asm = "; %s\n%s proc near\n%s\n%s endp\n"
      final_asm = final_asm % (row["prototype"], row["name"], asm, row["name"])
      src = highlight(final_asm, NasmLexer(), fmt)
      title = "Assembly for %s" % row["name"]
      cdiffer = CHtmlViewer()
      cdiffer.Show(src, title)
    cur.close() 
Example #3
Source File: rainbow.py    From rainbow with GNU Lesser General Public License v3.0 5 votes vote down vote up
def __init__(self, trace=True, sca_mode=False,sca_HD=False):
        self.breakpoints = []
        self.skips = []
        self.emu = None
        self.disasm = None
        self.uc_reg = None
        self.mapped_regions = []
        self.page_size = 0
        self.functions = {}
        self.function_names = {}
        self.profile_counter = 0

        self.OTHER_REGS = {}
        self.OTHER_REGS_NAMES = {}

        # Tracing properties
        self.trace = trace
        self.mem_trace = False
        self.function_calls = False
        self.trace_regs = False
        self.stubbed_functions = {}

        self.sca_mode = sca_mode

        ## Prepare a live disassembler
        self.asm_hl = NasmLexer()
        self.asm_fmt = formatter(outencoding="utf-8")

        colorama.init()

        self.trace_reset()

        # Take into account another leakage model
        self.sca_HD = sca_HD 
Example #4
Source File: context_view.py    From angrgdb with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def cap_disasm(self, ip):
        md = capstone.Cs(self.state.project.arch.cs_arch, self.state.project.arch.cs_mode)
        r = ""
        code = self.state.memory.load(ip, MAX_DISASS_LENGHT*10)
        code = self.state.solver.eval(code, cast_to=bytes)
        cnt = 0
        for i in md.disasm(code, MAX_DISASS_LENGHT*10):
            r += "0x%x:\t%s\t%s\n" % (ip + i.address, i.mnemonic, i.op_str)
            cnt += 1
            if cnt == 18: break
        return highlight(r, NasmLexer(), TerminalFormatter()) 
Example #5
Source File: context_view.py    From angrgdb with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def __pstr_codeblock(self, ip) -> str:
        """Get the pretty version of a basic block with Pygemnts"""
        try:
            block = self.state.project.factory.block(ip)
            code = self._disassembler.disass_block(block)
            return highlight(code, NasmLexer(), TerminalFormatter())
        except SimEngineError:
            return None 
Example #6
Source File: test_asm.py    From pygments with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def lexer_nasm():
    yield NasmLexer() 
Example #7
Source File: x86.py    From deen with Apache License 2.0 5 votes vote down vote up
def _syntax_highlighting(self, data):
        try:
            from pygments import highlight
            from pygments.lexers import NasmLexer, GasLexer
            from pygments.formatters import TerminalFormatter, Terminal256Formatter
            from pygments.styles import get_style_by_name
            style = get_style_by_name('colorful')
            import curses
            curses.setupterm()
            if curses.tigetnum('colors') >= 256:
                FORMATTER = Terminal256Formatter(style=style)
            else:
                FORMATTER = TerminalFormatter()
            if self.ks.syntax == keystone.KS_OPT_SYNTAX_INTEL:
                lexer = NasmLexer()
            else:
                lexer = GasLexer()
            # When pygments is available, we
            # can print the disassembled
            # instructions with syntax
            # highlighting.
            data = highlight(data, lexer, FORMATTER)
        except ImportError:
            pass
        finally:
            data = data.encode()
        return data 
Example #8
Source File: diaphora_ida.py    From diaphora with GNU Affero General Public License v3.0 5 votes vote down vote up
def show_asm_diff(self, item):
    cur = self.db_cursor()
    sql = """select *
               from (
             select prototype, assembly, name, 1
               from functions
              where address = ?
                and assembly is not null
       union select prototype, assembly, name, 2
               from diff.functions
              where address = ?
                and assembly 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 assembly available for either the first or the second database.")
    else:
      row1 = rows[0]
      row2 = rows[1]

      html_diff = CHtmlDiff()
      asm1 = self.prettify_asm(row1["assembly"])
      asm2 = self.prettify_asm(row2["assembly"])
      buf1 = "%s proc near\n%s\n%s endp" % (row1["name"], asm1, row1["name"])
      buf2 = "%s proc near\n%s\n%s endp" % (row2["name"], asm2, row2["name"])
      
      fmt = HtmlFormatter()
      fmt.noclasses = True
      fmt.linenos = False
      fmt.nobackground = True
      src = html_diff.make_file(buf1.split("\n"), buf2.split("\n"), fmt, NasmLexer())

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

    cur.close()