Skip to content

Commit

Permalink
Store zip entry inside
Browse files Browse the repository at this point in the history
  • Loading branch information
uholeschak committed Dec 21, 2024
1 parent cc0316d commit 4e7c27e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 26 deletions.
10 changes: 5 additions & 5 deletions Tools/ApkUncompress2/AssemblyStore/AssemblyStoreExplorer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ class AssemblyStoreExplorer
public IDictionary<string, AssemblyStoreItem>? 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");
}

Expand All @@ -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<AssemblyStoreExplorer>? explorers, string? errorMessage) Open (string inputFile)
Expand Down Expand Up @@ -174,7 +174,7 @@ public static (IList<AssemblyStoreExplorer>? 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;
}
}
Expand Down
21 changes: 12 additions & 9 deletions Tools/ApkUncompress2/AssemblyStore/AssemblyStoreReader.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using ICSharpCode.SharpZipLib.Zip;
using System;
using System.Collections.Generic;
using System.IO;
Expand All @@ -11,40 +12,42 @@ 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<AssemblyStoreItem>? 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;
}

return null;
}

static AssemblyStoreReader? MakeReaderReady (AssemblyStoreReader reader)
static AssemblyStoreReader? MakeReaderReady (AssemblyStoreReader reader)
{
if (!reader.IsSupported ()) {
return null;
Expand Down
5 changes: 3 additions & 2 deletions Tools/ApkUncompress2/AssemblyStore/StoreReader_V1.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using ICSharpCode.SharpZipLib.Zip;
using System.Collections.Generic;
using System.IO;

Expand All @@ -19,8 +20,8 @@ static StoreReader_V1 ()
AabBasePaths = new List<string> ().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 ()
Expand Down
20 changes: 10 additions & 10 deletions Tools/ApkUncompress2/AssemblyStore/StoreReader_V2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

using Xamarin.Android.Tools;
using Xamarin.Android.Tasks;
using ICSharpCode.SharpZipLib.Zip;

namespace Xamarin.Android.AssemblyStore;

Expand All @@ -28,9 +29,14 @@ partial class StoreReader_V2 : AssemblyStoreReader
public static IList<string> AabPaths { get; }
public static IList<string> AabBasePaths { get; }

readonly HashSet<uint> supportedVersions;
readonly HashSet<uint> supportedVersions = new HashSet<uint> {
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 ()
Expand Down Expand Up @@ -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<uint> {
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";
Expand Down

0 comments on commit 4e7c27e

Please sign in to comment.