当前位置:网站首页>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
边栏推荐
猜你喜欢

Idle fish is hard to turn over

Primary school, session 3 - afternoon: Web_ xxe

如何快速通过PMP考试?

昨晚 Spark Summit 重要功能发布全在这里(附超清视频)

qt中toLocal8Bit和toUtf8()有什么区别
![25: Chapter 3: developing pass service: 8: [registration / login] interface: receiving and verifying](/img/ff/727c4a20ff3816ec7221dced5a4770.png)
25: Chapter 3: developing pass service: 8: [registration / login] interface: receiving and verifying "mobile number and verification code" parameters; (it is important to know the application scenario

Lambda 表达式原理分析学习(2022.06.23)

TorchDrug--药物属性预测

Audio and video architecture construction in the super video era | science and Intel jointly launched the second season of "architect growth plan"

网易云签到可抽奖?那一年我能签到365天。不信?你看。
随机推荐
pycharm从安装到全副武装,学起来才嗖嗖的快,图片超多,因为过度详细!
Enterprise middle office planning and it architecture microservice transformation
WeakSet
【NLP】【TextCNN】 文本分类
网上炒股开户安全嘛!?
Primary school, session 3 - afternoon: Web_ xxe
How unity pulls one of multiple components
SecureCRTPortable的安装和使用(图文详解)
Client request external interface standard processing method
屏幕显示技术进化史
PS2手柄-1「建议收藏」
一文读懂目标检测:R-CNN、Fast R-CNN、Faster R-CNN、YOLO、SSD「建议收藏」
This morning, investors began to travel collectively
十分之坑,tar命令解压文件的时候竟然不能解析英文括号“()”
Graduates
Meeting, onemeeting, OK!
大神詳解開源 BUFF 增益攻略丨直播
Qt:qaxobject operation Excel
Tensorflow2.4 implementation of repvgg
Lombok