Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;

using Xamarin.Android.AssemblyStore;
using Xamarin.Android.Tools;
using Xamarin.Tools.Zip;

namespace Xamarin.Android.Tools.DecompressAssemblies
{
Expand Down Expand Up @@ -79,15 +79,15 @@ static bool ExtractIndividualEntries (ZipArchive apk, string filePath, string as
{
bool retVal = true;
int assemblyCount = 0;
foreach (ZipEntry entry in apk) {
foreach (var entry in apk.Entries) {
if (!TryGetAssemblyOutputPath (entry.FullName, assembliesPath, nativeLibrariesPath, out string assemblyName)) {
continue;
}

assemblyCount++;

using (var stream = new MemoryStream ()) {
entry.Extract (stream);
Utils.Extract (entry, stream);
stream.Seek (0, SeekOrigin.Begin);
string outputFile = GetSafeOutputFile (outputDirectory, assemblyName);
using var payload = new MemoryStream ();
Expand Down Expand Up @@ -166,15 +166,15 @@ static string GetAndroidAbi (AndroidTargetArch arch)

static bool HasAssemblyStore (ZipArchive apk, string assembliesPath, string nativeLibrariesPath)
{
if (apk.ContainsEntry ($"{assembliesPath}assemblies.blob")) {
if (Utils.ContainsEntry (apk, $"{assembliesPath}assemblies.blob", caseSensitive: true)) {
return true;
}

foreach (AndroidTargetArch arch in targetArchitectures) {
string abi = GetAndroidAbi (arch);
if (
apk.ContainsEntry ($"{nativeLibrariesPath}{abi}/libassembly-store.so") ||
apk.ContainsEntry ($"{nativeLibrariesPath}{abi}/libassemblies.{abi}.blob.so")
Utils.ContainsEntry (apk, $"{nativeLibrariesPath}{abi}/libassembly-store.so", caseSensitive: true) ||
Utils.ContainsEntry (apk, $"{nativeLibrariesPath}{abi}/libassemblies.{abi}.blob.so", caseSensitive: true)
) {
return true;
}
Expand All @@ -185,7 +185,7 @@ static bool HasAssemblyStore (ZipArchive apk, string assembliesPath, string nati

static bool ExtractFromArchive (string filePath, string assembliesPath, string nativeLibrariesPath, string outputDirectory)
{
using (ZipArchive apk = ZipArchive.Open (filePath, FileMode.Open)) {
using (ZipArchive apk = Utils.OpenZip (filePath)) {
if (HasAssemblyStore (apk, assembliesPath, nativeLibrariesPath)) {
return ExtractAssemblyStores (filePath, outputDirectory);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Xamarin.LibZipSharp" Version="$(LibZipSharpVersion)" />
<PackageReference Include="System.IO.Hashing" Version="$(SystemIOHashingPackageVersion)" />
<PackageReference Include="ELFSharp" Version="$(ELFSharpVersion)" />
<PackageReference Include="K4os.Compression.LZ4" Version="$(LZ4PackageVersion)" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;

using Xamarin.Android.Tools;
using Xamarin.Tools.Zip;

namespace Xamarin.Android.AssemblyStore;

Expand Down Expand Up @@ -127,7 +127,7 @@ public static (IList<AssemblyStoreExplorer>? explorers, string? errorMessage) Op
static (IList<AssemblyStoreExplorer>? explorers, string? errorMessage) OpenArchive (FileInfo fi, IList<string> paths)
{
string? errorMessage;
using (var zip = ZipArchive.Open (fi.FullName, FileMode.Open)) {
using (var zip = Utils.OpenZip (fi.FullName)) {
(IList<AssemblyStoreExplorer>? explorers, string? loadError, bool pathsFound) = TryLoad (fi, zip, paths);
if (pathsFound) {
return (explorers, loadError);
Expand Down Expand Up @@ -172,13 +172,15 @@ static bool IsV1Store (FileInfo info)
var ret = new List<AssemblyStoreExplorer> ();

foreach (string path in paths) {
if (!zip.ContainsEntry (path)) {
if (!Utils.ContainsEntry (zip, path, caseSensitive: true)) {
continue;
}

ZipEntry entry = zip.ReadEntry (path);
var entry = Utils.ReadEntry (zip, path, caseSensitive: true);
if (entry == null)
continue;
var stream = new MemoryStream ();
entry.Extract (stream);
Utils.Extract (entry, stream);
ret.Add (new AssemblyStoreExplorer (stream, $"{fi.FullName}!{path}"));
}

Expand Down
34 changes: 31 additions & 3 deletions .github/skills/read-assembly-store/src/AssemblyStore/Utils.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using System;
using System.IO;
using System.Buffers;
using System.IO.Compression;
using System.Linq;

using ELFSharp.ELF;
using ELFSharp.ELF.Sections;
using Xamarin.Tools.Zip;

namespace Xamarin.Android.AssemblyStore;

Expand Down Expand Up @@ -224,7 +225,7 @@ public static (FileFormat format, FileInfo? info) DetectFileFormat (string path)

static FileFormat DetectAndroidArchive (FileInfo info, FileFormat defaultFormat)
{
using var zip = ZipArchive.Open (info.FullName, FileMode.Open);
using var zip = OpenZip (info.FullName);

if (HasAllEntries (zip, aabZipEntries)) {
return FileFormat.Aab;
Expand All @@ -244,11 +245,38 @@ static FileFormat DetectAndroidArchive (FileInfo info, FileFormat defaultFormat)
static bool HasAllEntries (ZipArchive zip, string[] entries)
{
foreach (string entry in entries) {
if (!zip.ContainsEntry (entry, caseSensitive: true)) {
if (!ContainsEntry (zip, entry, caseSensitive: true)) {
return false;
}
}

return true;
}

public static ZipArchive OpenZip (string path)
{
return ZipFile.OpenRead (path);
}

public static ZipArchive OpenZip (Stream stream, bool leaveOpen = false)
{
return new ZipArchive (stream, ZipArchiveMode.Read, leaveOpen);
}

public static bool ContainsEntry (ZipArchive archive, string entryName, bool caseSensitive = false)
{
return ReadEntry (archive, entryName, caseSensitive) != null;
}

public static ZipArchiveEntry? ReadEntry (ZipArchive archive, string entryName, bool caseSensitive = false)
{
var comparison = caseSensitive ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase;
return archive.Entries.FirstOrDefault (entry => string.Equals (entry.FullName, entryName, comparison));
}

public static void Extract (ZipArchiveEntry entry, Stream destination)
{
using var stream = entry.Open ();
stream.CopyTo (destination);
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System;
using System.Collections.Generic;
using System.IO;

using Xamarin.Tools.Zip;
using System.IO.Compression;
using Xamarin.Android.AssemblyStore;

namespace Xamarin.Android.AssemblyStore.V1
{
Expand Down Expand Up @@ -215,20 +215,20 @@ void ReadStoreSetFromArchive (string baseName, string archivePath, string extens
}

basePathInArchive = $"{basePathInArchive}/{baseName}.";
using (ZipArchive archive = ZipArchive.Open (archivePath, FileMode.Open)) {
using (ZipArchive archive = Utils.OpenZip (archivePath)) {
ReadStoreSetFromArchive (archive, basePathInArchive);
}
}

void ReadStoreSetFromArchive (ZipArchive archive, string basePathInArchive)
{
foreach (ZipEntry entry in archive) {
foreach (var entry in archive.Entries) {
if (!entry.FullName.StartsWith (basePathInArchive, StringComparison.Ordinal)) {
continue;
}

using (var stream = new MemoryStream ()) {
entry.Extract (stream);
Utils.Extract (entry, stream);

if (entry.FullName.EndsWith (".blob", StringComparison.Ordinal)) {
AddStore (new AssemblyStoreReader (stream, GetStoreArch (entry.FullName), keepStoreInMemory));
Expand Down
8 changes: 0 additions & 8 deletions .github/skills/update-tpn/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ Search `.csproj` files for `<PackageReference>` elements. Current third-party Nu
|---------|------------|-------------|
| ELFSharp | KonradKuczynski/ELFSharp | https://elfsharp.it/ (MIT + LLVM) |
| K4os.Compression.LZ4 | MiloszKrajewski/K4os.Compression.LZ4 | https://github.com/MiloszKrajewski/K4os.Compression.LZ4/ (MIT) |
| Xamarin.LibZipSharp | xamarin/LibZipSharp | https://github.com/xamarin/LibZipSharp/ (MIT) |
| Irony | IronyProject/Irony | https://github.com/IronyProject/Irony (MIT) |
| Newtonsoft.Json | JamesNK/Newtonsoft.Json | https://github.com/JamesNK/Newtonsoft.Json (MIT) |
| NuGet.ProjectModel | NuGet/NuGet.Client | https://github.com/NuGet/NuGet.Client (Apache 2.0) |
Expand Down Expand Up @@ -111,13 +110,6 @@ These are downloaded and shipped with the SDK:
| r8 | google/r8 | https://r8.googlesource.com/r8/ (BSD-3-Clause) |
| binutils | gnu/binutils | https://sourceware.org/git/?p=binutils-gdb.git;a=tree;hb=HEAD (GPLv3) |

#### libzip (via LibZipSharp NuGet)
LibZipSharp bundles libzip internally:

| Source | Name in TPN | License Location |
|--------|------------|-----------------|
| libzip (in LibZipSharp NuGet) | nih-at/libzip | LibZipSharp NuGet `Licences/libzip/LICENSE` or https://github.com/nih-at/libzip/ (BSD-3-Clause) |

### Step 2 — Cross-reference

Compare the inventory against the current entries in `THIRD-PARTY-NOTICES.TXT`:
Expand Down
1 change: 0 additions & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@

<!-- Common <PackageReference/> versions -->
<PropertyGroup>
<LibZipSharpVersion>3.3.0</LibZipSharpVersion>
<MicroBuildCoreVersion>1.0.0</MicroBuildCoreVersion>
<NewtonsoftJsonPackageVersion>13.0.3</NewtonsoftJsonPackageVersion>
<NuGetApiPackageVersion>5.4.0</NuGetApiPackageVersion>
Expand Down
75 changes: 2 additions & 73 deletions THIRD-PARTY-NOTICES.TXT
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,8 @@ implication, estoppel or otherwise.
19. MiloszKrajewski/K4os.Compression.LZ4 (https://github.com/MiloszKrajewski/K4os.Compression.LZ4/)
20. mono/cecil (https://github.com/mono/cecil/)
21. mono/linker (https://github.com/mono/linker/)
22. nih-at/libzip (https://github.com/nih-at/libzip/)
23. NuGet/NuGet.Client (https://github.com/NuGet/NuGet.Client)
24. tessil/robin-map (https://github.com/Tessil/robin-map)
25. xamarin/LibZipSharp (https://github.com/xamarin/LibZipSharp/)
22. NuGet/NuGet.Client (https://github.com/NuGet/NuGet.Client)
23. tessil/robin-map (https://github.com/Tessil/robin-map)

%% Android API documentation NOTICES AND INFORMATION BEGIN HERE
================================================================
Expand Down Expand Up @@ -2401,45 +2399,6 @@ SOFTWARE.
END OF mono/linker NOTICES AND INFORMATION


%% nih-at/libzip NOTICES AND INFORMATION BEGIN HERE
===================================================
Copyright (C) 1999-2020 Dieter Baron and Thomas Klausner

The authors can be contacted at <info@libzip.org>

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:

1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.

3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.

THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


===================================================
END OF nih-at/libzip NOTICES AND INFORMATION


%% NuGet/NuGet.Client NOTICES AND INFORMATION BEGIN HERE
========================================================
Copyright (c) .NET Foundation and Contributors.
Expand Down Expand Up @@ -2491,33 +2450,3 @@ SOFTWARE.
======================================================
END OF tessil/robin-map NOTICES AND INFORMATION


%% xamarin/LibZipSharp NOTICES AND INFORMATION BEGIN HERE
=========================================================
The MIT License (MIT)

Copyright (c) 2016 Marek Habersack

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.


=========================================================
END OF xamarin/LibZipSharp NOTICES AND INFORMATION


Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

<PropertyGroup>
<TargetFramework>$(DotNetStableTargetFramework)</TargetFramework>
<LibZipSharpBundleAllNativeLibraries>true</LibZipSharpBundleAllNativeLibraries>
<OutputPath>$(BootstrapOutputDirectory)</OutputPath>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.IO.Compression;
using System.Linq;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
using Xamarin.Tools.Zip;
using Microsoft.Android.Build.Tasks;

namespace Xamarin.Android.Tools.BootstrapTasks
{
Expand Down Expand Up @@ -133,11 +134,12 @@ public override bool Execute ()
var zipFiles = Directory.GetFiles (referenceContractPath.Parent.FullName, "*.zip");
foreach (var zipFile in zipFiles) {
var zipDateTime = File.GetLastWriteTimeUtc (zipFile);
using (var zip = ZipArchive.Open (zipFile, FileMode.Open)) {
foreach (var entry in zip) {
var path = Path.Combine (referenceContractPath.FullName, entry.NativeFullName);
using (var zip = ZipArchiveExtensions.OpenZipRead (zipFile)) {
foreach (var entry in zip.Entries) {
var path = Path.Combine (referenceContractPath.FullName, entry.FullName.Replace ('/', Path.DirectorySeparatorChar));
if (!File.Exists (path) || File.GetLastWriteTimeUtc (path) < zipDateTime) {
Log.LogMessage ($"Extracting: {path}");
Directory.CreateDirectory (Path.GetDirectoryName (path));
using (var fileStream = File.Create (path)) {
entry.Extract (fileStream);
}
Expand Down
Loading
Loading