当前位置:网站首页>DEX file parsing - Method_ IDS resolution
DEX file parsing - Method_ IDS resolution
2022-06-30 20:13:00 【asjhan】
In the last article, I introduced field_ids Parsing , Then the next step is to learn method_ids Parsing .
1. method_ids structure
stay android Of aosp Source code ,method_ids The structure is as follows :
aosp Source location :art/libdexfile/dex/dex_file.h
// Raw method_id_item.
struct MethodId {
dex::TypeIndex class_idx_; // index into type_ids_ array for defining class
uint16_t proto_idx_; // index into proto_ids_ array for method prototype
dex::StringIndex name_idx_; // index into string_ids_ array for method name
private:
DISALLOW_COPY_AND_ASSIGN(MethodId);
};
StringIndex
class StringIndex {
public:
uint32_t index_;
....
....
};
TypeIndex
class TypeIndex {
public:
uint16_t index_;
....
....
};
from method The following points can be seen from the structure of :
dex::TypeIndex class_idx_: Unsignedinttype , Occupy2Bytes . Type index listIndexes / Subscript, It meansThe class of the methoduint16_t proto_idx_: Unsignedinttype , Occupy2Bytes . Prototype index listIndexes / Subscript, It meansPrototypes of methods ( Signature )dex::StringIndex name_idx_: Unsignedinttype , Occupy4Bytes . String index listIndexes / Subscript, It meansMethod name
2.010Editor analysis

3.method_ids analysis
/** * analysis MethodIds * @param raf * @return */
private static List<MethodId> toParseDexMethodIds(RandomAccessFile raf) {
try {
List<MethodId> methodIdList = new ArrayList<>();
// Get the file offset to the method index list
int method_ids_off = mDexHeader.getMethod_ids_off();
// Get the size of the method index list
int method_ids_size = mDexHeader.getMethod_ids_size();
// Offset to method index list position
raf.seek(method_ids_off);
for (int i = 0; i < method_ids_size; i++) {
// obtain The class name of the class where this field is located , Class name idx In the type index list
int class_idx = NumConversion.byteToInt(readData(raf, 2), false);
// obtain Prototype of this field ( Method signature ), Prototype idx In the prototype index list
int proto_idx = NumConversion.byteToInt(readData(raf,2),false);
// obtain The method name of this field , Method name idx In the string index list
int name_idx = NumConversion.byteToInt(readData(raf,4),false);
// Print data
// Get method name
StringId name_string_id = mStringIds.get(name_idx);
String name_string = new String(name_string_id.getData());
// Get class
TypeId class_type_id = mTypeIds.get(class_idx);
StringId class_type_string_id = mStringIds.get(class_type_id.getTypeDescriptorIdx());
String class_type_string = new String(class_type_string_id.getData());
// Get return value type
ProtoId proto_id = mProtyIds.get(proto_idx);
TypeId return_type_id = mTypeIds.get(proto_id.getReturnIdx());
StringId return_type_string_id = mStringIds.get(return_type_id.getTypeDescriptorIdx());
String return_type_string = new String(return_type_string_id.getData());
// Get a list of method parameters
StringBuilder sb = new StringBuilder("(");
for (int j=0;j<proto_id.getParameter_size();j++) {
int parame_idx = proto_id.getParameterIdxs()[j];
TypeId parame_type_id = mTypeIds.get(parame_idx);
StringId parame_string_id = mStringIds.get(parame_type_id.getTypeDescriptorIdx());
sb.append(new String(parame_string_id.getData()));
if (j == proto_id.getParameter_size()-1) {
sb.append(")");
}else if (proto_id.getParameter_size() != 1) {
sb.append(", ");
}
}
if (proto_id.getParameter_size() == 0) sb.append(")");
// Create entity class
MethodId methodId = new MethodId();
methodId.setClass_idx(class_idx);
methodId.setProto_idx(proto_idx);
methodId.setName_idx(name_idx);
methodIdList.add(methodId);
System.out.println(i+" stay " + class_type_string + " Class , Method :" +return_type_string+" "+name_string+sb.toString());
}
return methodIdList;
}catch (Exception e) {
e.printStackTrace();
}
return null;
}
public static byte[] readData(RandomAccessFile raf,int limit) {
byte[] buff = new byte[limit];
try {
raf.read(buff);
} catch (IOException e) {
e.printStackTrace();
}
return buff;
}
Entity class MethodId
public class MethodId {
private int class_idx;
private int proto_idx;
private int name_idx;
public int getClass_idx() {
return class_idx;
}
public void setClass_idx(int class_idx) {
this.class_idx = class_idx;
}
public int getProto_idx() {
return proto_idx;
}
public void setProto_idx(int proto_idx) {
this.proto_idx = proto_idx;
}
public int getName_idx() {
return name_idx;
}
public void setName_idx(int name_idx) {
this.name_idx = name_idx;
}
}
Tool class NumConversion
public class NumConversion {
public static int byteToInt(byte[] bytes,boolean isBigEndian) {
if (bytes.length <=0 || bytes.length > 4) return -1;
int result = 0;
for (int i=0;i<bytes.length;i++) {
int b ;
if(isBigEndian){
b = (bytes[i] & 0xFF) << (8*(bytes.length-1-i));
}else {
b = (bytes[i] & 0xFF) << (8*i);
}
result = result | b;
}
return result;
}
}
asjhan for Android reverse
边栏推荐
- Source code analysis of redis ziplist compressed list
- 计网 | 【五 传输层、六 应用层】知识点及例题
- The former king of fruit juice sold for 1.6 billion yuan
- PHP文件上传小结(乱码,移动失败,权限,显示图片)
- yolo 目标检测
- QQmlApplicationEngine failed to load component qrc:/main.qml:-1 No such file or directory
- 项目经理不应该犯的错误
- [try to hack] windows system account security
- 开会,OneMeeting,OK!
- Application of JDBC in performance test
猜你喜欢

Cv+deep learning network architecture pytoch recurrence series basenets (backbones) (I)

8 - 函数

Halcon知识:盘点一下计量对象【1】
Detailed steps for Django to upload excel tables and write data to the database

This morning, investors began to travel collectively

屏幕显示技术进化史

Idle fish is hard to turn over

为什么一定要从DevOps走向BizDevOps?
![Network planning | [five transport layers and six application layers] knowledge points and examples](/img/4f/31acce51b584bed5ef56b2093c4db3.png)
Network planning | [five transport layers and six application layers] knowledge points and examples

如何快速通过PMP考试?
随机推荐
MySQL数据库误删回滚的解决
标配10个安全气囊,奇瑞艾瑞泽8安全防护无死角
静态类使用@Resource注解注入
以全栈全功能解决方案,应对多样工具复杂环境DevOps落地难题
杰理之检测灵敏度级别确定【篇】
originpro 2021 附安装教程
将秒数转换为**小时**分钟
太湖 “中国健康农产品·手机直播万里行”走进太湖
Inventory the six second level capabilities of Huawei cloud gaussdb (for redis)
好高的佣金,《新程序员》合伙人计划来袭,人人皆可参与
Application of JDBC in performance test
25:第三章:开发通行证服务:8:【注册/登录】接口:接收并校验“手机号和验证码”参数;(重点需要知道【利用redis来暂存数据,获取数据的】的应用场景)(使用到了【@Valid注解】参数校验)
Lombok
Primary school, session 3 - afternoon: Web_ xxe
Perl转换文件的编码类型
Qt:qaxobject operation Excel
杰理之触摸按键识别流程【篇】
8 - 函数
PostgreSQL heap堆表 存储引擎实现原理
Is it safe to open an account in Guangzhou stock exchange by mobile phone?