mirror of
https://github.com/revanced/smali.git
synced 2025-05-29 04:10:13 +02:00
Disallow spaces in Simple name prior to the future API level 30.
This commit is contained in:
parent
586ec594e2
commit
209ba3b0a6
@ -153,7 +153,7 @@ public class Smali {
|
|||||||
fis = new FileInputStream(smaliFile);
|
fis = new FileInputStream(smaliFile);
|
||||||
InputStreamReader reader = new InputStreamReader(fis, "UTF-8");
|
InputStreamReader reader = new InputStreamReader(fis, "UTF-8");
|
||||||
|
|
||||||
LexerErrorInterface lexer = new smaliFlexLexer(reader);
|
LexerErrorInterface lexer = new smaliFlexLexer(reader, options.apiLevel);
|
||||||
((smaliFlexLexer)lexer).setSourceFile(smaliFile);
|
((smaliFlexLexer)lexer).setSourceFile(smaliFile);
|
||||||
CommonTokenStream tokens = new CommonTokenStream((TokenSource)lexer);
|
CommonTokenStream tokens = new CommonTokenStream((TokenSource)lexer);
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ public class SmaliTestUtils {
|
|||||||
|
|
||||||
Reader reader = new StringReader(smaliText);
|
Reader reader = new StringReader(smaliText);
|
||||||
|
|
||||||
lexer = new smaliFlexLexer(reader);
|
lexer = new smaliFlexLexer(reader, apiLevel);
|
||||||
tokens = new CommonTokenStream((TokenSource)lexer);
|
tokens = new CommonTokenStream((TokenSource)lexer);
|
||||||
|
|
||||||
smaliParser parser = new smaliParser(tokens);
|
smaliParser parser = new smaliParser(tokens);
|
||||||
|
@ -18,6 +18,11 @@ import static org.jf.smali.smaliParser.*;
|
|||||||
%column
|
%column
|
||||||
%char
|
%char
|
||||||
|
|
||||||
|
%ctorarg int apiLevel
|
||||||
|
%init{
|
||||||
|
this.apiLevel = apiLevel;
|
||||||
|
%init}
|
||||||
|
|
||||||
%{
|
%{
|
||||||
private StringBuffer sb = new StringBuffer();
|
private StringBuffer sb = new StringBuffer();
|
||||||
private String stringOrCharError = null;
|
private String stringOrCharError = null;
|
||||||
@ -31,6 +36,8 @@ import static org.jf.smali.smaliParser.*;
|
|||||||
|
|
||||||
private boolean suppressErrors;
|
private boolean suppressErrors;
|
||||||
|
|
||||||
|
private int apiLevel;
|
||||||
|
|
||||||
public Token nextToken() {
|
public Token nextToken() {
|
||||||
try {
|
try {
|
||||||
Token token = yylex();
|
Token token = yylex();
|
||||||
@ -129,6 +136,13 @@ import static org.jf.smali.smaliParser.*;
|
|||||||
return invalidToken(message, yytext());
|
return invalidToken(message, yytext());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Token simpleNameToken(String text, boolean quoted) {
|
||||||
|
if (quoted) {
|
||||||
|
text = text.substring(1, text.length() - 1); /* strip backticks */
|
||||||
|
}
|
||||||
|
return newToken(SIMPLE_NAME, text);
|
||||||
|
}
|
||||||
|
|
||||||
private void beginStringOrChar(int state) {
|
private void beginStringOrChar(int state) {
|
||||||
yybegin(state);
|
yybegin(state);
|
||||||
sb.setLength(0);
|
sb.setLength(0);
|
||||||
@ -228,8 +242,9 @@ SimpleNameCharacter = ({HighSurrogate} {LowSurrogate}) | [A-Za-z0-9$\-_\u00a1-\u
|
|||||||
UnicodeSpace = [\u0020\u00A0\u1680\u2000-\u200A\u202F\u205F\u3000] /* Zs category */
|
UnicodeSpace = [\u0020\u00A0\u1680\u2000-\u200A\u202F\u205F\u3000] /* Zs category */
|
||||||
|
|
||||||
SimpleNameRaw = {SimpleNameCharacter}+
|
SimpleNameRaw = {SimpleNameCharacter}+
|
||||||
SimpleNameQuoted = [`] ({SimpleNameCharacter} | {UnicodeSpace})+ [`]
|
SimpleNameQuoted = [`] {SimpleNameCharacter}+ [`]
|
||||||
SimpleName = {SimpleNameRaw} | {SimpleNameQuoted}
|
SimpleNameQuotedWithSpaces = [`] ({SimpleNameCharacter} | {UnicodeSpace})+ [`]
|
||||||
|
SimpleName = {SimpleNameRaw} | {SimpleNameQuoted} | {SimpleNameQuotedWithSpaces}
|
||||||
|
|
||||||
PrimitiveType = [ZBSCIJFD]
|
PrimitiveType = [ZBSCIJFD]
|
||||||
|
|
||||||
@ -685,11 +700,14 @@ Type = {PrimitiveType} | {ClassDescriptor} | {ArrayPrefix} ({ClassDescriptor} |
|
|||||||
yybegin(PARAM_LIST);
|
yybegin(PARAM_LIST);
|
||||||
}
|
}
|
||||||
|
|
||||||
{SimpleNameRaw} { return newToken(SIMPLE_NAME); }
|
{SimpleNameRaw} { return simpleNameToken(yytext(), false); }
|
||||||
{SimpleNameQuoted} {
|
{SimpleNameQuoted} { return simpleNameToken(yytext(), true); }
|
||||||
String quoted = yytext();
|
{SimpleNameQuotedWithSpaces} {
|
||||||
String raw = quoted.substring(1, quoted.length() - 1); /* strip backticks */
|
if (apiLevel < 30) {
|
||||||
return newToken(SIMPLE_NAME, raw);
|
String message = "spaces in SimpleName are not allowed prior to API level 30";
|
||||||
|
return new InvalidToken(message, yytext());
|
||||||
|
}
|
||||||
|
return simpleNameToken(yytext(), true);
|
||||||
}
|
}
|
||||||
"<" {SimpleNameRaw} ">" { return newToken(MEMBER_NAME); }
|
"<" {SimpleNameRaw} ">" { return newToken(MEMBER_NAME); }
|
||||||
}
|
}
|
||||||
|
@ -158,7 +158,8 @@ public class LexerTest {
|
|||||||
if (smaliStream == null) {
|
if (smaliStream == null) {
|
||||||
Assert.fail("Could not load " + smaliFile);
|
Assert.fail("Could not load " + smaliFile);
|
||||||
}
|
}
|
||||||
smaliFlexLexer lexer = new smaliFlexLexer(new InputStreamReader(smaliStream));
|
smaliFlexLexer lexer = new smaliFlexLexer(new InputStreamReader(smaliStream),
|
||||||
|
10000 /* most recent API level */);
|
||||||
lexer.setSourceFile(new File(test + ".smali"));
|
lexer.setSourceFile(new File(test + ".smali"));
|
||||||
lexer.setSuppressErrors(true);
|
lexer.setSuppressErrors(true);
|
||||||
|
|
||||||
|
@ -55,4 +55,5 @@ III
|
|||||||
|
|
||||||
[I->clone()Ljava/lang/Object;
|
[I->clone()Ljava/lang/Object;
|
||||||
|
|
||||||
`method_with_spaces_20 a0 1680 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 200a 202f 205f 3000 `
|
`simple_name_in_backticks`
|
||||||
|
`simple_name_with_spaces_20 a0 1680 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 200a 202f 205f 3000 `
|
||||||
|
@ -109,4 +109,5 @@ OPEN_PAREN("(")
|
|||||||
CLOSE_PAREN(")")
|
CLOSE_PAREN(")")
|
||||||
CLASS_DESCRIPTOR("Ljava/lang/Object;")
|
CLASS_DESCRIPTOR("Ljava/lang/Object;")
|
||||||
|
|
||||||
SIMPLE_NAME("method_with_spaces_20 a0 1680 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 200a 202f 205f 3000 ")
|
SIMPLE_NAME("simple_name_in_backticks")
|
||||||
|
SIMPLE_NAME("simple_name_with_spaces_20 a0 1680 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 200a 202f 205f 3000 ")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user