smali语法
一、类型
| V | void 空类型,仅用做返回类型 |
| Z | boolean布尔型 |
| B | byte字节型 |
| S | short短整型 16位 |
| C | char字符型 |
| I | int整型 |
| J | long 长整型 64位 |
| F | float浮点型 |
| D | double双精度型 64位 |
(2)对象
(3)数组(数组维度最多255)
| [I | 等同于int[ ] |
| [[I | 等同于int[ ][ ] |
v1 第二个local register
v2 p0 第一个parameter register
v3 p1 第二个parameter register
v4 p2 第三个parameter register
p1 I
p2,p3 J
p4 Z
invoke-virtual {v0}, Ljava/lang/Object;->toString();
blah.toString();


publicclass example {
privatestaticintCounter;
public example(){Counter=16;}

publicstaticvoidLoopExample()
{
for(int i =0; i <Counter; i++)
System.out.println("current val for loop: "+ i);
}

publicstaticvoidSwitchExample()
{
int val =42;
switch(val){
case1:System.out.println("val 1");break;
case2:System.out.println("val 2");break;
case42:System.out.println("val 42");break;
case5:System.out.println("val 5");break;
default:System.out.println("invalid value");break;
}
}

在smali中,switch结构,首先使用spare-switch解析default分支,接着处理其他分支.这种处理流程,会导致在使用dex2jar进行反编译时(将dex文件转换为jar)出错,使用ded进行反编译的结果会稍微好一点。publicstaticvoidTryCatchExample()
{
String urlStr ="google.com";
try{
// Get the image
URL url =new URL(urlStr);
InputStreamis= url.openStream();
is.close();
}catch(MalformedURLException e){
// Print out the exception that occurred
System.out.println("Invalid_URL"+ urlStr +" :"+ e.getMessage());
}catch(IOException e){
// Print out the exception that occurred
System.out.println("Unable?to?execute"+ urlStr +":"+ e.getMessage());
}
}

publicstaticvoidArrayExample()
{
String someArray[]=newString[5];
someArray[0]="set value at index 0";
someArray[1]="index 1 has this value";
if( someArray[0].equals(someArray[1]))
{
System.out.println("array at index 0 = 1 (wont?happen)");
}
}

Android恶意代码分析 claud

浙公网安备 33010602011771号