BVB Source Codes

voltron Show lexers.py Source code

Return Download voltron: download lexers.py Source code - Download voltron Source code - Type:.py
  1. import re
  2.  
  3. from pygments.lexer import RegexLexer, include, bygroups, using, DelegatingLexer
  4. from pygments.lexers import get_lexer_by_name
  5. from pygments.token import *
  6.  
  7.  
  8. class DisassemblyLexer(RegexLexer):
  9.     """
  10.    For Nasm (Intel) disassembly from LLDB.
  11.  
  12.    Based on the NasmLexer included with Pygments
  13.    """
  14.     name = 'LLDB Intel syntax disassembly'
  15.     aliases = ['lldb_intel']
  16.     filenames = []
  17.     mimetypes = []
  18.  
  19.     identifier = r'[<a-z$._?][\w$.?#@~\+>]*'
  20.     hexn = r'(?:0[xX][0-9a-f]+|$0[0-9a-f]*|[0-9]+[0-9a-f]*h)'
  21.     octn = r'[0-7]+q'
  22.     binn = r'[01]+b'
  23.     decn = r'[0-9]+'
  24.     floatn = decn + r'\.e?' + decn
  25.     string = r'"(\\"|[^"\n])*"|' + r"'(\\'|[^'\n])*'|" + r"`(\\`|[^`\n])*`"
  26.     declkw = r'(?:res|d)[bwdqt]|times'
  27.     register = (r'r[0-9]+[bwd]{0,1}|'
  28.                 r'[a-d][lh]|[er]?[a-d]x|[er]?[sbi]p|[er]?[sd]i|[c-gs]s|st[0-7]|'
  29.                 r'mm[0-7]|cr[0-4]|dr[0-367]|tr[3-7]|.mm\d+')
  30.     wordop = r'seg|wrt|strict'
  31.     type = r'byte|[dq]?word|ptr|xmmword|opaque'
  32.  
  33.     flags = re.IGNORECASE | re.MULTILINE
  34.     tokens = {
  35.         'root': [
  36.             (identifier + '`' + identifier, Name.Function),
  37.             ('->', Generic.Prompt),
  38.             include('whitespace'),
  39.             (r'^\s*%', Comment.Preproc, 'preproc'),
  40.             (identifier + ':', Name.Label),
  41.             (r'(%s)(\s+)(equ)' % identifier,
  42.                 bygroups(Name.Constant, Keyword.Declaration, Keyword.Declaration),
  43.                 'instruction-args'),
  44.             (declkw, Keyword.Declaration, 'instruction-args'),
  45.             (identifier, Keyword.Declaration, 'instruction-args'),
  46.             (r' *' + hexn, Name.Label),
  47.             (r'[:]', Text),
  48.             (r'^->', Error),
  49.             (r'[\r\n]+', Text)
  50.         ],
  51.         'instruction-args': [
  52.             (register, Name.Builtin),
  53.             (string, String),
  54.             (hexn, Number.Hex),
  55.             (octn, Number.Oct),
  56.             (binn, Number.Bin),
  57.             (floatn, Number.Float),
  58.             (decn, Number.Integer),
  59.             include('punctuation'),
  60.             (identifier, Name.Variable),
  61.             (r'[\r\n]+', Text, '#pop'),
  62.             include('whitespace')
  63.         ],
  64.         'preproc': [
  65.             (r'[^;\n]+', Comment.Preproc),
  66.             (r';.*?\n', Comment.Single, '#pop'),
  67.             (r'\n', Comment.Preproc, '#pop'),
  68.         ],
  69.         'whitespace': [
  70.             (r'\n', Text),
  71.             (r'[ \t]+', Text),
  72.             (r';.*', Comment.Single),
  73.             (r'#.*', Comment.Single)
  74.         ],
  75.         'punctuation': [
  76.             (r'[,():\[\]]+', Punctuation),
  77.             (r'[&|^<>+*/%~-]+', Operator),
  78.             (r'[$]+', Keyword.Constant),
  79.             (wordop, Operator.Word),
  80.             (type, Keyword.Type)
  81.         ],
  82.     }
  83.  
  84.  
  85. class LLDBIntelLexer(DisassemblyLexer):
  86.     name = 'LLDB Intel syntax disassembly'
  87.     aliases = ['lldb_intel']
  88.  
  89.  
  90. class LLDBATTLexer(DisassemblyLexer):
  91.     name = 'LLDB AT&T syntax disassembly'
  92.     aliases = ['lldb_att']
  93.  
  94.  
  95. class GDBATTLexer(DisassemblyLexer):
  96.     name = 'GDB AT&T syntax disassembly'
  97.     aliases = ['gdb_att']
  98.  
  99.  
  100. class GDBIntelLexer(DisassemblyLexer):
  101.     name = 'GDB Intel syntax disassembly'
  102.     aliases = ['gdb_intel']
  103.  
  104.  
  105. class VDBATTLexer(DisassemblyLexer):
  106.     name = 'VDB AT&T syntax disassembly'
  107.     aliases = ['vdb_att']
  108.  
  109.  
  110. class CapstoneIntelLexer(DisassemblyLexer):
  111.     name = 'Capstone Intel syntax disassembly'
  112.     aliases = ['capstone_intel']
  113.  
  114.  
  115. class VDBIntelLexer(RegexLexer):
  116.     """
  117.    For Nasm (Intel) disassembly from VDB.
  118.  
  119.    Based on the LLDBIntelLexer above.
  120.    major difference is the raw instruction hex after the instruction address.
  121.  
  122.    example:
  123.      rip     0x000000000056eb4f: 4885ff            test rdi,rdi ;0x7f4f8740ca50,0x7f4f8740ca50
  124.              0x000000000056eb52: 740f              jz 0x0056eb63
  125.    """
  126.     name = 'VDB Intel syntax disassembly'
  127.     aliases = ['vdb_intel']
  128.     filenames = []
  129.     mimetypes = []
  130.  
  131.     space = r'[ \t]+'
  132.     identifier = r'[<a-z$._?][\w$.?#@~\+>]*'
  133.     hexn = r'(?:0[xX][0-9a-f]+|$0[0-9a-f]*|[0-9]+[0-9a-f]*h)'  # hex number
  134.     hexr = r'(?:[0-9a-f]+)'  # hex raw (no leader/trailer)
  135.     octn = r'[0-7]+q'
  136.     binn = r'[01]+b'
  137.     decn = r'[0-9]+'
  138.     floatn = decn + r'\.e?' + decn
  139.     string = r'"(\\"|[^"\n])*"|' + r"'(\\'|[^'\n])*'|" + r"`(\\`|[^`\n])*`"
  140.     register = (r'r[0-9]+[bwd]{0,1}|'
  141.                 r'[a-d][lh]|[er]?[a-d]x|[er]?[sbi]p|[er]?[sd]i|[c-gs]s|st[0-7]|'
  142.                 r'mm[0-7]|cr[0-4]|dr[0-367]|tr[3-7]|.mm\d*')
  143.     wordop = r'seg|wrt|strict'
  144.     type = r'byte|[dq]?word|ptr'
  145.  
  146.     flags = re.IGNORECASE | re.MULTILINE
  147.     tokens = {
  148.         'root': [
  149.             (r'^(%s)(%s)(%s)(: )(%s)(%s)' % (register, space, hexn, hexr, space),
  150.              bygroups(Name.Builtin, Text, Name.Label, Text, Number.Hex, Text),
  151.              "instruction"),
  152.             (r'^(%s)(%s)(: )(%s)(%s)' % (space, hexn, hexr, space),
  153.              bygroups(Text, Name.Label, Text, Number.Hex, Text),
  154.              "instruction")
  155.         ],
  156.         'instruction': [
  157.             (space, Text),
  158.             (r"(rep[a-z]*)( )", bygroups(Name.Function, Text)),
  159.             (r"(%s)" % identifier, Name.Function, ("#pop", "instruction-args")),
  160.         ],
  161.         'instruction-args': [
  162.             (space, Text),
  163.             (string, String),
  164.             (hexn, Number.Hex),
  165.             (octn, Number.Oct),
  166.             (binn, Number.Bin),
  167.             (floatn, Number.Float),
  168.             (decn, Number.Integer),
  169.             include('punctuation'),
  170.             (register, Name.Builtin),
  171.             (identifier, Name.Variable),
  172.             (r'[\r\n]+', Text, '#pop'),
  173.             (r';', Text, ("#pop", 'comment')),
  174.         ],
  175.         'comment': [
  176.             (space, Text),
  177.             (string, Comment.Single),
  178.             (hexn, Number.Hex),
  179.             (octn, Number.Oct),
  180.             (binn, Number.Bin),
  181.             (floatn, Number.Float),
  182.             (decn, Number.Integer),
  183.             include('punctuation'),
  184.             (register, Name.Builtin),
  185.             (identifier, Name.Variable),
  186.             (r'[\r\n]+', Text, '#pop'),
  187.         ],
  188.         'punctuation': [
  189.             (r'[,():\[\]]+', Punctuation),
  190.             (r'[&|^<>+*/%~-]+', Operator),
  191.             (r'[$]+', Keyword.Constant),
  192.             (wordop, Operator.Word),
  193.             (type, Keyword.Type)
  194.         ],
  195.     }
  196.  
  197.  
  198. class WinDbgIntelLexer(RegexLexer):
  199.     name = 'WinDbg Intel syntax disassembly'
  200.     aliases = ['windbg_intel']
  201.     filenames = []
  202.     mimetypes = []
  203.  
  204.     identifier = r'[<a-z$._?][\w$.?#@~>]*'
  205.     hexn = r'(0[xX])?([0-9a-f]+|$0[0-9a-f`]*|[0-9]+[0-9a-f]*h)'
  206.     addr = r'(0[xX])?([0-9a-f`]+|$0[0-9a-f`]*|[0-9]+[0-9a-f`]*h)'
  207.     octn = r'[0-7]+q'
  208.     binn = r'[01]+b'
  209.     decn = r'[0-9]+'
  210.     floatn = decn + r'\.e?' + decn
  211.     string = r'"(\\"|[^"\n])*"|' + r"'(\\'|[^'\n])*'|" + r"`(\\`|[^`\n])*`"
  212.     declkw = r'(?:res|d)[bwdqt]|times'
  213.     register = (r'r[0-9]+?[bwd]{0,1}|'
  214.                 r'[a-d][lh]|[er]?[a-d]x|[er]?[sbi]p|[er]?[sd]i|[c-gs]s|st[0-7]|'
  215.                 r'mm[0-7]|cr[0-4]|dr[0-367]|tr[3-7]|.mm\d*')
  216.     wordop = r'seg|wrt|strict'
  217.     type = r'byte|[dq]?word|ptr'
  218.     func = r'[a-zA-Z]*\!?'
  219.  
  220.     flags = re.IGNORECASE | re.MULTILINE
  221.     tokens = {
  222.         'root': [
  223.             (addr, Number.Hex, 'instruction-line'),
  224.             include('whitespace'),
  225.             (identifier, Name.Class, 'label'),
  226.             (r'[:]', Text),
  227.             (r'[\r\n]+', Text)
  228.         ],
  229.         'instruction-line': [
  230.             (r' ', Text),
  231.             (hexn, Text, 'instruction'),
  232.         ],
  233.         'instruction': [
  234.             include('whitespace'),
  235.             (r'(%s)(\s+)(equ)' % identifier,
  236.                 bygroups(Name.Constant, Keyword.Declaration, Keyword.Declaration),
  237.                 'instruction-args'),
  238.             (declkw, Keyword.Declaration, 'instruction-args'),
  239.             (identifier, Name.Function, 'instruction-args'),
  240.         ],
  241.         'label': [
  242.             (r'[!+]', Operator),
  243.             (identifier, Name.Function),
  244.             (hexn, Number.Hex),
  245.             (r'[:]', Text, '#pop'),
  246.  
  247.         ],
  248.         'instruction-args': [
  249.             (string, String),
  250.             include('punctuation'),
  251.             (register, Name.Builtin),
  252.             include('label'),
  253.             (identifier, Name.Variable),
  254.             (r'[\r\n]+', Text, '#pop:3'),
  255.             include('whitespace'),
  256.             (hexn, Number.Hex),
  257.             (addr, Number.Hex),
  258.             (octn, Number.Oct),
  259.             (binn, Number.Bin),
  260.             (floatn, Number.Float),
  261.             (decn, Number.Integer),
  262.         ],
  263.         'preproc': [
  264.             (r'[^;\n]+', Comment.Preproc),
  265.             (r';.*?\n', Comment.Single, '#pop'),
  266.             (r'\n', Comment.Preproc, '#pop'),
  267.         ],
  268.         'whitespace': [
  269.             (r'\n', Text),
  270.             (r'[ \t]+', Text),
  271.             (r';.*', Comment.Single),
  272.             (r'#.*', Comment.Single)
  273.         ],
  274.         'punctuation': [
  275.             (r'[,():\[\]]+', Punctuation),
  276.             (r'[&|^<>+*/%~-]+', Operator),
  277.             (r'[$]+', Keyword.Constant),
  278.             (wordop, Operator.Word),
  279.             (type, Keyword.Type)
  280.         ],
  281.     }
  282.  
  283.  
  284. class WinDbgATTLexer(WinDbgIntelLexer):
  285.     name = 'WinDbg ATT syntax disassembly'
  286.     aliases = ['windbg_att']
  287.  
downloadlexers.py Source code - Download voltron Source code
Related Source Codes/Software:
IGListKit - A data-driven UICollectionView framework for build... 2017-01-11
androidmvp - MVP Android Example 2017-01-11
svelte - The magical disappearing UI framework ... 2017-01-11
kcptun - A Simple UDP Tunnel Based On KCP 2017-01-11
poisontap - Exploits locked/password protected computers over ... 2017-01-10
ecma262 - Status, process, and documents for ECMA262 ... 2017-01-11
react-native-elements - React Native Elements UI Toolkit 2017-01-11
tensorflow-zh - Google new open source ai system TensorFlow Chines... 2017-01-11
forum - Blue light (the Lantern) the official BBS 2017-01-11
socketcluster - Highly scalable realtime framework ... 2017-01-11
mobile-chrome-apps - Chrome apps on Android and iOS 2017-02-20
pycrumbs - Bits and bytes of Python from the Internet 2017-02-20
drupal - Verbatim mirror of the git.drupal.org repository f... 2017-02-20
elasticsearch-head - A web front end for an elastic search cluster 2017-02-19
launchrocket - A Mac PrefPane to manage all your Homebrew-install... 2017-02-19
jquery-boilerplate - A jump-start for jQuery plugins development ... 2017-02-19
MVVMReactiveCocoa - GitBucket iOS A 2017-02-19
ios-webkit-debug-proxy - A DevTools proxy (Chrome Remote Debugging Protocol... 2017-02-19
jump.js - A modern smooth scrolling library. ... 2017-02-19
GoSublime - A Golang plugin collection for SublimeText **3**, ... 2017-02-19

 Back to top