diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/dexanalyze/dexanalyze_bytecode.cc | 2 | ||||
-rw-r--r-- | tools/hiddenapi/hiddenapi.cc | 24 | ||||
-rw-r--r-- | tools/hiddenapi/hiddenapi_test.cc | 14 | ||||
-rw-r--r-- | tools/veridex/flow_analysis.cc | 8 | ||||
-rw-r--r-- | tools/veridex/hidden_api.cc | 4 | ||||
-rw-r--r-- | tools/veridex/resolver.cc | 18 | ||||
-rw-r--r-- | tools/veridex/veridex.h | 11 |
7 files changed, 42 insertions, 39 deletions
diff --git a/tools/dexanalyze/dexanalyze_bytecode.cc b/tools/dexanalyze/dexanalyze_bytecode.cc index 88db672ad7..ae88f379c0 100644 --- a/tools/dexanalyze/dexanalyze_bytecode.cc +++ b/tools/dexanalyze/dexanalyze_bytecode.cc @@ -360,7 +360,7 @@ void NewRegisterInstructions::ProcessCodeItem(const DexFile& dex_file, case Instruction::INVOKE_INTERFACE: case Instruction::INVOKE_SUPER: { const uint32_t method_idx = DexMethodIndex(inst.Inst()); - const DexFile::MethodId& method = dex_file.GetMethodId(method_idx); + const dex::MethodId& method = dex_file.GetMethodId(method_idx); const dex::TypeIndex receiver_type = method.class_idx_; if (Enabled(kExperimentInvoke)) { if (count_types) { diff --git a/tools/hiddenapi/hiddenapi.cc b/tools/hiddenapi/hiddenapi.cc index 3e38b97889..6af822d6b6 100644 --- a/tools/hiddenapi/hiddenapi.cc +++ b/tools/hiddenapi/hiddenapi.cc @@ -113,7 +113,7 @@ class DexClass : public ClassAccessor { std::set<std::string> GetInterfaceDescriptors() const { std::set<std::string> list; - const DexFile::TypeList* ifaces = dex_file_.GetInterfacesList(GetClassDef()); + const dex::TypeList* ifaces = dex_file_.GetInterfacesList(GetClassDef()); for (uint32_t i = 0; ifaces != nullptr && i < ifaces->Size(); ++i) { list.insert(dex_file_.StringByTypeIdx(ifaces->GetTypeItem(i).type_idx_)); } @@ -201,12 +201,12 @@ class DexMember { return down_cast<const ClassAccessor::Method&>(item_); } - inline const DexFile::MethodId& GetMethodId() const { + inline const dex::MethodId& GetMethodId() const { DCHECK(IsMethod()); return item_.GetDexFile().GetMethodId(item_.GetIndex()); } - inline const DexFile::FieldId& GetFieldId() const { + inline const dex::FieldId& GetFieldId() const { DCHECK(!IsMethod()); return item_.GetDexFile().GetFieldId(item_.GetIndex()); } @@ -665,7 +665,7 @@ class DexFileEditor final { } // Find the old MapList, find its size. - const DexFile::MapList* old_map = old_dex_.GetMapList(); + const dex::MapList* old_map = old_dex_.GetMapList(); CHECK_LT(old_map->size_, std::numeric_limits<uint32_t>::max()); // Compute the size of the new dex file. We append the HiddenapiClassData, @@ -674,7 +674,7 @@ class DexFileEditor final { << "End of input dex file is not 4-byte aligned, possibly because its MapList is not " << "at the end of the file."; size_t size_delta = - RoundUp(hiddenapi_class_data_.size(), kMapListAlignment) + sizeof(DexFile::MapItem); + RoundUp(hiddenapi_class_data_.size(), kMapListAlignment) + sizeof(dex::MapItem); size_t new_size = old_dex_.Size() + size_delta; AllocateMemory(new_size); @@ -742,7 +742,7 @@ class DexFileEditor final { // Load the location of header and map list before we start editing the file. loaded_dex_header_ = const_cast<DexFile::Header*>(&loaded_dex_->GetHeader()); - loaded_dex_maplist_ = const_cast<DexFile::MapList*>(loaded_dex_->GetMapList()); + loaded_dex_maplist_ = const_cast<dex::MapList*>(loaded_dex_->GetMapList()); } DexFile::Header& GetHeader() const { @@ -750,7 +750,7 @@ class DexFileEditor final { return *loaded_dex_header_; } - DexFile::MapList& GetMapList() const { + dex::MapList& GetMapList() const { CHECK(loaded_dex_maplist_ != nullptr); return *loaded_dex_maplist_; } @@ -804,16 +804,16 @@ class DexFileEditor final { InsertPadding(/* alignment= */ kMapListAlignment); size_t new_map_offset = offset_; - DexFile::MapList* map = Append(old_dex_.GetMapList(), old_dex_.GetMapList()->Size()); + dex::MapList* map = Append(old_dex_.GetMapList(), old_dex_.GetMapList()->Size()); // Check last map entry is a pointer to itself. - DexFile::MapItem& old_item = map->list_[map->size_ - 1]; + dex::MapItem& old_item = map->list_[map->size_ - 1]; CHECK(old_item.type_ == DexFile::kDexTypeMapList); CHECK_EQ(old_item.size_, 1u); CHECK_EQ(old_item.offset_, GetHeader().map_off_); // Create a new MapItem entry with new MapList details. - DexFile::MapItem new_item; + dex::MapItem new_item; new_item.type_ = old_item.type_; new_item.unused_ = 0u; // initialize to ensure dex output is deterministic (b/119308882) new_item.size_ = old_item.size_; @@ -824,7 +824,7 @@ class DexFileEditor final { // Append a new MapItem and return its pointer. map->size_++; - Append(&new_item, sizeof(DexFile::MapItem)); + Append(&new_item, sizeof(dex::MapItem)); // Change penultimate entry to point to metadata. old_item.type_ = DexFile::kDexTypeHiddenapiClassData; @@ -853,7 +853,7 @@ class DexFileEditor final { std::unique_ptr<const DexFile> loaded_dex_; DexFile::Header* loaded_dex_header_; - DexFile::MapList* loaded_dex_maplist_; + dex::MapList* loaded_dex_maplist_; }; class HiddenApi final { diff --git a/tools/hiddenapi/hiddenapi_test.cc b/tools/hiddenapi/hiddenapi_test.cc index f10d3f4e12..2689eedc10 100644 --- a/tools/hiddenapi/hiddenapi_test.cc +++ b/tools/hiddenapi/hiddenapi_test.cc @@ -113,17 +113,17 @@ class HiddenApiTest : public CommonRuntimeTest { return ofs; } - const DexFile::ClassDef& FindClass(const char* desc, const DexFile& dex_file) { - const DexFile::TypeId* type_id = dex_file.FindTypeId(desc); + const dex::ClassDef& FindClass(const char* desc, const DexFile& dex_file) { + const dex::TypeId* type_id = dex_file.FindTypeId(desc); CHECK(type_id != nullptr) << "Could not find class " << desc; - const DexFile::ClassDef* found = dex_file.FindClassDef(dex_file.GetIndexForTypeId(*type_id)); + const dex::ClassDef* found = dex_file.FindClassDef(dex_file.GetIndexForTypeId(*type_id)); CHECK(found != nullptr) << "Could not find class " << desc; return *found; } hiddenapi::ApiList GetFieldHiddenFlags(const char* name, uint32_t expected_visibility, - const DexFile::ClassDef& class_def, + const dex::ClassDef& class_def, const DexFile& dex_file) { ClassAccessor accessor(dex_file, class_def, /* parse hiddenapi flags */ true); CHECK(accessor.HasClassData()) << "Class " << accessor.GetDescriptor() << " has no data"; @@ -133,7 +133,7 @@ class HiddenApiTest : public CommonRuntimeTest { } for (const ClassAccessor::Field& field : accessor.GetFields()) { - const DexFile::FieldId& fid = dex_file.GetFieldId(field.GetIndex()); + const dex::FieldId& fid = dex_file.GetFieldId(field.GetIndex()); if (strcmp(name, dex_file.GetFieldName(fid)) == 0) { const uint32_t actual_visibility = field.GetAccessFlags() & kAccVisibilityFlags; CHECK_EQ(actual_visibility, expected_visibility) @@ -150,7 +150,7 @@ class HiddenApiTest : public CommonRuntimeTest { hiddenapi::ApiList GetMethodHiddenFlags(const char* name, uint32_t expected_visibility, bool expected_native, - const DexFile::ClassDef& class_def, + const dex::ClassDef& class_def, const DexFile& dex_file) { ClassAccessor accessor(dex_file, class_def, /* parse hiddenapi flags */ true); CHECK(accessor.HasClassData()) << "Class " << accessor.GetDescriptor() << " has no data"; @@ -160,7 +160,7 @@ class HiddenApiTest : public CommonRuntimeTest { } for (const ClassAccessor::Method& method : accessor.GetMethods()) { - const DexFile::MethodId& mid = dex_file.GetMethodId(method.GetIndex()); + const dex::MethodId& mid = dex_file.GetMethodId(method.GetIndex()); if (strcmp(name, dex_file.GetMethodName(mid)) == 0) { CHECK_EQ(expected_native, method.MemberIsNative()) << "Method " << name << " in class " << accessor.GetDescriptor(); diff --git a/tools/veridex/flow_analysis.cc b/tools/veridex/flow_analysis.cc index 1fca7e1ae7..65f236325e 100644 --- a/tools/veridex/flow_analysis.cc +++ b/tools/veridex/flow_analysis.cc @@ -131,15 +131,15 @@ const RegisterValue& VeriFlowAnalysis::GetRegister(uint32_t dex_register) const RegisterValue VeriFlowAnalysis::GetReturnType(uint32_t method_index) { const DexFile& dex_file = resolver_->GetDexFile(); - const DexFile::MethodId& method_id = dex_file.GetMethodId(method_index); - const DexFile::ProtoId& proto_id = dex_file.GetMethodPrototype(method_id); + const dex::MethodId& method_id = dex_file.GetMethodId(method_index); + const dex::ProtoId& proto_id = dex_file.GetMethodPrototype(method_id); VeriClass* cls = resolver_->GetVeriClass(proto_id.return_type_idx_); return RegisterValue(RegisterSource::kMethod, DexFileReference(&dex_file, method_index), cls); } RegisterValue VeriFlowAnalysis::GetFieldType(uint32_t field_index) { const DexFile& dex_file = resolver_->GetDexFile(); - const DexFile::FieldId& field_id = dex_file.GetFieldId(field_index); + const dex::FieldId& field_id = dex_file.GetFieldId(field_index); VeriClass* cls = resolver_->GetVeriClass(field_id.type_idx_); return RegisterValue(RegisterSource::kField, DexFileReference(&dex_file, field_index), cls); } @@ -716,7 +716,7 @@ RegisterValue FlowAnalysisCollector::AnalyzeInvoke(const Instruction& instructio RegisterValue obj = GetRegister(GetParameterAt(instruction, is_range, args, 0)); const VeriClass* cls = obj.GetType(); if (cls != nullptr && cls->GetClassDef() != nullptr) { - const DexFile::ClassDef* def = cls->GetClassDef(); + const dex::ClassDef* def = cls->GetClassDef(); return RegisterValue( RegisterSource::kClass, DexFileReference(&resolver_->GetDexFileOf(*cls), def->class_idx_.index_), diff --git a/tools/veridex/hidden_api.cc b/tools/veridex/hidden_api.cc index 6a04365a3a..2af7b50a73 100644 --- a/tools/veridex/hidden_api.cc +++ b/tools/veridex/hidden_api.cc @@ -78,7 +78,7 @@ void HiddenApi::AddSignatureToApiList(const std::string& signature, hiddenapi::A std::string HiddenApi::GetApiMethodName(const DexFile& dex_file, uint32_t method_index) { std::stringstream ss; - const DexFile::MethodId& method_id = dex_file.GetMethodId(method_index); + const dex::MethodId& method_id = dex_file.GetMethodId(method_index); ss << dex_file.StringByTypeIdx(method_id.class_idx_) << "->" << dex_file.GetMethodName(method_id) @@ -88,7 +88,7 @@ std::string HiddenApi::GetApiMethodName(const DexFile& dex_file, uint32_t method std::string HiddenApi::GetApiFieldName(const DexFile& dex_file, uint32_t field_index) { std::stringstream ss; - const DexFile::FieldId& field_id = dex_file.GetFieldId(field_index); + const dex::FieldId& field_id = dex_file.GetFieldId(field_index); ss << dex_file.StringByTypeIdx(field_id.class_idx_) << "->" << dex_file.GetFieldName(field_id) diff --git a/tools/veridex/resolver.cc b/tools/veridex/resolver.cc index 56729fffd0..0d769cda31 100644 --- a/tools/veridex/resolver.cc +++ b/tools/veridex/resolver.cc @@ -46,7 +46,7 @@ void VeridexResolver::Run() { } static bool HasSameNameAndSignature(const DexFile& dex_file, - const DexFile::MethodId& method_id, + const dex::MethodId& method_id, const char* method_name, const char* type) { return strcmp(method_name, dex_file.GetMethodName(method_id)) == 0 && @@ -54,7 +54,7 @@ static bool HasSameNameAndSignature(const DexFile& dex_file, } static bool HasSameNameAndSignature(const DexFile& dex_file, - const DexFile::MethodId& method_id, + const dex::MethodId& method_id, const char* method_name, const Signature& signature) { return strcmp(method_name, dex_file.GetMethodName(method_id)) == 0 && @@ -62,7 +62,7 @@ static bool HasSameNameAndSignature(const DexFile& dex_file, } static bool HasSameNameAndType(const DexFile& dex_file, - const DexFile::FieldId& field_id, + const dex::FieldId& field_id, const char* field_name, const char* field_type) { return strcmp(field_name, dex_file.GetFieldName(field_id)) == 0 && @@ -139,7 +139,7 @@ VeriMethod VeridexResolver::LookupMethodIn(const VeriClass& kls, const DexFile& other_dex_file = resolver->dex_file_; ClassAccessor other_dex_accessor(other_dex_file, *kls.GetClassDef()); for (const ClassAccessor::Method& method : other_dex_accessor.GetMethods()) { - const DexFile::MethodId& other_method_id = other_dex_file.GetMethodId(method.GetIndex()); + const dex::MethodId& other_method_id = other_dex_file.GetMethodId(method.GetIndex()); if (HasSameNameAndSignature(other_dex_file, other_method_id, method_name, @@ -160,7 +160,7 @@ VeriMethod VeridexResolver::LookupMethodIn(const VeriClass& kls, } // Look at methods in `kls`'s interface hierarchy. - const DexFile::TypeList* interfaces = other_dex_file.GetInterfacesList(*kls.GetClassDef()); + const dex::TypeList* interfaces = other_dex_file.GetInterfacesList(*kls.GetClassDef()); if (interfaces != nullptr) { for (size_t i = 0; i < interfaces->Size(); i++) { dex::TypeIndex idx = interfaces->GetTypeItem(i).type_idx_; @@ -194,7 +194,7 @@ VeriField VeridexResolver::LookupFieldIn(const VeriClass& kls, const DexFile& other_dex_file = resolver->dex_file_; ClassAccessor other_dex_accessor(other_dex_file, *kls.GetClassDef()); for (const ClassAccessor::Field& field : other_dex_accessor.GetFields()) { - const DexFile::FieldId& other_field_id = other_dex_file.GetFieldId(field.GetIndex()); + const dex::FieldId& other_field_id = other_dex_file.GetFieldId(field.GetIndex()); if (HasSameNameAndType(other_dex_file, other_field_id, field_name, @@ -204,7 +204,7 @@ VeriField VeridexResolver::LookupFieldIn(const VeriClass& kls, } // Look at fields in `kls`'s interface hierarchy. - const DexFile::TypeList* interfaces = other_dex_file.GetInterfacesList(*kls.GetClassDef()); + const dex::TypeList* interfaces = other_dex_file.GetInterfacesList(*kls.GetClassDef()); if (interfaces != nullptr) { for (size_t i = 0; i < interfaces->Size(); i++) { dex::TypeIndex idx = interfaces->GetTypeItem(i).type_idx_; @@ -258,7 +258,7 @@ VeriMethod VeridexResolver::GetMethod(uint32_t method_index) { VeriMethod method_info = method_infos_[method_index]; if (method_info == nullptr) { // Method is defined in another dex file. - const DexFile::MethodId& method_id = dex_file_.GetMethodId(method_index); + const dex::MethodId& method_id = dex_file_.GetMethodId(method_index); VeriClass* kls = GetVeriClass(method_id.class_idx_); if (kls == nullptr) { return nullptr; @@ -276,7 +276,7 @@ VeriField VeridexResolver::GetField(uint32_t field_index) { VeriField field_info = field_infos_[field_index]; if (field_info == nullptr) { // Field is defined in another dex file. - const DexFile::FieldId& field_id = dex_file_.GetFieldId(field_index); + const dex::FieldId& field_id = dex_file_.GetFieldId(field_index); VeriClass* kls = GetVeriClass(field_id.class_idx_); if (kls == nullptr) { return nullptr; diff --git a/tools/veridex/veridex.h b/tools/veridex/veridex.h index e0d82616ae..f02de96150 100644 --- a/tools/veridex/veridex.h +++ b/tools/veridex/veridex.h @@ -19,11 +19,14 @@ #include <map> -#include "dex/dex_file.h" #include "dex/primitive.h" namespace art { +namespace dex { +struct ClassDef; +} // namespace dex + static int gTargetSdkVersion = 1000; // Will be initialized after parsing options. /** @@ -45,7 +48,7 @@ using VeriMethod = const uint8_t*; class VeriClass { public: VeriClass() = default; - VeriClass(Primitive::Type k, uint8_t dims, const DexFile::ClassDef* cl) + VeriClass(Primitive::Type k, uint8_t dims, const dex::ClassDef* cl) : kind_(k), dimensions_(dims), class_def_(cl) {} bool IsUninitialized() const { @@ -62,7 +65,7 @@ class VeriClass { Primitive::Type GetKind() const { return kind_; } uint8_t GetDimensions() const { return dimensions_; } - const DexFile::ClassDef* GetClassDef() const { return class_def_; } + const dex::ClassDef* GetClassDef() const { return class_def_; } static VeriClass* object_; static VeriClass* class_; @@ -92,7 +95,7 @@ class VeriClass { private: Primitive::Type kind_; uint8_t dimensions_; - const DexFile::ClassDef* class_def_; + const dex::ClassDef* class_def_; }; inline bool IsGetMethod(VeriMethod method) { |