Added support for Smali (#2419)
This commit is contained in:
parent
a13ee8d981
commit
22eb5cadf1
File diff suppressed because one or more lines are too long
|
@ -987,6 +987,10 @@
|
|||
"require": "bash",
|
||||
"owner": "RunDevelopment"
|
||||
},
|
||||
"smali": {
|
||||
"title": "Smali",
|
||||
"owner": "RunDevelopment"
|
||||
},
|
||||
"smalltalk": {
|
||||
"title": "Smalltalk",
|
||||
"owner": "Golmote"
|
||||
|
|
|
@ -0,0 +1,86 @@
|
|||
// Test files for the parser itself:
|
||||
// https://github.com/JesusFreke/smali/tree/master/smali/src/test/resources/LexerTest
|
||||
|
||||
Prism.languages.smali = {
|
||||
'comment': /#.*/,
|
||||
'string': {
|
||||
pattern: /"(?:[^\r\n\\"]|\\.)*"|'(?:[^\r\n\\']|\\(?:.|u[\da-fA-F]{4}))'/,
|
||||
greedy: true
|
||||
},
|
||||
|
||||
'class-name': {
|
||||
pattern: /L(?:(?:\w+|`[^`\r\n]*`)\/)*(?:[\w$]+|`[^`\r\n]*`)(?=\s*;)/,
|
||||
inside: {
|
||||
'class-name': {
|
||||
pattern: /(^L|\/)(?:[\w$]+|`[^`\r\n]*`)$/,
|
||||
lookbehind: true
|
||||
},
|
||||
'namespace': {
|
||||
pattern: /^(L)(?:(?:\w+|`[^`\r\n]*`)\/)+/,
|
||||
lookbehind: true,
|
||||
inside: {
|
||||
'punctuation': /\//
|
||||
}
|
||||
},
|
||||
'builtin': /^L/
|
||||
}
|
||||
},
|
||||
'builtin': [
|
||||
{
|
||||
// Reference: https://github.com/JesusFreke/smali/wiki/TypesMethodsAndFields#types
|
||||
pattern: /([();\[])[BCDFIJSVZ]+/,
|
||||
lookbehind: true
|
||||
},
|
||||
{
|
||||
// e.g. .field mWifiOnUid:I
|
||||
pattern: /([\w$>]:)[BCDFIJSVZ]/,
|
||||
lookbehind: true
|
||||
}
|
||||
],
|
||||
'keyword': [
|
||||
{
|
||||
pattern: /(\.end\s+)[\w-]+/,
|
||||
lookbehind: true
|
||||
},
|
||||
{
|
||||
pattern: /(^|[^\w.-])\.(?!\d)[\w-]+/,
|
||||
lookbehind: true
|
||||
},
|
||||
{
|
||||
pattern: /(^|[^\w.-])(?:abstract|annotation|bridge|constructor|enum|final|interface|private|protected|public|runtime|static|synthetic|system|transient)(?![\w.-])/,
|
||||
lookbehind: true
|
||||
}
|
||||
],
|
||||
'function': {
|
||||
pattern: /(^|[^\w.-])(?:\w+|<[\w$-]+>)(?=\()/,
|
||||
lookbehind: true
|
||||
},
|
||||
|
||||
'field': {
|
||||
pattern: /[\w$]+(?=:)/,
|
||||
alias: 'variable'
|
||||
},
|
||||
'register': {
|
||||
pattern: /(^|[^\w.-])[vp]\d(?![\w.-])/,
|
||||
lookbehind: true,
|
||||
alias: 'variable'
|
||||
},
|
||||
|
||||
'boolean': {
|
||||
pattern: /(^|[^\w.-])(?:true|false)(?![\w.-])/,
|
||||
lookbehind: true
|
||||
},
|
||||
'number': {
|
||||
pattern: /(^|[^/\w.-])-?(?:NAN|INFINITY|0x(?:[\dA-F]+(?:\.[\dA-F]*)?|\.[\dA-F]+)(?:p[+-]?[\dA-F]+)?|(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?)[dflst]?(?![\w.-])/i,
|
||||
lookbehind: true
|
||||
},
|
||||
|
||||
'label': {
|
||||
pattern: /(:)\w+/,
|
||||
lookbehind: true,
|
||||
alias: 'property'
|
||||
},
|
||||
|
||||
'operator': /->|\.\.|[\[=]/,
|
||||
'punctuation': /[{}(),;:]/
|
||||
};
|
|
@ -0,0 +1 @@
|
|||
Prism.languages.smali={comment:/#.*/,string:{pattern:/"(?:[^\r\n\\"]|\\.)*"|'(?:[^\r\n\\']|\\(?:.|u[\da-fA-F]{4}))'/,greedy:!0},"class-name":{pattern:/L(?:(?:\w+|`[^`\r\n]*`)\/)*(?:[\w$]+|`[^`\r\n]*`)(?=\s*;)/,inside:{"class-name":{pattern:/(^L|\/)(?:[\w$]+|`[^`\r\n]*`)$/,lookbehind:!0},namespace:{pattern:/^(L)(?:(?:\w+|`[^`\r\n]*`)\/)+/,lookbehind:!0,inside:{punctuation:/\//}},builtin:/^L/}},builtin:[{pattern:/([();\[])[BCDFIJSVZ]+/,lookbehind:!0},{pattern:/([\w$>]:)[BCDFIJSVZ]/,lookbehind:!0}],keyword:[{pattern:/(\.end\s+)[\w-]+/,lookbehind:!0},{pattern:/(^|[^\w.-])\.(?!\d)[\w-]+/,lookbehind:!0},{pattern:/(^|[^\w.-])(?:abstract|annotation|bridge|constructor|enum|final|interface|private|protected|public|runtime|static|synthetic|system|transient)(?![\w.-])/,lookbehind:!0}],function:{pattern:/(^|[^\w.-])(?:\w+|<[\w$-]+>)(?=\()/,lookbehind:!0},field:{pattern:/[\w$]+(?=:)/,alias:"variable"},register:{pattern:/(^|[^\w.-])[vp]\d(?![\w.-])/,lookbehind:!0,alias:"variable"},boolean:{pattern:/(^|[^\w.-])(?:true|false)(?![\w.-])/,lookbehind:!0},number:{pattern:/(^|[^/\w.-])-?(?:NAN|INFINITY|0x(?:[\dA-F]+(?:\.[\dA-F]*)?|\.[\dA-F]+)(?:p[+-]?[\dA-F]+)?|(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?)[dflst]?(?![\w.-])/i,lookbehind:!0},label:{pattern:/(:)\w+/,lookbehind:!0,alias:"property"},operator:/->|\.\.|[\[=]/,punctuation:/[{}(),;:]/};
|
|
@ -0,0 +1,30 @@
|
|||
<h2>Full example</h2>
|
||||
<pre><code># Source: https://github.com/JesusFreke/smali/blob/master/examples/HelloWorld/HelloWorld.smali
|
||||
|
||||
.class public LHelloWorld;
|
||||
|
||||
#Ye olde hello world application
|
||||
#To assemble and run this on a phone or emulator:
|
||||
#
|
||||
#java -jar smali.jar -o classes.dex HelloWorld.smali
|
||||
#zip HelloWorld.zip classes.dex
|
||||
#adb push HelloWorld.zip /data/local
|
||||
#adb shell dalvikvm -cp /data/local/HelloWorld.zip HelloWorld
|
||||
#
|
||||
#if you get out of memory type errors when running smali.jar, try
|
||||
#java -Xmx512m -jar smali.jar HelloWorld.smali
|
||||
#instead
|
||||
|
||||
.super Ljava/lang/Object;
|
||||
|
||||
.method public static main([Ljava/lang/String;)V
|
||||
.registers 2
|
||||
|
||||
sget-object v0, Ljava/lang/System;->out:Ljava/io/PrintStream;
|
||||
|
||||
const-string v1, "Hello World!"
|
||||
|
||||
invoke-virtual {v0, v1}, Ljava/io/PrintStream;->println(Ljava/lang/String;)V
|
||||
|
||||
return-void
|
||||
.end method</code></pre>
|
|
@ -0,0 +1,13 @@
|
|||
true
|
||||
false
|
||||
|
||||
----------------------------------------------------
|
||||
|
||||
[
|
||||
["boolean", "true"],
|
||||
["boolean", "false"]
|
||||
]
|
||||
|
||||
----------------------------------------------------
|
||||
|
||||
Checks for booleans.
|
|
@ -0,0 +1,125 @@
|
|||
LMain;
|
||||
Ljava/lang/String;
|
||||
Lfoo/bar/Foo$Bar;
|
||||
LFoo$Bar;
|
||||
|
||||
Ljava/lang/String;
|
||||
LI;
|
||||
LV;
|
||||
LI/I/I;
|
||||
L`single`;
|
||||
L`java`/lang/String;
|
||||
L`java`/`lang`/`String`;
|
||||
Lspace/test/`20 a0 1680 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 200a 202f 205f 3000 `;
|
||||
|
||||
|
||||
----------------------------------------------------
|
||||
|
||||
[
|
||||
["class-name", [
|
||||
["builtin", "L"],
|
||||
["class-name", "Main"]
|
||||
]],
|
||||
["punctuation", ";"],
|
||||
["class-name", [
|
||||
["builtin", "L"],
|
||||
["namespace", [
|
||||
"java",
|
||||
["punctuation", "/"],
|
||||
"lang",
|
||||
["punctuation", "/"]
|
||||
]],
|
||||
["class-name", "String"]
|
||||
]],
|
||||
["punctuation", ";"],
|
||||
["class-name", [
|
||||
["builtin", "L"],
|
||||
["namespace", [
|
||||
"foo",
|
||||
["punctuation", "/"],
|
||||
"bar",
|
||||
["punctuation", "/"]
|
||||
]],
|
||||
["class-name", "Foo$Bar"]
|
||||
]],
|
||||
["punctuation", ";"],
|
||||
["class-name", [
|
||||
["builtin", "L"],
|
||||
["class-name", "Foo$Bar"]
|
||||
]],
|
||||
["punctuation", ";"],
|
||||
["class-name", [
|
||||
["builtin", "L"],
|
||||
["namespace", [
|
||||
"java",
|
||||
["punctuation", "/"],
|
||||
"lang",
|
||||
["punctuation", "/"]
|
||||
]],
|
||||
["class-name", "String"]
|
||||
]],
|
||||
["punctuation", ";"],
|
||||
["class-name", [
|
||||
["builtin", "L"],
|
||||
["class-name", "I"]
|
||||
]],
|
||||
["punctuation", ";"],
|
||||
["class-name", [
|
||||
["builtin", "L"],
|
||||
["class-name", "V"]
|
||||
]],
|
||||
["punctuation", ";"],
|
||||
["class-name", [
|
||||
["builtin", "L"],
|
||||
["namespace", [
|
||||
"I",
|
||||
["punctuation", "/"],
|
||||
"I",
|
||||
["punctuation", "/"]
|
||||
]],
|
||||
["class-name", "I"]
|
||||
]],
|
||||
["punctuation", ";"],
|
||||
["class-name", [
|
||||
["builtin", "L"],
|
||||
["class-name", "`single`"]
|
||||
]],
|
||||
["punctuation", ";"],
|
||||
["class-name", [
|
||||
["builtin", "L"],
|
||||
["namespace", [
|
||||
"`java`",
|
||||
["punctuation", "/"],
|
||||
"lang",
|
||||
["punctuation", "/"]
|
||||
]],
|
||||
["class-name", "String"]
|
||||
]],
|
||||
["punctuation", ";"],
|
||||
["class-name", [
|
||||
["builtin", "L"],
|
||||
["namespace", [
|
||||
"`java`",
|
||||
["punctuation", "/"],
|
||||
"`lang`",
|
||||
["punctuation", "/"]
|
||||
]],
|
||||
["class-name", "`String`"]
|
||||
]],
|
||||
["punctuation", ";"],
|
||||
["class-name", [
|
||||
["builtin", "L"],
|
||||
["namespace", [
|
||||
"space",
|
||||
["punctuation", "/"],
|
||||
"test",
|
||||
["punctuation", "/"]
|
||||
]],
|
||||
["class-name", "`20 a0 1680 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 200a 202f 205f 3000 `"]
|
||||
]],
|
||||
["punctuation", ";"]
|
||||
]
|
||||
|
||||
----------------------------------------------------
|
||||
|
||||
Checks for class names.
|
|
@ -0,0 +1,11 @@
|
|||
# comment
|
||||
|
||||
----------------------------------------------------
|
||||
|
||||
[
|
||||
["comment", "# comment"]
|
||||
]
|
||||
|
||||
----------------------------------------------------
|
||||
|
||||
Checks for comments.
|
|
@ -0,0 +1,18 @@
|
|||
foo:
|
||||
$VALUES:
|
||||
12:
|
||||
|
||||
----------------------------------------------------
|
||||
|
||||
[
|
||||
["field", "foo"],
|
||||
["punctuation", ":"],
|
||||
["field", "$VALUES"],
|
||||
["punctuation", ":"],
|
||||
["field", "12"],
|
||||
["punctuation", ":"]
|
||||
]
|
||||
|
||||
----------------------------------------------------
|
||||
|
||||
Checks for fields.
|
|
@ -0,0 +1,85 @@
|
|||
foo()V
|
||||
<init>(Ljava/lang/String;I)V
|
||||
<clinit>()V
|
||||
|
||||
# a complex method
|
||||
method(I[[IILjava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;
|
||||
|
||||
----------------------------------------------------
|
||||
|
||||
[
|
||||
["function", "foo"],
|
||||
["punctuation", "("],
|
||||
["punctuation", ")"],
|
||||
["builtin", "V"],
|
||||
|
||||
["function", "<init>"],
|
||||
["punctuation", "("],
|
||||
["class-name", [
|
||||
["builtin", "L"],
|
||||
["namespace", [
|
||||
"java",
|
||||
["punctuation", "/"],
|
||||
"lang",
|
||||
["punctuation", "/"]
|
||||
]],
|
||||
["class-name", "String"]
|
||||
]],
|
||||
["punctuation", ";"],
|
||||
["builtin", "I"],
|
||||
["punctuation", ")"],
|
||||
["builtin", "V"],
|
||||
|
||||
["function", "<clinit>"],
|
||||
["punctuation", "("],
|
||||
["punctuation", ")"],
|
||||
["builtin", "V"],
|
||||
|
||||
["comment", "# a complex method"],
|
||||
|
||||
["function", "method"],
|
||||
["punctuation", "("],
|
||||
["builtin", "I"],
|
||||
["operator", "["],
|
||||
["operator", "["],
|
||||
["builtin", "II"],
|
||||
["class-name", [
|
||||
["builtin", "L"],
|
||||
["namespace", [
|
||||
"java",
|
||||
["punctuation", "/"],
|
||||
"lang",
|
||||
["punctuation", "/"]
|
||||
]],
|
||||
["class-name", "String"]
|
||||
]],
|
||||
["punctuation", ";"],
|
||||
["operator", "["],
|
||||
["class-name", [
|
||||
["builtin", "L"],
|
||||
["namespace", [
|
||||
"java",
|
||||
["punctuation", "/"],
|
||||
"lang",
|
||||
["punctuation", "/"]
|
||||
]],
|
||||
["class-name", "Object"]
|
||||
]],
|
||||
["punctuation", ";"],
|
||||
["punctuation", ")"],
|
||||
["class-name", [
|
||||
["builtin", "L"],
|
||||
["namespace", [
|
||||
"java",
|
||||
["punctuation", "/"],
|
||||
"lang",
|
||||
["punctuation", "/"]
|
||||
]],
|
||||
["class-name", "String"]
|
||||
]],
|
||||
["punctuation", ";"]
|
||||
]
|
||||
|
||||
----------------------------------------------------
|
||||
|
||||
Checks for functions/methods.
|
|
@ -0,0 +1,45 @@
|
|||
abstract
|
||||
annotation
|
||||
bridge
|
||||
constructor
|
||||
enum
|
||||
final
|
||||
interface
|
||||
private
|
||||
protected
|
||||
public
|
||||
runtime
|
||||
static
|
||||
synthetic
|
||||
system
|
||||
transient
|
||||
|
||||
.something
|
||||
.end something
|
||||
|
||||
----------------------------------------------------
|
||||
|
||||
[
|
||||
["keyword", "abstract"],
|
||||
["keyword", "annotation"],
|
||||
["keyword", "bridge"],
|
||||
["keyword", "constructor"],
|
||||
["keyword", "enum"],
|
||||
["keyword", "final"],
|
||||
["keyword", "interface"],
|
||||
["keyword", "private"],
|
||||
["keyword", "protected"],
|
||||
["keyword", "public"],
|
||||
["keyword", "runtime"],
|
||||
["keyword", "static"],
|
||||
["keyword", "synthetic"],
|
||||
["keyword", "system"],
|
||||
["keyword", "transient"],
|
||||
["keyword", ".something"],
|
||||
["keyword", ".end"],
|
||||
["keyword", "something"]
|
||||
]
|
||||
|
||||
----------------------------------------------------
|
||||
|
||||
Checks for keywords.
|
|
@ -0,0 +1,88 @@
|
|||
123
|
||||
-123
|
||||
123t
|
||||
123s
|
||||
123l
|
||||
123T
|
||||
123S
|
||||
123L
|
||||
|
||||
123f
|
||||
123.0f
|
||||
123.0
|
||||
-1234e-9
|
||||
.2e-2
|
||||
-.2e-2
|
||||
-1234.D
|
||||
.2f
|
||||
|
||||
0xFF
|
||||
0xFFt
|
||||
0x0FFs
|
||||
0x0FFl
|
||||
0x123ABCp-1D
|
||||
0x12AB.12ABp10d
|
||||
|
||||
infinity
|
||||
infinityd
|
||||
infinityf
|
||||
infinityD
|
||||
infinityF
|
||||
|
||||
INFINITY
|
||||
INFINITYd
|
||||
INFINITYf
|
||||
INFINITYD
|
||||
INFINITYF
|
||||
|
||||
NaN
|
||||
NaNd
|
||||
NaNf
|
||||
NaND
|
||||
NaNF
|
||||
|
||||
----------------------------------------------------
|
||||
|
||||
[
|
||||
["number", "123"],
|
||||
["number", "-123"],
|
||||
["number", "123t"],
|
||||
["number", "123s"],
|
||||
["number", "123l"],
|
||||
["number", "123T"],
|
||||
["number", "123S"],
|
||||
["number", "123L"],
|
||||
["number", "123f"],
|
||||
["number", "123.0f"],
|
||||
["number", "123.0"],
|
||||
["number", "-1234e-9"],
|
||||
["number", ".2e-2"],
|
||||
["number", "-.2e-2"],
|
||||
["number", "-1234.D"],
|
||||
["number", ".2f"],
|
||||
["number", "0xFF"],
|
||||
["number", "0xFFt"],
|
||||
["number", "0x0FFs"],
|
||||
["number", "0x0FFl"],
|
||||
["number", "0x123ABCp-1D"],
|
||||
["number", "0x12AB.12ABp10d"],
|
||||
["number", "infinity"],
|
||||
["number", "infinityd"],
|
||||
["number", "infinityf"],
|
||||
["number", "infinityD"],
|
||||
["number", "infinityF"],
|
||||
["number", "INFINITY"],
|
||||
["number", "INFINITYd"],
|
||||
["number", "INFINITYf"],
|
||||
["number", "INFINITYD"],
|
||||
["number", "INFINITYF"],
|
||||
["number", "NaN"],
|
||||
["number", "NaNd"],
|
||||
["number", "NaNf"],
|
||||
["number", "NaND"],
|
||||
["number", "NaNF"]
|
||||
]
|
||||
|
||||
----------------------------------------------------
|
||||
|
||||
Checks for numbers.
|
|
@ -0,0 +1,16 @@
|
|||
""
|
||||
"foo"
|
||||
|
||||
'c'
|
||||
|
||||
----------------------------------------------------
|
||||
|
||||
[
|
||||
["string", "\"\""],
|
||||
["string", "\"foo\""],
|
||||
["string", "'c'"]
|
||||
]
|
||||
|
||||
----------------------------------------------------
|
||||
|
||||
Checks for strings and chars.
|
Loading…
Reference in New Issue