Пример #1
0
def _TableFromFlatBytes(data):
  # https://cs.android.com/android/platform/superproject/+/master:frameworks/base/tools/aapt2/format/Container.cpp
  size_idx = len(_FLAT_ARSC_HEADER)
  proto_idx = size_idx + 8
  if data[:size_idx] != _FLAT_ARSC_HEADER:
    raise Exception('Error parsing {} in {}'.format(info.filename, zip_path))
  # Size is stored as uint64.
  size = struct.unpack('<Q', data[size_idx:proto_idx])[0]
  table = Resources_pb2.ResourceTable()
  proto_bytes = data[proto_idx:proto_idx + size]
  table.ParseFromString(proto_bytes)
  return table
Пример #2
0
 def process_func(filename, data):
   if filename == 'resources.pb':
     table = Resources_pb2.ResourceTable()
     table.ParseFromString(data)
     _HardcodeInTable(table, is_bundle_module, shared_resources_allowlist)
     data = table.SerializeToString()
   elif filename.endswith('.xml') and not filename.startswith('res/raw'):
     xml_node = Resources_pb2.XmlNode()
     xml_node.ParseFromString(data)
     _ProcessProtoXmlNode(xml_node)
     data = xml_node.SerializeToString()
   return data
Пример #3
0
def _HardcodeSharedLibraryDynamicAttributes(zip_path):
    """Hardcodes the package IDs of dynamic attributes to 0x02.

  This is a workaround for b/147674078, which affects Android versions pre-N.

  Args:
    zip_path: Path to proto APK file.
  """
    with build_utils.TempDir() as tmp_dir:
        build_utils.ExtractAll(zip_path, path=tmp_dir)

        # First process the resources file.
        table = Resources_pb2.ResourceTable()
        with open(os.path.join(tmp_dir, 'resources.pb')) as f:
            table.ParseFromString(f.read())

        for package in table.package:
            for _type in package.type:
                for entry in _type.entry:
                    for config_value in entry.config_value:
                        _ProcessProtoValue(config_value.value)

        with open(os.path.join(tmp_dir, 'resources.pb'), 'w') as f:
            f.write(table.SerializeToString())

        # Next process all the XML files.
        xml_files = build_utils.FindInDirectory(tmp_dir, '*.xml')
        for xml_file in xml_files:
            xml_node = Resources_pb2.XmlNode()
            with open(xml_file) as f:
                xml_node.ParseFromString(f.read())

            _ProcessProtoXmlNode(xml_node)

            with open(xml_file, 'w') as f:
                f.write(xml_node.SerializeToString())

        # Overwrite the original zip file.
        build_utils.ZipDir(zip_path, tmp_dir)