summaryrefslogtreecommitdiffstats
path: root/libdexfile
diff options
context:
space:
mode:
Diffstat (limited to 'libdexfile')
-rw-r--r--libdexfile/dex/art_dex_file_loader_test.cc44
-rw-r--r--libdexfile/dex/class_accessor-inl.h8
-rw-r--r--libdexfile/dex/class_accessor.h8
-rw-r--r--libdexfile/dex/class_accessor_test.cc2
-rw-r--r--libdexfile/dex/code_item_accessors-inl.h18
-rw-r--r--libdexfile/dex/code_item_accessors.h25
-rw-r--r--libdexfile/dex/code_item_accessors_test.cc2
-rw-r--r--libdexfile/dex/compact_dex_file.cc2
-rw-r--r--libdexfile/dex/compact_dex_file.h4
-rw-r--r--libdexfile/dex/dex_file-inl.h66
-rw-r--r--libdexfile/dex/dex_file.cc74
-rw-r--r--libdexfile/dex/dex_file.h487
-rw-r--r--libdexfile/dex/dex_file_exception_helpers.cc7
-rw-r--r--libdexfile/dex/dex_file_exception_helpers.h10
-rw-r--r--libdexfile/dex/dex_file_loader_test.cc5
-rw-r--r--libdexfile/dex/dex_file_structs.h298
-rw-r--r--libdexfile/dex/dex_file_tracking_registrar.cc18
-rw-r--r--libdexfile/dex/dex_file_verifier.cc268
-rw-r--r--libdexfile/dex/dex_file_verifier.h18
-rw-r--r--libdexfile/dex/dex_file_verifier_test.cc14
-rw-r--r--libdexfile/dex/method_reference.h14
-rw-r--r--libdexfile/dex/standard_dex_file.cc2
-rw-r--r--libdexfile/dex/standard_dex_file.h4
-rw-r--r--libdexfile/dex/test_dex_file_builder.h24
-rw-r--r--libdexfile/dex/type_lookup_table.cc12
25 files changed, 756 insertions, 678 deletions
diff --git a/libdexfile/dex/art_dex_file_loader_test.cc b/libdexfile/dex/art_dex_file_loader_test.cc
index f7a20629f5..f9516dbb89 100644
--- a/libdexfile/dex/art_dex_file_loader_test.cc
+++ b/libdexfile/dex/art_dex_file_loader_test.cc
@@ -107,13 +107,13 @@ TEST_F(ArtDexFileLoaderTest, ClassDefs) {
ASSERT_TRUE(raw.get() != nullptr);
EXPECT_EQ(3U, raw->NumClassDefs());
- const DexFile::ClassDef& c0 = raw->GetClassDef(0);
+ const dex::ClassDef& c0 = raw->GetClassDef(0);
EXPECT_STREQ("LNested$1;", raw->GetClassDescriptor(c0));
- const DexFile::ClassDef& c1 = raw->GetClassDef(1);
+ const dex::ClassDef& c1 = raw->GetClassDef(1);
EXPECT_STREQ("LNested$Inner;", raw->GetClassDescriptor(c1));
- const DexFile::ClassDef& c2 = raw->GetClassDef(2);
+ const dex::ClassDef& c2 = raw->GetClassDef(2);
EXPECT_STREQ("LNested;", raw->GetClassDescriptor(c2));
}
@@ -122,7 +122,7 @@ TEST_F(ArtDexFileLoaderTest, GetMethodSignature) {
ASSERT_TRUE(raw.get() != nullptr);
EXPECT_EQ(1U, raw->NumClassDefs());
- const DexFile::ClassDef& class_def = raw->GetClassDef(0);
+ const dex::ClassDef& class_def = raw->GetClassDef(0);
ASSERT_STREQ("LGetMethodSignature;", raw->GetClassDescriptor(class_def));
ClassAccessor accessor(*raw, class_def);
@@ -133,7 +133,7 @@ TEST_F(ArtDexFileLoaderTest, GetMethodSignature) {
// Check the signature for the static initializer.
{
ASSERT_EQ(1U, accessor.NumDirectMethods());
- const DexFile::MethodId& method_id = raw->GetMethodId(cur_method->GetIndex());
+ const dex::MethodId& method_id = raw->GetMethodId(cur_method->GetIndex());
const char* name = raw->StringDataByIdx(method_id.name_idx_);
ASSERT_STREQ("<init>", name);
std::string signature(raw->GetMethodSignature(method_id).ToString());
@@ -207,7 +207,7 @@ TEST_F(ArtDexFileLoaderTest, GetMethodSignature) {
for (const Result& r : results) {
++cur_method;
ASSERT_TRUE(cur_method != methods.end());
- const DexFile::MethodId& method_id = raw->GetMethodId(cur_method->GetIndex());
+ const dex::MethodId& method_id = raw->GetMethodId(cur_method->GetIndex());
const char* name = raw->StringDataByIdx(method_id.name_idx_);
ASSERT_STREQ(r.name, name);
@@ -232,7 +232,7 @@ TEST_F(ArtDexFileLoaderTest, FindStringId) {
"D", "I", "J", nullptr };
for (size_t i = 0; strings[i] != nullptr; i++) {
const char* str = strings[i];
- const DexFile::StringId* str_id = raw->FindStringId(str);
+ const dex::StringId* str_id = raw->FindStringId(str);
const char* dex_str = raw->GetStringData(*str_id);
EXPECT_STREQ(dex_str, str);
}
@@ -241,10 +241,10 @@ TEST_F(ArtDexFileLoaderTest, FindStringId) {
TEST_F(ArtDexFileLoaderTest, FindTypeId) {
for (size_t i = 0; i < java_lang_dex_file_->NumTypeIds(); i++) {
const char* type_str = java_lang_dex_file_->StringByTypeIdx(dex::TypeIndex(i));
- const DexFile::StringId* type_str_id = java_lang_dex_file_->FindStringId(type_str);
+ const dex::StringId* type_str_id = java_lang_dex_file_->FindStringId(type_str);
ASSERT_TRUE(type_str_id != nullptr);
dex::StringIndex type_str_idx = java_lang_dex_file_->GetIndexForStringId(*type_str_id);
- const DexFile::TypeId* type_id = java_lang_dex_file_->FindTypeId(type_str_idx);
+ const dex::TypeId* type_id = java_lang_dex_file_->FindTypeId(type_str_idx);
ASSERT_EQ(type_id, java_lang_dex_file_->FindTypeId(type_str));
ASSERT_TRUE(type_id != nullptr);
EXPECT_EQ(java_lang_dex_file_->GetIndexForTypeId(*type_id).index_, i);
@@ -253,15 +253,15 @@ TEST_F(ArtDexFileLoaderTest, FindTypeId) {
TEST_F(ArtDexFileLoaderTest, FindProtoId) {
for (size_t i = 0; i < java_lang_dex_file_->NumProtoIds(); i++) {
- const DexFile::ProtoId& to_find = java_lang_dex_file_->GetProtoId(dex::ProtoIndex(i));
- const DexFile::TypeList* to_find_tl = java_lang_dex_file_->GetProtoParameters(to_find);
+ const dex::ProtoId& to_find = java_lang_dex_file_->GetProtoId(dex::ProtoIndex(i));
+ const dex::TypeList* to_find_tl = java_lang_dex_file_->GetProtoParameters(to_find);
std::vector<dex::TypeIndex> to_find_types;
if (to_find_tl != nullptr) {
for (size_t j = 0; j < to_find_tl->Size(); j++) {
to_find_types.push_back(to_find_tl->GetTypeItem(j).type_idx_);
}
}
- const DexFile::ProtoId* found =
+ const dex::ProtoId* found =
java_lang_dex_file_->FindProtoId(to_find.return_type_idx_, to_find_types);
ASSERT_TRUE(found != nullptr);
EXPECT_EQ(java_lang_dex_file_->GetIndexForProtoId(*found), dex::ProtoIndex(i));
@@ -270,11 +270,11 @@ TEST_F(ArtDexFileLoaderTest, FindProtoId) {
TEST_F(ArtDexFileLoaderTest, FindMethodId) {
for (size_t i = 0; i < java_lang_dex_file_->NumMethodIds(); i++) {
- const DexFile::MethodId& to_find = java_lang_dex_file_->GetMethodId(i);
- const DexFile::TypeId& klass = java_lang_dex_file_->GetTypeId(to_find.class_idx_);
- const DexFile::StringId& name = java_lang_dex_file_->GetStringId(to_find.name_idx_);
- const DexFile::ProtoId& signature = java_lang_dex_file_->GetProtoId(to_find.proto_idx_);
- const DexFile::MethodId* found = java_lang_dex_file_->FindMethodId(klass, name, signature);
+ const dex::MethodId& to_find = java_lang_dex_file_->GetMethodId(i);
+ const dex::TypeId& klass = java_lang_dex_file_->GetTypeId(to_find.class_idx_);
+ const dex::StringId& name = java_lang_dex_file_->GetStringId(to_find.name_idx_);
+ const dex::ProtoId& signature = java_lang_dex_file_->GetProtoId(to_find.proto_idx_);
+ const dex::MethodId* found = java_lang_dex_file_->FindMethodId(klass, name, signature);
ASSERT_TRUE(found != nullptr) << "Didn't find method " << i << ": "
<< java_lang_dex_file_->StringByTypeIdx(to_find.class_idx_) << "."
<< java_lang_dex_file_->GetStringData(name)
@@ -285,11 +285,11 @@ TEST_F(ArtDexFileLoaderTest, FindMethodId) {
TEST_F(ArtDexFileLoaderTest, FindFieldId) {
for (size_t i = 0; i < java_lang_dex_file_->NumFieldIds(); i++) {
- const DexFile::FieldId& to_find = java_lang_dex_file_->GetFieldId(i);
- const DexFile::TypeId& klass = java_lang_dex_file_->GetTypeId(to_find.class_idx_);
- const DexFile::StringId& name = java_lang_dex_file_->GetStringId(to_find.name_idx_);
- const DexFile::TypeId& type = java_lang_dex_file_->GetTypeId(to_find.type_idx_);
- const DexFile::FieldId* found = java_lang_dex_file_->FindFieldId(klass, name, type);
+ const dex::FieldId& to_find = java_lang_dex_file_->GetFieldId(i);
+ const dex::TypeId& klass = java_lang_dex_file_->GetTypeId(to_find.class_idx_);
+ const dex::StringId& name = java_lang_dex_file_->GetStringId(to_find.name_idx_);
+ const dex::TypeId& type = java_lang_dex_file_->GetTypeId(to_find.type_idx_);
+ const dex::FieldId* found = java_lang_dex_file_->FindFieldId(klass, name, type);
ASSERT_TRUE(found != nullptr) << "Didn't find field " << i << ": "
<< java_lang_dex_file_->StringByTypeIdx(to_find.type_idx_) << " "
<< java_lang_dex_file_->StringByTypeIdx(to_find.class_idx_) << "."
diff --git a/libdexfile/dex/class_accessor-inl.h b/libdexfile/dex/class_accessor-inl.h
index 334b0720c9..c9e5360f31 100644
--- a/libdexfile/dex/class_accessor-inl.h
+++ b/libdexfile/dex/class_accessor-inl.h
@@ -31,7 +31,7 @@ inline ClassAccessor::ClassAccessor(const ClassIteratorData& data)
: ClassAccessor(data.dex_file_, data.class_def_idx_) {}
inline ClassAccessor::ClassAccessor(const DexFile& dex_file,
- const DexFile::ClassDef& class_def,
+ const dex::ClassDef& class_def,
bool parse_hiddenapi_class_data)
: ClassAccessor(dex_file,
dex_file.GetClassData(class_def),
@@ -54,7 +54,7 @@ inline ClassAccessor::ClassAccessor(const DexFile& dex_file,
num_direct_methods_(ptr_pos_ != nullptr ? DecodeUnsignedLeb128(&ptr_pos_) : 0u),
num_virtual_methods_(ptr_pos_ != nullptr ? DecodeUnsignedLeb128(&ptr_pos_) : 0u) {
if (parse_hiddenapi_class_data && class_def_index != DexFile::kDexNoIndex32) {
- const DexFile::HiddenapiClassData* hiddenapi_class_data = dex_file.GetHiddenapiClassData();
+ const dex::HiddenapiClassData* hiddenapi_class_data = dex_file.GetHiddenapiClassData();
if (hiddenapi_class_data != nullptr) {
hiddenapi_ptr_pos_ = hiddenapi_class_data->GetFlagsPointer(class_def_index);
}
@@ -131,7 +131,7 @@ inline void ClassAccessor::VisitFields(const StaticFieldVisitor& static_field_vi
VoidFunctor());
}
-inline const DexFile::CodeItem* ClassAccessor::GetCodeItem(const Method& method) const {
+inline const dex::CodeItem* ClassAccessor::GetCodeItem(const Method& method) const {
return dex_file_.GetCodeItem(method.GetCodeItemOffset());
}
@@ -147,7 +147,7 @@ inline const char* ClassAccessor::GetDescriptor() const {
return dex_file_.StringByTypeIdx(GetClassIdx());
}
-inline const DexFile::CodeItem* ClassAccessor::Method::GetCodeItem() const {
+inline const dex::CodeItem* ClassAccessor::Method::GetCodeItem() const {
return dex_file_.GetCodeItem(code_off_);
}
diff --git a/libdexfile/dex/class_accessor.h b/libdexfile/dex/class_accessor.h
index bd7b912cb4..cf6e5095d6 100644
--- a/libdexfile/dex/class_accessor.h
+++ b/libdexfile/dex/class_accessor.h
@@ -99,7 +99,7 @@ class ClassAccessor {
CodeItemInstructionAccessor GetInstructions() const;
CodeItemDataAccessor GetInstructionsAndData() const;
- const DexFile::CodeItem* GetCodeItem() const;
+ const dex::CodeItem* GetCodeItem() const;
bool IsStaticOrDirect() const {
return is_static_or_direct_;
@@ -266,7 +266,7 @@ class ClassAccessor {
ALWAYS_INLINE ClassAccessor(const ClassIteratorData& data); // NOLINT [runtime/explicit] [5]
ALWAYS_INLINE ClassAccessor(const DexFile& dex_file,
- const DexFile::ClassDef& class_def,
+ const dex::ClassDef& class_def,
bool parse_hiddenapi_class_data = false);
ALWAYS_INLINE ClassAccessor(const DexFile& dex_file, uint32_t class_def_index);
@@ -277,7 +277,7 @@ class ClassAccessor {
bool parse_hiddenapi_class_data = false);
// Return the code item for a method.
- const DexFile::CodeItem* GetCodeItem(const Method& method) const;
+ const dex::CodeItem* GetCodeItem(const Method& method) const;
// Iterator data is not very iterator friendly, use visitors to get around this.
template <typename StaticFieldVisitor,
@@ -361,7 +361,7 @@ class ClassAccessor {
return class_def_index_;
}
- const DexFile::ClassDef& GetClassDef() const {
+ const dex::ClassDef& GetClassDef() const {
return dex_file_.GetClassDef(GetClassDefIndex());
}
diff --git a/libdexfile/dex/class_accessor_test.cc b/libdexfile/dex/class_accessor_test.cc
index 1f30ae54d6..9f2ee23327 100644
--- a/libdexfile/dex/class_accessor_test.cc
+++ b/libdexfile/dex/class_accessor_test.cc
@@ -30,7 +30,7 @@ TEST_F(ClassAccessorTest, TestVisiting) {
uint32_t class_def_idx = 0u;
ASSERT_GT(dex_file->NumClassDefs(), 0u);
for (ClassAccessor accessor : dex_file->GetClasses()) {
- const DexFile::ClassDef& class_def = dex_file->GetClassDef(accessor.GetClassDefIndex());
+ const dex::ClassDef& class_def = dex_file->GetClassDef(accessor.GetClassDefIndex());
EXPECT_EQ(accessor.GetDescriptor(), dex_file->StringByTypeIdx(class_def.class_idx_));
EXPECT_EQ(class_def_idx, accessor.GetClassDefIndex());
++class_def_idx;
diff --git a/libdexfile/dex/code_item_accessors-inl.h b/libdexfile/dex/code_item_accessors-inl.h
index bbf2224b06..15e34b74be 100644
--- a/libdexfile/dex/code_item_accessors-inl.h
+++ b/libdexfile/dex/code_item_accessors-inl.h
@@ -48,7 +48,7 @@ inline void CodeItemInstructionAccessor::Init(const StandardDexFile::CodeItem& c
}
inline void CodeItemInstructionAccessor::Init(const DexFile& dex_file,
- const DexFile::CodeItem* code_item) {
+ const dex::CodeItem* code_item) {
if (code_item != nullptr) {
DCHECK(dex_file.IsInDataSection(code_item));
if (dex_file.IsCompactDexFile()) {
@@ -62,7 +62,7 @@ inline void CodeItemInstructionAccessor::Init(const DexFile& dex_file,
inline CodeItemInstructionAccessor::CodeItemInstructionAccessor(
const DexFile& dex_file,
- const DexFile::CodeItem* code_item) {
+ const dex::CodeItem* code_item) {
Init(dex_file, code_item);
}
@@ -101,7 +101,7 @@ inline void CodeItemDataAccessor::Init(const StandardDexFile::CodeItem& code_ite
}
inline void CodeItemDataAccessor::Init(const DexFile& dex_file,
- const DexFile::CodeItem* code_item) {
+ const dex::CodeItem* code_item) {
if (code_item != nullptr) {
if (dex_file.IsCompactDexFile()) {
CodeItemDataAccessor::Init(down_cast<const CompactDexFile::CodeItem&>(*code_item));
@@ -113,12 +113,12 @@ inline void CodeItemDataAccessor::Init(const DexFile& dex_file,
}
inline CodeItemDataAccessor::CodeItemDataAccessor(const DexFile& dex_file,
- const DexFile::CodeItem* code_item) {
+ const dex::CodeItem* code_item) {
Init(dex_file, code_item);
}
-inline IterationRange<const DexFile::TryItem*> CodeItemDataAccessor::TryItems() const {
- const DexFile::TryItem* try_items = DexFile::GetTryItems(end(), 0u);
+inline IterationRange<const dex::TryItem*> CodeItemDataAccessor::TryItems() const {
+ const dex::TryItem* try_items = DexFile::GetTryItems(end(), 0u);
return {
try_items,
try_items + TriesSize() };
@@ -128,8 +128,8 @@ inline const uint8_t* CodeItemDataAccessor::GetCatchHandlerData(size_t offset) c
return DexFile::GetCatchHandlerData(end(), TriesSize(), offset);
}
-inline const DexFile::TryItem* CodeItemDataAccessor::FindTryItem(uint32_t try_dex_pc) const {
- IterationRange<const DexFile::TryItem*> try_items(TryItems());
+inline const dex::TryItem* CodeItemDataAccessor::FindTryItem(uint32_t try_dex_pc) const {
+ IterationRange<const dex::TryItem*> try_items(TryItems());
int32_t index = DexFile::FindTryItem(try_items.begin(),
try_items.end() - try_items.begin(),
try_dex_pc);
@@ -158,7 +158,7 @@ inline const void* CodeItemDataAccessor::CodeItemDataEnd() const {
}
inline void CodeItemDebugInfoAccessor::Init(const DexFile& dex_file,
- const DexFile::CodeItem* code_item,
+ const dex::CodeItem* code_item,
uint32_t dex_method_index) {
if (code_item == nullptr) {
return;
diff --git a/libdexfile/dex/code_item_accessors.h b/libdexfile/dex/code_item_accessors.h
index c307c9f70b..0ae5905860 100644
--- a/libdexfile/dex/code_item_accessors.h
+++ b/libdexfile/dex/code_item_accessors.h
@@ -19,21 +19,28 @@
#ifndef ART_LIBDEXFILE_DEX_CODE_ITEM_ACCESSORS_H_
#define ART_LIBDEXFILE_DEX_CODE_ITEM_ACCESSORS_H_
+#include <android-base/logging.h>
+
#include "compact_dex_file.h"
-#include "dex_file.h"
#include "dex_instruction_iterator.h"
#include "standard_dex_file.h"
namespace art {
+namespace dex {
+struct CodeItem;
+struct TryItem;
+} // namespace dex
+
class ArtMethod;
+class DexFile;
// Abstracts accesses to the instruction fields of code items for CompactDexFile and
// StandardDexFile.
class CodeItemInstructionAccessor {
public:
ALWAYS_INLINE CodeItemInstructionAccessor(const DexFile& dex_file,
- const DexFile::CodeItem* code_item);
+ const dex::CodeItem* code_item);
ALWAYS_INLINE explicit CodeItemInstructionAccessor(ArtMethod* method);
@@ -73,7 +80,7 @@ class CodeItemInstructionAccessor {
ALWAYS_INLINE void Init(uint32_t insns_size_in_code_units, const uint16_t* insns);
ALWAYS_INLINE void Init(const CompactDexFile::CodeItem& code_item);
ALWAYS_INLINE void Init(const StandardDexFile::CodeItem& code_item);
- ALWAYS_INLINE void Init(const DexFile& dex_file, const DexFile::CodeItem* code_item);
+ ALWAYS_INLINE void Init(const DexFile& dex_file, const dex::CodeItem* code_item);
private:
// size of the insns array, in 2 byte code units. 0 if there is no code item.
@@ -87,7 +94,7 @@ class CodeItemInstructionAccessor {
// StandardDexFile.
class CodeItemDataAccessor : public CodeItemInstructionAccessor {
public:
- ALWAYS_INLINE CodeItemDataAccessor(const DexFile& dex_file, const DexFile::CodeItem* code_item);
+ ALWAYS_INLINE CodeItemDataAccessor(const DexFile& dex_file, const dex::CodeItem* code_item);
uint16_t RegistersSize() const {
return registers_size_;
@@ -105,11 +112,11 @@ class CodeItemDataAccessor : public CodeItemInstructionAccessor {
return tries_size_;
}
- IterationRange<const DexFile::TryItem*> TryItems() const;
+ IterationRange<const dex::TryItem*> TryItems() const;
const uint8_t* GetCatchHandlerData(size_t offset = 0) const;
- const DexFile::TryItem* FindTryItem(uint32_t try_dex_pc) const;
+ const dex::TryItem* FindTryItem(uint32_t try_dex_pc) const;
inline const void* CodeItemDataEnd() const;
@@ -118,7 +125,7 @@ class CodeItemDataAccessor : public CodeItemInstructionAccessor {
ALWAYS_INLINE void Init(const CompactDexFile::CodeItem& code_item);
ALWAYS_INLINE void Init(const StandardDexFile::CodeItem& code_item);
- ALWAYS_INLINE void Init(const DexFile& dex_file, const DexFile::CodeItem* code_item);
+ ALWAYS_INLINE void Init(const DexFile& dex_file, const dex::CodeItem* code_item);
private:
// Fields mirrored from the dex/cdex code item.
@@ -136,13 +143,13 @@ class CodeItemDebugInfoAccessor : public CodeItemDataAccessor {
// Initialize with an existing offset.
ALWAYS_INLINE CodeItemDebugInfoAccessor(const DexFile& dex_file,
- const DexFile::CodeItem* code_item,
+ const dex::CodeItem* code_item,
uint32_t dex_method_index) {
Init(dex_file, code_item, dex_method_index);
}
ALWAYS_INLINE void Init(const DexFile& dex_file,
- const DexFile::CodeItem* code_item,
+ const dex::CodeItem* code_item,
uint32_t dex_method_index);
ALWAYS_INLINE explicit CodeItemDebugInfoAccessor(ArtMethod* method);
diff --git a/libdexfile/dex/code_item_accessors_test.cc b/libdexfile/dex/code_item_accessors_test.cc
index 87f4bab672..c5891f9d46 100644
--- a/libdexfile/dex/code_item_accessors_test.cc
+++ b/libdexfile/dex/code_item_accessors_test.cc
@@ -71,7 +71,7 @@ TEST(CodeItemAccessorsTest, TestDexInstructionsAccessor) {
static constexpr size_t kInsnsSizeInCodeUnits = 5;
auto verify_code_item = [&](const DexFile* dex,
- const DexFile::CodeItem* item,
+ const dex::CodeItem* item,
const uint16_t* insns) {
CodeItemInstructionAccessor insns_accessor(*dex, item);
EXPECT_TRUE(insns_accessor.HasCodeItem());
diff --git a/libdexfile/dex/compact_dex_file.cc b/libdexfile/dex/compact_dex_file.cc
index 641c523158..a5044aad7e 100644
--- a/libdexfile/dex/compact_dex_file.cc
+++ b/libdexfile/dex/compact_dex_file.cc
@@ -55,7 +55,7 @@ bool CompactDexFile::SupportsDefaultMethods() const {
static_cast<uint32_t>(FeatureFlags::kDefaultMethods)) != 0;
}
-uint32_t CompactDexFile::GetCodeItemSize(const DexFile::CodeItem& item) const {
+uint32_t CompactDexFile::GetCodeItemSize(const dex::CodeItem& item) const {
DCHECK(IsInDataSection(&item));
return reinterpret_cast<uintptr_t>(CodeItemDataAccessor(*this, &item).CodeItemDataEnd()) -
reinterpret_cast<uintptr_t>(&item);
diff --git a/libdexfile/dex/compact_dex_file.h b/libdexfile/dex/compact_dex_file.h
index 8eade6dba8..47edd517fa 100644
--- a/libdexfile/dex/compact_dex_file.h
+++ b/libdexfile/dex/compact_dex_file.h
@@ -84,7 +84,7 @@ class CompactDexFile : public DexFile {
// Like the standard code item except without a debug info offset. Each code item may have a
// preheader to encode large methods. In 99% of cases, the preheader is not used. This enables
// smaller size with a good fast path case in the accessors.
- struct CodeItem : public DexFile::CodeItem {
+ struct CodeItem : public dex::CodeItem {
static constexpr size_t kAlignment = sizeof(uint16_t);
// Max preheader size in uint16_ts.
static constexpr size_t kMaxPreHeaderSize = 6;
@@ -271,7 +271,7 @@ class CompactDexFile : public DexFile {
bool SupportsDefaultMethods() const override;
- uint32_t GetCodeItemSize(const DexFile::CodeItem& item) const override;
+ uint32_t GetCodeItemSize(const dex::CodeItem& item) const override;
uint32_t GetDebugInfoOffset(uint32_t dex_method_index) const {
return debug_info_offsets_.GetOffset(dex_method_index);
diff --git a/libdexfile/dex/dex_file-inl.h b/libdexfile/dex/dex_file-inl.h
index c884eee88b..cacd7ddba1 100644
--- a/libdexfile/dex/dex_file-inl.h
+++ b/libdexfile/dex/dex_file-inl.h
@@ -31,12 +31,12 @@
namespace art {
-inline int32_t DexFile::GetStringLength(const StringId& string_id) const {
+inline int32_t DexFile::GetStringLength(const dex::StringId& string_id) const {
const uint8_t* ptr = DataBegin() + string_id.string_data_off_;
return DecodeUnsignedLeb128(&ptr);
}
-inline const char* DexFile::GetStringDataAndUtf16Length(const StringId& string_id,
+inline const char* DexFile::GetStringDataAndUtf16Length(const dex::StringId& string_id,
uint32_t* utf16_length) const {
DCHECK(utf16_length != nullptr) << GetLocation();
const uint8_t* ptr = DataBegin() + string_id.string_data_off_;
@@ -44,7 +44,7 @@ inline const char* DexFile::GetStringDataAndUtf16Length(const StringId& string_i
return reinterpret_cast<const char*>(ptr);
}
-inline const char* DexFile::GetStringData(const StringId& string_id) const {
+inline const char* DexFile::GetStringData(const dex::StringId& string_id) const {
uint32_t ignored;
return GetStringDataAndUtf16Length(string_id, &ignored);
}
@@ -55,7 +55,7 @@ inline const char* DexFile::StringDataAndUtf16LengthByIdx(dex::StringIndex idx,
*utf16_length = 0;
return nullptr;
}
- const StringId& string_id = GetStringId(idx);
+ const dex::StringId& string_id = GetStringId(idx);
return GetStringDataAndUtf16Length(string_id, utf16_length);
}
@@ -68,7 +68,7 @@ inline const char* DexFile::StringByTypeIdx(dex::TypeIndex idx, uint32_t* unicod
if (!idx.IsValid()) {
return nullptr;
}
- const TypeId& type_id = GetTypeId(idx);
+ const dex::TypeId& type_id = GetTypeId(idx);
return StringDataAndUtf16LengthByIdx(type_id.descriptor_idx_, unicode_length);
}
@@ -76,41 +76,43 @@ inline const char* DexFile::StringByTypeIdx(dex::TypeIndex idx) const {
if (!idx.IsValid()) {
return nullptr;
}
- const TypeId& type_id = GetTypeId(idx);
+ const dex::TypeId& type_id = GetTypeId(idx);
return StringDataByIdx(type_id.descriptor_idx_);
}
-inline const char* DexFile::GetTypeDescriptor(const TypeId& type_id) const {
+inline const char* DexFile::GetTypeDescriptor(const dex::TypeId& type_id) const {
return StringDataByIdx(type_id.descriptor_idx_);
}
-inline const char* DexFile::GetFieldTypeDescriptor(const FieldId& field_id) const {
- const DexFile::TypeId& type_id = GetTypeId(field_id.type_idx_);
+inline const char* DexFile::GetFieldTypeDescriptor(const dex::FieldId& field_id) const {
+ const dex::TypeId& type_id = GetTypeId(field_id.type_idx_);
return GetTypeDescriptor(type_id);
}
-inline const char* DexFile::GetFieldName(const FieldId& field_id) const {
+inline const char* DexFile::GetFieldName(const dex::FieldId& field_id) const {
return StringDataByIdx(field_id.name_idx_);
}
-inline const char* DexFile::GetMethodDeclaringClassDescriptor(const MethodId& method_id) const {
- const DexFile::TypeId& type_id = GetTypeId(method_id.class_idx_);
+inline const char* DexFile::GetMethodDeclaringClassDescriptor(const dex::MethodId& method_id)
+ const {
+ const dex::TypeId& type_id = GetTypeId(method_id.class_idx_);
return GetTypeDescriptor(type_id);
}
-inline const Signature DexFile::GetMethodSignature(const MethodId& method_id) const {
+inline const Signature DexFile::GetMethodSignature(const dex::MethodId& method_id) const {
return Signature(this, GetProtoId(method_id.proto_idx_));
}
-inline const Signature DexFile::GetProtoSignature(const ProtoId& proto_id) const {
+inline const Signature DexFile::GetProtoSignature(const dex::ProtoId& proto_id) const {
return Signature(this, proto_id);
}
-inline const char* DexFile::GetMethodName(const MethodId& method_id) const {
+inline const char* DexFile::GetMethodName(const dex::MethodId& method_id) const {
return StringDataByIdx(method_id.name_idx_);
}
-inline const char* DexFile::GetMethodName(const MethodId& method_id, uint32_t* utf_length) const {
+inline const char* DexFile::GetMethodName(const dex::MethodId& method_id, uint32_t* utf_length)
+ const {
return StringDataAndUtf16LengthByIdx(method_id.name_idx_, utf_length);
}
@@ -122,32 +124,34 @@ inline const char* DexFile::GetMethodShorty(uint32_t idx) const {
return StringDataByIdx(GetProtoId(GetMethodId(idx).proto_idx_).shorty_idx_);
}
-inline const char* DexFile::GetMethodShorty(const MethodId& method_id) const {
+inline const char* DexFile::GetMethodShorty(const dex::MethodId& method_id) const {
return StringDataByIdx(GetProtoId(method_id.proto_idx_).shorty_idx_);
}
-inline const char* DexFile::GetMethodShorty(const MethodId& method_id, uint32_t* length) const {
+inline const char* DexFile::GetMethodShorty(const dex::MethodId& method_id, uint32_t* length)
+ const {
// Using the UTF16 length is safe here as shorties are guaranteed to be ASCII characters.
return StringDataAndUtf16LengthByIdx(GetProtoId(method_id.proto_idx_).shorty_idx_, length);
}
-inline const char* DexFile::GetClassDescriptor(const ClassDef& class_def) const {
+inline const char* DexFile::GetClassDescriptor(const dex::ClassDef& class_def) const {
return StringByTypeIdx(class_def.class_idx_);
}
-inline const char* DexFile::GetReturnTypeDescriptor(const ProtoId& proto_id) const {
+inline const char* DexFile::GetReturnTypeDescriptor(const dex::ProtoId& proto_id) const {
return StringByTypeIdx(proto_id.return_type_idx_);
}
inline const char* DexFile::GetShorty(dex::ProtoIndex proto_idx) const {
- const ProtoId& proto_id = GetProtoId(proto_idx);
+ const dex::ProtoId& proto_id = GetProtoId(proto_idx);
return StringDataByIdx(proto_id.shorty_idx_);
}
-inline const DexFile::TryItem* DexFile::GetTryItems(const DexInstructionIterator& code_item_end,
- uint32_t offset) {
- return reinterpret_cast<const TryItem*>
- (RoundUp(reinterpret_cast<uintptr_t>(&code_item_end.Inst()), TryItem::kAlignment)) + offset;
+inline const dex::TryItem* DexFile::GetTryItems(const DexInstructionIterator& code_item_end,
+ uint32_t offset) {
+ return reinterpret_cast<const dex::TryItem*>
+ (RoundUp(reinterpret_cast<uintptr_t>(&code_item_end.Inst()), dex::TryItem::kAlignment)) +
+ offset;
}
static inline bool DexFileStringEquals(const DexFile* df1, dex::StringIndex sidx1,
@@ -184,8 +188,8 @@ inline bool Signature::operator==(const Signature& rhs) const {
}
}
if (lhs_shorty[0] == 'L') {
- const DexFile::TypeId& return_type_id = dex_file_->GetTypeId(proto_id_->return_type_idx_);
- const DexFile::TypeId& rhs_return_type_id =
+ const dex::TypeId& return_type_id = dex_file_->GetTypeId(proto_id_->return_type_idx_);
+ const dex::TypeId& rhs_return_type_id =
rhs.dex_file_->GetTypeId(rhs.proto_id_->return_type_idx_);
if (!DexFileStringEquals(dex_file_, return_type_id.descriptor_idx_,
rhs.dex_file_, rhs_return_type_id.descriptor_idx_)) {
@@ -193,16 +197,16 @@ inline bool Signature::operator==(const Signature& rhs) const {
}
}
if (lhs_shorty.find('L', 1) != StringPiece::npos) {
- const DexFile::TypeList* params = dex_file_->GetProtoParameters(*proto_id_);
- const DexFile::TypeList* rhs_params = rhs.dex_file_->GetProtoParameters(*rhs.proto_id_);
+ const dex::TypeList* params = dex_file_->GetProtoParameters(*proto_id_);
+ const dex::TypeList* rhs_params = rhs.dex_file_->GetProtoParameters(*rhs.proto_id_);
// We found a reference parameter in the matching shorty, so both lists must be non-empty.
DCHECK(params != nullptr);
DCHECK(rhs_params != nullptr);
uint32_t params_size = params->Size();
DCHECK_EQ(params_size, rhs_params->Size()); // Parameter list size must match.
for (uint32_t i = 0; i < params_size; ++i) {
- const DexFile::TypeId& param_id = dex_file_->GetTypeId(params->GetTypeItem(i).type_idx_);
- const DexFile::TypeId& rhs_param_id =
+ const dex::TypeId& param_id = dex_file_->GetTypeId(params->GetTypeItem(i).type_idx_);
+ const dex::TypeId& rhs_param_id =
rhs.dex_file_->GetTypeId(rhs_params->GetTypeItem(i).type_idx_);
if (!DexFileStringEquals(dex_file_, param_id.descriptor_idx_,
rhs.dex_file_, rhs_param_id.descriptor_idx_)) {
diff --git a/libdexfile/dex/dex_file.cc b/libdexfile/dex/dex_file.cc
index 7ccb9c0bad..ff519064f1 100644
--- a/libdexfile/dex/dex_file.cc
+++ b/libdexfile/dex/dex_file.cc
@@ -41,6 +41,19 @@ namespace art {
using android::base::StringPrintf;
+using dex::CallSiteIdItem;
+using dex::ClassDef;
+using dex::FieldId;
+using dex::MapList;
+using dex::MapItem;
+using dex::MethodHandleItem;
+using dex::MethodId;
+using dex::ProtoId;
+using dex::StringId;
+using dex::TryItem;
+using dex::TypeId;
+using dex::TypeList;
+
static_assert(sizeof(dex::StringIndex) == sizeof(uint32_t), "StringIndex size is wrong");
static_assert(std::is_trivially_copyable<dex::StringIndex>::value, "StringIndex not trivial");
static_assert(sizeof(dex::TypeIndex) == sizeof(uint16_t), "TypeIndex size is wrong");
@@ -195,7 +208,7 @@ uint32_t DexFile::Header::GetVersion() const {
return atoi(version);
}
-const DexFile::ClassDef* DexFile::FindClassDef(dex::TypeIndex type_idx) const {
+const ClassDef* DexFile::FindClassDef(dex::TypeIndex type_idx) const {
size_t num_class_defs = NumClassDefs();
// Fast path for rare no class defs case.
if (num_class_defs == 0) {
@@ -210,8 +223,7 @@ const DexFile::ClassDef* DexFile::FindClassDef(dex::TypeIndex type_idx) const {
return nullptr;
}
-uint32_t DexFile::FindCodeItemOffset(const DexFile::ClassDef& class_def,
- uint32_t method_idx) const {
+uint32_t DexFile::FindCodeItemOffset(const ClassDef& class_def, uint32_t method_idx) const {
ClassAccessor accessor(*this, class_def);
CHECK(accessor.HasClassData());
for (const ClassAccessor::Method& method : accessor.GetMethods()) {
@@ -223,9 +235,9 @@ uint32_t DexFile::FindCodeItemOffset(const DexFile::ClassDef& class_def,
UNREACHABLE();
}
-const DexFile::FieldId* DexFile::FindFieldId(const DexFile::TypeId& declaring_klass,
- const DexFile::StringId& name,
- const DexFile::TypeId& type) const {
+const FieldId* DexFile::FindFieldId(const TypeId& declaring_klass,
+ const StringId& name,
+ const TypeId& type) const {
// Binary search MethodIds knowing that they are sorted by class_idx, name_idx then proto_idx
const dex::TypeIndex class_idx = GetIndexForTypeId(declaring_klass);
const dex::StringIndex name_idx = GetIndexForStringId(name);
@@ -234,7 +246,7 @@ const DexFile::FieldId* DexFile::FindFieldId(const DexFile::TypeId& declaring_kl
int32_t hi = NumFieldIds() - 1;
while (hi >= lo) {
int32_t mid = (hi + lo) / 2;
- const DexFile::FieldId& field = GetFieldId(mid);
+ const FieldId& field = GetFieldId(mid);
if (class_idx > field.class_idx_) {
lo = mid + 1;
} else if (class_idx < field.class_idx_) {
@@ -258,9 +270,9 @@ const DexFile::FieldId* DexFile::FindFieldId(const DexFile::TypeId& declaring_kl
return nullptr;
}
-const DexFile::MethodId* DexFile::FindMethodId(const DexFile::TypeId& declaring_klass,
- const DexFile::StringId& name,
- const DexFile::ProtoId& signature) const {
+const MethodId* DexFile::FindMethodId(const TypeId& declaring_klass,
+ const StringId& name,
+ const ProtoId& signature) const {
// Binary search MethodIds knowing that they are sorted by class_idx, name_idx then proto_idx
const dex::TypeIndex class_idx = GetIndexForTypeId(declaring_klass);
const dex::StringIndex name_idx = GetIndexForStringId(name);
@@ -269,7 +281,7 @@ const DexFile::MethodId* DexFile::FindMethodId(const DexFile::TypeId& declaring_
int32_t hi = NumMethodIds() - 1;
while (hi >= lo) {
int32_t mid = (hi + lo) / 2;
- const DexFile::MethodId& method = GetMethodId(mid);
+ const MethodId& method = GetMethodId(mid);
if (class_idx > method.class_idx_) {
lo = mid + 1;
} else if (class_idx < method.class_idx_) {
@@ -293,12 +305,12 @@ const DexFile::MethodId* DexFile::FindMethodId(const DexFile::TypeId& declaring_
return nullptr;
}
-const DexFile::StringId* DexFile::FindStringId(const char* string) const {
+const StringId* DexFile::FindStringId(const char* string) const {
int32_t lo = 0;
int32_t hi = NumStringIds() - 1;
while (hi >= lo) {
int32_t mid = (hi + lo) / 2;
- const DexFile::StringId& str_id = GetStringId(dex::StringIndex(mid));
+ const StringId& str_id = GetStringId(dex::StringIndex(mid));
const char* str = GetStringData(str_id);
int compare = CompareModifiedUtf8ToModifiedUtf8AsUtf16CodePointValues(string, str);
if (compare > 0) {
@@ -312,13 +324,13 @@ const DexFile::StringId* DexFile::FindStringId(const char* string) const {
return nullptr;
}
-const DexFile::TypeId* DexFile::FindTypeId(const char* string) const {
+const TypeId* DexFile::FindTypeId(const char* string) const {
int32_t lo = 0;
int32_t hi = NumTypeIds() - 1;
while (hi >= lo) {
int32_t mid = (hi + lo) / 2;
const TypeId& type_id = GetTypeId(dex::TypeIndex(mid));
- const DexFile::StringId& str_id = GetStringId(type_id.descriptor_idx_);
+ const StringId& str_id = GetStringId(type_id.descriptor_idx_);
const char* str = GetStringData(str_id);
int compare = CompareModifiedUtf8ToModifiedUtf8AsUtf16CodePointValues(string, str);
if (compare > 0) {
@@ -332,7 +344,7 @@ const DexFile::TypeId* DexFile::FindTypeId(const char* string) const {
return nullptr;
}
-const DexFile::TypeId* DexFile::FindTypeId(dex::StringIndex string_idx) const {
+const TypeId* DexFile::FindTypeId(dex::StringIndex string_idx) const {
int32_t lo = 0;
int32_t hi = NumTypeIds() - 1;
while (hi >= lo) {
@@ -349,15 +361,15 @@ const DexFile::TypeId* DexFile::FindTypeId(dex::StringIndex string_idx) const {
return nullptr;
}
-const DexFile::ProtoId* DexFile::FindProtoId(dex::TypeIndex return_type_idx,
- const dex::TypeIndex* signature_type_idxs,
- uint32_t signature_length) const {
+const ProtoId* DexFile::FindProtoId(dex::TypeIndex return_type_idx,
+ const dex::TypeIndex* signature_type_idxs,
+ uint32_t signature_length) const {
int32_t lo = 0;
int32_t hi = NumProtoIds() - 1;
while (hi >= lo) {
int32_t mid = (hi + lo) / 2;
const dex::ProtoIndex proto_idx = static_cast<dex::ProtoIndex>(mid);
- const DexFile::ProtoId& proto = GetProtoId(proto_idx);
+ const ProtoId& proto = GetProtoId(proto_idx);
int compare = return_type_idx.index_ - proto.return_type_idx_.index_;
if (compare == 0) {
DexFileParameterIterator it(*this, proto);
@@ -422,7 +434,7 @@ bool DexFile::CreateTypeList(const StringPiece& signature,
}
// TODO: avoid creating a std::string just to get a 0-terminated char array
std::string descriptor(signature.data() + start_offset, offset - start_offset);
- const DexFile::TypeId* type_id = FindTypeId(descriptor.c_str());
+ const TypeId* type_id = FindTypeId(descriptor.c_str());
if (type_id == nullptr) {
return false;
}
@@ -457,7 +469,7 @@ int32_t DexFile::FindTryItem(const TryItem* try_items, uint32_t tries_size, uint
while (min < max) {
const uint32_t mid = (min + max) / 2;
- const art::DexFile::TryItem& ti = try_items[mid];
+ const TryItem& ti = try_items[mid];
const uint32_t start = ti.start_addr_;
const uint32_t end = start + ti.insn_count_;
@@ -523,9 +535,9 @@ std::string DexFile::PrettyMethod(uint32_t method_idx, bool with_signature) cons
if (method_idx >= NumMethodIds()) {
return StringPrintf("<<invalid-method-idx-%d>>", method_idx);
}
- const DexFile::MethodId& method_id = GetMethodId(method_idx);
+ const MethodId& method_id = GetMethodId(method_idx);
std::string result;
- const DexFile::ProtoId* proto_id = with_signature ? &GetProtoId(method_id.proto_idx_) : nullptr;
+ const ProtoId* proto_id = with_signature ? &GetProtoId(method_id.proto_idx_) : nullptr;
if (with_signature) {
AppendPrettyDescriptor(StringByTypeIdx(proto_id->return_type_idx_), &result);
result += ' ';
@@ -535,7 +547,7 @@ std::string DexFile::PrettyMethod(uint32_t method_idx, bool with_signature) cons
result += GetMethodName(method_id);
if (with_signature) {
result += '(';
- const DexFile::TypeList* params = GetProtoParameters(*proto_id);
+ const TypeList* params = GetProtoParameters(*proto_id);
if (params != nullptr) {
const char* separator = "";
for (uint32_t i = 0u, size = params->Size(); i != size; ++i) {
@@ -553,7 +565,7 @@ std::string DexFile::PrettyField(uint32_t field_idx, bool with_type) const {
if (field_idx >= NumFieldIds()) {
return StringPrintf("<<invalid-field-idx-%d>>", field_idx);
}
- const DexFile::FieldId& field_id = GetFieldId(field_idx);
+ const FieldId& field_id = GetFieldId(field_idx);
std::string result;
if (with_type) {
result += GetFieldTypeDescriptor(field_id);
@@ -569,12 +581,12 @@ std::string DexFile::PrettyType(dex::TypeIndex type_idx) const {
if (type_idx.index_ >= NumTypeIds()) {
return StringPrintf("<<invalid-type-idx-%d>>", type_idx.index_);
}
- const DexFile::TypeId& type_id = GetTypeId(type_idx);
+ const TypeId& type_id = GetTypeId(type_idx);
return PrettyDescriptor(GetTypeDescriptor(type_id));
}
dex::ProtoIndex DexFile::GetProtoIndexForCallSite(uint32_t call_site_idx) const {
- const DexFile::CallSiteIdItem& csi = GetCallSiteId(call_site_idx);
+ const CallSiteIdItem& csi = GetCallSiteId(call_site_idx);
CallSiteArrayValueIterator it(*this, csi);
it.Next();
it.Next();
@@ -597,7 +609,7 @@ std::string Signature::ToString() const {
CHECK(proto_id_ == nullptr);
return "<no signature>";
}
- const DexFile::TypeList* params = dex_file_->GetProtoParameters(*proto_id_);
+ const TypeList* params = dex_file_->GetProtoParameters(*proto_id_);
std::string result;
if (params == nullptr) {
result += "()";
@@ -613,7 +625,7 @@ std::string Signature::ToString() const {
}
uint32_t Signature::GetNumberOfParameters() const {
- const DexFile::TypeList* params = dex_file_->GetProtoParameters(*proto_id_);
+ const TypeList* params = dex_file_->GetProtoParameters(*proto_id_);
return (params != nullptr) ? params->Size() : 0;
}
@@ -631,7 +643,7 @@ bool Signature::operator==(const StringPiece& rhs) const {
return false; // Invalid signature
}
tail.remove_prefix(1); // "(";
- const DexFile::TypeList* params = dex_file_->GetProtoParameters(*proto_id_);
+ const TypeList* params = dex_file_->GetProtoParameters(*proto_id_);
if (params != nullptr) {
for (uint32_t i = 0; i < params->Size(); ++i) {
StringPiece param(dex_file_->StringByTypeIdx(params->GetTypeItem(i).type_idx_));
diff --git a/libdexfile/dex/dex_file.h b/libdexfile/dex/dex_file.h
index 83f47fec19..104c38de40 100644
--- a/libdexfile/dex/dex_file.h
+++ b/libdexfile/dex/dex_file.h
@@ -28,6 +28,7 @@
#include "base/macros.h"
#include "base/value_object.h"
#include "class_iterator.h"
+#include "dex_file_structs.h"
#include "dex_file_types.h"
#include "jni.h"
#include "modifiers.h"
@@ -136,150 +137,6 @@ class DexFile {
kDexTypeHiddenapiClassData = 0xF000,
};
- struct MapItem {
- uint16_t type_;
- uint16_t unused_;
- uint32_t size_;
- uint32_t offset_;
- };
-
- struct MapList {
- uint32_t size_;
- MapItem list_[1];
-
- size_t Size() const { return sizeof(uint32_t) + (size_ * sizeof(MapItem)); }
-
- private:
- DISALLOW_COPY_AND_ASSIGN(MapList);
- };
-
- // Raw string_id_item.
- struct StringId {
- uint32_t string_data_off_; // offset in bytes from the base address
-
- private:
- DISALLOW_COPY_AND_ASSIGN(StringId);
- };
-
- // Raw type_id_item.
- struct TypeId {
- dex::StringIndex descriptor_idx_; // index into string_ids
-
- private:
- DISALLOW_COPY_AND_ASSIGN(TypeId);
- };
-
- // Raw field_id_item.
- struct FieldId {
- dex::TypeIndex class_idx_; // index into type_ids_ array for defining class
- dex::TypeIndex type_idx_; // index into type_ids_ array for field type
- dex::StringIndex name_idx_; // index into string_ids_ array for field name
-
- private:
- DISALLOW_COPY_AND_ASSIGN(FieldId);
- };
-
- // Raw proto_id_item.
- struct ProtoId {
- dex::StringIndex shorty_idx_; // index into string_ids array for shorty descriptor
- dex::TypeIndex return_type_idx_; // index into type_ids array for return type
- uint16_t pad_; // padding = 0
- uint32_t parameters_off_; // file offset to type_list for parameter types
-
- private:
- DISALLOW_COPY_AND_ASSIGN(ProtoId);
- };
-
- // Raw method_id_item.
- struct MethodId {
- dex::TypeIndex class_idx_; // index into type_ids_ array for defining class
- dex::ProtoIndex 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);
- };
-
- // Base code_item, compact dex and standard dex have different code item layouts.
- struct CodeItem {
- protected:
- CodeItem() = default;
-
- private:
- DISALLOW_COPY_AND_ASSIGN(CodeItem);
- };
-
- // Raw class_def_item.
- struct ClassDef {
- dex::TypeIndex class_idx_; // index into type_ids_ array for this class
- uint16_t pad1_; // padding = 0
- uint32_t access_flags_;
- dex::TypeIndex superclass_idx_; // index into type_ids_ array for superclass
- uint16_t pad2_; // padding = 0
- uint32_t interfaces_off_; // file offset to TypeList
- dex::StringIndex source_file_idx_; // index into string_ids_ for source file name
- uint32_t annotations_off_; // file offset to annotations_directory_item
- uint32_t class_data_off_; // file offset to class_data_item
- uint32_t static_values_off_; // file offset to EncodedArray
-
- // Returns the valid access flags, that is, Java modifier bits relevant to the ClassDef type
- // (class or interface). These are all in the lower 16b and do not contain runtime flags.
- uint32_t GetJavaAccessFlags() const {
- // Make sure that none of our runtime-only flags are set.
- static_assert((kAccValidClassFlags & kAccJavaFlagsMask) == kAccValidClassFlags,
- "Valid class flags not a subset of Java flags");
- static_assert((kAccValidInterfaceFlags & kAccJavaFlagsMask) == kAccValidInterfaceFlags,
- "Valid interface flags not a subset of Java flags");
-
- if ((access_flags_ & kAccInterface) != 0) {
- // Interface.
- return access_flags_ & kAccValidInterfaceFlags;
- } else {
- // Class.
- return access_flags_ & kAccValidClassFlags;
- }
- }
-
- private:
- DISALLOW_COPY_AND_ASSIGN(ClassDef);
- };
-
- // Raw type_item.
- struct TypeItem {
- dex::TypeIndex type_idx_; // index into type_ids section
-
- private:
- DISALLOW_COPY_AND_ASSIGN(TypeItem);
- };
-
- // Raw type_list.
- class TypeList {
- public:
- uint32_t Size() const {
- return size_;
- }
-
- const TypeItem& GetTypeItem(uint32_t idx) const {
- DCHECK_LT(idx, this->size_);
- return this->list_[idx];
- }
-
- // Size in bytes of the part of the list that is common.
- static constexpr size_t GetHeaderSize() {
- return 4U;
- }
-
- // Size in bytes of the whole type list including all the stored elements.
- static constexpr size_t GetListSize(size_t count) {
- return GetHeaderSize() + sizeof(TypeItem) * count;
- }
-
- private:
- uint32_t size_; // size of the list, in entries
- TypeItem list_[1]; // elements of the list
- DISALLOW_COPY_AND_ASSIGN(TypeList);
- };
-
// MethodHandle Types
enum class MethodHandleType : uint16_t { // private
kStaticPut = 0x0000, // a setter for a given static field.
@@ -296,37 +153,6 @@ class DexFile {
kLast = kInvokeInterface
};
- // raw method_handle_item
- struct MethodHandleItem {
- uint16_t method_handle_type_;
- uint16_t reserved1_; // Reserved for future use.
- uint16_t field_or_method_idx_; // Field index for accessors, method index otherwise.
- uint16_t reserved2_; // Reserved for future use.
- private:
- DISALLOW_COPY_AND_ASSIGN(MethodHandleItem);
- };
-
- // raw call_site_id_item
- struct CallSiteIdItem {
- uint32_t data_off_; // Offset into data section pointing to encoded array items.
- private:
- DISALLOW_COPY_AND_ASSIGN(CallSiteIdItem);
- };
-
- // Raw try_item.
- struct TryItem {
- static constexpr size_t kAlignment = sizeof(uint32_t);
-
- uint32_t start_addr_;
- uint16_t insn_count_;
- uint16_t handler_off_;
-
- private:
- TryItem() = default;
- friend class DexWriter;
- DISALLOW_COPY_AND_ASSIGN(TryItem);
- };
-
// Annotation constants.
enum {
kDexVisibilityBuild = 0x00, /* annotation visibility */
@@ -356,92 +182,6 @@ class DexFile {
kDexAnnotationValueArgShift = 5,
};
- struct AnnotationsDirectoryItem {
- uint32_t class_annotations_off_;
- uint32_t fields_size_;
- uint32_t methods_size_;
- uint32_t parameters_size_;
-
- private:
- DISALLOW_COPY_AND_ASSIGN(AnnotationsDirectoryItem);
- };
-
- struct FieldAnnotationsItem {
- uint32_t field_idx_;
- uint32_t annotations_off_;
-
- private:
- DISALLOW_COPY_AND_ASSIGN(FieldAnnotationsItem);
- };
-
- struct MethodAnnotationsItem {
- uint32_t method_idx_;
- uint32_t annotations_off_;
-
- private:
- DISALLOW_COPY_AND_ASSIGN(MethodAnnotationsItem);
- };
-
- struct ParameterAnnotationsItem {
- uint32_t method_idx_;
- uint32_t annotations_off_;
-
- private:
- DISALLOW_COPY_AND_ASSIGN(ParameterAnnotationsItem);
- };
-
- struct AnnotationSetRefItem {
- uint32_t annotations_off_;
-
- private:
- DISALLOW_COPY_AND_ASSIGN(AnnotationSetRefItem);
- };
-
- struct AnnotationSetRefList {
- uint32_t size_;
- AnnotationSetRefItem list_[1];
-
- private:
- DISALLOW_COPY_AND_ASSIGN(AnnotationSetRefList);
- };
-
- struct AnnotationSetItem {
- uint32_t size_;
- uint32_t entries_[1];
-
- private:
- DISALLOW_COPY_AND_ASSIGN(AnnotationSetItem);
- };
-
- struct AnnotationItem {
- uint8_t visibility_;
- uint8_t annotation_[1];
-
- private:
- DISALLOW_COPY_AND_ASSIGN(AnnotationItem);
- };
-
- struct HiddenapiClassData {
- uint32_t size_; // total size of the item
- uint32_t flags_offset_[1]; // array of offsets from the beginning of this item,
- // indexed by class def index
-
- // Returns a pointer to the beginning of a uleb128-stream of hiddenapi
- // flags for a class def of given index. Values are in the same order
- // as fields/methods in the class data. Returns null if the class does
- // not have class data.
- const uint8_t* GetFlagsPointer(uint32_t class_def_idx) const {
- if (flags_offset_[class_def_idx] == 0) {
- return nullptr;
- } else {
- return reinterpret_cast<const uint8_t*>(this) + flags_offset_[class_def_idx];
- }
- }
-
- private:
- DISALLOW_COPY_AND_ASSIGN(HiddenapiClassData);
- };
-
enum AnnotationResultStyle { // private
kAllObjects,
kPrimitivesOrObjects,
@@ -496,25 +236,26 @@ class DexFile {
}
// Returns the StringId at the specified index.
- const StringId& GetStringId(dex::StringIndex idx) const {
+ const dex::StringId& GetStringId(dex::StringIndex idx) const {
DCHECK_LT(idx.index_, NumStringIds()) << GetLocation();
return string_ids_[idx.index_];
}
- dex::StringIndex GetIndexForStringId(const StringId& string_id) const {
+ dex::StringIndex GetIndexForStringId(const dex::StringId& string_id) const {
CHECK_GE(&string_id, string_ids_) << GetLocation();
CHECK_LT(&string_id, string_ids_ + header_->string_ids_size_) << GetLocation();
return dex::StringIndex(&string_id - string_ids_);
}
- int32_t GetStringLength(const StringId& string_id) const;
+ int32_t GetStringLength(const dex::StringId& string_id) const;
// Returns a pointer to the UTF-8 string data referred to by the given string_id as well as the
// length of the string when decoded as a UTF-16 string. Note the UTF-16 length is not the same
// as the string length of the string data.
- const char* GetStringDataAndUtf16Length(const StringId& string_id, uint32_t* utf16_length) const;
+ const char* GetStringDataAndUtf16Length(const dex::StringId& string_id,
+ uint32_t* utf16_length) const;
- const char* GetStringData(const StringId& string_id) const;
+ const char* GetStringData(const dex::StringId& string_id) const;
// Index version of GetStringDataAndUtf16Length.
const char* StringDataAndUtf16LengthByIdx(dex::StringIndex idx, uint32_t* utf16_length) const;
@@ -522,9 +263,9 @@ class DexFile {
const char* StringDataByIdx(dex::StringIndex idx) const;
// Looks up a string id for a given modified utf8 string.
- const StringId* FindStringId(const char* string) const;
+ const dex::StringId* FindStringId(const char* string) const;
- const TypeId* FindTypeId(const char* string) const;
+ const dex::TypeId* FindTypeId(const char* string) const;
// Returns the number of type identifiers in the .dex file.
uint32_t NumTypeIds() const {
@@ -537,12 +278,12 @@ class DexFile {
}
// Returns the TypeId at the specified index.
- const TypeId& GetTypeId(dex::TypeIndex idx) const {
+ const dex::TypeId& GetTypeId(dex::TypeIndex idx) const {
DCHECK_LT(idx.index_, NumTypeIds()) << GetLocation();
return type_ids_[idx.index_];
}
- dex::TypeIndex GetIndexForTypeId(const TypeId& type_id) const {
+ dex::TypeIndex GetIndexForTypeId(const dex::TypeId& type_id) const {
CHECK_GE(&type_id, type_ids_) << GetLocation();
CHECK_LT(&type_id, type_ids_ + header_->type_ids_size_) << GetLocation();
size_t result = &type_id - type_ids_;
@@ -556,10 +297,10 @@ class DexFile {
const char* StringByTypeIdx(dex::TypeIndex idx) const;
// Returns the type descriptor string of a type id.
- const char* GetTypeDescriptor(const TypeId& type_id) const;
+ const char* GetTypeDescriptor(const dex::TypeId& type_id) const;
// Looks up a type for the given string index
- const TypeId* FindTypeId(dex::StringIndex string_idx) const;
+ const dex::TypeId* FindTypeId(dex::StringIndex string_idx) const;
// Returns the number of field identifiers in the .dex file.
size_t NumFieldIds() const {
@@ -568,38 +309,38 @@ class DexFile {
}
// Returns the FieldId at the specified index.
- const FieldId& GetFieldId(uint32_t idx) const {
+ const dex::FieldId& GetFieldId(uint32_t idx) const {
DCHECK_LT(idx, NumFieldIds()) << GetLocation();
return field_ids_[idx];
}
- uint32_t GetIndexForFieldId(const FieldId& field_id) const {
+ uint32_t GetIndexForFieldId(const dex::FieldId& field_id) const {
CHECK_GE(&field_id, field_ids_) << GetLocation();
CHECK_LT(&field_id, field_ids_ + header_->field_ids_size_) << GetLocation();
return &field_id - field_ids_;
}
// Looks up a field by its declaring class, name and type
- const FieldId* FindFieldId(const DexFile::TypeId& declaring_klass,
- const DexFile::StringId& name,
- const DexFile::TypeId& type) const;
+ const dex::FieldId* FindFieldId(const dex::TypeId& declaring_klass,
+ const dex::StringId& name,
+ const dex::TypeId& type) const;
- uint32_t FindCodeItemOffset(const DexFile::ClassDef& class_def,
+ uint32_t FindCodeItemOffset(const dex::ClassDef& class_def,
uint32_t dex_method_idx) const;
- virtual uint32_t GetCodeItemSize(const DexFile::CodeItem& disk_code_item) const = 0;
+ virtual uint32_t GetCodeItemSize(const dex::CodeItem& disk_code_item) const = 0;
// Returns the declaring class descriptor string of a field id.
- const char* GetFieldDeclaringClassDescriptor(const FieldId& field_id) const {
- const DexFile::TypeId& type_id = GetTypeId(field_id.class_idx_);
+ const char* GetFieldDeclaringClassDescriptor(const dex::FieldId& field_id) const {
+ const dex::TypeId& type_id = GetTypeId(field_id.class_idx_);
return GetTypeDescriptor(type_id);
}
// Returns the class descriptor string of a field id.
- const char* GetFieldTypeDescriptor(const FieldId& field_id) const;
+ const char* GetFieldTypeDescriptor(const dex::FieldId& field_id) const;
// Returns the name of a field id.
- const char* GetFieldName(const FieldId& field_id) const;
+ const char* GetFieldName(const dex::FieldId& field_id) const;
// Returns the number of method identifiers in the .dex file.
size_t NumMethodIds() const {
@@ -608,47 +349,47 @@ class DexFile {
}
// Returns the MethodId at the specified index.
- const MethodId& GetMethodId(uint32_t idx) const {
+ const dex::MethodId& GetMethodId(uint32_t idx) const {
DCHECK_LT(idx, NumMethodIds()) << GetLocation();
return method_ids_[idx];
}
- uint32_t GetIndexForMethodId(const MethodId& method_id) const {
+ uint32_t GetIndexForMethodId(const dex::MethodId& method_id) const {
CHECK_GE(&method_id, method_ids_) << GetLocation();
CHECK_LT(&method_id, method_ids_ + header_->method_ids_size_) << GetLocation();
return &method_id - method_ids_;
}
// Looks up a method by its declaring class, name and proto_id
- const MethodId* FindMethodId(const DexFile::TypeId& declaring_klass,
- const DexFile::StringId& name,
- const DexFile::ProtoId& signature) const;
+ const dex::MethodId* FindMethodId(const dex::TypeId& declaring_klass,
+ const dex::StringId& name,
+ const dex::ProtoId& signature) const;
// Returns the declaring class descriptor string of a method id.
- const char* GetMethodDeclaringClassDescriptor(const MethodId& method_id) const;
+ const char* GetMethodDeclaringClassDescriptor(const dex::MethodId& method_id) const;
// Returns the prototype of a method id.
- const ProtoId& GetMethodPrototype(const MethodId& method_id) const {
+ const dex::ProtoId& GetMethodPrototype(const dex::MethodId& method_id) const {
return GetProtoId(method_id.proto_idx_);
}
// Returns a representation of the signature of a method id.
- const Signature GetMethodSignature(const MethodId& method_id) const;
+ const Signature GetMethodSignature(const dex::MethodId& method_id) const;
// Returns a representation of the signature of a proto id.
- const Signature GetProtoSignature(const ProtoId& proto_id) const;
+ const Signature GetProtoSignature(const dex::ProtoId& proto_id) const;
// Returns the name of a method id.
- const char* GetMethodName(const MethodId& method_id) const;
- const char* GetMethodName(const MethodId& method_id, uint32_t* utf_length) const;
+ const char* GetMethodName(const dex::MethodId& method_id) const;
+ const char* GetMethodName(const dex::MethodId& method_id, uint32_t* utf_length) const;
const char* GetMethodName(uint32_t idx, uint32_t* utf_length) const;
// Returns the shorty of a method by its index.
const char* GetMethodShorty(uint32_t idx) const;
// Returns the shorty of a method id.
- const char* GetMethodShorty(const MethodId& method_id) const;
- const char* GetMethodShorty(const MethodId& method_id, uint32_t* length) const;
+ const char* GetMethodShorty(const dex::MethodId& method_id) const;
+ const char* GetMethodShorty(const dex::MethodId& method_id, uint32_t* length) const;
// Returns the number of class definitions in the .dex file.
uint32_t NumClassDefs() const {
@@ -657,32 +398,32 @@ class DexFile {
}
// Returns the ClassDef at the specified index.
- const ClassDef& GetClassDef(uint16_t idx) const {
+ const dex::ClassDef& GetClassDef(uint16_t idx) const {
DCHECK_LT(idx, NumClassDefs()) << GetLocation();
return class_defs_[idx];
}
- uint16_t GetIndexForClassDef(const ClassDef& class_def) const {
+ uint16_t GetIndexForClassDef(const dex::ClassDef& class_def) const {
CHECK_GE(&class_def, class_defs_) << GetLocation();
CHECK_LT(&class_def, class_defs_ + header_->class_defs_size_) << GetLocation();
return &class_def - class_defs_;
}
// Returns the class descriptor string of a class definition.
- const char* GetClassDescriptor(const ClassDef& class_def) const;
+ const char* GetClassDescriptor(const dex::ClassDef& class_def) const;
// Looks up a class definition by its type index.
- const ClassDef* FindClassDef(dex::TypeIndex type_idx) const;
+ const dex::ClassDef* FindClassDef(dex::TypeIndex type_idx) const;
- const TypeList* GetInterfacesList(const ClassDef& class_def) const {
- return DataPointer<TypeList>(class_def.interfaces_off_);
+ const dex::TypeList* GetInterfacesList(const dex::ClassDef& class_def) const {
+ return DataPointer<dex::TypeList>(class_def.interfaces_off_);
}
uint32_t NumMethodHandles() const {
return num_method_handles_;
}
- const MethodHandleItem& GetMethodHandle(uint32_t idx) const {
+ const dex::MethodHandleItem& GetMethodHandle(uint32_t idx) const {
CHECK_LT(idx, NumMethodHandles());
return method_handles_[idx];
}
@@ -691,23 +432,23 @@ class DexFile {
return num_call_site_ids_;
}
- const CallSiteIdItem& GetCallSiteId(uint32_t idx) const {
+ const dex::CallSiteIdItem& GetCallSiteId(uint32_t idx) const {
CHECK_LT(idx, NumCallSiteIds());
return call_site_ids_[idx];
}
// Returns a pointer to the raw memory mapped class_data_item
- const uint8_t* GetClassData(const ClassDef& class_def) const {
+ const uint8_t* GetClassData(const dex::ClassDef& class_def) const {
return DataPointer<uint8_t>(class_def.class_data_off_);
}
// Return the code item for a provided offset.
- const CodeItem* GetCodeItem(const uint32_t code_off) const {
+ const dex::CodeItem* GetCodeItem(const uint32_t code_off) const {
// May be null for native or abstract methods.
- return DataPointer<CodeItem>(code_off);
+ return DataPointer<dex::CodeItem>(code_off);
}
- const char* GetReturnTypeDescriptor(const ProtoId& proto_id) const;
+ const char* GetReturnTypeDescriptor(const dex::ProtoId& proto_id) const;
// Returns the number of prototype identifiers in the .dex file.
size_t NumProtoIds() const {
@@ -716,23 +457,23 @@ class DexFile {
}
// Returns the ProtoId at the specified index.
- const ProtoId& GetProtoId(dex::ProtoIndex idx) const {
+ const dex::ProtoId& GetProtoId(dex::ProtoIndex idx) const {
DCHECK_LT(idx.index_, NumProtoIds()) << GetLocation();
return proto_ids_[idx.index_];
}
- dex::ProtoIndex GetIndexForProtoId(const ProtoId& proto_id) const {
+ dex::ProtoIndex GetIndexForProtoId(const dex::ProtoId& proto_id) const {
CHECK_GE(&proto_id, proto_ids_) << GetLocation();
CHECK_LT(&proto_id, proto_ids_ + header_->proto_ids_size_) << GetLocation();
return dex::ProtoIndex(&proto_id - proto_ids_);
}
// Looks up a proto id for a given return type and signature type list
- const ProtoId* FindProtoId(dex::TypeIndex return_type_idx,
- const dex::TypeIndex* signature_type_idxs,
+ const dex::ProtoId* FindProtoId(dex::TypeIndex return_type_idx,
+ const dex::TypeIndex* signature_type_idxs,
uint32_t signature_length) const;
- const ProtoId* FindProtoId(dex::TypeIndex return_type_idx,
- const std::vector<dex::TypeIndex>& signature_type_idxs) const {
+ const dex::ProtoId* FindProtoId(dex::TypeIndex return_type_idx,
+ const std::vector<dex::TypeIndex>& signature_type_idxs) const {
return FindProtoId(return_type_idx, &signature_type_idxs[0], signature_type_idxs.size());
}
@@ -748,21 +489,22 @@ class DexFile {
// Returns the short form method descriptor for the given prototype.
const char* GetShorty(dex::ProtoIndex proto_idx) const;
- const TypeList* GetProtoParameters(const ProtoId& proto_id) const {
- return DataPointer<TypeList>(proto_id.parameters_off_);
+ const dex::TypeList* GetProtoParameters(const dex::ProtoId& proto_id) const {
+ return DataPointer<dex::TypeList>(proto_id.parameters_off_);
}
- const uint8_t* GetEncodedStaticFieldValuesArray(const ClassDef& class_def) const {
+ const uint8_t* GetEncodedStaticFieldValuesArray(const dex::ClassDef& class_def) const {
return DataPointer<uint8_t>(class_def.static_values_off_);
}
- const uint8_t* GetCallSiteEncodedValuesArray(const CallSiteIdItem& call_site_id) const {
+ const uint8_t* GetCallSiteEncodedValuesArray(const dex::CallSiteIdItem& call_site_id) const {
return DataBegin() + call_site_id.data_off_;
}
dex::ProtoIndex GetProtoIndexForCallSite(uint32_t call_site_idx) const;
- static const TryItem* GetTryItems(const DexInstructionIterator& code_item_end, uint32_t offset);
+ static const dex::TryItem* GetTryItems(const DexInstructionIterator& code_item_end,
+ uint32_t offset);
// Get the base of the encoded data for the given DexCode.
static const uint8_t* GetCatchHandlerData(const DexInstructionIterator& code_item_end,
@@ -770,7 +512,7 @@ class DexFile {
uint32_t offset);
// Find which try region is associated with the given address (ie dex pc). Returns -1 if none.
- static int32_t FindTryItem(const TryItem* try_items, uint32_t tries_size, uint32_t address);
+ static int32_t FindTryItem(const dex::TryItem* try_items, uint32_t tries_size, uint32_t address);
// Get the pointer to the start of the debugging data
const uint8_t* GetDebugInfoStream(uint32_t debug_info_off) const {
@@ -807,76 +549,83 @@ class DexFile {
// Callback for "new locals table entry".
typedef void (*DexDebugNewLocalCb)(void* context, const LocalInfo& entry);
- const AnnotationsDirectoryItem* GetAnnotationsDirectory(const ClassDef& class_def) const {
- return DataPointer<AnnotationsDirectoryItem>(class_def.annotations_off_);
+ const dex::AnnotationsDirectoryItem* GetAnnotationsDirectory(const dex::ClassDef& class_def)
+ const {
+ return DataPointer<dex::AnnotationsDirectoryItem>(class_def.annotations_off_);
}
- const AnnotationSetItem* GetClassAnnotationSet(const AnnotationsDirectoryItem* anno_dir) const {
- return DataPointer<AnnotationSetItem>(anno_dir->class_annotations_off_);
+ const dex::AnnotationSetItem* GetClassAnnotationSet(const dex::AnnotationsDirectoryItem* anno_dir)
+ const {
+ return DataPointer<dex::AnnotationSetItem>(anno_dir->class_annotations_off_);
}
- const FieldAnnotationsItem* GetFieldAnnotations(const AnnotationsDirectoryItem* anno_dir) const {
+ const dex::FieldAnnotationsItem* GetFieldAnnotations(
+ const dex::AnnotationsDirectoryItem* anno_dir) const {
return (anno_dir->fields_size_ == 0)
? nullptr
- : reinterpret_cast<const FieldAnnotationsItem*>(&anno_dir[1]);
+ : reinterpret_cast<const dex::FieldAnnotationsItem*>(&anno_dir[1]);
}
- const MethodAnnotationsItem* GetMethodAnnotations(const AnnotationsDirectoryItem* anno_dir)
- const {
+ const dex::MethodAnnotationsItem* GetMethodAnnotations(
+ const dex::AnnotationsDirectoryItem* anno_dir) const {
if (anno_dir->methods_size_ == 0) {
return nullptr;
}
// Skip past the header and field annotations.
const uint8_t* addr = reinterpret_cast<const uint8_t*>(&anno_dir[1]);
- addr += anno_dir->fields_size_ * sizeof(FieldAnnotationsItem);
- return reinterpret_cast<const MethodAnnotationsItem*>(addr);
+ addr += anno_dir->fields_size_ * sizeof(dex::FieldAnnotationsItem);
+ return reinterpret_cast<const dex::MethodAnnotationsItem*>(addr);
}
- const ParameterAnnotationsItem* GetParameterAnnotations(const AnnotationsDirectoryItem* anno_dir)
- const {
+ const dex::ParameterAnnotationsItem* GetParameterAnnotations(
+ const dex::AnnotationsDirectoryItem* anno_dir) const {
if (anno_dir->parameters_size_ == 0) {
return nullptr;
}
// Skip past the header, field annotations, and method annotations.
const uint8_t* addr = reinterpret_cast<const uint8_t*>(&anno_dir[1]);
- addr += anno_dir->fields_size_ * sizeof(FieldAnnotationsItem);
- addr += anno_dir->methods_size_ * sizeof(MethodAnnotationsItem);
- return reinterpret_cast<const ParameterAnnotationsItem*>(addr);
+ addr += anno_dir->fields_size_ * sizeof(dex::FieldAnnotationsItem);
+ addr += anno_dir->methods_size_ * sizeof(dex::MethodAnnotationsItem);
+ return reinterpret_cast<const dex::ParameterAnnotationsItem*>(addr);
}
- const AnnotationSetItem* GetFieldAnnotationSetItem(const FieldAnnotationsItem& anno_item) const {
- return DataPointer<AnnotationSetItem>(anno_item.annotations_off_);
+ const dex::AnnotationSetItem* GetFieldAnnotationSetItem(
+ const dex::FieldAnnotationsItem& anno_item) const {
+ return DataPointer<dex::AnnotationSetItem>(anno_item.annotations_off_);
}
- const AnnotationSetItem* GetMethodAnnotationSetItem(const MethodAnnotationsItem& anno_item)
- const {
- return DataPointer<AnnotationSetItem>(anno_item.annotations_off_);
+ const dex::AnnotationSetItem* GetMethodAnnotationSetItem(
+ const dex::MethodAnnotationsItem& anno_item) const {
+ return DataPointer<dex::AnnotationSetItem>(anno_item.annotations_off_);
}
- const AnnotationSetRefList* GetParameterAnnotationSetRefList(
- const ParameterAnnotationsItem* anno_item) const {
- return DataPointer<AnnotationSetRefList>(anno_item->annotations_off_);
+ const dex::AnnotationSetRefList* GetParameterAnnotationSetRefList(
+ const dex::ParameterAnnotationsItem* anno_item) const {
+ return DataPointer<dex::AnnotationSetRefList>(anno_item->annotations_off_);
}
- ALWAYS_INLINE const AnnotationItem* GetAnnotationItemAtOffset(uint32_t offset) const {
- return DataPointer<AnnotationItem>(offset);
+ ALWAYS_INLINE const dex::AnnotationItem* GetAnnotationItemAtOffset(uint32_t offset) const {
+ return DataPointer<dex::AnnotationItem>(offset);
}
- ALWAYS_INLINE const HiddenapiClassData* GetHiddenapiClassDataAtOffset(uint32_t offset) const {
- return DataPointer<HiddenapiClassData>(offset);
+ ALWAYS_INLINE const dex::HiddenapiClassData* GetHiddenapiClassDataAtOffset(uint32_t offset)
+ const {
+ return DataPointer<dex::HiddenapiClassData>(offset);
}
- ALWAYS_INLINE const HiddenapiClassData* GetHiddenapiClassData() const {
+ ALWAYS_INLINE const dex::HiddenapiClassData* GetHiddenapiClassData() const {
return hiddenapi_class_data_;
}
- const AnnotationItem* GetAnnotationItem(const AnnotationSetItem* set_item, uint32_t index) const {
+ const dex::AnnotationItem* GetAnnotationItem(const dex::AnnotationSetItem* set_item,
+ uint32_t index) const {
DCHECK_LE(index, set_item->size_);
return GetAnnotationItemAtOffset(set_item->entries_[index]);
}
- const AnnotationSetItem* GetSetRefItemItem(const AnnotationSetRefItem* anno_item) const {
- return DataPointer<AnnotationSetItem>(anno_item->annotations_off_);
+ const dex::AnnotationSetItem* GetSetRefItemItem(const dex::AnnotationSetRefItem* anno_item)
+ const {
+ return DataPointer<dex::AnnotationSetItem>(anno_item->annotations_off_);
}
// Debug info opcodes and constants
@@ -925,7 +674,7 @@ class DexFile {
const IndexToStringData& index_to_string_data,
const DexDebugNewPosition& position_functor);
- const char* GetSourceFile(const ClassDef& class_def) const {
+ const char* GetSourceFile(const dex::ClassDef& class_def) const {
if (!class_def.source_file_idx_.IsValid()) {
return nullptr;
} else {
@@ -973,8 +722,8 @@ class DexFile {
}
// Read MapItems and validate/set remaining offsets.
- const DexFile::MapList* GetMapList() const {
- return reinterpret_cast<const DexFile::MapList*>(DataBegin() + header_->map_off_);
+ const dex::MapList* GetMapList() const {
+ return reinterpret_cast<const dex::MapList*>(DataBegin() + header_->map_off_);
}
// Utility methods for reading integral values from a buffer.
@@ -1078,38 +827,38 @@ class DexFile {
const Header* const header_;
// Points to the base of the string identifier list.
- const StringId* const string_ids_;
+ const dex::StringId* const string_ids_;
// Points to the base of the type identifier list.
- const TypeId* const type_ids_;
+ const dex::TypeId* const type_ids_;
// Points to the base of the field identifier list.
- const FieldId* const field_ids_;
+ const dex::FieldId* const field_ids_;
// Points to the base of the method identifier list.
- const MethodId* const method_ids_;
+ const dex::MethodId* const method_ids_;
// Points to the base of the prototype identifier list.
- const ProtoId* const proto_ids_;
+ const dex::ProtoId* const proto_ids_;
// Points to the base of the class definition list.
- const ClassDef* const class_defs_;
+ const dex::ClassDef* const class_defs_;
// Points to the base of the method handles list.
- const MethodHandleItem* method_handles_;
+ const dex::MethodHandleItem* method_handles_;
// Number of elements in the method handles list.
size_t num_method_handles_;
// Points to the base of the call sites id list.
- const CallSiteIdItem* call_site_ids_;
+ const dex::CallSiteIdItem* call_site_ids_;
// Number of elements in the call sites list.
size_t num_call_site_ids_;
// Points to the base of the hiddenapi class data item_, or nullptr if the dex
// file does not have one.
- const HiddenapiClassData* hiddenapi_class_data_;
+ const dex::HiddenapiClassData* hiddenapi_class_data_;
// If this dex file was loaded from an oat file, oat_dex_file_ contains a
// pointer to the OatDexFile it was loaded from. Otherwise oat_dex_file_ is
@@ -1135,7 +884,7 @@ std::ostream& operator<<(std::ostream& os, const DexFile& dex_file);
// Iterate over a dex file's ProtoId's paramters
class DexFileParameterIterator {
public:
- DexFileParameterIterator(const DexFile& dex_file, const DexFile::ProtoId& proto_id)
+ DexFileParameterIterator(const DexFile& dex_file, const dex::ProtoId& proto_id)
: dex_file_(dex_file) {
type_list_ = dex_file_.GetProtoParameters(proto_id);
if (type_list_ != nullptr) {
@@ -1153,7 +902,7 @@ class DexFileParameterIterator {
}
private:
const DexFile& dex_file_;
- const DexFile::TypeList* type_list_ = nullptr;
+ const dex::TypeList* type_list_ = nullptr;
uint32_t size_ = 0;
uint32_t pos_ = 0;
DISALLOW_IMPLICIT_CONSTRUCTORS(DexFileParameterIterator);
@@ -1179,7 +928,7 @@ class Signature : public ValueObject {
bool operator==(const StringPiece& rhs) const;
private:
- Signature(const DexFile* dex, const DexFile::ProtoId& proto) : dex_file_(dex), proto_id_(&proto) {
+ Signature(const DexFile* dex, const dex::ProtoId& proto) : dex_file_(dex), proto_id_(&proto) {
}
Signature() = default;
@@ -1187,7 +936,7 @@ class Signature : public ValueObject {
friend class DexFile;
const DexFile* const dex_file_ = nullptr;
- const DexFile::ProtoId* const proto_id_ = nullptr;
+ const dex::ProtoId* const proto_id_ = nullptr;
};
std::ostream& operator<<(std::ostream& os, const Signature& sig);
@@ -1242,7 +991,7 @@ std::ostream& operator<<(std::ostream& os, const EncodedArrayValueIterator::Valu
class EncodedStaticFieldValueIterator : public EncodedArrayValueIterator {
public:
EncodedStaticFieldValueIterator(const DexFile& dex_file,
- const DexFile::ClassDef& class_def)
+ const dex::ClassDef& class_def)
: EncodedArrayValueIterator(dex_file,
dex_file.GetEncodedStaticFieldValuesArray(class_def))
{}
@@ -1255,7 +1004,7 @@ std::ostream& operator<<(std::ostream& os, const EncodedStaticFieldValueIterator
class CallSiteArrayValueIterator : public EncodedArrayValueIterator {
public:
CallSiteArrayValueIterator(const DexFile& dex_file,
- const DexFile::CallSiteIdItem& call_site_id)
+ const dex::CallSiteIdItem& call_site_id)
: EncodedArrayValueIterator(dex_file,
dex_file.GetCallSiteEncodedValuesArray(call_site_id))
{}
diff --git a/libdexfile/dex/dex_file_exception_helpers.cc b/libdexfile/dex/dex_file_exception_helpers.cc
index 8e597fd3dd..72b2554d7f 100644
--- a/libdexfile/dex/dex_file_exception_helpers.cc
+++ b/libdexfile/dex/dex_file_exception_helpers.cc
@@ -17,6 +17,7 @@
#include "dex_file_exception_helpers.h"
#include "code_item_accessors-inl.h"
+#include "dex_file_structs.h"
namespace art {
@@ -29,7 +30,7 @@ CatchHandlerIterator::CatchHandlerIterator(const CodeItemDataAccessor& accessor,
case 0:
break;
case 1: {
- const DexFile::TryItem* tries = accessor.TryItems().begin();
+ const dex::TryItem* tries = accessor.TryItems().begin();
uint32_t start = tries->start_addr_;
if (address >= start) {
uint32_t end = start + tries->insn_count_;
@@ -40,7 +41,7 @@ CatchHandlerIterator::CatchHandlerIterator(const CodeItemDataAccessor& accessor,
break;
}
default: {
- const DexFile::TryItem* try_item = accessor.FindTryItem(address);
+ const dex::TryItem* try_item = accessor.FindTryItem(address);
offset = try_item != nullptr ? try_item->handler_off_ : -1;
break;
}
@@ -49,7 +50,7 @@ CatchHandlerIterator::CatchHandlerIterator(const CodeItemDataAccessor& accessor,
}
CatchHandlerIterator::CatchHandlerIterator(const CodeItemDataAccessor& accessor,
- const DexFile::TryItem& try_item) {
+ const dex::TryItem& try_item) {
handler_.address_ = -1;
Init(accessor, try_item.handler_off_);
}
diff --git a/libdexfile/dex/dex_file_exception_helpers.h b/libdexfile/dex/dex_file_exception_helpers.h
index a05fd68e86..08127c865d 100644
--- a/libdexfile/dex/dex_file_exception_helpers.h
+++ b/libdexfile/dex/dex_file_exception_helpers.h
@@ -17,17 +17,23 @@
#ifndef ART_LIBDEXFILE_DEX_DEX_FILE_EXCEPTION_HELPERS_H_
#define ART_LIBDEXFILE_DEX_DEX_FILE_EXCEPTION_HELPERS_H_
-#include "dex_file.h"
+#include <android-base/logging.h>
+
+#include "dex_file_types.h"
namespace art {
+namespace dex {
+struct TryItem;
+} // namespace dex
+
class CodeItemDataAccessor;
class CatchHandlerIterator {
public:
CatchHandlerIterator(const CodeItemDataAccessor& accessor, uint32_t address);
- CatchHandlerIterator(const CodeItemDataAccessor& accessor, const DexFile::TryItem& try_item);
+ CatchHandlerIterator(const CodeItemDataAccessor& accessor, const dex::TryItem& try_item);
explicit CatchHandlerIterator(const uint8_t* handler_data) {
Init(handler_data);
diff --git a/libdexfile/dex/dex_file_loader_test.cc b/libdexfile/dex/dex_file_loader_test.cc
index 9c61d1ac5f..8b7ca1776f 100644
--- a/libdexfile/dex/dex_file_loader_test.cc
+++ b/libdexfile/dex/dex_file_loader_test.cc
@@ -487,10 +487,9 @@ TEST_F(DexFileLoaderTest, OpenDexDebugInfoLocalNullType) {
0xf25f2b38U,
true,
&dex_bytes);
- const DexFile::ClassDef& class_def = raw->GetClassDef(0);
+ const dex::ClassDef& class_def = raw->GetClassDef(0);
constexpr uint32_t kMethodIdx = 1;
- const DexFile::CodeItem* code_item = raw->GetCodeItem(raw->FindCodeItemOffset(class_def,
- kMethodIdx));
+ const dex::CodeItem* code_item = raw->GetCodeItem(raw->FindCodeItemOffset(class_def, kMethodIdx));
CodeItemDebugInfoAccessor accessor(*raw, code_item, kMethodIdx);
ASSERT_TRUE(accessor.DecodeDebugLocalInfo(true, 1, VoidFunctor()));
}
diff --git a/libdexfile/dex/dex_file_structs.h b/libdexfile/dex/dex_file_structs.h
new file mode 100644
index 0000000000..2d252270f3
--- /dev/null
+++ b/libdexfile/dex/dex_file_structs.h
@@ -0,0 +1,298 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ART_LIBDEXFILE_DEX_DEX_FILE_STRUCTS_H_
+#define ART_LIBDEXFILE_DEX_DEX_FILE_STRUCTS_H_
+
+#include <android-base/logging.h>
+#include <android-base/macros.h>
+
+#include <inttypes.h>
+
+#include "dex_file_types.h"
+#include "modifiers.h"
+
+namespace art {
+
+class DexWriter;
+
+namespace dex {
+
+struct MapItem {
+ uint16_t type_;
+ uint16_t unused_;
+ uint32_t size_;
+ uint32_t offset_;
+};
+
+struct MapList {
+ uint32_t size_;
+ MapItem list_[1];
+
+ size_t Size() const { return sizeof(uint32_t) + (size_ * sizeof(MapItem)); }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(MapList);
+};
+
+// Raw string_id_item.
+struct StringId {
+ uint32_t string_data_off_; // offset in bytes from the base address
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(StringId);
+};
+
+// Raw type_id_item.
+struct TypeId {
+ dex::StringIndex descriptor_idx_; // index into string_ids
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(TypeId);
+};
+
+// Raw field_id_item.
+struct FieldId {
+ dex::TypeIndex class_idx_; // index into type_ids_ array for defining class
+ dex::TypeIndex type_idx_; // index into type_ids_ array for field type
+ dex::StringIndex name_idx_; // index into string_ids_ array for field name
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(FieldId);
+};
+
+// Raw proto_id_item.
+struct ProtoId {
+ dex::StringIndex shorty_idx_; // index into string_ids array for shorty descriptor
+ dex::TypeIndex return_type_idx_; // index into type_ids array for return type
+ uint16_t pad_; // padding = 0
+ uint32_t parameters_off_; // file offset to type_list for parameter types
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(ProtoId);
+};
+
+// Raw method_id_item.
+struct MethodId {
+ dex::TypeIndex class_idx_; // index into type_ids_ array for defining class
+ dex::ProtoIndex 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);
+};
+
+// Base code_item, compact dex and standard dex have different code item layouts.
+struct CodeItem {
+ protected:
+ CodeItem() = default;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(CodeItem);
+};
+
+// Raw class_def_item.
+struct ClassDef {
+ dex::TypeIndex class_idx_; // index into type_ids_ array for this class
+ uint16_t pad1_; // padding = 0
+ uint32_t access_flags_;
+ dex::TypeIndex superclass_idx_; // index into type_ids_ array for superclass
+ uint16_t pad2_; // padding = 0
+ uint32_t interfaces_off_; // file offset to TypeList
+ dex::StringIndex source_file_idx_; // index into string_ids_ for source file name
+ uint32_t annotations_off_; // file offset to annotations_directory_item
+ uint32_t class_data_off_; // file offset to class_data_item
+ uint32_t static_values_off_; // file offset to EncodedArray
+
+ // Returns the valid access flags, that is, Java modifier bits relevant to the ClassDef type
+ // (class or interface). These are all in the lower 16b and do not contain runtime flags.
+ uint32_t GetJavaAccessFlags() const {
+ // Make sure that none of our runtime-only flags are set.
+ static_assert((kAccValidClassFlags & kAccJavaFlagsMask) == kAccValidClassFlags,
+ "Valid class flags not a subset of Java flags");
+ static_assert((kAccValidInterfaceFlags & kAccJavaFlagsMask) == kAccValidInterfaceFlags,
+ "Valid interface flags not a subset of Java flags");
+
+ if ((access_flags_ & kAccInterface) != 0) {
+ // Interface.
+ return access_flags_ & kAccValidInterfaceFlags;
+ } else {
+ // Class.
+ return access_flags_ & kAccValidClassFlags;
+ }
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(ClassDef);
+};
+
+// Raw type_item.
+struct TypeItem {
+ dex::TypeIndex type_idx_; // index into type_ids section
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(TypeItem);
+};
+
+// Raw type_list.
+class TypeList {
+ public:
+ uint32_t Size() const {
+ return size_;
+ }
+
+ const TypeItem& GetTypeItem(uint32_t idx) const {
+ DCHECK_LT(idx, this->size_);
+ return this->list_[idx];
+ }
+
+ // Size in bytes of the part of the list that is common.
+ static constexpr size_t GetHeaderSize() {
+ return 4U;
+ }
+
+ // Size in bytes of the whole type list including all the stored elements.
+ static constexpr size_t GetListSize(size_t count) {
+ return GetHeaderSize() + sizeof(TypeItem) * count;
+ }
+
+ private:
+ uint32_t size_; // size of the list, in entries
+ TypeItem list_[1]; // elements of the list
+ DISALLOW_COPY_AND_ASSIGN(TypeList);
+};
+
+// raw method_handle_item
+struct MethodHandleItem {
+ uint16_t method_handle_type_;
+ uint16_t reserved1_; // Reserved for future use.
+ uint16_t field_or_method_idx_; // Field index for accessors, method index otherwise.
+ uint16_t reserved2_; // Reserved for future use.
+ private:
+ DISALLOW_COPY_AND_ASSIGN(MethodHandleItem);
+};
+
+// raw call_site_id_item
+struct CallSiteIdItem {
+ uint32_t data_off_; // Offset into data section pointing to encoded array items.
+ private:
+ DISALLOW_COPY_AND_ASSIGN(CallSiteIdItem);
+};
+
+// Raw try_item.
+struct TryItem {
+ static constexpr size_t kAlignment = sizeof(uint32_t);
+
+ uint32_t start_addr_;
+ uint16_t insn_count_;
+ uint16_t handler_off_;
+
+ private:
+ TryItem() = default;
+ friend class ::art::DexWriter;
+ DISALLOW_COPY_AND_ASSIGN(TryItem);
+};
+
+struct AnnotationsDirectoryItem {
+ uint32_t class_annotations_off_;
+ uint32_t fields_size_;
+ uint32_t methods_size_;
+ uint32_t parameters_size_;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(AnnotationsDirectoryItem);
+};
+
+struct FieldAnnotationsItem {
+ uint32_t field_idx_;
+ uint32_t annotations_off_;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(FieldAnnotationsItem);
+};
+
+struct MethodAnnotationsItem {
+ uint32_t method_idx_;
+ uint32_t annotations_off_;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(MethodAnnotationsItem);
+};
+
+struct ParameterAnnotationsItem {
+ uint32_t method_idx_;
+ uint32_t annotations_off_;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(ParameterAnnotationsItem);
+};
+
+struct AnnotationSetRefItem {
+ uint32_t annotations_off_;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(AnnotationSetRefItem);
+};
+
+struct AnnotationSetRefList {
+ uint32_t size_;
+ AnnotationSetRefItem list_[1];
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(AnnotationSetRefList);
+};
+
+struct AnnotationSetItem {
+ uint32_t size_;
+ uint32_t entries_[1];
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(AnnotationSetItem);
+};
+
+struct AnnotationItem {
+ uint8_t visibility_;
+ uint8_t annotation_[1];
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(AnnotationItem);
+};
+
+struct HiddenapiClassData {
+ uint32_t size_; // total size of the item
+ uint32_t flags_offset_[1]; // array of offsets from the beginning of this item,
+ // indexed by class def index
+
+ // Returns a pointer to the beginning of a uleb128-stream of hiddenapi
+ // flags for a class def of given index. Values are in the same order
+ // as fields/methods in the class data. Returns null if the class does
+ // not have class data.
+ const uint8_t* GetFlagsPointer(uint32_t class_def_idx) const {
+ if (flags_offset_[class_def_idx] == 0) {
+ return nullptr;
+ } else {
+ return reinterpret_cast<const uint8_t*>(this) + flags_offset_[class_def_idx];
+ }
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(HiddenapiClassData);
+};
+
+} // namespace dex
+} // namespace art
+
+#endif // ART_LIBDEXFILE_DEX_DEX_FILE_STRUCTS_H_
diff --git a/libdexfile/dex/dex_file_tracking_registrar.cc b/libdexfile/dex/dex_file_tracking_registrar.cc
index 29ff6be4fc..1903dc946f 100644
--- a/libdexfile/dex/dex_file_tracking_registrar.cc
+++ b/libdexfile/dex/dex_file_tracking_registrar.cc
@@ -158,7 +158,7 @@ void DexFileTrackingRegistrar::SetDexFileRegistration(bool should_poison) {
void DexFileTrackingRegistrar::SetAllCodeItemRegistration(bool should_poison) {
for (ClassAccessor accessor : dex_file_->GetClasses()) {
for (const ClassAccessor::Method& method : accessor.GetMethods()) {
- const DexFile::CodeItem* code_item = method.GetCodeItem();
+ const dex::CodeItem* code_item = method.GetCodeItem();
if (code_item != nullptr) {
const void* code_item_begin = reinterpret_cast<const void*>(code_item);
size_t code_item_size = dex_file_->GetCodeItemSize(*code_item);
@@ -171,7 +171,7 @@ void DexFileTrackingRegistrar::SetAllCodeItemRegistration(bool should_poison) {
void DexFileTrackingRegistrar::SetAllCodeItemStartRegistration(bool should_poison) {
for (ClassAccessor class_accessor : dex_file_->GetClasses()) {
for (const ClassAccessor::Method& method : class_accessor.GetMethods()) {
- const DexFile::CodeItem* code_item = method.GetCodeItem();
+ const dex::CodeItem* code_item = method.GetCodeItem();
if (code_item != nullptr) {
const void* code_item_begin = reinterpret_cast<const void*>(code_item);
size_t code_item_start = reinterpret_cast<size_t>(code_item);
@@ -189,7 +189,7 @@ void DexFileTrackingRegistrar::SetAllCodeItemStartRegistration(bool should_poiso
void DexFileTrackingRegistrar::SetAllInsnsRegistration(bool should_poison) {
for (ClassAccessor class_accessor : dex_file_->GetClasses()) {
for (const ClassAccessor::Method& method : class_accessor.GetMethods()) {
- const DexFile::CodeItem* code_item = method.GetCodeItem();
+ const dex::CodeItem* code_item = method.GetCodeItem();
if (code_item != nullptr) {
CodeItemInstructionAccessor accessor(*dex_file_, code_item);
const void* insns_begin = reinterpret_cast<const void*>(accessor.Insns());
@@ -204,9 +204,9 @@ void DexFileTrackingRegistrar::SetAllInsnsRegistration(bool should_poison) {
void DexFileTrackingRegistrar::SetCodeItemRegistration(const char* class_name, bool should_poison) {
for (ClassAccessor accessor : dex_file_->GetClasses()) {
for (const ClassAccessor::Method& method : accessor.GetMethods()) {
- const DexFile::MethodId& methodid_item = dex_file_->GetMethodId(method.GetIndex());
+ const dex::MethodId& methodid_item = dex_file_->GetMethodId(method.GetIndex());
const char * methodid_name = dex_file_->GetMethodName(methodid_item);
- const DexFile::CodeItem* code_item = method.GetCodeItem();
+ const dex::CodeItem* code_item = method.GetCodeItem();
if (code_item != nullptr && strcmp(methodid_name, class_name) == 0) {
const void* code_item_begin = reinterpret_cast<const void*>(code_item);
size_t code_item_size = dex_file_->GetCodeItemSize(*code_item);
@@ -218,7 +218,7 @@ void DexFileTrackingRegistrar::SetCodeItemRegistration(const char* class_name, b
void DexFileTrackingRegistrar::SetAllStringDataStartRegistration(bool should_poison) {
for (size_t stringid_ctr = 0; stringid_ctr < dex_file_->NumStringIds(); ++stringid_ctr) {
- const DexFile::StringId & string_id = dex_file_->GetStringId(StringIndex(stringid_ctr));
+ const dex::StringId & string_id = dex_file_->GetStringId(StringIndex(stringid_ctr));
const void* string_data_begin = reinterpret_cast<const void*>(dex_file_->Begin() + string_id.string_data_off_);
// Data Section of String Data Item
const void* string_data_data_begin = reinterpret_cast<const void*>(dex_file_->GetStringData(string_id));
@@ -229,11 +229,11 @@ void DexFileTrackingRegistrar::SetAllStringDataStartRegistration(bool should_poi
void DexFileTrackingRegistrar::SetAllStringDataRegistration(bool should_poison) {
size_t map_offset = dex_file_->GetHeader().map_off_;
- auto map_list = reinterpret_cast<const DexFile::MapList*>(dex_file_->Begin() + map_offset);
+ auto map_list = reinterpret_cast<const dex::MapList*>(dex_file_->Begin() + map_offset);
for (size_t map_ctr = 0; map_ctr < map_list->size_; ++map_ctr) {
- const DexFile::MapItem& map_item = map_list->list_[map_ctr];
+ const dex::MapItem& map_item = map_list->list_[map_ctr];
if (map_item.type_ == DexFile::kDexTypeStringDataItem) {
- const DexFile::MapItem& next_map_item = map_list->list_[map_ctr + 1];
+ const dex::MapItem& next_map_item = map_list->list_[map_ctr + 1];
const void* string_data_begin = reinterpret_cast<const void*>(dex_file_->Begin() + map_item.offset_);
size_t string_data_size = next_map_item.offset_ - map_item.offset_;
range_values_.push_back(std::make_tuple(string_data_begin, string_data_size, should_poison));
diff --git a/libdexfile/dex/dex_file_verifier.cc b/libdexfile/dex/dex_file_verifier.cc
index 78e4618f04..f376c4dc7b 100644
--- a/libdexfile/dex/dex_file_verifier.cc
+++ b/libdexfile/dex/dex_file_verifier.cc
@@ -116,22 +116,22 @@ const char* DexFileVerifier::CheckLoadStringByTypeIdx(dex::TypeIndex type_idx,
return CheckLoadStringByIdx(dex_file_->GetTypeId(type_idx).descriptor_idx_, error_string);
}
-const DexFile::FieldId* DexFileVerifier::CheckLoadFieldId(uint32_t idx, const char* error_string) {
+const dex::FieldId* DexFileVerifier::CheckLoadFieldId(uint32_t idx, const char* error_string) {
if (UNLIKELY(!CheckIndex(idx, dex_file_->NumFieldIds(), error_string))) {
return nullptr;
}
return &dex_file_->GetFieldId(idx);
}
-const DexFile::MethodId* DexFileVerifier::CheckLoadMethodId(uint32_t idx, const char* err_string) {
+const dex::MethodId* DexFileVerifier::CheckLoadMethodId(uint32_t idx, const char* err_string) {
if (UNLIKELY(!CheckIndex(idx, dex_file_->NumMethodIds(), err_string))) {
return nullptr;
}
return &dex_file_->GetMethodId(idx);
}
-const DexFile::ProtoId* DexFileVerifier::CheckLoadProtoId(dex::ProtoIndex idx,
- const char* err_string) {
+const dex::ProtoId* DexFileVerifier::CheckLoadProtoId(dex::ProtoIndex idx,
+ const char* err_string) {
if (UNLIKELY(!CheckIndex(idx.index_, dex_file_->NumProtoIds(), err_string))) {
return nullptr;
}
@@ -154,14 +154,14 @@ const DexFile::ProtoId* DexFileVerifier::CheckLoadProtoId(dex::ProtoIndex idx,
// Helper macro to load method id. Return last parameter on error.
#define LOAD_METHOD(var, idx, error_string, error_stmt) \
- const DexFile::MethodId* (var) = CheckLoadMethodId(idx, error_string); \
+ const dex::MethodId* (var) = CheckLoadMethodId(idx, error_string); \
if (UNLIKELY((var) == nullptr)) { \
error_stmt; \
}
// Helper macro to load method id. Return last parameter on error.
#define LOAD_FIELD(var, idx, fmt, error_stmt) \
- const DexFile::FieldId* (var) = CheckLoadFieldId(idx, fmt); \
+ const dex::FieldId* (var) = CheckLoadFieldId(idx, fmt); \
if (UNLIKELY((var) == nullptr)) { \
error_stmt; \
}
@@ -385,14 +385,13 @@ bool DexFileVerifier::CheckHeader() {
}
bool DexFileVerifier::CheckMap() {
- const DexFile::MapList* map = reinterpret_cast<const DexFile::MapList*>(begin_ +
- header_->map_off_);
+ const dex::MapList* map = reinterpret_cast<const dex::MapList*>(begin_ + header_->map_off_);
// Check that map list content is available.
- if (!CheckListSize(map, 1, sizeof(DexFile::MapList), "maplist content")) {
+ if (!CheckListSize(map, 1, sizeof(dex::MapList), "maplist content")) {
return false;
}
- const DexFile::MapItem* item = map->list_;
+ const dex::MapItem* item = map->list_;
uint32_t count = map->size_;
uint32_t last_offset = 0;
@@ -402,7 +401,7 @@ bool DexFileVerifier::CheckMap() {
uint32_t used_bits = 0;
// Sanity check the size of the map list.
- if (!CheckListSize(item, count, sizeof(DexFile::MapItem), "map size")) {
+ if (!CheckListSize(item, count, sizeof(dex::MapItem), "map size")) {
return false;
}
@@ -526,8 +525,9 @@ uint32_t DexFileVerifier::ReadUnsignedLittleEndian(uint32_t size) {
return false; \
}
-bool DexFileVerifier::CheckAndGetHandlerOffsets(const DexFile::CodeItem* code_item,
- uint32_t* handler_offsets, uint32_t handlers_size) {
+bool DexFileVerifier::CheckAndGetHandlerOffsets(const dex::CodeItem* code_item,
+ uint32_t* handler_offsets,
+ uint32_t handlers_size) {
CodeItemDataAccessor accessor(*dex_file_, code_item);
const uint8_t* handlers_base = accessor.GetCatchHandlerData();
@@ -587,8 +587,7 @@ bool DexFileVerifier::CheckClassDataItemField(uint32_t idx,
// Check that it's the right class.
dex::TypeIndex my_class_index =
- (reinterpret_cast<const DexFile::FieldId*>(begin_ + header_->field_ids_off_) + idx)->
- class_idx_;
+ (reinterpret_cast<const dex::FieldId*>(begin_ + header_->field_ids_off_) + idx)->class_idx_;
if (class_type_index != my_class_index) {
ErrorStringPrintf("Field's class index unexpected, %" PRIu16 "vs %" PRIu16,
my_class_index.index_,
@@ -625,8 +624,8 @@ bool DexFileVerifier::CheckClassDataItemMethod(uint32_t idx,
return false;
}
- const DexFile::MethodId& method_id =
- *(reinterpret_cast<const DexFile::MethodId*>(begin_ + header_->method_ids_off_) + idx);
+ const dex::MethodId& method_id =
+ *(reinterpret_cast<const dex::MethodId*>(begin_ + header_->method_ids_off_) + idx);
// Check that it's the right class.
dex::TypeIndex my_class_index = method_id.class_idx_;
@@ -911,7 +910,7 @@ bool DexFileVerifier::CheckEncodedAnnotation() {
bool DexFileVerifier::FindClassIndexAndDef(uint32_t index,
bool is_field,
dex::TypeIndex* class_type_index,
- const DexFile::ClassDef** output_class_def) {
+ const dex::ClassDef** output_class_def) {
DCHECK(class_type_index != nullptr);
DCHECK(output_class_def != nullptr);
@@ -923,11 +922,11 @@ bool DexFileVerifier::FindClassIndexAndDef(uint32_t index,
// Next get the type index.
if (is_field) {
*class_type_index =
- (reinterpret_cast<const DexFile::FieldId*>(begin_ + header_->field_ids_off_) + index)->
+ (reinterpret_cast<const dex::FieldId*>(begin_ + header_->field_ids_off_) + index)->
class_idx_;
} else {
*class_type_index =
- (reinterpret_cast<const DexFile::MethodId*>(begin_ + header_->method_ids_off_) + index)->
+ (reinterpret_cast<const dex::MethodId*>(begin_ + header_->method_ids_off_) + index)->
class_idx_;
}
@@ -938,10 +937,10 @@ bool DexFileVerifier::FindClassIndexAndDef(uint32_t index,
// Now search for the class def. This is basically a specialized version of the DexFile code, as
// we should not trust that this is a valid DexFile just yet.
- const DexFile::ClassDef* class_def_begin =
- reinterpret_cast<const DexFile::ClassDef*>(begin_ + header_->class_defs_off_);
+ const dex::ClassDef* class_def_begin =
+ reinterpret_cast<const dex::ClassDef*>(begin_ + header_->class_defs_off_);
for (size_t i = 0; i < header_->class_defs_size_; ++i) {
- const DexFile::ClassDef* class_def = class_def_begin + i;
+ const dex::ClassDef* class_def = class_def_begin + i;
if (class_def->class_idx_ == *class_type_index) {
*output_class_def = class_def;
return true;
@@ -965,7 +964,7 @@ bool DexFileVerifier::CheckOrder(const char* type_descr,
return true;
}
-bool DexFileVerifier::CheckStaticFieldTypes(const DexFile::ClassDef* class_def) {
+bool DexFileVerifier::CheckStaticFieldTypes(const dex::ClassDef* class_def) {
if (class_def == nullptr) {
return true;
}
@@ -978,7 +977,7 @@ bool DexFileVerifier::CheckStaticFieldTypes(const DexFile::ClassDef* class_def)
break;
}
uint32_t index = field.GetIndex();
- const DexFile::TypeId& type_id = dex_file_->GetTypeId(dex_file_->GetFieldId(index).type_idx_);
+ const dex::TypeId& type_id = dex_file_->GetTypeId(dex_file_->GetFieldId(index).type_idx_);
const char* field_type_name =
dex_file_->GetStringData(dex_file_->GetStringId(type_id.descriptor_idx_));
Primitive::Type field_type = Primitive::GetType(field_type_name[0]);
@@ -1069,7 +1068,7 @@ bool DexFileVerifier::CheckIntraClassDataItemFields(size_t count,
ClassAccessor::Field* field,
bool* have_class,
dex::TypeIndex* class_type_index,
- const DexFile::ClassDef** class_def) {
+ const dex::ClassDef** class_def) {
DCHECK(field != nullptr);
constexpr const char* kTypeDescr = kStatic ? "static field" : "instance field";
@@ -1121,7 +1120,7 @@ bool DexFileVerifier::CheckIntraClassDataItemMethods(ClassAccessor::Method* meth
size_t num_directs,
bool* have_class,
dex::TypeIndex* class_type_index,
- const DexFile::ClassDef** class_def) {
+ const dex::ClassDef** class_def) {
DCHECK(method != nullptr);
const char* kTypeDescr = method->IsStaticOrDirect() ? "direct method" : "virtual method";
@@ -1176,7 +1175,7 @@ bool DexFileVerifier::CheckIntraClassDataItem() {
// as the lookup is expensive, cache the result.
bool have_class = false;
dex::TypeIndex class_type_index;
- const DexFile::ClassDef* class_def = nullptr;
+ const dex::ClassDef* class_def = nullptr;
ClassAccessor::Field field(*dex_file_, accessor.ptr_pos_);
// Check fields.
@@ -1232,8 +1231,8 @@ bool DexFileVerifier::CheckIntraClassDataItem() {
}
bool DexFileVerifier::CheckIntraCodeItem() {
- const DexFile::CodeItem* code_item = reinterpret_cast<const DexFile::CodeItem*>(ptr_);
- if (!CheckListSize(code_item, 1, sizeof(DexFile::CodeItem), "code")) {
+ const dex::CodeItem* code_item = reinterpret_cast<const dex::CodeItem*>(ptr_);
+ if (!CheckListSize(code_item, 1, sizeof(dex::CodeItem), "code")) {
return false;
}
@@ -1275,8 +1274,8 @@ bool DexFileVerifier::CheckIntraCodeItem() {
return false;
}
- const DexFile::TryItem* try_items = accessor.TryItems().begin();
- if (!CheckListSize(try_items, try_items_size, sizeof(DexFile::TryItem), "try_items size")) {
+ const dex::TryItem* try_items = accessor.TryItems().begin();
+ if (!CheckListSize(try_items, try_items_size, sizeof(dex::TryItem), "try_items size")) {
return false;
}
@@ -1558,8 +1557,7 @@ bool DexFileVerifier::CheckIntraAnnotationItem() {
}
bool DexFileVerifier::CheckIntraHiddenapiClassData() {
- const DexFile::HiddenapiClassData* item =
- reinterpret_cast<const DexFile::HiddenapiClassData*>(ptr_);
+ const dex::HiddenapiClassData* item = reinterpret_cast<const dex::HiddenapiClassData*>(ptr_);
// Check expected header size.
uint32_t num_header_elems = dex_file_->NumClassDefs() + 1;
@@ -1586,7 +1584,7 @@ bool DexFileVerifier::CheckIntraHiddenapiClassData() {
// Check offsets for each class def.
for (uint32_t i = 0; i < dex_file_->NumClassDefs(); ++i) {
- const DexFile::ClassDef& class_def = dex_file_->GetClassDef(i);
+ const dex::ClassDef& class_def = dex_file_->GetClassDef(i);
const uint8_t* class_data = dex_file_->GetClassData(class_def);
uint32_t offset = item->flags_offset_[i];
@@ -1659,24 +1657,28 @@ bool DexFileVerifier::CheckIntraHiddenapiClassData() {
}
bool DexFileVerifier::CheckIntraAnnotationsDirectoryItem() {
- const DexFile::AnnotationsDirectoryItem* item =
- reinterpret_cast<const DexFile::AnnotationsDirectoryItem*>(ptr_);
- if (!CheckListSize(item, 1, sizeof(DexFile::AnnotationsDirectoryItem), "annotations_directory")) {
+ const dex::AnnotationsDirectoryItem* item =
+ reinterpret_cast<const dex::AnnotationsDirectoryItem*>(ptr_);
+ if (!CheckListSize(item, 1, sizeof(dex::AnnotationsDirectoryItem), "annotations_directory")) {
return false;
}
// Field annotations follow immediately after the annotations directory.
- const DexFile::FieldAnnotationsItem* field_item =
- reinterpret_cast<const DexFile::FieldAnnotationsItem*>(item + 1);
+ const dex::FieldAnnotationsItem* field_item =
+ reinterpret_cast<const dex::FieldAnnotationsItem*>(item + 1);
uint32_t field_count = item->fields_size_;
- if (!CheckListSize(field_item, field_count, sizeof(DexFile::FieldAnnotationsItem), "field_annotations list")) {
+ if (!CheckListSize(field_item,
+ field_count,
+ sizeof(dex::FieldAnnotationsItem),
+ "field_annotations list")) {
return false;
}
uint32_t last_idx = 0;
for (uint32_t i = 0; i < field_count; i++) {
if (UNLIKELY(last_idx >= field_item->field_idx_ && i != 0)) {
- ErrorStringPrintf("Out-of-order field_idx for annotation: %x then %x", last_idx, field_item->field_idx_);
+ ErrorStringPrintf("Out-of-order field_idx for annotation: %x then %x",
+ last_idx, field_item->field_idx_);
return false;
}
last_idx = field_item->field_idx_;
@@ -1684,10 +1686,13 @@ bool DexFileVerifier::CheckIntraAnnotationsDirectoryItem() {
}
// Method annotations follow immediately after field annotations.
- const DexFile::MethodAnnotationsItem* method_item =
- reinterpret_cast<const DexFile::MethodAnnotationsItem*>(field_item);
+ const dex::MethodAnnotationsItem* method_item =
+ reinterpret_cast<const dex::MethodAnnotationsItem*>(field_item);
uint32_t method_count = item->methods_size_;
- if (!CheckListSize(method_item, method_count, sizeof(DexFile::MethodAnnotationsItem), "method_annotations list")) {
+ if (!CheckListSize(method_item,
+ method_count,
+ sizeof(dex::MethodAnnotationsItem),
+ "method_annotations list")) {
return false;
}
@@ -1703,10 +1708,10 @@ bool DexFileVerifier::CheckIntraAnnotationsDirectoryItem() {
}
// Parameter annotations follow immediately after method annotations.
- const DexFile::ParameterAnnotationsItem* parameter_item =
- reinterpret_cast<const DexFile::ParameterAnnotationsItem*>(method_item);
+ const dex::ParameterAnnotationsItem* parameter_item =
+ reinterpret_cast<const dex::ParameterAnnotationsItem*>(method_item);
uint32_t parameter_count = item->parameters_size_;
- if (!CheckListSize(parameter_item, parameter_count, sizeof(DexFile::ParameterAnnotationsItem),
+ if (!CheckListSize(parameter_item, parameter_count, sizeof(dex::ParameterAnnotationsItem),
"parameter_annotations list")) {
return false;
}
@@ -1757,69 +1762,69 @@ bool DexFileVerifier::CheckIntraSectionIterate(size_t offset, uint32_t section_c
const uint8_t* start_ptr = ptr_;
switch (kType) {
case DexFile::kDexTypeStringIdItem: {
- if (!CheckListSize(ptr_, 1, sizeof(DexFile::StringId), "string_ids")) {
+ if (!CheckListSize(ptr_, 1, sizeof(dex::StringId), "string_ids")) {
return false;
}
- ptr_ += sizeof(DexFile::StringId);
+ ptr_ += sizeof(dex::StringId);
break;
}
case DexFile::kDexTypeTypeIdItem: {
- if (!CheckListSize(ptr_, 1, sizeof(DexFile::TypeId), "type_ids")) {
+ if (!CheckListSize(ptr_, 1, sizeof(dex::TypeId), "type_ids")) {
return false;
}
- ptr_ += sizeof(DexFile::TypeId);
+ ptr_ += sizeof(dex::TypeId);
break;
}
case DexFile::kDexTypeProtoIdItem: {
- if (!CheckListSize(ptr_, 1, sizeof(DexFile::ProtoId), "proto_ids")) {
+ if (!CheckListSize(ptr_, 1, sizeof(dex::ProtoId), "proto_ids")) {
return false;
}
- ptr_ += sizeof(DexFile::ProtoId);
+ ptr_ += sizeof(dex::ProtoId);
break;
}
case DexFile::kDexTypeFieldIdItem: {
- if (!CheckListSize(ptr_, 1, sizeof(DexFile::FieldId), "field_ids")) {
+ if (!CheckListSize(ptr_, 1, sizeof(dex::FieldId), "field_ids")) {
return false;
}
- ptr_ += sizeof(DexFile::FieldId);
+ ptr_ += sizeof(dex::FieldId);
break;
}
case DexFile::kDexTypeMethodIdItem: {
- if (!CheckListSize(ptr_, 1, sizeof(DexFile::MethodId), "method_ids")) {
+ if (!CheckListSize(ptr_, 1, sizeof(dex::MethodId), "method_ids")) {
return false;
}
- ptr_ += sizeof(DexFile::MethodId);
+ ptr_ += sizeof(dex::MethodId);
break;
}
case DexFile::kDexTypeClassDefItem: {
- if (!CheckListSize(ptr_, 1, sizeof(DexFile::ClassDef), "class_defs")) {
+ if (!CheckListSize(ptr_, 1, sizeof(dex::ClassDef), "class_defs")) {
return false;
}
- ptr_ += sizeof(DexFile::ClassDef);
+ ptr_ += sizeof(dex::ClassDef);
break;
}
case DexFile::kDexTypeCallSiteIdItem: {
- if (!CheckListSize(ptr_, 1, sizeof(DexFile::CallSiteIdItem), "call_site_ids")) {
+ if (!CheckListSize(ptr_, 1, sizeof(dex::CallSiteIdItem), "call_site_ids")) {
return false;
}
- ptr_ += sizeof(DexFile::CallSiteIdItem);
+ ptr_ += sizeof(dex::CallSiteIdItem);
break;
}
case DexFile::kDexTypeMethodHandleItem: {
- if (!CheckListSize(ptr_, 1, sizeof(DexFile::MethodHandleItem), "method_handles")) {
+ if (!CheckListSize(ptr_, 1, sizeof(dex::MethodHandleItem), "method_handles")) {
return false;
}
- ptr_ += sizeof(DexFile::MethodHandleItem);
+ ptr_ += sizeof(dex::MethodHandleItem);
break;
}
case DexFile::kDexTypeTypeList: {
- if (!CheckList(sizeof(DexFile::TypeItem), "type_list", &ptr_)) {
+ if (!CheckList(sizeof(dex::TypeItem), "type_list", &ptr_)) {
return false;
}
break;
}
case DexFile::kDexTypeAnnotationSetRefList: {
- if (!CheckList(sizeof(DexFile::AnnotationSetRefItem), "annotation_set_ref_list", &ptr_)) {
+ if (!CheckList(sizeof(dex::AnnotationSetRefItem), "annotation_set_ref_list", &ptr_)) {
return false;
}
break;
@@ -1986,9 +1991,8 @@ bool DexFileVerifier::CheckIntraDataSection(size_t offset, uint32_t count) {
}
bool DexFileVerifier::CheckIntraSection() {
- const DexFile::MapList* map =
- reinterpret_cast<const DexFile::MapList*>(begin_ + header_->map_off_);
- const DexFile::MapItem* item = map->list_;
+ const dex::MapList* map = reinterpret_cast<const dex::MapList*>(begin_ + header_->map_off_);
+ const dex::MapItem* item = map->list_;
size_t offset = 0;
uint32_t count = map->size_;
ptr_ = begin_;
@@ -2052,8 +2056,8 @@ bool DexFileVerifier::CheckIntraSection() {
section_offset, header_->map_off_);
return false;
}
- ptr_ += sizeof(uint32_t) + (map->size_ * sizeof(DexFile::MapItem));
- offset = section_offset + sizeof(uint32_t) + (map->size_ * sizeof(DexFile::MapItem));
+ ptr_ += sizeof(uint32_t) + (map->size_ * sizeof(dex::MapItem));
+ offset = section_offset + sizeof(uint32_t) + (map->size_ * sizeof(dex::MapItem));
break;
#define CHECK_INTRA_SECTION_ITERATE_CASE(type) \
@@ -2137,26 +2141,26 @@ dex::TypeIndex DexFileVerifier::FindFirstClassDataDefiner(const uint8_t* ptr, bo
dex::TypeIndex DexFileVerifier::FindFirstAnnotationsDirectoryDefiner(const uint8_t* ptr,
bool* success) {
- const DexFile::AnnotationsDirectoryItem* item =
- reinterpret_cast<const DexFile::AnnotationsDirectoryItem*>(ptr);
+ const dex::AnnotationsDirectoryItem* item =
+ reinterpret_cast<const dex::AnnotationsDirectoryItem*>(ptr);
*success = true;
if (item->fields_size_ != 0) {
- DexFile::FieldAnnotationsItem* field_items = (DexFile::FieldAnnotationsItem*) (item + 1);
+ dex::FieldAnnotationsItem* field_items = (dex::FieldAnnotationsItem*) (item + 1);
LOAD_FIELD(field, field_items[0].field_idx_, "first_annotations_dir_definer field_id",
*success = false; return dex::TypeIndex(DexFile::kDexNoIndex16))
return field->class_idx_;
}
if (item->methods_size_ != 0) {
- DexFile::MethodAnnotationsItem* method_items = (DexFile::MethodAnnotationsItem*) (item + 1);
+ dex::MethodAnnotationsItem* method_items = (dex::MethodAnnotationsItem*) (item + 1);
LOAD_METHOD(method, method_items[0].method_idx_, "first_annotations_dir_definer method id",
*success = false; return dex::TypeIndex(DexFile::kDexNoIndex16))
return method->class_idx_;
}
if (item->parameters_size_ != 0) {
- DexFile::ParameterAnnotationsItem* parameter_items = (DexFile::ParameterAnnotationsItem*) (item + 1);
+ dex::ParameterAnnotationsItem* parameter_items = (dex::ParameterAnnotationsItem*) (item + 1);
LOAD_METHOD(method, parameter_items[0].method_idx_, "first_annotations_dir_definer method id",
*success = false; return dex::TypeIndex(DexFile::kDexNoIndex16))
return method->class_idx_;
@@ -2166,7 +2170,7 @@ dex::TypeIndex DexFileVerifier::FindFirstAnnotationsDirectoryDefiner(const uint8
}
bool DexFileVerifier::CheckInterStringIdItem() {
- const DexFile::StringId* item = reinterpret_cast<const DexFile::StringId*>(ptr_);
+ const dex::StringId* item = reinterpret_cast<const dex::StringId*>(ptr_);
// Check the map to make sure it has the right offset->type.
if (!CheckOffsetToTypeMap(item->string_data_off_, DexFile::kDexTypeStringDataItem)) {
@@ -2175,7 +2179,7 @@ bool DexFileVerifier::CheckInterStringIdItem() {
// Check ordering between items.
if (previous_item_ != nullptr) {
- const DexFile::StringId* prev_item = reinterpret_cast<const DexFile::StringId*>(previous_item_);
+ const dex::StringId* prev_item = reinterpret_cast<const dex::StringId*>(previous_item_);
const char* prev_str = dex_file_->GetStringData(*prev_item);
const char* str = dex_file_->GetStringData(*item);
if (UNLIKELY(CompareModifiedUtf8ToModifiedUtf8AsUtf16CodePointValues(prev_str, str) >= 0)) {
@@ -2184,12 +2188,12 @@ bool DexFileVerifier::CheckInterStringIdItem() {
}
}
- ptr_ += sizeof(DexFile::StringId);
+ ptr_ += sizeof(dex::StringId);
return true;
}
bool DexFileVerifier::CheckInterTypeIdItem() {
- const DexFile::TypeId* item = reinterpret_cast<const DexFile::TypeId*>(ptr_);
+ const dex::TypeId* item = reinterpret_cast<const dex::TypeId*>(ptr_);
LOAD_STRING(descriptor, item->descriptor_idx_, "inter_type_id_item descriptor_idx")
@@ -2201,7 +2205,7 @@ bool DexFileVerifier::CheckInterTypeIdItem() {
// Check ordering between items.
if (previous_item_ != nullptr) {
- const DexFile::TypeId* prev_item = reinterpret_cast<const DexFile::TypeId*>(previous_item_);
+ const dex::TypeId* prev_item = reinterpret_cast<const dex::TypeId*>(previous_item_);
if (UNLIKELY(prev_item->descriptor_idx_ >= item->descriptor_idx_)) {
ErrorStringPrintf("Out-of-order type_ids: %x then %x",
prev_item->descriptor_idx_.index_,
@@ -2210,12 +2214,12 @@ bool DexFileVerifier::CheckInterTypeIdItem() {
}
}
- ptr_ += sizeof(DexFile::TypeId);
+ ptr_ += sizeof(dex::TypeId);
return true;
}
bool DexFileVerifier::CheckInterProtoIdItem() {
- const DexFile::ProtoId* item = reinterpret_cast<const DexFile::ProtoId*>(ptr_);
+ const dex::ProtoId* item = reinterpret_cast<const dex::ProtoId*>(ptr_);
LOAD_STRING(shorty, item->shorty_idx_, "inter_proto_id_item shorty_idx")
@@ -2258,7 +2262,7 @@ bool DexFileVerifier::CheckInterProtoIdItem() {
// Check ordering between items. This relies on type_ids being in order.
if (previous_item_ != nullptr) {
- const DexFile::ProtoId* prev = reinterpret_cast<const DexFile::ProtoId*>(previous_item_);
+ const dex::ProtoId* prev = reinterpret_cast<const dex::ProtoId*>(previous_item_);
if (UNLIKELY(prev->return_type_idx_ > item->return_type_idx_)) {
ErrorStringPrintf("Out-of-order proto_id return types");
return false;
@@ -2291,12 +2295,12 @@ bool DexFileVerifier::CheckInterProtoIdItem() {
}
}
- ptr_ += sizeof(DexFile::ProtoId);
+ ptr_ += sizeof(dex::ProtoId);
return true;
}
bool DexFileVerifier::CheckInterFieldIdItem() {
- const DexFile::FieldId* item = reinterpret_cast<const DexFile::FieldId*>(ptr_);
+ const dex::FieldId* item = reinterpret_cast<const dex::FieldId*>(ptr_);
// Check that the class descriptor is valid.
LOAD_STRING_BY_TYPE(class_descriptor, item->class_idx_, "inter_field_id_item class_idx")
@@ -2321,7 +2325,7 @@ bool DexFileVerifier::CheckInterFieldIdItem() {
// Check ordering between items. This relies on the other sections being in order.
if (previous_item_ != nullptr) {
- const DexFile::FieldId* prev_item = reinterpret_cast<const DexFile::FieldId*>(previous_item_);
+ const dex::FieldId* prev_item = reinterpret_cast<const dex::FieldId*>(previous_item_);
if (UNLIKELY(prev_item->class_idx_ > item->class_idx_)) {
ErrorStringPrintf("Out-of-order field_ids");
return false;
@@ -2338,12 +2342,12 @@ bool DexFileVerifier::CheckInterFieldIdItem() {
}
}
- ptr_ += sizeof(DexFile::FieldId);
+ ptr_ += sizeof(dex::FieldId);
return true;
}
bool DexFileVerifier::CheckInterMethodIdItem() {
- const DexFile::MethodId* item = reinterpret_cast<const DexFile::MethodId*>(ptr_);
+ const dex::MethodId* item = reinterpret_cast<const dex::MethodId*>(ptr_);
// Check that the class descriptor is a valid reference name.
LOAD_STRING_BY_TYPE(class_descriptor, item->class_idx_, "inter_method_id_item class_idx")
@@ -2368,7 +2372,7 @@ bool DexFileVerifier::CheckInterMethodIdItem() {
// Check ordering between items. This relies on the other sections being in order.
if (previous_item_ != nullptr) {
- const DexFile::MethodId* prev_item = reinterpret_cast<const DexFile::MethodId*>(previous_item_);
+ const dex::MethodId* prev_item = reinterpret_cast<const dex::MethodId*>(previous_item_);
if (UNLIKELY(prev_item->class_idx_ > item->class_idx_)) {
ErrorStringPrintf("Out-of-order method_ids");
return false;
@@ -2385,12 +2389,12 @@ bool DexFileVerifier::CheckInterMethodIdItem() {
}
}
- ptr_ += sizeof(DexFile::MethodId);
+ ptr_ += sizeof(dex::MethodId);
return true;
}
bool DexFileVerifier::CheckInterClassDefItem() {
- const DexFile::ClassDef* item = reinterpret_cast<const DexFile::ClassDef*>(ptr_);
+ const dex::ClassDef* item = reinterpret_cast<const dex::ClassDef*>(ptr_);
// Check that class_idx_ is representable as a uint16_t;
if (UNLIKELY(!IsValidTypeId(item->class_idx_.index_, item->pad1_))) {
@@ -2452,7 +2456,7 @@ bool DexFileVerifier::CheckInterClassDefItem() {
// Check that a class is defined after its super class (if the
// latter is defined in the same Dex file).
- const DexFile::ClassDef* superclass_def = dex_file_->FindClassDef(item->superclass_idx_);
+ const dex::ClassDef* superclass_def = dex_file_->FindClassDef(item->superclass_idx_);
if (superclass_def != nullptr) {
// The superclass is defined in this Dex file.
if (superclass_def > item) {
@@ -2476,7 +2480,7 @@ bool DexFileVerifier::CheckInterClassDefItem() {
}
// Check interfaces.
- const DexFile::TypeList* interfaces = dex_file_->GetInterfacesList(*item);
+ const dex::TypeList* interfaces = dex_file_->GetInterfacesList(*item);
if (interfaces != nullptr) {
uint32_t size = interfaces->Size();
for (uint32_t i = 0; i < size; i++) {
@@ -2491,7 +2495,7 @@ bool DexFileVerifier::CheckInterClassDefItem() {
// Check that a class is defined after the interfaces it implements
// (if they are defined in the same Dex file).
- const DexFile::ClassDef* interface_def =
+ const dex::ClassDef* interface_def =
dex_file_->FindClassDef(interfaces->GetTypeItem(i).type_idx_);
if (interface_def != nullptr) {
// The interface is defined in this Dex file.
@@ -2567,12 +2571,12 @@ bool DexFileVerifier::CheckInterClassDefItem() {
}
}
- ptr_ += sizeof(DexFile::ClassDef);
+ ptr_ += sizeof(dex::ClassDef);
return true;
}
bool DexFileVerifier::CheckInterCallSiteIdItem() {
- const DexFile::CallSiteIdItem* item = reinterpret_cast<const DexFile::CallSiteIdItem*>(ptr_);
+ const dex::CallSiteIdItem* item = reinterpret_cast<const dex::CallSiteIdItem*>(ptr_);
// Check call site referenced by item is in encoded array section.
if (!CheckOffsetToTypeMap(item->data_off_, DexFile::kDexTypeEncodedArrayItem)) {
@@ -2622,12 +2626,12 @@ bool DexFileVerifier::CheckInterCallSiteIdItem() {
return false;
}
- ptr_ += sizeof(DexFile::CallSiteIdItem);
+ ptr_ += sizeof(dex::CallSiteIdItem);
return true;
}
bool DexFileVerifier::CheckInterMethodHandleItem() {
- const DexFile::MethodHandleItem* item = reinterpret_cast<const DexFile::MethodHandleItem*>(ptr_);
+ const dex::MethodHandleItem* item = reinterpret_cast<const dex::MethodHandleItem*>(ptr_);
DexFile::MethodHandleType method_handle_type =
static_cast<DexFile::MethodHandleType>(item->method_handle_type_);
@@ -2655,14 +2659,13 @@ bool DexFileVerifier::CheckInterMethodHandleItem() {
}
}
- ptr_ += sizeof(DexFile::MethodHandleItem);
+ ptr_ += sizeof(dex::MethodHandleItem);
return true;
}
bool DexFileVerifier::CheckInterAnnotationSetRefList() {
- const DexFile::AnnotationSetRefList* list =
- reinterpret_cast<const DexFile::AnnotationSetRefList*>(ptr_);
- const DexFile::AnnotationSetRefItem* item = list->list_;
+ const dex::AnnotationSetRefList* list = reinterpret_cast<const dex::AnnotationSetRefList*>(ptr_);
+ const dex::AnnotationSetRefItem* item = list->list_;
uint32_t count = list->size_;
for (; count != 0u; --count) {
@@ -2678,7 +2681,7 @@ bool DexFileVerifier::CheckInterAnnotationSetRefList() {
}
bool DexFileVerifier::CheckInterAnnotationSetItem() {
- const DexFile::AnnotationSetItem* set = reinterpret_cast<const DexFile::AnnotationSetItem*>(ptr_);
+ const dex::AnnotationSetItem* set = reinterpret_cast<const dex::AnnotationSetItem*>(ptr_);
const uint32_t* offsets = set->entries_;
uint32_t count = set->size_;
uint32_t last_idx = 0;
@@ -2689,8 +2692,8 @@ bool DexFileVerifier::CheckInterAnnotationSetItem() {
}
// Get the annotation from the offset and the type index for the annotation.
- const DexFile::AnnotationItem* annotation =
- reinterpret_cast<const DexFile::AnnotationItem*>(begin_ + *offsets);
+ const dex::AnnotationItem* annotation =
+ reinterpret_cast<const dex::AnnotationItem*>(begin_ + *offsets);
const uint8_t* data = annotation->annotation_;
DECODE_UNSIGNED_CHECKED_FROM(data, idx);
@@ -2741,8 +2744,8 @@ bool DexFileVerifier::CheckInterClassDataItem() {
}
bool DexFileVerifier::CheckInterAnnotationsDirectoryItem() {
- const DexFile::AnnotationsDirectoryItem* item =
- reinterpret_cast<const DexFile::AnnotationsDirectoryItem*>(ptr_);
+ const dex::AnnotationsDirectoryItem* item =
+ reinterpret_cast<const dex::AnnotationsDirectoryItem*>(ptr_);
bool success;
dex::TypeIndex defining_class = FindFirstAnnotationsDirectoryDefiner(ptr_, &success);
if (!success) {
@@ -2755,8 +2758,8 @@ bool DexFileVerifier::CheckInterAnnotationsDirectoryItem() {
}
// Field annotations follow immediately after the annotations directory.
- const DexFile::FieldAnnotationsItem* field_item =
- reinterpret_cast<const DexFile::FieldAnnotationsItem*>(item + 1);
+ const dex::FieldAnnotationsItem* field_item =
+ reinterpret_cast<const dex::FieldAnnotationsItem*>(item + 1);
uint32_t field_count = item->fields_size_;
for (uint32_t i = 0; i < field_count; i++) {
LOAD_FIELD(field, field_item->field_idx_, "inter_annotations_directory_item field_id",
@@ -2772,8 +2775,8 @@ bool DexFileVerifier::CheckInterAnnotationsDirectoryItem() {
}
// Method annotations follow immediately after field annotations.
- const DexFile::MethodAnnotationsItem* method_item =
- reinterpret_cast<const DexFile::MethodAnnotationsItem*>(field_item);
+ const dex::MethodAnnotationsItem* method_item =
+ reinterpret_cast<const dex::MethodAnnotationsItem*>(field_item);
uint32_t method_count = item->methods_size_;
for (uint32_t i = 0; i < method_count; i++) {
LOAD_METHOD(method, method_item->method_idx_, "inter_annotations_directory_item method_id",
@@ -2789,8 +2792,8 @@ bool DexFileVerifier::CheckInterAnnotationsDirectoryItem() {
}
// Parameter annotations follow immediately after method annotations.
- const DexFile::ParameterAnnotationsItem* parameter_item =
- reinterpret_cast<const DexFile::ParameterAnnotationsItem*>(method_item);
+ const dex::ParameterAnnotationsItem* parameter_item =
+ reinterpret_cast<const dex::ParameterAnnotationsItem*>(method_item);
uint32_t parameter_count = item->parameters_size_;
for (uint32_t i = 0; i < parameter_count; i++) {
LOAD_METHOD(parameter_method, parameter_item->method_idx_,
@@ -2946,8 +2949,8 @@ bool DexFileVerifier::CheckInterSectionIterate(size_t offset,
}
bool DexFileVerifier::CheckInterSection() {
- const DexFile::MapList* map = reinterpret_cast<const DexFile::MapList*>(begin_ + header_->map_off_);
- const DexFile::MapItem* item = map->list_;
+ const dex::MapList* map = reinterpret_cast<const dex::MapList*>(begin_ + header_->map_off_);
+ const dex::MapItem* item = map->list_;
uint32_t count = map->size_;
// Cross check the items listed in the map.
@@ -3056,9 +3059,8 @@ static std::string GetStringOrError(const uint8_t* const begin,
return "(error)";
}
- const DexFile::StringId* string_id =
- reinterpret_cast<const DexFile::StringId*>(begin + header->string_ids_off_)
- + string_idx.index_;
+ const dex::StringId* string_id =
+ reinterpret_cast<const dex::StringId*>(begin + header->string_ids_off_) + string_idx.index_;
// Assume that the data is OK at this point. String data has been checked at this point.
@@ -3079,8 +3081,8 @@ static std::string GetClassOrError(const uint8_t* const begin,
// a valid defining class.
CHECK_LT(class_idx.index_, header->type_ids_size_);
- const DexFile::TypeId* type_id =
- reinterpret_cast<const DexFile::TypeId*>(begin + header->type_ids_off_) + class_idx.index_;
+ const dex::TypeId* type_id =
+ reinterpret_cast<const dex::TypeId*>(begin + header->type_ids_off_) + class_idx.index_;
// Assume that the data is OK at this point. Type id offsets have been checked at this point.
@@ -3093,8 +3095,8 @@ static std::string GetFieldDescriptionOrError(const uint8_t* const begin,
// The `idx` has already been checked in `DexFileVerifier::CheckClassDataItemField()`.
CHECK_LT(idx, header->field_ids_size_);
- const DexFile::FieldId* field_id =
- reinterpret_cast<const DexFile::FieldId*>(begin + header->field_ids_off_) + idx;
+ const dex::FieldId* field_id =
+ reinterpret_cast<const dex::FieldId*>(begin + header->field_ids_off_) + idx;
// Assume that the data is OK at this point. Field id offsets have been checked at this point.
@@ -3110,8 +3112,8 @@ static std::string GetMethodDescriptionOrError(const uint8_t* const begin,
// The `idx` has already been checked in `DexFileVerifier::CheckClassDataItemMethod()`.
CHECK_LT(idx, header->method_ids_size_);
- const DexFile::MethodId* method_id =
- reinterpret_cast<const DexFile::MethodId*>(begin + header->method_ids_off_) + idx;
+ const dex::MethodId* method_id =
+ reinterpret_cast<const dex::MethodId*>(begin + header->method_ids_off_) + idx;
// Assume that the data is OK at this point. Method id offsets have been checked at this point.
@@ -3202,16 +3204,16 @@ bool DexFileVerifier::CheckFieldAccessFlags(uint32_t idx,
void DexFileVerifier::FindStringRangesForMethodNames() {
// Use DexFile::StringId* as RandomAccessIterator.
- const DexFile::StringId* first = reinterpret_cast<const DexFile::StringId*>(
+ const dex::StringId* first = reinterpret_cast<const dex::StringId*>(
begin_ + header_->string_ids_off_);
- const DexFile::StringId* last = first + header_->string_ids_size_;
+ const dex::StringId* last = first + header_->string_ids_size_;
- auto get_string = [begin = begin_](const DexFile::StringId& id) {
+ auto get_string = [begin = begin_](const dex::StringId& id) {
const uint8_t* str_data_ptr = begin + id.string_data_off_;
DecodeUnsignedLeb128(&str_data_ptr);
return reinterpret_cast<const char*>(str_data_ptr);
};
- auto compare = [&get_string](const DexFile::StringId& lhs, const char* rhs) {
+ auto compare = [&get_string](const dex::StringId& lhs, const char* rhs) {
return CompareModifiedUtf8ToModifiedUtf8AsUtf16CodePointValues(get_string(lhs), rhs) < 0;
};
@@ -3451,8 +3453,8 @@ bool DexFileVerifier::CheckConstructorProperties(
constructor_flags == (kAccConstructor | kAccStatic));
// Check signature matches expectations.
- const DexFile::MethodId* const method_id = CheckLoadMethodId(method_index,
- "Bad <init>/<clinit> method id");
+ const dex::MethodId* const method_id = CheckLoadMethodId(method_index,
+ "Bad <init>/<clinit> method id");
if (method_id == nullptr) {
return false;
}
@@ -3462,8 +3464,8 @@ bool DexFileVerifier::CheckConstructorProperties(
// TODO(oth): the error message here is to satisfy the MethodId test
// in the DexFileVerifierTest. The test is checking that the error
// contains this string if the index is out of range.
- const DexFile::ProtoId* const proto_id = CheckLoadProtoId(method_id->proto_idx_,
- "inter_method_id_item proto_idx");
+ const dex::ProtoId* const proto_id = CheckLoadProtoId(method_id->proto_idx_,
+ "inter_method_id_item proto_idx");
if (proto_id == nullptr) {
return false;
}
diff --git a/libdexfile/dex/dex_file_verifier.h b/libdexfile/dex/dex_file_verifier.h
index a81df48398..b51a417297 100644
--- a/libdexfile/dex/dex_file_verifier.h
+++ b/libdexfile/dex/dex_file_verifier.h
@@ -79,7 +79,7 @@ class DexFileVerifier {
bool CheckMap();
uint32_t ReadUnsignedLittleEndian(uint32_t size);
- bool CheckAndGetHandlerOffsets(const DexFile::CodeItem* code_item,
+ bool CheckAndGetHandlerOffsets(const dex::CodeItem* code_item,
uint32_t* handler_offsets, uint32_t handlers_size);
bool CheckClassDataItemField(uint32_t idx,
uint32_t access_flags,
@@ -95,7 +95,7 @@ class DexFileVerifier {
size_t* remaining_directs);
ALWAYS_INLINE
bool CheckOrder(const char* type_descr, uint32_t curr_index, uint32_t prev_index);
- bool CheckStaticFieldTypes(const DexFile::ClassDef* class_def);
+ bool CheckStaticFieldTypes(const dex::ClassDef* class_def);
bool CheckPadding(size_t offset, uint32_t aligned_offset, DexFile::MapItemType type);
bool CheckEncodedValue();
@@ -110,7 +110,7 @@ class DexFileVerifier {
ClassAccessor::Field* field,
bool* have_class,
dex::TypeIndex* class_type_index,
- const DexFile::ClassDef** class_def);
+ const dex::ClassDef** class_def);
// Check all methods of the given type from the given iterator. Load the class data from the first
// method, if necessary (and return it), or use the given values.
bool CheckIntraClassDataItemMethods(ClassAccessor::Method* method,
@@ -119,7 +119,7 @@ class DexFileVerifier {
size_t num_directs,
bool* have_class,
dex::TypeIndex* class_type_index,
- const DexFile::ClassDef** class_def);
+ const dex::ClassDef** class_def);
bool CheckIntraCodeItem();
bool CheckIntraStringDataItem();
@@ -166,9 +166,9 @@ class DexFileVerifier {
// Load a field/method/proto Id by index. Checks whether the index is in bounds, printing the
// error if not. If there is an error, null is returned.
- const DexFile::FieldId* CheckLoadFieldId(uint32_t idx, const char* error_fmt);
- const DexFile::MethodId* CheckLoadMethodId(uint32_t idx, const char* error_fmt);
- const DexFile::ProtoId* CheckLoadProtoId(dex::ProtoIndex idx, const char* error_fmt);
+ const dex::FieldId* CheckLoadFieldId(uint32_t idx, const char* error_fmt);
+ const dex::MethodId* CheckLoadMethodId(uint32_t idx, const char* error_fmt);
+ const dex::ProtoId* CheckLoadProtoId(dex::ProtoIndex idx, const char* error_fmt);
void ErrorStringPrintf(const char* fmt, ...)
__attribute__((__format__(__printf__, 2, 3))) COLD_ATTR;
@@ -182,7 +182,7 @@ class DexFileVerifier {
bool FindClassIndexAndDef(uint32_t index,
bool is_field,
dex::TypeIndex* class_type_index,
- const DexFile::ClassDef** output_class_def);
+ const dex::ClassDef** output_class_def);
// Check validity of the given access flags, interpreted for a field in the context of a class
// with the given second access flags.
@@ -247,7 +247,7 @@ class DexFileVerifier {
std::string failure_reason_;
// Set of type ids for which there are ClassDef elements in the dex file.
- std::unordered_set<decltype(DexFile::ClassDef::class_idx_)> defined_classes_;
+ std::unordered_set<decltype(dex::ClassDef::class_idx_)> defined_classes_;
// Cached string indices for "interesting" entries wrt/ method names. Will be populated by
// FindStringRangesForMethodNames (which is automatically called before verifying the
diff --git a/libdexfile/dex/dex_file_verifier_test.cc b/libdexfile/dex/dex_file_verifier_test.cc
index c3180f0660..b2cff4f311 100644
--- a/libdexfile/dex/dex_file_verifier_test.cc
+++ b/libdexfile/dex/dex_file_verifier_test.cc
@@ -153,7 +153,7 @@ TEST_F(DexFileVerifierTest, MethodId) {
kGoodTestDex,
"method_id_class_idx",
[](DexFile* dex_file) {
- DexFile::MethodId* method_id = const_cast<DexFile::MethodId*>(&dex_file->GetMethodId(0));
+ dex::MethodId* method_id = const_cast<dex::MethodId*>(&dex_file->GetMethodId(0));
method_id->class_idx_ = dex::TypeIndex(0xFF);
},
"could not find declaring class for direct method index 0");
@@ -163,7 +163,7 @@ TEST_F(DexFileVerifierTest, MethodId) {
kGoodTestDex,
"method_id_proto_idx",
[](DexFile* dex_file) {
- DexFile::MethodId* method_id = const_cast<DexFile::MethodId*>(&dex_file->GetMethodId(0));
+ dex::MethodId* method_id = const_cast<dex::MethodId*>(&dex_file->GetMethodId(0));
method_id->proto_idx_ = dex::ProtoIndex(0xFF);
},
"inter_method_id_item proto_idx");
@@ -173,7 +173,7 @@ TEST_F(DexFileVerifierTest, MethodId) {
kGoodTestDex,
"method_id_name_idx",
[](DexFile* dex_file) {
- DexFile::MethodId* method_id = const_cast<DexFile::MethodId*>(&dex_file->GetMethodId(0));
+ dex::MethodId* method_id = const_cast<dex::MethodId*>(&dex_file->GetMethodId(0));
method_id->name_idx_ = dex::StringIndex(0xFF);
},
"Bad index for method flags verification");
@@ -244,7 +244,7 @@ static const uint8_t* FindMethodData(const DexFile* dex_file,
for (const ClassAccessor::Method& method : accessor.GetMethods()) {
uint32_t method_index = method.GetIndex();
dex::StringIndex name_index = dex_file->GetMethodId(method_index).name_idx_;
- const DexFile::StringId& string_id = dex_file->GetStringId(name_index);
+ const dex::StringId& string_id = dex_file->GetStringId(name_index);
const char* str = dex_file->GetStringData(string_id);
if (strcmp(name, str) == 0) {
if (method_idx != nullptr) {
@@ -837,7 +837,7 @@ static const uint8_t* FindFieldData(const DexFile* dex_file, const char* name) {
for (const ClassAccessor::Field& field : accessor.GetFields()) {
uint32_t field_index = field.GetIndex();
dex::StringIndex name_index = dex_file->GetFieldId(field_index).name_idx_;
- const DexFile::StringId& string_id = dex_file->GetStringId(name_index);
+ const dex::StringId& string_id = dex_file->GetStringId(name_index);
const char* str = dex_file->GetStringData(string_id);
if (strcmp(name, str) == 0) {
// Go to the back of the access flags.
@@ -1415,9 +1415,9 @@ TEST_F(DexFileVerifierTest, ProtoOrdering) {
dex_file->GetMethodId(method_idx + 1).proto_idx_.index_);
// Their return types should be the same.
dex::ProtoIndex proto1_idx = dex_file->GetMethodId(method_idx).proto_idx_;
- const DexFile::ProtoId& proto1 = dex_file->GetProtoId(proto1_idx);
+ const dex::ProtoId& proto1 = dex_file->GetProtoId(proto1_idx);
dex::ProtoIndex proto2_idx(proto1_idx.index_ + 1u);
- const DexFile::ProtoId& proto2 = dex_file->GetProtoId(proto2_idx);
+ const dex::ProtoId& proto2 = dex_file->GetProtoId(proto2_idx);
CHECK_EQ(proto1.return_type_idx_, proto2.return_type_idx_);
// And the first should not have any parameters while the second should have some.
CHECK(!DexFileParameterIterator(*dex_file, proto1).HasNext());
diff --git a/libdexfile/dex/method_reference.h b/libdexfile/dex/method_reference.h
index 266582b059..f66ac30c53 100644
--- a/libdexfile/dex/method_reference.h
+++ b/libdexfile/dex/method_reference.h
@@ -31,7 +31,7 @@ class MethodReference : public DexFileReference {
std::string PrettyMethod(bool with_signature = true) const {
return dex_file->PrettyMethod(index, with_signature);
}
- const DexFile::MethodId& GetMethodId() const {
+ const dex::MethodId& GetMethodId() const {
return dex_file->GetMethodId(index);
}
};
@@ -50,8 +50,8 @@ struct MethodReferenceValueComparator {
bool SlowCompare(MethodReference mr1, MethodReference mr2) const {
// The order is the same as for method ids in a single dex file.
// Compare the class descriptors first.
- const DexFile::MethodId& mid1 = mr1.GetMethodId();
- const DexFile::MethodId& mid2 = mr2.GetMethodId();
+ const dex::MethodId& mid1 = mr1.GetMethodId();
+ const dex::MethodId& mid2 = mr2.GetMethodId();
int descriptor_diff = strcmp(mr1.dex_file->StringByTypeIdx(mid1.class_idx_),
mr2.dex_file->StringByTypeIdx(mid2.class_idx_));
if (descriptor_diff != 0) {
@@ -63,17 +63,17 @@ struct MethodReferenceValueComparator {
return name_diff < 0;
}
// And then compare proto ids, starting with return type comparison.
- const DexFile::ProtoId& prid1 = mr1.dex_file->GetProtoId(mid1.proto_idx_);
- const DexFile::ProtoId& prid2 = mr2.dex_file->GetProtoId(mid2.proto_idx_);
+ const dex::ProtoId& prid1 = mr1.dex_file->GetProtoId(mid1.proto_idx_);
+ const dex::ProtoId& prid2 = mr2.dex_file->GetProtoId(mid2.proto_idx_);
int return_type_diff = strcmp(mr1.dex_file->StringByTypeIdx(prid1.return_type_idx_),
mr2.dex_file->StringByTypeIdx(prid2.return_type_idx_));
if (return_type_diff != 0) {
return return_type_diff < 0;
}
// And finishing with lexicographical parameter comparison.
- const DexFile::TypeList* params1 = mr1.dex_file->GetProtoParameters(prid1);
+ const dex::TypeList* params1 = mr1.dex_file->GetProtoParameters(prid1);
size_t param1_size = (params1 != nullptr) ? params1->Size() : 0u;
- const DexFile::TypeList* params2 = mr2.dex_file->GetProtoParameters(prid2);
+ const dex::TypeList* params2 = mr2.dex_file->GetProtoParameters(prid2);
size_t param2_size = (params2 != nullptr) ? params2->Size() : 0u;
for (size_t i = 0, num = std::min(param1_size, param2_size); i != num; ++i) {
int param_diff = strcmp(mr1.dex_file->StringByTypeIdx(params1->GetTypeItem(i).type_idx_),
diff --git a/libdexfile/dex/standard_dex_file.cc b/libdexfile/dex/standard_dex_file.cc
index 40dcafde74..8bac44e02e 100644
--- a/libdexfile/dex/standard_dex_file.cc
+++ b/libdexfile/dex/standard_dex_file.cc
@@ -72,7 +72,7 @@ bool StandardDexFile::SupportsDefaultMethods() const {
return GetDexVersion() >= DexFile::kDefaultMethodsVersion;
}
-uint32_t StandardDexFile::GetCodeItemSize(const DexFile::CodeItem& item) const {
+uint32_t StandardDexFile::GetCodeItemSize(const dex::CodeItem& item) const {
DCHECK(IsInDataSection(&item));
return reinterpret_cast<uintptr_t>(CodeItemDataAccessor(*this, &item).CodeItemDataEnd()) -
reinterpret_cast<uintptr_t>(&item);
diff --git a/libdexfile/dex/standard_dex_file.h b/libdexfile/dex/standard_dex_file.h
index fd7e78f19f..838d4e3e78 100644
--- a/libdexfile/dex/standard_dex_file.h
+++ b/libdexfile/dex/standard_dex_file.h
@@ -32,7 +32,7 @@ class StandardDexFile : public DexFile {
// Same for now.
};
- struct CodeItem : public DexFile::CodeItem {
+ struct CodeItem : public dex::CodeItem {
static constexpr size_t kAlignment = 4;
private:
@@ -81,7 +81,7 @@ class StandardDexFile : public DexFile {
bool SupportsDefaultMethods() const override;
- uint32_t GetCodeItemSize(const DexFile::CodeItem& item) const override;
+ uint32_t GetCodeItemSize(const dex::CodeItem& item) const override;
size_t GetDequickenedSize() const override {
return Size();
diff --git a/libdexfile/dex/test_dex_file_builder.h b/libdexfile/dex/test_dex_file_builder.h
index 072aafb394..2b0bad0854 100644
--- a/libdexfile/dex/test_dex_file_builder.h
+++ b/libdexfile/dex/test_dex_file_builder.h
@@ -112,7 +112,7 @@ class TestDexFileBuilder {
header->string_ids_size_ = strings_.size();
header->string_ids_off_ = strings_.empty() ? 0u : string_ids_offset;
- uint32_t type_ids_offset = string_ids_offset + strings_.size() * sizeof(DexFile::StringId);
+ uint32_t type_ids_offset = string_ids_offset + strings_.size() * sizeof(dex::StringId);
uint32_t type_idx = 0u;
for (auto& entry : types_) {
entry.second = type_idx;
@@ -121,7 +121,7 @@ class TestDexFileBuilder {
header->type_ids_size_ = types_.size();
header->type_ids_off_ = types_.empty() ? 0u : type_ids_offset;
- uint32_t proto_ids_offset = type_ids_offset + types_.size() * sizeof(DexFile::TypeId);
+ uint32_t proto_ids_offset = type_ids_offset + types_.size() * sizeof(dex::TypeId);
uint32_t proto_idx = 0u;
for (auto& entry : protos_) {
entry.second.idx = proto_idx;
@@ -129,7 +129,7 @@ class TestDexFileBuilder {
size_t num_args = entry.first.args.size();
if (num_args != 0u) {
entry.second.data_offset = RoundUp(data_section_size, 4u);
- data_section_size = entry.second.data_offset + 4u + num_args * sizeof(DexFile::TypeItem);
+ data_section_size = entry.second.data_offset + 4u + num_args * sizeof(dex::TypeItem);
} else {
entry.second.data_offset = 0u;
}
@@ -137,7 +137,7 @@ class TestDexFileBuilder {
header->proto_ids_size_ = protos_.size();
header->proto_ids_off_ = protos_.empty() ? 0u : proto_ids_offset;
- uint32_t field_ids_offset = proto_ids_offset + protos_.size() * sizeof(DexFile::ProtoId);
+ uint32_t field_ids_offset = proto_ids_offset + protos_.size() * sizeof(dex::ProtoId);
uint32_t field_idx = 0u;
for (auto& entry : fields_) {
entry.second = field_idx;
@@ -146,7 +146,7 @@ class TestDexFileBuilder {
header->field_ids_size_ = fields_.size();
header->field_ids_off_ = fields_.empty() ? 0u : field_ids_offset;
- uint32_t method_ids_offset = field_ids_offset + fields_.size() * sizeof(DexFile::FieldId);
+ uint32_t method_ids_offset = field_ids_offset + fields_.size() * sizeof(dex::FieldId);
uint32_t method_idx = 0u;
for (auto& entry : methods_) {
entry.second = method_idx;
@@ -159,7 +159,7 @@ class TestDexFileBuilder {
header->class_defs_size_ = 0u;
header->class_defs_off_ = 0u;
- uint32_t data_section_offset = method_ids_offset + methods_.size() * sizeof(DexFile::MethodId);
+ uint32_t data_section_offset = method_ids_offset + methods_.size() * sizeof(dex::MethodId);
header->data_size_ = data_section_size;
header->data_off_ = (data_section_size != 0u) ? data_section_offset : 0u;
@@ -172,11 +172,11 @@ class TestDexFileBuilder {
uint32_t raw_offset = data_section_offset + entry.second.data_offset;
dex_file_data_[raw_offset] = static_cast<uint8_t>(entry.first.size());
std::memcpy(&dex_file_data_[raw_offset + 1], entry.first.c_str(), entry.first.size() + 1);
- Write32(string_ids_offset + entry.second.idx * sizeof(DexFile::StringId), raw_offset);
+ Write32(string_ids_offset + entry.second.idx * sizeof(dex::StringId), raw_offset);
}
for (const auto& entry : types_) {
- Write32(type_ids_offset + entry.second * sizeof(DexFile::TypeId), GetStringIdx(entry.first));
+ Write32(type_ids_offset + entry.second * sizeof(dex::TypeId), GetStringIdx(entry.first));
++type_idx;
}
@@ -184,7 +184,7 @@ class TestDexFileBuilder {
size_t num_args = entry.first.args.size();
uint32_t type_list_offset =
(num_args != 0u) ? data_section_offset + entry.second.data_offset : 0u;
- uint32_t raw_offset = proto_ids_offset + entry.second.idx * sizeof(DexFile::ProtoId);
+ uint32_t raw_offset = proto_ids_offset + entry.second.idx * sizeof(dex::ProtoId);
Write32(raw_offset + 0u, GetStringIdx(entry.first.shorty));
Write16(raw_offset + 4u, GetTypeIdx(entry.first.return_type));
Write32(raw_offset + 8u, type_list_offset);
@@ -192,21 +192,21 @@ class TestDexFileBuilder {
CHECK_NE(entry.second.data_offset, 0u);
Write32(type_list_offset, num_args);
for (size_t i = 0; i != num_args; ++i) {
- Write16(type_list_offset + 4u + i * sizeof(DexFile::TypeItem),
+ Write16(type_list_offset + 4u + i * sizeof(dex::TypeItem),
GetTypeIdx(entry.first.args[i]));
}
}
}
for (const auto& entry : fields_) {
- uint32_t raw_offset = field_ids_offset + entry.second * sizeof(DexFile::FieldId);
+ uint32_t raw_offset = field_ids_offset + entry.second * sizeof(dex::FieldId);
Write16(raw_offset + 0u, GetTypeIdx(entry.first.class_descriptor));
Write16(raw_offset + 2u, GetTypeIdx(entry.first.type));
Write32(raw_offset + 4u, GetStringIdx(entry.first.name));
}
for (const auto& entry : methods_) {
- uint32_t raw_offset = method_ids_offset + entry.second * sizeof(DexFile::MethodId);
+ uint32_t raw_offset = method_ids_offset + entry.second * sizeof(dex::MethodId);
Write16(raw_offset + 0u, GetTypeIdx(entry.first.class_descriptor));
auto it = protos_.find(*entry.first.proto);
CHECK(it != protos_.end());
diff --git a/libdexfile/dex/type_lookup_table.cc b/libdexfile/dex/type_lookup_table.cc
index 7d80a2e7f7..c46b488cd8 100644
--- a/libdexfile/dex/type_lookup_table.cc
+++ b/libdexfile/dex/type_lookup_table.cc
@@ -47,9 +47,9 @@ TypeLookupTable TypeLookupTable::Create(const DexFile& dex_file) {
// occupied then delay the insertion of the element to the second stage to reduce probing
// distance.
for (size_t class_def_idx = 0; class_def_idx < dex_file.NumClassDefs(); ++class_def_idx) {
- const DexFile::ClassDef& class_def = dex_file.GetClassDef(class_def_idx);
- const DexFile::TypeId& type_id = dex_file.GetTypeId(class_def.class_idx_);
- const DexFile::StringId& str_id = dex_file.GetStringId(type_id.descriptor_idx_);
+ const dex::ClassDef& class_def = dex_file.GetClassDef(class_def_idx);
+ const dex::TypeId& type_id = dex_file.GetTypeId(class_def.class_idx_);
+ const dex::StringId& str_id = dex_file.GetStringId(type_id.descriptor_idx_);
const uint32_t hash = ComputeModifiedUtf8Hash(dex_file.GetStringData(str_id));
const uint32_t pos = hash & mask;
if (entries[pos].IsEmpty()) {
@@ -62,9 +62,9 @@ TypeLookupTable TypeLookupTable::Create(const DexFile& dex_file) {
// The second stage. The initial position of these elements had a collision. Put these elements
// into the nearest free cells and link them together by updating next_pos_delta.
for (uint16_t class_def_idx : conflict_class_defs) {
- const DexFile::ClassDef& class_def = dex_file.GetClassDef(class_def_idx);
- const DexFile::TypeId& type_id = dex_file.GetTypeId(class_def.class_idx_);
- const DexFile::StringId& str_id = dex_file.GetStringId(type_id.descriptor_idx_);
+ const dex::ClassDef& class_def = dex_file.GetClassDef(class_def_idx);
+ const dex::TypeId& type_id = dex_file.GetTypeId(class_def.class_idx_);
+ const dex::StringId& str_id = dex_file.GetStringId(type_id.descriptor_idx_);
const uint32_t hash = ComputeModifiedUtf8Hash(dex_file.GetStringData(str_id));
// Find the last entry in the chain.
uint32_t tail_pos = hash & mask;