public static void assertSmaliCompiledEquals(String source, String expected, BaksmaliOptions options, boolean stripComments) throws IOException, RecognitionException { ClassDef classDef = SmaliTestUtils.compileSmali(source, options.apiLevel); // Remove unnecessary whitespace and optionally strip all comments from smali file String normalizedActual = getNormalizedSmali(classDef, options, stripComments); String normalizedExpected = normalizeSmali(expected, stripComments); // Assert that normalized strings are now equal Assert.assertEquals(normalizedExpected, normalizedActual); }
@Test public void testImplicitFieldReference() throws RecognitionException, IOException { ClassDef classDef = SmaliTestUtils.compileSmali("" + ".class public LHelloWorld;\n" + ".super Ljava/lang/Object;\n" +
@Test public void testImplicitMethodReference() throws RecognitionException, IOException { ClassDef classDef = SmaliTestUtils.compileSmali("" + ".class public LHelloWorld;\n" + ".super Ljava/lang/Object;\n" +
public static ClassDef compileSmali(String smaliText, int apiLevel) throws RecognitionException, IOException { CommonTokenStream tokens; LexerErrorInterface lexer; DexBuilder dexBuilder = new DexBuilder(Opcodes.forApi(apiLevel)); Reader reader = new StringReader(smaliText); lexer = new smaliFlexLexer(reader); tokens = new CommonTokenStream((TokenSource)lexer); smaliParser parser = new smaliParser(tokens); parser.setVerboseErrors(true); parser.setAllowOdex(false); parser.setApiLevel(apiLevel); smaliParser.smali_file_return result = parser.smali_file(); if(parser.getNumberOfSyntaxErrors() > 0 || lexer.getNumberOfSyntaxErrors() > 0) { throw new RuntimeException("Error occurred while compiling text"); } CommonTree t = result.getTree(); CommonTreeNodeStream treeStream = new CommonTreeNodeStream(t); treeStream.setTokenStream(tokens); smaliTreeWalker dexGen = new smaliTreeWalker(treeStream); dexGen.setApiLevel(apiLevel); dexGen.setVerboseErrors(true);
public static ClassDef compileSmali(String smaliText, int apiLevel) throws RecognitionException, IOException { CommonTokenStream tokens; LexerErrorInterface lexer; DexBuilder dexBuilder = new DexBuilder(Opcodes.forApi(apiLevel)); Reader reader = new StringReader(smaliText); lexer = new smaliFlexLexer(reader); tokens = new CommonTokenStream((TokenSource)lexer); smaliParser parser = new smaliParser(tokens); parser.setVerboseErrors(true); parser.setAllowOdex(false); parser.setApiLevel(apiLevel); smaliParser.smali_file_return result = parser.smali_file(); if(parser.getNumberOfSyntaxErrors() > 0 || lexer.getNumberOfSyntaxErrors() > 0) { throw new RuntimeException("Error occurred while compiling text"); } CommonTree t = result.getTree(); CommonTreeNodeStream treeStream = new CommonTreeNodeStream(t); treeStream.setTokenStream(tokens); smaliTreeWalker dexGen = new smaliTreeWalker(treeStream); dexGen.setApiLevel(apiLevel); dexGen.setVerboseErrors(true);
@Test public void testImplicitFieldLiteral() throws RecognitionException, IOException { ClassDef classDef = SmaliTestUtils.compileSmali("" + ".class public LHelloWorld;\n" + ".super Ljava/lang/Object;\n" +
@Test public void testImplicitMethodLiteral() throws RecognitionException, IOException { ClassDef classDef = SmaliTestUtils.compileSmali("" + ".class public LHelloWorld;\n" + ".super Ljava/lang/Object;\n" +