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

RP prototype resource sharing - shopping app

好高的佣金,《新程序员》合伙人计划来袭,人人皆可参与

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

mysql主从同步

Kubevela 1.4: make application delivery safer, easier to use, and more transparent

分析超700万个研发需求发现,这八大编程语言才是行业最需要的

神经网络入门(上)

Conditional compilation

To eliminate bugs, developers must know several bug exploration and testing artifacts.

解决arm_release_ver of this libmali is ‘g2p0-01eac0‘,rk_so_ver is ‘4‘,libgl1-mesa-dev不会被安装,存在未满足的依赖关系
随机推荐
太湖 “中国健康农产品·手机直播万里行”走进太湖
新出生的机器狗,打滚1小时后自己掌握走路,吴恩达开山大弟子最新成果
NLP skill tree learning route - (I) route overview
杰理之触摸按键识别流程【篇】
[iccv 2019] characteristics precise supervision of feature super resolution for small object detection
Meeting, onemeeting, OK!
【论文阅读】Trajectory-guided Control Prediction for End-to-end Autonomous Driving: A Simple yet Strong Baseline
The former king of fruit juice sold for 1.6 billion yuan
【NLP】【TextCNN】 文本分类
【ICLR 2021】半监督目标检测:Unbiased Teacher For Semi-Supervised Object Detection
Primary school, session 3 - afternoon: Web_ sessionlfi
Is it safe to open an account in Guangzhou stock exchange by mobile phone?
The prospectus of pelt medical was "invalid" for the second time in the Hong Kong stock exchange, and the listing plan was substantially delayed
Audio and video architecture construction in the super video era | science and Intel jointly launched the second season of "architect growth plan"
杰理之检测灵敏度级别确定【篇】
屏幕显示技术进化史
C语言:hashTable
网易云签到可抽奖?那一年我能签到365天。不信?你看。
DNS服务器搭建、转发、主从配置
建立自己的网站(20)