diff options
author | Ryan Mitchell <rtmitchell@google.com> | 2020-11-16 23:08:18 +0000 |
---|---|---|
committer | Ryan Mitchell <rtmitchell@google.com> | 2020-11-17 23:01:35 +0000 |
commit | db21f09a8e02bcfd3fefea68084667688268f1fa (patch) | |
tree | c9b22a2676936eaf56ee1160c9349632ccd7ba44 /tools/aapt2/process/SymbolTable.cpp | |
parent | 687f5e163f24ff31f822f986fd7a99b8832b6286 (diff) |
Revert^2 "libandroidfw hardening for IncFs"
55ef6167a2c235bd88c7216238b2001b46795b79
Change-Id: I02d4890d181655dfd0a14c188468db512559d27b
Diffstat (limited to 'tools/aapt2/process/SymbolTable.cpp')
-rw-r--r-- | tools/aapt2/process/SymbolTable.cpp | 51 |
1 files changed, 31 insertions, 20 deletions
diff --git a/tools/aapt2/process/SymbolTable.cpp b/tools/aapt2/process/SymbolTable.cpp index 897fa80ffedb..ad716c78d65d 100644 --- a/tools/aapt2/process/SymbolTable.cpp +++ b/tools/aapt2/process/SymbolTable.cpp @@ -265,21 +265,22 @@ bool AssetManagerSymbolSource::IsPackageDynamic(uint32_t packageId, static std::unique_ptr<SymbolTable::Symbol> LookupAttributeInTable( android::AssetManager2& am, ResourceId id) { + using namespace android; if (am.GetApkAssets().empty()) { return {}; } - const android::ResolvedBag* bag = am.GetBag(id.id); - if (bag == nullptr) { + auto bag_result = am.GetBag(id.id); + if (!bag_result.has_value()) { return nullptr; } // We found a resource. std::unique_ptr<SymbolTable::Symbol> s = util::make_unique<SymbolTable::Symbol>(id); - + const ResolvedBag* bag = *bag_result; const size_t count = bag->entry_count; for (uint32_t i = 0; i < count; i++) { - if (bag->entries[i].key == android::ResTable_map::ATTR_TYPE) { + if (bag->entries[i].key == ResTable_map::ATTR_TYPE) { s->attribute = std::make_shared<Attribute>(bag->entries[i].value.data); break; } @@ -287,25 +288,25 @@ static std::unique_ptr<SymbolTable::Symbol> LookupAttributeInTable( if (s->attribute) { for (size_t i = 0; i < count; i++) { - const android::ResolvedBag::Entry& map_entry = bag->entries[i]; + const ResolvedBag::Entry& map_entry = bag->entries[i]; if (Res_INTERNALID(map_entry.key)) { switch (map_entry.key) { - case android::ResTable_map::ATTR_MIN: + case ResTable_map::ATTR_MIN: s->attribute->min_int = static_cast<int32_t>(map_entry.value.data); break; - case android::ResTable_map::ATTR_MAX: + case ResTable_map::ATTR_MAX: s->attribute->max_int = static_cast<int32_t>(map_entry.value.data); break; } continue; } - android::AssetManager2::ResourceName name; - if (!am.GetResourceName(map_entry.key, &name)) { + auto name = am.GetResourceName(map_entry.key); + if (!name.has_value()) { return nullptr; } - Maybe<ResourceName> parsed_name = ResourceUtils::ToResourceName(name); + Maybe<ResourceName> parsed_name = ResourceUtils::ToResourceName(*name); if (!parsed_name) { return nullptr; } @@ -328,7 +329,7 @@ std::unique_ptr<SymbolTable::Symbol> AssetManagerSymbolSource::FindByName( bool found = false; ResourceId res_id = 0; - uint32_t type_spec_flags; + uint32_t type_spec_flags = 0; ResourceName real_name; // There can be mangled resources embedded within other packages. Here we will @@ -340,8 +341,19 @@ std::unique_ptr<SymbolTable::Symbol> AssetManagerSymbolSource::FindByName( real_name.package = package_name; } - res_id = asset_manager_.GetResourceId(real_name.to_string()); - if (res_id.is_valid_static() && asset_manager_.GetResourceFlags(res_id.id, &type_spec_flags)) { + auto real_res_id = asset_manager_.GetResourceId(real_name.to_string()); + if (!real_res_id.has_value()) { + return true; + } + + res_id.id = *real_res_id; + if (!res_id.is_valid_static()) { + return true; + } + + auto value = asset_manager_.GetResource(res_id.id, true /* may_be_bag */); + if (value.has_value()) { + type_spec_flags = value->flags; found = true; return false; } @@ -371,11 +383,11 @@ std::unique_ptr<SymbolTable::Symbol> AssetManagerSymbolSource::FindByName( static Maybe<ResourceName> GetResourceName(android::AssetManager2& am, ResourceId id) { - android::AssetManager2::ResourceName name; - if (!am.GetResourceName(id.id, &name)) { + auto name = am.GetResourceName(id.id); + if (!name.has_value()) { return {}; } - return ResourceUtils::ToResourceName(name); + return ResourceUtils::ToResourceName(*name); } std::unique_ptr<SymbolTable::Symbol> AssetManagerSymbolSource::FindById( @@ -394,9 +406,8 @@ std::unique_ptr<SymbolTable::Symbol> AssetManagerSymbolSource::FindById( return {}; } - - uint32_t type_spec_flags = 0; - if (!asset_manager_.GetResourceFlags(id.id, &type_spec_flags)) { + auto value = asset_manager_.GetResource(id.id, true /* may_be_bag */); + if (!value.has_value()) { return {}; } @@ -411,7 +422,7 @@ std::unique_ptr<SymbolTable::Symbol> AssetManagerSymbolSource::FindById( } if (s) { - s->is_public = (type_spec_flags & android::ResTable_typeSpec::SPEC_PUBLIC) != 0; + s->is_public = (value->flags & android::ResTable_typeSpec::SPEC_PUBLIC) != 0; return s; } return {}; |