Skip to content

Commit

Permalink
update antlr to 4.9.3 (#599)
Browse files Browse the repository at this point in the history
Co-authored-by: Nico Mexis <[email protected]>
  • Loading branch information
pxb1988 and ThexXTURBOXx authored Sep 1, 2023
1 parent 7fafa42 commit ee63470
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 17 deletions.
4 changes: 2 additions & 2 deletions d2j-smali/build.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
apply plugin: 'antlr'

dependencies {
compile 'org.antlr:antlr4-runtime:4.5'
compile 'org.antlr:antlr4-runtime:4.9.3' // Newer versions only for Java 11+
compile project(':dex-reader')
antlr 'org.antlr:antlr4:4.5'
antlr 'org.antlr:antlr4:4.9.3' // Newer versions only for Java 11+
compile project(':d2j-base-cmd')
compile project(':dex-writer')
testImplementation "com.android.tools.smali:smali-baksmali:3.0.3"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ HEX_DIGIT : ('0'..'9'|'a'..'f'|'A'..'F') ;

fragment
ESC_SEQ
: '\\' ('b'|'t'|'n'|'f'|'r'|'\''|'\"'|'\\')
: '\\' ('b'|'t'|'n'|'f'|'r'|'\''|'"'|'\\')
| UNICODE_ESC
| OCTAL_ESC
;
Expand All @@ -58,7 +58,7 @@ fragment
FRAGMENT_ARRAY_TYPE: ('[')+ (FRAGMENT_PRIMITIVE_TYPE|FRAGMENT_OBJECT_TYPE);

fragment
FRAGMENT_ID: (ESC_SEQ| ~('\\'|'\r'|'\n'|'\t'|' '|':'|'-'|'='|','|'{'|'}'|'('|')'|'+'|'\"'|'\''|'#'|'/'|'.'|';'|'@'))+;
FRAGMENT_ID: (ESC_SEQ| ~('\\'|'\r'|'\n'|'\t'|' '|':'|'-'|'='|','|'{'|'}'|'('|')'|'+'|'"'|'\''|'#'|'/'|'.'|';'|'@'))+;
fragment
FRAGMENT_METHOD_PROTO: '(' (FRAGMENT_OBJECT_TYPE|FRAGMENT_ARRAY_TYPE|FRAGMENT_PRIMITIVE_TYPE)* ')' ('V' | FRAGMENT_OBJECT_TYPE|FRAGMENT_ARRAY_TYPE|FRAGMENT_PRIMITIVE_TYPE)
;
Expand Down
26 changes: 13 additions & 13 deletions d2j-smali/src/main/java/com/googlecode/d2j/smali/Smali.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@
import com.googlecode.d2j.smali.antlr4.SmaliLexer;
import com.googlecode.d2j.smali.antlr4.SmaliParser;
import com.googlecode.d2j.visitors.DexFileVisitor;
import org.antlr.v4.runtime.*;

import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.CharStreams;
import org.antlr.v4.runtime.CodePointCharStream;
import org.antlr.v4.runtime.CommonTokenStream;

import java.io.IOException;
import java.io.InputStream;
Expand All @@ -37,22 +41,19 @@
public class Smali {
public static void smaliFile(Path path, DexFileVisitor dcv) throws IOException {
try (Reader reader = Files.newBufferedReader(path, StandardCharsets.UTF_8)) {
ANTLRInputStream is = new ANTLRInputStream(reader);
is.name = path.toString();
CodePointCharStream is = CharStreams.fromReader(reader, path.toString());
smali0(dcv, is);
}
}

public static void smaliFile(String name, String buff, DexFileVisitor dcv) throws IOException {
ANTLRInputStream is = new ANTLRInputStream(buff);
is.name = name;
public static void smaliFile(String name, String buff, DexFileVisitor dcv) {
CodePointCharStream is = CharStreams.fromString(buff, name);
smali0(dcv, is);
}

public static void smaliFile(String name, InputStream in, DexFileVisitor dcv) throws IOException {
try (InputStreamReader reader = new InputStreamReader(in, StandardCharsets.UTF_8)) {
ANTLRInputStream is = new ANTLRInputStream(reader);
is.name = name;
CodePointCharStream is = CharStreams.fromReader(reader, name);
smali0(dcv, is);
}
}
Expand All @@ -63,13 +64,13 @@ public static DexClassNode smaliFile2Node(String name, InputStream in) throws IO
return dfn.clzs.size() > 0 ? dfn.clzs.get(0) : null;
}

public static DexClassNode smaliFile2Node(String name, String buff) throws IOException {
public static DexClassNode smaliFile2Node(String name, String buff) {
DexFileNode dfn = new DexFileNode();
smaliFile(name, buff, dfn);
return dfn.clzs.size() > 0 ? dfn.clzs.get(0) : null;
}

private static void smali0(DexFileVisitor dcv, CharStream is) throws IOException {
private static void smali0(DexFileVisitor dcv, CharStream is) {
SmaliLexer lexer = new SmaliLexer(is);
CommonTokenStream ts = new CommonTokenStream(lexer);
SmaliParser parser = new SmaliParser(ts);
Expand All @@ -79,10 +80,9 @@ private static void smali0(DexFileVisitor dcv, CharStream is) throws IOException
}
}

public static void smaliFile(String fileName, char[] data, DexFileVisitor dcv) throws IOException {
public static void smaliFile(String fileName, char[] data, DexFileVisitor dcv) {
// System.err.println("parsing " + f.getAbsoluteFile());
ANTLRInputStream is = new ANTLRInputStream(data, data.length);
is.name = fileName;
CodePointCharStream is = CharStreams.fromString(new String(data), fileName);
smali0(dcv, is);
}

Expand Down
4 changes: 4 additions & 0 deletions d2j-smali/src/test/java/a/SmaliTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ public void test2() throws IOException {
for (File f : fs) {
if (f.getName().endsWith(".dex") || f.getName().endsWith(".apk")) {
System.out.println(f.getName());
if (f.getName().equals("dex040.dex")) {
// FIXME smali 3.0.3 not support space in SimpleName
continue;
}
dotest(f);
}
}
Expand Down

0 comments on commit ee63470

Please sign in to comment.