当前位置:网站首页>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
边栏推荐
- 屏幕显示技术进化史
- Build document editor based on slate
- 杰理之关于长按复位【篇】
- 数据智能——DTCC2022!中国数据库技术大会即将开幕
- 【ICCV 2019】特征超分检测:Towards Precise Supervision of Feature Super-Resolution for Small Object Detection
- 4.3-inch touch screen 12 channel control port programmable network central control supports mutual backup of 5 central control hosts
- 启动PHP报错ERROR: [pool www] cannot get uid for user ‘@[email protected]’
- Idle fish is hard to turn over
- 大神詳解開源 BUFF 增益攻略丨直播
- Smarter! Airiot accelerates the upgrading of energy conservation and emission reduction in the coal industry
猜你喜欢
随机推荐
Solution to rollback of MySQL database by mistake deletion
[ICLR 2021] semi supervised object detection: unbiased teacher for semi supervised object detection
MySQL master-slave synchronization
Tensorflow2.4 implementation of repvgg
2022 最新 JCR正式发布全球最新影响因子名单(前600名)
C language: hashtable
CADD course learning (1) -- basic knowledge of drug design
PS2手柄-1「建议收藏」
exness:流动性系列-流动性清洗和反转、决策区间
C语言:hashTable
静态类使用@Resource注解注入
将秒数转换为**小时**分钟
以全栈全功能解决方案,应对多样工具复杂环境DevOps落地难题
Lambda 表达式原理分析学习(2022.06.23)
网上炒股开户安全嘛!?
MySQL数据库误删回滚的解决
NLP技能树学习路线-(一)路线总览
DNS服务器搭建、转发、主从配置
Halcon知识:盘点一下计量对象【1】
discuz 论坛提速之删除data/log下的xxx.php文件








