smali.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. Language: Smali
  3. Author: Dennis Titze <dennis.titze@gmail.com>
  4. Description: Basic Smali highlighting
  5. Website: https://github.com/JesusFreke/smali
  6. Category: assembler
  7. */
  8. function smali(hljs) {
  9. const smali_instr_low_prio = [
  10. 'add',
  11. 'and',
  12. 'cmp',
  13. 'cmpg',
  14. 'cmpl',
  15. 'const',
  16. 'div',
  17. 'double',
  18. 'float',
  19. 'goto',
  20. 'if',
  21. 'int',
  22. 'long',
  23. 'move',
  24. 'mul',
  25. 'neg',
  26. 'new',
  27. 'nop',
  28. 'not',
  29. 'or',
  30. 'rem',
  31. 'return',
  32. 'shl',
  33. 'shr',
  34. 'sput',
  35. 'sub',
  36. 'throw',
  37. 'ushr',
  38. 'xor'
  39. ];
  40. const smali_instr_high_prio = [
  41. 'aget',
  42. 'aput',
  43. 'array',
  44. 'check',
  45. 'execute',
  46. 'fill',
  47. 'filled',
  48. 'goto/16',
  49. 'goto/32',
  50. 'iget',
  51. 'instance',
  52. 'invoke',
  53. 'iput',
  54. 'monitor',
  55. 'packed',
  56. 'sget',
  57. 'sparse'
  58. ];
  59. const smali_keywords = [
  60. 'transient',
  61. 'constructor',
  62. 'abstract',
  63. 'final',
  64. 'synthetic',
  65. 'public',
  66. 'private',
  67. 'protected',
  68. 'static',
  69. 'bridge',
  70. 'system'
  71. ];
  72. return {
  73. name: 'Smali',
  74. contains: [
  75. {
  76. className: 'string',
  77. begin: '"',
  78. end: '"',
  79. relevance: 0
  80. },
  81. hljs.COMMENT(
  82. '#',
  83. '$',
  84. { relevance: 0 }
  85. ),
  86. {
  87. className: 'keyword',
  88. variants: [
  89. { begin: '\\s*\\.end\\s[a-zA-Z0-9]*' },
  90. {
  91. begin: '^[ ]*\\.[a-zA-Z]*',
  92. relevance: 0
  93. },
  94. {
  95. begin: '\\s:[a-zA-Z_0-9]*',
  96. relevance: 0
  97. },
  98. { begin: '\\s(' + smali_keywords.join('|') + ')' }
  99. ]
  100. },
  101. {
  102. className: 'built_in',
  103. variants: [
  104. { begin: '\\s(' + smali_instr_low_prio.join('|') + ')\\s' },
  105. {
  106. begin: '\\s(' + smali_instr_low_prio.join('|') + ')((-|/)[a-zA-Z0-9]+)+\\s',
  107. relevance: 10
  108. },
  109. {
  110. begin: '\\s(' + smali_instr_high_prio.join('|') + ')((-|/)[a-zA-Z0-9]+)*\\s',
  111. relevance: 10
  112. }
  113. ]
  114. },
  115. {
  116. className: 'class',
  117. begin: 'L[^\(;:\n]*;',
  118. relevance: 0
  119. },
  120. { begin: '[vp][0-9]+' }
  121. ]
  122. };
  123. }
  124. export { smali as default };