google在android8.0新增加了vdex文件,定义如下
art\runtime\ vdex_file.h
// VDEX files contain extracted DEXfiles. The VdexFile class maps the file to
// memory and provides tools foraccessing its individual sections.
//
// File format:
// VdexFile::Header fixed-lengthheader
//
// DEX[0] array of theinput DEX files
// DEX[1] the bytecodemay have been quickened
// ...
// DEX[D]
//
Vdex的文件头定义
struct Header {
public:
Header(uint32_tnumber_of_dex_files_,
uint32_tdex_size,
uint32_tverifier_deps_size,
uint32_tquickening_info_size);
const char*GetMagic() const { return reinterpret_cast<const char*>(magic_); }
const char*GetVersion() const { return reinterpret_cast<const char*>(version_); }
boolIsMagicValid() const;
boolIsVersionValid() const;
bool IsValid()const { return IsMagicValid() && IsVersionValid(); }
uint32_tGetDexSize() const { return dex_size_; }
uint32_tGetVerifierDepsSize() const { return verifier_deps_size_; }
uint32_tGetQuickeningInfoSize() const { return quickening_info_size_; }
uint32_tGetNumberOfDexFiles() const { return number_of_dex_files_; }
static constexpr uint8_t kVdexInvalidMagic[]= { 'w', 'd', 'e', 'x' };
private:
staticconstexpr uint8_t kVdexMagic[] = { 'v', 'd', 'e', 'x' };
staticconstexpr uint8_t kVdexVersion[] = { '0', '0', '5', '\0' }; // access flags
uint8_t magic_[4];
uint8_tversion_[4];
uint32_tnumber_of_dex_files_;
uint32_tdex_size_;
uint32_tverifier_deps_size_;
uint32_tquickening_info_size_;
friend classVdexFile;
};
//VDEX的转换代码
art\dex2oat\dex2oat.cc
示例分析:
Vdex header部分
地址 |
字节数 |
描述 |
备注 |
示例含义 |
0x00 |
4 |
Magic Number |
0x76,0x64,0x65,0x78, (’v’,’d’,’e’,’x’,) |
|
0x04 |
4 |
version |
005 |
|
0x08 |
4 |
number_of_dex_files |
Dex个数 |
01 |
0x0c |
4 |
dex_size_ |
bc f0 06 00 |
符合后面dex header描述 |
0x10 |
4 |
verifier_deps_size_ |
00 00 17 98 |
|
0x14 |
4 |
quickening_info_size_ |
|
00 00 b2 f4 |
0x18 |
4 |
未知,是否是VdexFile的类地址? |
|
bd e5 c4 1f |
Dex部分:
地址 |
字节数 |
描述 |
备注 |
示例含义 |
|
0x1c |
8 |
Magic Number |
0x64,0x65,0x78,0x0a, (’d’,’e’,’x’,’/’,’0’,’3’,’7’,0) |
|
|
0x24 |
4 |
checksum |
|
|
|
0x28 |
20 |
SHA-1 签名 |
|
|
|
0x3c |
4 |
Dex文件长度 |
bc f0 06 00 |
加上0x1c的偏移,该dex在00 06 f0 d7结束 |
|
0x40 |
4 |
dex文件头大小 |
035到037版本都是70 |
Dex文件头在0x8b处结束 |
|
0x44 |
4 |
Endian |
78 56 34 12 |
表示小头字节序 |
|
0x48 |
4 |
Link size |
0 |
0表示无动态链接 |
|
0x4c |
4 |
Link off |
0 |
|
|
0x50 |
4 |
Map off |
00 06 ef e0 |
|
Dex结束处 00 06 f0 d7
MAP数据
在dex ids数据结束后,后面的是data数据和link数据,详细分析见dex文件格式分析。