summaryrefslogtreecommitdiffstats
path: root/libdexfile/dex/dex_file.h
diff options
context:
space:
mode:
authorAndreas Gampe <agampe@google.com>2018-12-28 09:39:56 -0800
committerAndreas Gampe <agampe@google.com>2019-01-02 10:32:25 -0800
commit3f1dcd39e134d994ac88dcc4f30ec8cabcd8decf (patch)
tree365d20ad6b68ff1dbd4903764b63880324136e4d /libdexfile/dex/dex_file.h
parent0f0a4e40667c87fbd4ae5480eddbfd701bfabfa2 (diff)
downloadart-3f1dcd39e134d994ac88dcc4f30ec8cabcd8decf.tar.gz
art-3f1dcd39e134d994ac88dcc4f30ec8cabcd8decf.tar.bz2
art-3f1dcd39e134d994ac88dcc4f30ec8cabcd8decf.zip
ART: Move dex structs into own header
Separating out the structs from DexFile allows them to be forward- declared, which reduces the need to include the dex_file header. Bug: 119869270 Test: m Change-Id: I32dde5a632884bca7435cd584b4a81883de2e7b4
Diffstat (limited to 'libdexfile/dex/dex_file.h')
-rw-r--r--libdexfile/dex/dex_file.h487
1 files changed, 118 insertions, 369 deletions
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))
{}