summaryrefslogtreecommitdiff
path: root/tools/aapt2/format/binary/BinaryResourceParser.cpp
diff options
context:
space:
mode:
authorRyan Mitchell <rtmitchell@google.com>2018-12-12 18:45:34 -0800
committerRyan Mitchell <rtmitchell@google.com>2019-01-11 14:45:09 -0800
commitef5673a4c4021ca27b40e48020203928d71c95a8 (patch)
treeb97e02462524775bd8a1a5a6104ff0b726d3a478 /tools/aapt2/format/binary/BinaryResourceParser.cpp
parent56ac01ebb4475440669f5f009c453dba0a86f6dd (diff)
Add encoding of name and actor overlayable fields
Encode the actor and name attributes of <overlayable> elements in the overlayable chunks. Two chunks cannot have the same name. Bug: 110869880 Bug: 119390855 Test: aapt2_tests and libandroidfw_tests Change-Id: I0ed95efef640b3927046b6155d1840f0d96030dd
Diffstat (limited to 'tools/aapt2/format/binary/BinaryResourceParser.cpp')
-rw-r--r--tools/aapt2/format/binary/BinaryResourceParser.cpp26
1 files changed, 20 insertions, 6 deletions
diff --git a/tools/aapt2/format/binary/BinaryResourceParser.cpp b/tools/aapt2/format/binary/BinaryResourceParser.cpp
index c496ff0e159b..7d4c6f348403 100644
--- a/tools/aapt2/format/binary/BinaryResourceParser.cpp
+++ b/tools/aapt2/format/binary/BinaryResourceParser.cpp
@@ -42,6 +42,19 @@ namespace aapt {
namespace {
+static std::u16string strcpy16_dtoh(const char16_t* src, size_t len) {
+ size_t utf16_len = strnlen16(src, len);
+ if (utf16_len == 0) {
+ return {};
+ }
+ std::u16string dst;
+ dst.resize(utf16_len);
+ for (size_t i = 0; i < utf16_len; i++) {
+ dst[i] = util::DeviceToHost16(src[i]);
+ }
+ return dst;
+}
+
// Visitor that converts a reference's resource ID to a resource name, given a mapping from
// resource ID to resource name.
class ReferenceIdToNameVisitor : public DescendingValueVisitor {
@@ -176,12 +189,8 @@ bool BinaryResourceParser::ParsePackage(const ResChunk_header* chunk) {
}
// Extract the package name.
- size_t len = strnlen16((const char16_t*)package_header->name, arraysize(package_header->name));
- std::u16string package_name;
- package_name.resize(len);
- for (size_t i = 0; i < len; i++) {
- package_name[i] = util::DeviceToHost16(package_header->name[i]);
- }
+ std::u16string package_name = strcpy16_dtoh((const char16_t*)package_header->name,
+ arraysize(package_header->name));
ResourceTablePackage* package =
table_->CreatePackage(util::Utf16ToUtf8(package_name), static_cast<uint8_t>(package_id));
@@ -435,6 +444,11 @@ bool BinaryResourceParser::ParseOverlayable(const ResChunk_header* chunk) {
}
auto overlayable = std::make_shared<Overlayable>();
+ overlayable->name = util::Utf16ToUtf8(strcpy16_dtoh((const char16_t*)header->name,
+ arraysize(header->name)));
+ overlayable->actor = util::Utf16ToUtf8(strcpy16_dtoh((const char16_t*)header->actor,
+ arraysize(header->name)));
+ overlayable->source = source_.WithLine(0);
ResChunkPullParser parser(GetChunkData(chunk),
GetChunkDataLen(chunk));