From 45526449b5a0fc880ce6bba6277ea09030ef5ffe Mon Sep 17 00:00:00 2001 From: uholeschak Date: Fri, 20 Dec 2024 21:47:15 +0100 Subject: [PATCH] Ported to SharpZipLib --- .../AssemblyStore/AssemblyStoreExplorer.cs | 38 ++++++++++++------- .../Utilities/MonoAndroidHelper.Basic.cs | 12 +++--- 2 files changed, 31 insertions(+), 19 deletions(-) diff --git a/Tools/ApkUncompress2/AssemblyStore/AssemblyStoreExplorer.cs b/Tools/ApkUncompress2/AssemblyStore/AssemblyStoreExplorer.cs index 64fce6a28..e200315cd 100644 --- a/Tools/ApkUncompress2/AssemblyStore/AssemblyStoreExplorer.cs +++ b/Tools/ApkUncompress2/AssemblyStore/AssemblyStoreExplorer.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.IO; +using ICSharpCode.SharpZipLib.Core; using ICSharpCode.SharpZipLib.Zip; using Xamarin.Android.Tools; @@ -35,10 +36,14 @@ protected AssemblyStoreExplorer (Stream storeStream, string path) Is64Bit = reader.Is64Bit; var dict = new Dictionary (StringComparer.Ordinal); - foreach (AssemblyStoreItem item in Assemblies) { - dict.Add (item.Name, item); - } - AssembliesByName = dict.AsReadOnly (); + if (Assemblies != null) + { + foreach (AssemblyStoreItem item in Assemblies) + { + dict.Add(item.Name, item); + } + } + AssembliesByName = dict.AsReadOnly (); } protected AssemblyStoreExplorer (FileInfo storeInfo) @@ -151,16 +156,23 @@ public static (IList? explorers, string? errorMessage) Op { var ret = new List (); - foreach (string path in paths) { - if (!zip.ContainsEntry (path)) { - continue; - } + foreach (string path in paths) + { + foreach (ZipEntry zipEntry in zf) + { + if (!zipEntry.IsFile) + { + continue; // Ignore directories + } - ZipEntry entry = zip.ReadEntry (path); - var stream = new MemoryStream (); - entry.Extract (stream); - ret.Add (new AssemblyStoreExplorer (stream, $"{fi.FullName}!{path}")); - } + if (string.Compare(zipEntry.Name, path, StringComparison.OrdinalIgnoreCase) == 0) + { + Stream zipStream = zf.GetInputStream(zipEntry); + ret.Add(new AssemblyStoreExplorer(zipStream, $"{fi.FullName}!{path}")); + break; + } + } + } if (ret.Count == 0) { return (null, null, false); diff --git a/Tools/ApkUncompress2/Utilities/MonoAndroidHelper.Basic.cs b/Tools/ApkUncompress2/Utilities/MonoAndroidHelper.Basic.cs index 20a1b24ea..67aa11cbf 100644 --- a/Tools/ApkUncompress2/Utilities/MonoAndroidHelper.Basic.cs +++ b/Tools/ApkUncompress2/Utilities/MonoAndroidHelper.Basic.cs @@ -94,7 +94,7 @@ public static AndroidTargetArch AbiToTargetArch (string abi) public static string AbiToRid (string abi) { - if (!AbiToRidMap.TryGetValue (abi, out string rid)) { + if (!AbiToRidMap.TryGetValue (abi, out string? rid)) { throw new NotSupportedException ($"Internal error: unsupported ABI '{abi}'"); }; @@ -103,7 +103,7 @@ public static string AbiToRid (string abi) public static string RidToAbi (string rid) { - if (!RidToAbiMap.TryGetValue (rid, out string abi)) { + if (!RidToAbiMap.TryGetValue (rid, out string? abi)) { throw new NotSupportedException ($"Internal error: unsupported Runtime Identifier '{rid}'"); }; @@ -131,7 +131,7 @@ public static AndroidTargetArch RidToArch (string rid) public static string ArchToRid (AndroidTargetArch arch) { - if (!ArchToRidMap.TryGetValue (arch, out string rid)) { + if (!ArchToRidMap.TryGetValue (arch, out string? rid)) { throw new InvalidOperationException ($"Internal error: unsupported architecture '{arch}'"); }; @@ -140,7 +140,7 @@ public static string ArchToRid (AndroidTargetArch arch) public static string ArchToAbi (AndroidTargetArch arch) { - if (!ArchToAbiMap.TryGetValue (arch, out string abi)) { + if (!ArchToAbiMap.TryGetValue (arch, out string? abi)) { throw new InvalidOperationException ($"Internal error: unsupported architecture '{arch}'"); }; @@ -158,9 +158,9 @@ public static string ArchToAbi (AndroidTargetArch arch) return Convert.ToString (obj, CultureInfo.InvariantCulture); } - public static string MapAndroidAbiToClang (string androidAbi) + public static string? MapAndroidAbiToClang (string androidAbi) { - if (ClangAbiMap.TryGetValue (androidAbi, out string clangAbi)) { + if (ClangAbiMap.TryGetValue (androidAbi, out string? clangAbi)) { return clangAbi; } return null;