diff --git a/examples/AnnotationTypes/Main.smali b/examples/AnnotationTypes/Main.smali index 14ba9796..293edc4d 100644 --- a/examples/AnnotationTypes/Main.smali +++ b/examples/AnnotationTypes/Main.smali @@ -2,11 +2,11 @@ .super Ljava/lang/Object; -;expected output: -;@ClassAnnotation() -;@MethodAnnotation() -;@FieldAnnotation() -;@ParameterAnnotation() +#expected output: +#@ClassAnnotation() +#@MethodAnnotation() +#@FieldAnnotation() +#@ParameterAnnotation() .method public static main([Ljava/lang/String;)V diff --git a/examples/AnnotationValues/AnnotationWithValues.smali b/examples/AnnotationValues/AnnotationWithValues.smali index 417faa5f..54465105 100644 --- a/examples/AnnotationValues/AnnotationWithValues.smali +++ b/examples/AnnotationValues/AnnotationWithValues.smali @@ -38,9 +38,9 @@ .method public abstract methodValue()Ljava/lang/reflect/Method; .end method -;dalvik doesn't seem to like field values -;.method public abstract fieldValue()Ljava/lang/reflect/Field; -;.end method +#dalvik doesn't seem to like field values +#.method public abstract fieldValue()Ljava/lang/reflect/Field; +#.end method .method public abstract enumValue()LEnum; .end method diff --git a/examples/AnnotationValues/Main.smali b/examples/AnnotationValues/Main.smali index 82376e0a..5f35c9de 100644 --- a/examples/AnnotationValues/Main.smali +++ b/examples/AnnotationValues/Main.smali @@ -1,8 +1,8 @@ .class public LMain; .super Ljava/lang/Object; -;expected output: -;@AnnotationWithValues(booleanValue=false, byteValue=1, charValue=2, doubleValue=7.0, enumValue=12, floatValue=6.0, intValue=4, longValue=5, methodValue=public static void 10.11(), shortValue=3, stringValue=8, subAnnotationValue=@SubAnnotation(stringValue=9), typeValue=class 10) +#expected output: +#@AnnotationWithValues(booleanValue=false, byteValue=1, charValue=2, doubleValue=7.0, enumValue=12, floatValue=6.0, intValue=4, longValue=5, methodValue=public static void 10.11(), shortValue=3, stringValue=8, subAnnotationValue=@SubAnnotation(stringValue=9), typeValue=class 10) .method public static main([Ljava/lang/String;)V diff --git a/examples/Enums/Enum.smali b/examples/Enums/Enum.smali index 04c0d0e9..82d93686 100644 --- a/examples/Enums/Enum.smali +++ b/examples/Enums/Enum.smali @@ -1,8 +1,8 @@ .class public final enum LEnum; .super Ljava/lang/Enum; -;This class is an example of how to define an enum. You have -;to do all of the work that java normally takes care of +#This class is an example of how to define an enum. You have +#to do all of the work that java normally takes care of .field private static final synthetic $VALUES:[LEnum; @@ -12,37 +12,37 @@ .method static constructor ()V .registers 4 - ;create an instance of this class for the VALUE1 value + #create an instance of this class for the VALUE1 value new-instance v0, LEnum; const-string v1, "VALUE1" const/4 v2, 0 invoke-direct {v0, v1, v2}, LEnum;->(Ljava/lang/String;I)V - ;and store it in VALUE1 + #and store it in VALUE1 sput-object v0, LEnum;->VALUE1:LEnum; - ;create an instance of this class for the VALUE2 value + #create an instance of this class for the VALUE2 value new-instance v0, LEnum; const-string v1, "VALUE2" const/4 v3, 1 invoke-direct {v0, v1, v3}, LEnum;->(Ljava/lang/String;I)V - ;and store it in VALUE2 + #and store it in VALUE2 sput-object v0, LEnum;->VALUE2:LEnum; - ;create an array of Enums, for the $VALUES member + #create an array of Enums, for the $VALUES member const/4 v0, 2 new-array v0, v0, [LEnum; - ;add VALUE1 to the array + #add VALUE1 to the array sget-object v1, LEnum;->VALUE1:LEnum; aput-object v1, v0, v2 - ;add VALUE2 to the array + #add VALUE2 to the array sget-object v1, LEnum;->VALUE2:LEnum; aput-object v1, v0, v3 - ;and store the array in $VALUES + #and store the array in $VALUES sput-object v0, LEnum;->$VALUES:[LEnum; return-void diff --git a/examples/HelloWorld/HelloWorld.smali b/examples/HelloWorld/HelloWorld.smali index f3cae41f..178b6412 100644 --- a/examples/HelloWorld/HelloWorld.smali +++ b/examples/HelloWorld/HelloWorld.smali @@ -1,12 +1,12 @@ .class public LHelloWorld; -;Ye olde hello world application -;To assemble and run this on a phone or emulator: -; -;java -jar smali.jar --dex HelloWorld.smali -;zip HelloWorld.zip classes.dex -;adb push HelloWorld.zip /data/local -;adb shell dalvikvm -cp /data/local/HelloWorld.zip HelloWorld +#Ye olde hello world application +#To assemble and run this on a phone or emulator: +# +#java -jar smali.jar --dex HelloWorld.smali +#zip HelloWorld.zip classes.dex +#adb push HelloWorld.zip /data/local +#adb shell dalvikvm -cp /data/local/HelloWorld.zip HelloWorld .super Ljava/lang/Object; diff --git a/examples/RecursiveAnnotation/Main.smali b/examples/RecursiveAnnotation/Main.smali index 4cf3dcdb..d44bdca8 100644 --- a/examples/RecursiveAnnotation/Main.smali +++ b/examples/RecursiveAnnotation/Main.smali @@ -1,8 +1,8 @@ .class public LMain; .super Ljava/lang/Object; -;expected output (using the dalvik's default stack size) -;@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=java.lang.StackOverflowError)))))))))))))))))))))))))))))) +#expected output (using the dalvik's default stack size) +#@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=java.lang.StackOverflowError)))))))))))))))))))))))))))))) .method public static main([Ljava/lang/String;)V .registers 3 diff --git a/examples/RecursiveAnnotation/RecursiveAnnotation.smali b/examples/RecursiveAnnotation/RecursiveAnnotation.smali index dbacafa7..0fde4a88 100644 --- a/examples/RecursiveAnnotation/RecursiveAnnotation.smali +++ b/examples/RecursiveAnnotation/RecursiveAnnotation.smali @@ -2,9 +2,9 @@ .super Ljava/lang/Object; .implements Ljava/lang/annotation/Annotation; -;this is a recursive annotation that has a default value of itself. -;Trying to print .toString() on an instance of this annotation -;will cause a stack overflow +#this is a recursive annotation that has a default value of itself. +#Trying to print .toString() on an instance of this annotation +#will cause a stack overflow .method public abstract value()LRecursiveAnnotation; .end method diff --git a/src/main/antlr3/org/JesusFreke/smali/smaliLexer.g b/src/main/antlr3/org/JesusFreke/smali/smaliLexer.g index 748c0b2e..e4df537e 100644 --- a/src/main/antlr3/org/JesusFreke/smali/smaliLexer.g +++ b/src/main/antlr3/org/JesusFreke/smali/smaliLexer.g @@ -153,7 +153,6 @@ import java.util.ArrayDeque; } catch (RecognitionException re) { reportError(re); - // match() routine has already called recover() } } } @@ -176,6 +175,10 @@ import java.util.ArrayDeque; token.setChannel(channel); tokens.add(token); } + + public String getErrorHeader(RecognitionException e) { + return getSourceName()+"["+ e.line+","+e.charPositionInLine+"]"; + } } @@ -1413,12 +1416,12 @@ WHITE_SPACE fragment LINE_COMMENT_EMIT : LINE_COMMENT2 {emit($LINE_COMMENT2, LINE_COMMENT, Token.HIDDEN_CHANNEL);}; fragment LINE_COMMENT2 - : ';' ~('\n'|'\r')* ('\r\n' | '\r' | '\n'); + : '#' ~('\n'|'\r')* ('\r\n' | '\r' | '\n'); LINE_COMMENT - : (';' ~('\n'|'\r')* ('\r\n' | '\r' | '\n') - | ';' ~('\n'|'\r')*) + : ('#' ~('\n'|'\r')* ('\r\n' | '\r' | '\n') + | '#' ~('\n'|'\r')*) {$channel = HIDDEN;}; fragment EQUAL_EMIT diff --git a/src/main/java/org/JesusFreke/smali/smali.java b/src/main/java/org/JesusFreke/smali/smali.java index 61729ae4..e9b47476 100644 --- a/src/main/java/org/JesusFreke/smali/smali.java +++ b/src/main/java/org/JesusFreke/smali/smali.java @@ -168,6 +168,8 @@ public class smali private static void assembleSmaliFile(File smaliFile, DexFile dexFile) throws Exception { ANTLRInputStream input = new ANTLRInputStream(new FileInputStream(smaliFile)); + input.name = smaliFile.getAbsolutePath(); + smaliLexer lexer = new smaliLexer(input); CommonTokenStream tokens = new CommonTokenStream(lexer); diff --git a/src/test/smali/junit-tests/FieldTest/FieldTest.smali b/src/test/smali/junit-tests/FieldTest/FieldTest.smali index 73d142d9..b02bc5e8 100644 --- a/src/test/smali/junit-tests/FieldTest/FieldTest.smali +++ b/src/test/smali/junit-tests/FieldTest/FieldTest.smali @@ -2,7 +2,7 @@ .super Ljava/lang/Object; .source "FieldTest.smali" -;this class tests that fields of various types are working +#this class tests that fields of various types are working .method public constructor ()V .registers 4 @@ -37,10 +37,10 @@ const-string v0, "privateStringFieldValue" iput-object v0, v3, LFieldTest;->privateStringField:Ljava/lang/String; - const-string v0, "publicStaticStringFieldValue"; + const-string v0, "publicStaticStringFieldValue" sput-object v0, LFieldTest;->publicStaticStringField:Ljava/lang/String; - const-string v0, "privateStaticStringFieldValue"; + const-string v0, "privateStaticStringFieldValue" sput-object v0, LFieldTest;->privateStaticStringField:Ljava/lang/String; return-void diff --git a/src/test/smali/junit-tests/SpecialInstructionPaddingTest/SpecialInstructionPaddingTest.smali b/src/test/smali/junit-tests/SpecialInstructionPaddingTest/SpecialInstructionPaddingTest.smali index 2b79cf93..28ebd04e 100644 --- a/src/test/smali/junit-tests/SpecialInstructionPaddingTest/SpecialInstructionPaddingTest.smali +++ b/src/test/smali/junit-tests/SpecialInstructionPaddingTest/SpecialInstructionPaddingTest.smali @@ -21,6 +21,8 @@ const-wide/16 v2, 12 + #the real test is that dalvik loaded and verified this class. This is + #mostly just to make sure that the method was actually called invoke-static {v0, v1, v2, v3}, Lorg/junit/Assert;->assertEquals(JJ)V return-void @@ -50,9 +52,9 @@ Label13: const v1, 13 return v1 - ;this nop de-aligns the following packed-switch data - ;smali should generate another nop before the packed-switch - ;data to force alignment + #this nop de-aligns the following packed-switch data + #smali should generate another nop before the packed-switch + #data to force alignment nop PackedSwitch: diff --git a/src/test/smali/junit-tests/TestSuite.smali b/src/test/smali/junit-tests/TestSuite.smali index 374949dc..4463c747 100644 --- a/src/test/smali/junit-tests/TestSuite.smali +++ b/src/test/smali/junit-tests/TestSuite.smali @@ -1,19 +1,19 @@ .class public LAllTests; .super Ljava/lang/Object; -;This class is a wrapper for all the classes in the junit-tests directory -; -;To run the tests, you need to use dx on the junit jar and push that to the -;device/emulator, and then zip up the classes.dex containing this class -;and all of the tests and push that to the device/emulator. -; -;dx --dex --output=classes.dex junit-4.6.jar -;zip junit-4.6.zip classes.dex -;adb push junit-4.6.zip /data/local -;java -jar smali.jar --dex --output=classes.dex . -;zip smali-junit-tests.zip classes.dex -;adb push smali-junit-tests.zip /data/local -;adb shell dalvikvm -cp /data/local/junit-4.6.zip:/data/local/smali-junit-tests.zip org.junit.runner.JUnitCore AllTests +#This class is a wrapper for all the classes in the junit-tests directory +# +#To run the tests, you need to use dx on the junit jar and push that to the +#device/emulator, and then zip up the classes.dex containing this class +#and all of the tests and push that to the device/emulator. +# +#dx --dex --output=classes.dex junit-4.6.jar +#zip junit-4.6.zip classes.dex +#adb push junit-4.6.zip /data/local +#java -jar smali.jar --dex --output=classes.dex . +#zip smali-junit-tests.zip classes.dex +#adb push smali-junit-tests.zip /data/local +#adb shell dalvikvm -cp /data/local/junit-4.6.zip:/data/local/smali-junit-tests.zip org.junit.runner.JUnitCore AllTests .annotation runtime Lorg/junit/runner/RunWith; value = Lorg/junit/runners/Suite;