mirror of
https://github.com/revanced/smali.git
synced 2025-04-29 22:24:26 +02:00
- changed the comment char from ; to #
- updated the tests and examples to use the new comment style - changed the lexer error messages to include the source file path git-svn-id: https://smali.googlecode.com/svn/trunk@83 55b6fa8a-2a1e-11de-a435-ffa8d773f76a
This commit is contained in:
parent
e53f5ae41b
commit
1834b365d6
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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 <clinit>()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;-><init>(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;-><init>(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
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
@ -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 <init>()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
|
||||
|
@ -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:
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user