smali.js 2.3 KB

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