From 4e7c27e4996878f98083e076643993b5ee8990ef Mon Sep 17 00:00:00 2001 From: uholeschak Date: Sat, 21 Dec 2024 02:33:22 +0100 Subject: [PATCH] Store zip entry inside --- .../AssemblyStore/AssemblyStoreExplorer.cs | 10 ++++----- .../AssemblyStore/AssemblyStoreReader.cs | 21 +++++++++++-------- .../AssemblyStore/StoreReader_V1.cs | 5 +++-- .../AssemblyStore/StoreReader_V2.cs | 20 +++++++++--------- 4 files changed, 30 insertions(+), 26 deletions(-) diff --git a/Tools/ApkUncompress2/AssemblyStore/AssemblyStoreExplorer.cs b/Tools/ApkUncompress2/AssemblyStore/AssemblyStoreExplorer.cs index 15355a81e..4facc640b 100644 --- a/Tools/ApkUncompress2/AssemblyStore/AssemblyStoreExplorer.cs +++ b/Tools/ApkUncompress2/AssemblyStore/AssemblyStoreExplorer.cs @@ -19,12 +19,12 @@ class AssemblyStoreExplorer public IDictionary? AssembliesByName { get; } public bool Is64Bit { get; } - protected AssemblyStoreExplorer (Stream storeStream, string path) + protected AssemblyStoreExplorer (Stream? storeStream, ZipEntry? zipEntry, string path) { StorePath = path; - var storeReader = AssemblyStoreReader.Create (storeStream, path); + var storeReader = AssemblyStoreReader.Create (storeStream, zipEntry, path); if (storeReader == null) { - storeStream.Dispose (); + storeStream?.Dispose (); throw new NotSupportedException ($"Format of assembly store '{path}' is unsupported"); } @@ -47,7 +47,7 @@ protected AssemblyStoreExplorer (Stream storeStream, string path) } protected AssemblyStoreExplorer (FileInfo storeInfo) - : this (storeInfo.OpenRead (), storeInfo.FullName) + : this (storeInfo.OpenRead (), null, storeInfo.FullName) {} public static (IList? explorers, string? errorMessage) Open (string inputFile) @@ -174,7 +174,7 @@ public static (IList? explorers, string? errorMessage) Op StreamUtils.Copy(zipStream, memoryStream, buffer); } - ret.Add(new AssemblyStoreExplorer(memoryStream, $"{fi.FullName}!{path}")); + ret.Add(new AssemblyStoreExplorer(memoryStream, zipEntry, $"{fi.FullName}!{path}")); break; } } diff --git a/Tools/ApkUncompress2/AssemblyStore/AssemblyStoreReader.cs b/Tools/ApkUncompress2/AssemblyStore/AssemblyStoreReader.cs index 982b62645..dfc0bef66 100644 --- a/Tools/ApkUncompress2/AssemblyStore/AssemblyStoreReader.cs +++ b/Tools/ApkUncompress2/AssemblyStore/AssemblyStoreReader.cs @@ -1,3 +1,4 @@ +using ICSharpCode.SharpZipLib.Zip; using System; using System.Collections.Generic; using System.IO; @@ -11,32 +12,34 @@ abstract class AssemblyStoreReader { static readonly UTF8Encoding ReaderEncoding = new UTF8Encoding (false); - protected Stream StoreStream { get; } + protected Stream? StoreStream { get; } + protected ZipEntry? ZipEntry { get; } - public abstract string Description { get; } + public abstract string Description { get; } public abstract bool NeedsExtensionInName { get; } public string StorePath { get; } - public AndroidTargetArch TargetArch { get; protected set; } = AndroidTargetArch.Arm; + public AndroidTargetArch TargetArch { get; protected set; } = AndroidTargetArch.Arm; public uint AssemblyCount { get; protected set; } public uint IndexEntryCount { get; protected set; } public IList? Assemblies { get; protected set; } public bool Is64Bit { get; protected set; } - protected AssemblyStoreReader (Stream store, string path) + protected AssemblyStoreReader (Stream? store, ZipEntry? zipEntry, string path) { StoreStream = store; - StorePath = path; + ZipEntry = zipEntry; + StorePath = path; } - public static AssemblyStoreReader? Create (Stream store, string path) + public static AssemblyStoreReader? Create (Stream? store, ZipEntry? zipEntry, string path) { - AssemblyStoreReader? reader = MakeReaderReady (new StoreReader_V1 (store, path)); + AssemblyStoreReader? reader = MakeReaderReady (new StoreReader_V1 (store, zipEntry, path)); if (reader != null) { return reader; } - reader = MakeReaderReady (new StoreReader_V2 (store, path)); + reader = MakeReaderReady (new StoreReader_V2 (store, zipEntry, path)); if (reader != null) { return reader; } @@ -44,7 +47,7 @@ protected AssemblyStoreReader (Stream store, string path) return null; } - static AssemblyStoreReader? MakeReaderReady (AssemblyStoreReader reader) + static AssemblyStoreReader? MakeReaderReady (AssemblyStoreReader reader) { if (!reader.IsSupported ()) { return null; diff --git a/Tools/ApkUncompress2/AssemblyStore/StoreReader_V1.cs b/Tools/ApkUncompress2/AssemblyStore/StoreReader_V1.cs index f60fa3a06..b72c5508d 100644 --- a/Tools/ApkUncompress2/AssemblyStore/StoreReader_V1.cs +++ b/Tools/ApkUncompress2/AssemblyStore/StoreReader_V1.cs @@ -1,3 +1,4 @@ +using ICSharpCode.SharpZipLib.Zip; using System.Collections.Generic; using System.IO; @@ -19,8 +20,8 @@ static StoreReader_V1 () AabBasePaths = new List ().AsReadOnly (); } - public StoreReader_V1 (Stream store, string path) - : base (store, path) + public StoreReader_V1 (Stream? store, ZipEntry? zipEntry, string path) + : base (store, zipEntry, path) {} protected override bool IsSupported () diff --git a/Tools/ApkUncompress2/AssemblyStore/StoreReader_V2.cs b/Tools/ApkUncompress2/AssemblyStore/StoreReader_V2.cs index a43960102..9951ccfeb 100644 --- a/Tools/ApkUncompress2/AssemblyStore/StoreReader_V2.cs +++ b/Tools/ApkUncompress2/AssemblyStore/StoreReader_V2.cs @@ -5,6 +5,7 @@ using Xamarin.Android.Tools; using Xamarin.Android.Tasks; +using ICSharpCode.SharpZipLib.Zip; namespace Xamarin.Android.AssemblyStore; @@ -28,9 +29,14 @@ partial class StoreReader_V2 : AssemblyStoreReader public static IList AabPaths { get; } public static IList AabBasePaths { get; } - readonly HashSet supportedVersions; + readonly HashSet supportedVersions = new HashSet { + ASSEMBLY_STORE_FORMAT_VERSION_64BIT | ASSEMBLY_STORE_ABI_AARCH64, + ASSEMBLY_STORE_FORMAT_VERSION_64BIT | ASSEMBLY_STORE_ABI_X64, + ASSEMBLY_STORE_FORMAT_VERSION_32BIT | ASSEMBLY_STORE_ABI_ARM, + ASSEMBLY_STORE_FORMAT_VERSION_32BIT | ASSEMBLY_STORE_ABI_X86, + }; - Header? header; + Header? header; ulong elfOffset = 0; static StoreReader_V2 () @@ -71,15 +77,9 @@ string GetArchPath (AndroidTargetArch arch, string? root = null) } } - public StoreReader_V2 (Stream store, string path) - : base (store, path) + public StoreReader_V2 (Stream? store, ZipEntry? zipEntry, string path) + : base (store, zipEntry, path) { - supportedVersions = new HashSet { - ASSEMBLY_STORE_FORMAT_VERSION_64BIT | ASSEMBLY_STORE_ABI_AARCH64, - ASSEMBLY_STORE_FORMAT_VERSION_64BIT | ASSEMBLY_STORE_ABI_X64, - ASSEMBLY_STORE_FORMAT_VERSION_32BIT | ASSEMBLY_STORE_ABI_ARM, - ASSEMBLY_STORE_FORMAT_VERSION_32BIT | ASSEMBLY_STORE_ABI_X86, - }; } static string GetBlobName (string abi) => $"libassemblies.{abi}.blob.so";