-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a13ee8d
commit 22eb5ca
Showing
13 changed files
with
523 additions
and
1 deletion.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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': /[{}(),;:]/ | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
true | ||
false | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["boolean", "true"], | ||
["boolean", "false"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for booleans. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# comment | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["comment", "# comment"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for comments. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
foo: | ||
$VALUES: | ||
12: | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["field", "foo"], | ||
["punctuation", ":"], | ||
["field", "$VALUES"], | ||
["punctuation", ":"], | ||
["field", "12"], | ||
["punctuation", ":"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for fields. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
Oops, something went wrong.