Android逆向学习笔记1:Dalvik语言基础(2)

目录

2.1Dalvik指令格式

1、格式ID:

2、Dalvik指令语法:

2.2Dalvik寄存器:

2.3Dalvik字节码:

1、类型

 2、方法

3、字段


DVM有专用的指令集和专门的指令格式DEX。

其一些特点如下:

1、基于寄存器的设计。方法在内存创建后有固定大小的栈帧。

2、如果整数与浮点数按位表示,可以用32位寄存器来存放。

3、指令流以16位无符号整型为存储单元。

2.1Dalvik指令格式

例如,“B|A|op CCCC”格式表示其包含两个 16 位代码单元。第一个指令字的高八位是 2 个四位值,低八位是指令码;第二个指令字是一个 16 位值。

例:A|G|op BBBB F|E|D|C

每16位用空格隔开;

每个字母表示4位,中间可以用“|”隔开;

在大部分情况下,字母按照代码单元的顺序进行排列,代码单元中按照从低位到高位的顺序进行排序;

顺序采用大写A~Z字母表示4位值,op表示8位操作码;

1、格式ID:

用来确定指定指令格式的编码。是格式表中的第二列表示格式的短标识符,用于在其他文档和代码中识别该格式。

大多数格式 ID 包含三个字符:例:21t

前两个是十进制数,最后一个是字母。

第一个十进制数表示格式中 16 位代码单元的数量。

第二个数字表示格式所含寄存器的数量上限(因为某些格式使用的寄存器数量是可变的),特殊标识“r”表示编码了一系列寄存器。

最后一个字母以半助记符的形式表示该格式编码的任何其他数据类型。

例如,“21t”格式的长度为 2,包含一个寄存器引用,另外还包含一个分支目标。

助记符位数含义
b8有符号立即数(字节)
c16、32常量池索引
f16接口常量(仅对静态链接格式有效)
h16有符号立即数 hat(32 位或 64 位值的高阶位,低阶位全为 0
i32有符号立即数(整型)或 32 位浮点数
l64有符号立即数(长整型)或 64 位双精度浮点数
m16方法常量(仅对静态链接格式有效)
n4有符号立即数(半字节)
s16有符号立即数(短整型)
t8、16、32分支目标
x0无额外数据
2、Dalvik指令语法:

每条指令都是从操作码开始,后面紧跟参数,个数不定,用逗号“,”分隔。

参数为“vX”,说明是一个寄存器。

参数为“#+X”,说明是一个常量数字;

参数为“+X”,是相对指令的地址偏移量;

如果为“kind@X”格式,是常量池索引值。如果kind为string(字符串常量池索引),type(类型),field(字段),meth(方法)。

例:op vAA, string@BBBB

该指令使用了一个寄存器参数vAA,附加了一个字符串常量池索引值string@BBBB。

2.2Dalvik寄存器:

Dalvik使用的寄存器全部为32位。

一个指令: op vAAAA,vBBBB

其中每个大写字母代表四位,故AAAA,BBBB的最大值为2^{16}-1,即65535。寄存器初始值为0,范围为v0~v65535。

寄存器命名法:

源代码详细信息:http://t.csdn.cn/KAMH2

下面为v命名法

Virtual methods   -
    #0              : (in LHello;)
      name          : 'foo'
      type          : '(II)I'
      access        : 0x0001 (PUBLIC)
      code          -
      registers     : 5
      ins           : 3
      outs          : 0
      insns size    : 6 16-bit code units
000198:                                        |[000198] Hello.foo:(II)I
0001a8: 9000 0304                              |0000: add-int v0, v3, v4
0001ac: 9101 0304                              |0002: sub-int v1, v3, v4
0001b0: b210                                   |0004: mul-int/2addr v0, v1
0001b2: 0f00                                   |0005: return v0
      catches       : (none)
      positions     :
        0x0000 line=4
      locals        :
        0x0000 - 0x0006 reg=2 this LHello;
 
  source_file_idx   : 1 (Hello.java)

假设一个函数需使用M个寄存器,且该函数一共有N个参数。那么参数使用最后N个寄存器,局部变量使用前面M-N个寄存器。

例如上面的代码:由于foo()函数是非静态方法,被调用时会传入一个隐式的Hello对象引用,因此实际上传入了三个参数。

故v2,v3,v4这三个寄存器由参数使用。v2用于表示被传入的Hello对象的引用。v3,v4用于传入的两个整形参数。

v0,v1用于表示函数的局部变量寄存器。

p命名法就是将前面的v2,v3,v4换成p0,p1,p2。其余基本一致。

2.3Dalvik字节码:

1、类型

Dalvik字节码只有基本类型和引用类型。除了对象和数组属于引用对象,其余Java类型全为引用类型。

java类型类型描述符
booleanZ
byteB
shortS
charC
intI
longJ
floatF
doubleD
void,只用于返回值类型v
java类类型L
数组类型[

每个Dalvik寄存器都为32位,对J,D等64位的类型是用两个相邻的寄存器来存储。

例:

Lpackage/name/ObjectName;

L表示后面是一个java类,package/name/表示类所在的包,ObjectName表示对象的名称,分号表示对象名结束。 

对应的java代码:

package.name.ObjectName

 2、方法
Lpackage/name/ObjectName;->MethodName(III)Z

 类型(Lpackage/name/ObjectName;)、具体方法名(MethodName)、方法签名部分((III)Z)。其中三个III表示为三个int类型的参数;Z表示返回类型为boolean。

更复杂的例子:

method(I[[IIjava/lang/String;[Ljava/langObject;)Ljava/lang/String;

 对应的Java代码:

String method(int, int[][], int, String, Object[])

 baksmali生成的方法代码以 .method 开始,以  .endmethod  结束。

#后面的为注释;# virtual methods 虚方法 ; #direct methods 直接方法

3、字段

与方法类似,不过没有参数和返回值。

Lpackage/name/ObjectName;->FieldName:Ljava/lang/String;

 字段由类型(Lpackage/name/ObjectName;)、字段名(FeildName)、字段类型(Ljava/lang/String;)组成。其中名和类型中间用冒号“:”分隔。

 baksmali生成的字段代码以 .field指令开头。

# instance fields 实例字段 ; # static fields 静态字段

 参考书目:《Android软件安全权威指南》《Android进阶解密》

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
网传资源,如有侵权请联系/留言,资源过大,上传乃是下载链接,失效请留言,下面上大纲: 01.Android环境配置与常用工具介绍 02.Android smali 与 java 代码介绍1 : d% y( z) X- o& ~, e0 _; c1 I 03.Android smali 与 java 代码介绍2 c+ K& I/ q( b 04.Android smali 与 java 代码介绍3 % ]7 Z+ f! I! [5 S. O. N 05.Android smali 与 java 代码介绍4 7 A9 G6 c k; B 06.Android smali 与 java 代码介绍5 ; [. D3 O0 ~9 _0 ]3 W 07.常用Android快速定位关键点方法介绍 " v+ h0 Z5 x& }1 o4 c/ L 08.从0开始打造自己的破解代码库 09.Android 结构基础讲解 10.快速Hook代码搭建之 Cydia Substrate 11.快速Hook代码搭建之 Xposed 12.安装部署Android源码编译环境 13.Android源码目录结构与修改引导 / |3 T: f, f8 [2 @+ p 14.Android源码修改与刷机介绍 & D- q# v- o) o) ?/ u( A 15.Android Jni 编程 & Y6 ^/ J* G3 ] 16.arm 汇编代码讲解1 . J) E# f# h! Q4 x2 P+ K 17.arm 汇编代码讲解2 18.arm 汇编代码讲解3 19.arm 汇编代码讲解4 20.arm 汇编代码讲解5 ' B! y1 m7 _% U8 r2 G! R% h& L! a4 J0 B 21.class.dex文件格式讲解 22.Android 动态代码自修改原理 23.Android 动态代码自修改实现1 . F; Z5 @* D* r 24.Android 动态代码自修改实现2 25.Android dvm 脱壳1 26.elf结构详解1, d9 H, S" s2 }8 j' B6 v 27.elf结构详解2 8 A9 q+ O" `- v 28.elf文件变形与保护 1 g, b1 q, P( P& W, k3 F7 U 29.elf文件修复分析 9 K p" k/ `- s, w/ r: R( X 30.so加壳文件修复 31.常用调试检测方法与过检测方法 * G( L. J' P1 \+ }: N; r 32.Android源码定制添加反反调试机制 ' v/ q6 K1 {6 ] 33.Android dvm 脱壳2 34.Android dvm 脱壳3 H2 X- A# M4 s+ A6 K- b 35.Dalvik dex处理分析 ) x+ l1 l1 J R2 N) T" R) ^2 o 36.IDA脱壳脚本编写1) O7 `% E" Q. @1 X! o ~ 37.Odex修复方法 38.IDAOdex修复脚本编写 " X' w1 h: w3 N" u8 P5 z 39.Android 加壳原理 40.Android 加壳保护工具编写1 1 x4 k0 P/ V' C9 a( O 41.Android 加壳保护工具编写2 42.Android 加壳保护工具编写3
Android虚拟机Dalvik完整源码,宝贵资源,欢迎下载! This directory contains the Dalvik virtual machine and core class library, as well as related tools, libraries, and tests. A note about the licenses and header comments --------------------------------------------- Much of the code under this directory originally came from the Apache Harmony project, and as such contains the standard Apache header comment. Some of the code was written originally for the Android project, and as such contains the standard Android header comment. Some files contain code from both projects. In these cases, the header comment is a combination of the other two, and the portions of the code from Harmony are identified as indicated in the comment. Here is the combined header comment: /* * Copyright (C) The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * ---------- * * Portions of the code surrounded by "// BEGIN Harmony code" and * "// END Harmony code" are copyrighted and licensed separately, as * follows: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ Native SH call bridge --------------------- Native SH call bridge is written by Shin-ichiro KAWASAKI and Contributed to Android by Hitachi, Ltd. and Renesas Solutions Corp.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值