Skip to content

Commit 22eb5ca

Browse files
Added support for Smali (#2419)
1 parent a13ee8d commit 22eb5ca

13 files changed

+523
-1
lines changed

components.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components.json

+4
Original file line numberDiff line numberDiff line change
@@ -987,6 +987,10 @@
987987
"require": "bash",
988988
"owner": "RunDevelopment"
989989
},
990+
"smali": {
991+
"title": "Smali",
992+
"owner": "RunDevelopment"
993+
},
990994
"smalltalk": {
991995
"title": "Smalltalk",
992996
"owner": "Golmote"

components/prism-smali.js

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
// Test files for the parser itself:
2+
// https://github.com/JesusFreke/smali/tree/master/smali/src/test/resources/LexerTest
3+
4+
Prism.languages.smali = {
5+
'comment': /#.*/,
6+
'string': {
7+
pattern: /"(?:[^\r\n\\"]|\\.)*"|'(?:[^\r\n\\']|\\(?:.|u[\da-fA-F]{4}))'/,
8+
greedy: true
9+
},
10+
11+
'class-name': {
12+
pattern: /L(?:(?:\w+|`[^`\r\n]*`)\/)*(?:[\w$]+|`[^`\r\n]*`)(?=\s*;)/,
13+
inside: {
14+
'class-name': {
15+
pattern: /(^L|\/)(?:[\w$]+|`[^`\r\n]*`)$/,
16+
lookbehind: true
17+
},
18+
'namespace': {
19+
pattern: /^(L)(?:(?:\w+|`[^`\r\n]*`)\/)+/,
20+
lookbehind: true,
21+
inside: {
22+
'punctuation': /\//
23+
}
24+
},
25+
'builtin': /^L/
26+
}
27+
},
28+
'builtin': [
29+
{
30+
// Reference: https://github.com/JesusFreke/smali/wiki/TypesMethodsAndFields#types
31+
pattern: /([();\[])[BCDFIJSVZ]+/,
32+
lookbehind: true
33+
},
34+
{
35+
// e.g. .field mWifiOnUid:I
36+
pattern: /([\w$>]:)[BCDFIJSVZ]/,
37+
lookbehind: true
38+
}
39+
],
40+
'keyword': [
41+
{
42+
pattern: /(\.end\s+)[\w-]+/,
43+
lookbehind: true
44+
},
45+
{
46+
pattern: /(^|[^\w.-])\.(?!\d)[\w-]+/,
47+
lookbehind: true
48+
},
49+
{
50+
pattern: /(^|[^\w.-])(?:abstract|annotation|bridge|constructor|enum|final|interface|private|protected|public|runtime|static|synthetic|system|transient)(?![\w.-])/,
51+
lookbehind: true
52+
}
53+
],
54+
'function': {
55+
pattern: /(^|[^\w.-])(?:\w+|<[\w$-]+>)(?=\()/,
56+
lookbehind: true
57+
},
58+
59+
'field': {
60+
pattern: /[\w$]+(?=:)/,
61+
alias: 'variable'
62+
},
63+
'register': {
64+
pattern: /(^|[^\w.-])[vp]\d(?![\w.-])/,
65+
lookbehind: true,
66+
alias: 'variable'
67+
},
68+
69+
'boolean': {
70+
pattern: /(^|[^\w.-])(?:true|false)(?![\w.-])/,
71+
lookbehind: true
72+
},
73+
'number': {
74+
pattern: /(^|[^/\w.-])-?(?:NAN|INFINITY|0x(?:[\dA-F]+(?:\.[\dA-F]*)?|\.[\dA-F]+)(?:p[+-]?[\dA-F]+)?|(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?)[dflst]?(?![\w.-])/i,
75+
lookbehind: true
76+
},
77+
78+
'label': {
79+
pattern: /(:)\w+/,
80+
lookbehind: true,
81+
alias: 'property'
82+
},
83+
84+
'operator': /->|\.\.|[\[=]/,
85+
'punctuation': /[{}(),;:]/
86+
};

components/prism-smali.min.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/prism-smali.html

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<h2>Full example</h2>
2+
<pre><code># Source: https://github.com/JesusFreke/smali/blob/master/examples/HelloWorld/HelloWorld.smali
3+
4+
.class public LHelloWorld;
5+
6+
#Ye olde hello world application
7+
#To assemble and run this on a phone or emulator:
8+
#
9+
#java -jar smali.jar -o classes.dex HelloWorld.smali
10+
#zip HelloWorld.zip classes.dex
11+
#adb push HelloWorld.zip /data/local
12+
#adb shell dalvikvm -cp /data/local/HelloWorld.zip HelloWorld
13+
#
14+
#if you get out of memory type errors when running smali.jar, try
15+
#java -Xmx512m -jar smali.jar HelloWorld.smali
16+
#instead
17+
18+
.super Ljava/lang/Object;
19+
20+
.method public static main([Ljava/lang/String;)V
21+
.registers 2
22+
23+
sget-object v0, Ljava/lang/System;->out:Ljava/io/PrintStream;
24+
25+
const-string v1, "Hello World!"
26+
27+
invoke-virtual {v0, v1}, Ljava/io/PrintStream;->println(Ljava/lang/String;)V
28+
29+
return-void
30+
.end method</code></pre>
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
true
2+
false
3+
4+
----------------------------------------------------
5+
6+
[
7+
["boolean", "true"],
8+
["boolean", "false"]
9+
]
10+
11+
----------------------------------------------------
12+
13+
Checks for booleans.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
LMain;
2+
Ljava/lang/String;
3+
Lfoo/bar/Foo$Bar;
4+
LFoo$Bar;
5+
6+
Ljava/lang/String;
7+
LI;
8+
LV;
9+
LI/I/I;
10+
L`single`;
11+
L`java`/lang/String;
12+
L`java`/`lang`/`String`;
13+
Lspace/test/`20 a0 1680 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 200a 202f 205f 3000 `;
14+
15+
16+
----------------------------------------------------
17+
18+
[
19+
["class-name", [
20+
["builtin", "L"],
21+
["class-name", "Main"]
22+
]],
23+
["punctuation", ";"],
24+
["class-name", [
25+
["builtin", "L"],
26+
["namespace", [
27+
"java",
28+
["punctuation", "/"],
29+
"lang",
30+
["punctuation", "/"]
31+
]],
32+
["class-name", "String"]
33+
]],
34+
["punctuation", ";"],
35+
["class-name", [
36+
["builtin", "L"],
37+
["namespace", [
38+
"foo",
39+
["punctuation", "/"],
40+
"bar",
41+
["punctuation", "/"]
42+
]],
43+
["class-name", "Foo$Bar"]
44+
]],
45+
["punctuation", ";"],
46+
["class-name", [
47+
["builtin", "L"],
48+
["class-name", "Foo$Bar"]
49+
]],
50+
["punctuation", ";"],
51+
["class-name", [
52+
["builtin", "L"],
53+
["namespace", [
54+
"java",
55+
["punctuation", "/"],
56+
"lang",
57+
["punctuation", "/"]
58+
]],
59+
["class-name", "String"]
60+
]],
61+
["punctuation", ";"],
62+
["class-name", [
63+
["builtin", "L"],
64+
["class-name", "I"]
65+
]],
66+
["punctuation", ";"],
67+
["class-name", [
68+
["builtin", "L"],
69+
["class-name", "V"]
70+
]],
71+
["punctuation", ";"],
72+
["class-name", [
73+
["builtin", "L"],
74+
["namespace", [
75+
"I",
76+
["punctuation", "/"],
77+
"I",
78+
["punctuation", "/"]
79+
]],
80+
["class-name", "I"]
81+
]],
82+
["punctuation", ";"],
83+
["class-name", [
84+
["builtin", "L"],
85+
["class-name", "`single`"]
86+
]],
87+
["punctuation", ";"],
88+
["class-name", [
89+
["builtin", "L"],
90+
["namespace", [
91+
"`java`",
92+
["punctuation", "/"],
93+
"lang",
94+
["punctuation", "/"]
95+
]],
96+
["class-name", "String"]
97+
]],
98+
["punctuation", ";"],
99+
["class-name", [
100+
["builtin", "L"],
101+
["namespace", [
102+
"`java`",
103+
["punctuation", "/"],
104+
"`lang`",
105+
["punctuation", "/"]
106+
]],
107+
["class-name", "`String`"]
108+
]],
109+
["punctuation", ";"],
110+
["class-name", [
111+
["builtin", "L"],
112+
["namespace", [
113+
"space",
114+
["punctuation", "/"],
115+
"test",
116+
["punctuation", "/"]
117+
]],
118+
["class-name", "`20 a0 1680 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 200a 202f 205f 3000 `"]
119+
]],
120+
["punctuation", ";"]
121+
]
122+
123+
----------------------------------------------------
124+
125+
Checks for class names.
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# comment
2+
3+
----------------------------------------------------
4+
5+
[
6+
["comment", "# comment"]
7+
]
8+
9+
----------------------------------------------------
10+
11+
Checks for comments.
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
foo:
2+
$VALUES:
3+
12:
4+
5+
----------------------------------------------------
6+
7+
[
8+
["field", "foo"],
9+
["punctuation", ":"],
10+
["field", "$VALUES"],
11+
["punctuation", ":"],
12+
["field", "12"],
13+
["punctuation", ":"]
14+
]
15+
16+
----------------------------------------------------
17+
18+
Checks for fields.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
foo()V
2+
<init>(Ljava/lang/String;I)V
3+
<clinit>()V
4+
5+
# a complex method
6+
method(I[[IILjava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;
7+
8+
----------------------------------------------------
9+
10+
[
11+
["function", "foo"],
12+
["punctuation", "("],
13+
["punctuation", ")"],
14+
["builtin", "V"],
15+
16+
["function", "<init>"],
17+
["punctuation", "("],
18+
["class-name", [
19+
["builtin", "L"],
20+
["namespace", [
21+
"java",
22+
["punctuation", "/"],
23+
"lang",
24+
["punctuation", "/"]
25+
]],
26+
["class-name", "String"]
27+
]],
28+
["punctuation", ";"],
29+
["builtin", "I"],
30+
["punctuation", ")"],
31+
["builtin", "V"],
32+
33+
["function", "<clinit>"],
34+
["punctuation", "("],
35+
["punctuation", ")"],
36+
["builtin", "V"],
37+
38+
["comment", "# a complex method"],
39+
40+
["function", "method"],
41+
["punctuation", "("],
42+
["builtin", "I"],
43+
["operator", "["],
44+
["operator", "["],
45+
["builtin", "II"],
46+
["class-name", [
47+
["builtin", "L"],
48+
["namespace", [
49+
"java",
50+
["punctuation", "/"],
51+
"lang",
52+
["punctuation", "/"]
53+
]],
54+
["class-name", "String"]
55+
]],
56+
["punctuation", ";"],
57+
["operator", "["],
58+
["class-name", [
59+
["builtin", "L"],
60+
["namespace", [
61+
"java",
62+
["punctuation", "/"],
63+
"lang",
64+
["punctuation", "/"]
65+
]],
66+
["class-name", "Object"]
67+
]],
68+
["punctuation", ";"],
69+
["punctuation", ")"],
70+
["class-name", [
71+
["builtin", "L"],
72+
["namespace", [
73+
"java",
74+
["punctuation", "/"],
75+
"lang",
76+
["punctuation", "/"]
77+
]],
78+
["class-name", "String"]
79+
]],
80+
["punctuation", ";"]
81+
]
82+
83+
----------------------------------------------------
84+
85+
Checks for functions/methods.

0 commit comments

Comments
 (0)