当前位置:网站首页>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_
: Unsignedint
type , Occupy2
Bytes . Type index listIndexes / Subscript
, It meansThe class of the method
uint16_t proto_idx_
: Unsignedint
type , Occupy2
Bytes . Prototype index listIndexes / Subscript
, It meansPrototypes of methods ( Signature )
dex::StringIndex name_idx_
: Unsignedint
type , Occupy4
Bytes . 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
边栏推荐
- Kubevela 1.4: make application delivery safer, easier to use, and more transparent
- 线下门店为什么要做新零售?
- 4.3-inch touch screen 12 channel control port programmable network central control supports mutual backup of 5 central control hosts
- 屏幕显示技术进化史
- 如何做好测试用例设计
- Web主机iptables防火墙安全脚本
- arthas调试 确定问题工具包
- PHP文件上传小结(乱码,移动失败,权限,显示图片)
- “更福特、更中国”拨云见日,长安福特王牌产品订单过万
- CADD course learning (1) -- basic knowledge of drug design
猜你喜欢
Application of JDBC in performance test
CADD课程学习(2)-- 靶点晶体结构信息
GeoServer安装
【Try to Hack】Windows系统账户安全
漏洞扫描工具大全,妈妈再也不用担心我挖不到漏洞了
网易云签到可抽奖?那一年我能签到365天。不信?你看。
以全栈全功能解决方案,应对多样工具复杂环境DevOps落地难题
8 - 函数
Taihu Lake "China's healthy agricultural products · mobile phone live broadcast" enters Taihu Lake
Django上传excel表格并将数据写入数据库的详细步骤
随机推荐
项目经理面试常见问题及回答技巧
杰理之触摸按键识别流程【篇】
屏幕显示技术进化史
Client request external interface standard processing method
CADD课程学习(2)-- 靶点晶体结构信息
To eliminate bugs, developers must know several bug exploration and testing artifacts.
pytorch实现FLOPs和Params的计算
【ICLR 2021】半监督目标检测:Unbiased Teacher For Semi-Supervised Object Detection
开会,OneMeeting,OK!
Meeting, onemeeting, OK!
WeakSet
Filebeat custom indexes and fields
基于slate构建文档编辑器
传输层 使用滑动窗口实现流量控制
最新海康摄像机、NVR、流媒体服务器、回放取流RTSP地址规则说明[通俗易懂]
CADD课程学习(1)-- 药物设计基础知识
Detailed explanation of specific methods and steps for TCP communication between s7-1500 PLCs (picture and text)
DELL R720服务器安装网卡Broadcom 5720驱动
信息学奥赛一本通 1362:家庭问题(family)
计网 | 【五 传输层、六 应用层】知识点及例题