标签:DEX TypeId string int ids 索引 解析 type
在上一篇中介绍了string_ids的解析,那么接下来就要学习type_ids
的解析。
1. type_ids结构
在android
的aosp
源码中,type_ids
的结构如下:
aosp
源码位置:art/libdexfile/dex/dex_file.h
TypeId
// Raw type_id_item.
struct TypeId {
dex::StringIndex descriptor_idx_; // index into string_ids
private:
DISALLOW_COPY_AND_ASSIGN(TypeId);
};
StringIndex
class StringIndex {
public:
uint32_t index_;
....
....
};
TypeId
的结构,存储着一个无符号的8字节数据(StringIndex
对应的是无符号的int
类型),descriptor_idx_
对应的是字符串索引列表
的索引/下标
2. 010Editor解析
如图,仔细观察
3. type_ids解析
java
语言解析type_ids
/**
* 解析TypeIds
* @param raf
* @return
*/
private static List<TypeId> toParseDexTypeIds(RandomAccessFile raf) {
try {
List<TypeId> typeIdList = new ArrayList<>();
//获取类型索引列表的文件偏移量
int type_ids_off = mDexFile.getType_ids_off();
//获取类型索引列表的大小
int type_ids_size = mDexFile.getType_ids_size();
//偏移到类型索引列表的开始位置
raf.seek(type_ids_off);
//遍历类型索引列表,类型索引列表中存储着 字符串索引列表的 索引(下标)
for (int i=0;i<type_ids_size;i++) {
//获取 类型数据在字符串索引列表的索引(下标)
byte[] type_string_index_bytes = readData(raf, 4);
int type_string_index = NumConversion.byteToInt(type_string_index_bytes, false);
//获取 类型数据
StringId stringId = mStringIds.get(type_string_index);
String TypeData = new String(stringId.getData());
System.out.println("索引:"+i+" 索引对应的数据:"+TypeData);
//创建TypeIds实体类
TypeId typeId = new TypeId();
typeId.setTypeDescriptorIdx(type_string_index);
typeIdList.add(typeId);
}
return typeIdList;
}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;
}
实体类TypeId
public class TypeId {
private int typeDescriptorIdx; //存储着 字符串索引列表中的索引
public int getTypeDescriptorIdx() {
return typeDescriptorIdx;
}
public void setTypeDescriptorIdx(int typeDescriptorIdx) {
this.typeDescriptorIdx = typeDescriptorIdx;
}
}
工具类NumConversion
public class NumConversion {
/**
*byte转十六进制(String)
*/
public static String byteToString(byte[] bytes,String split) {
StringBuilder sb = new StringBuilder();
for (int i=0;i<bytes.length;i++) {
byte b = bytes[i];
String hex = Integer.toHexString(b &0xFF);
if(hex.length() <=1) hex = "0"+hex;
if(i!=bytes.length-1) hex = hex+split;
sb.append(hex);
}
return sb.toString();
}
}
asjhan for Android reverse
标签:DEX,TypeId,string,int,ids,索引,解析,type 来源: https://blog.csdn.net/qq_35993502/article/details/123591592
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。