Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Publish Sentry.Android.AssemblyReader as a separate nuget package #2127

Merged
merged 13 commits into from
Jan 27, 2023
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

### Features

- Publish `Sentry.Android.AssemblyReader` as a separate nuget package (for reuse by `Sentry.Xamarin`) ([#2127](https://github.com/getsentry/sentry-dotnet/pull/2127))

## 3.26.2

### Fixes
Expand Down
4 changes: 4 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@
<!-- Import the root global usings, except for samples. -->
<ItemGroup Condition="!$(MSBuildProjectName.Contains('Samples'))">
<Compile Include="$(MSBuildThisFileDirectory)GlobalUsings.cs" />

<!-- Add these here instead, so we can remove them for projects that don't have STJ available. -->
<Using Include="System.Text.Json" />
<Using Include="System.Text.Json.Serialization" />
</ItemGroup>

<!-- Set the version and local path for Sentry CLI (downloaded in the restore phase of Sentry.csproj) -->
Expand Down
3 changes: 1 addition & 2 deletions GlobalUsings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
global using System.Net.NetworkInformation;
global using System.Net.Sockets;
global using System.Reflection;
global using System.Reflection.PortableExecutable;
global using System.Runtime.CompilerServices;
global using System.Runtime.ExceptionServices;
global using System.Runtime.InteropServices;
Expand All @@ -25,6 +26,4 @@
global using System.Security.Claims;
global using System.Security.Cryptography;
global using System.Text;
global using System.Text.Json;
global using System.Text.Json.Serialization;
global using System.Text.RegularExpressions;
3 changes: 2 additions & 1 deletion Sentry-CI-Build-Linux.slnf
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"samples\\Sentry.Samples.ME.Logging\\Sentry.Samples.ME.Logging.csproj",
"samples\\Sentry.Samples.NLog\\Sentry.Samples.NLog.csproj",
"samples\\Sentry.Samples.Serilog\\Sentry.Samples.Serilog.csproj",
"src\\Sentry.Android.AssemblyReader\\Sentry.Android.AssemblyReader.csproj",
"src\\Sentry.AspNet\\Sentry.AspNet.csproj",
"src\\Sentry.AspNetCore.Grpc\\Sentry.AspNetCore.Grpc.csproj",
"src\\Sentry.AspNetCore\\Sentry.AspNetCore.csproj",
Expand All @@ -34,7 +35,7 @@
"src\\Sentry.NLog\\Sentry.NLog.csproj",
"src\\Sentry.Serilog\\Sentry.Serilog.csproj",
"src\\Sentry\\Sentry.csproj",
"test\\Sentry.Android.Tests\\Sentry.Android.Tests.csproj",
"test\\Sentry.Android.AssemblyReader.Tests\\Sentry.Android.AssemblyReader.Tests.csproj",
"test\\Sentry.AspNet.Tests\\Sentry.AspNet.Tests.csproj",
"test\\Sentry.AspNetCore.Grpc.Tests\\Sentry.AspNetCore.Grpc.Tests.csproj",
"test\\Sentry.AspNetCore.Tests\\Sentry.AspNetCore.Tests.csproj",
Expand Down
3 changes: 2 additions & 1 deletion Sentry-CI-Build-Windows.slnf
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"samples\\Sentry.Samples.ME.Logging\\Sentry.Samples.ME.Logging.csproj",
"samples\\Sentry.Samples.NLog\\Sentry.Samples.NLog.csproj",
"samples\\Sentry.Samples.Serilog\\Sentry.Samples.Serilog.csproj",
"src\\Sentry.Android.AssemblyReader\\Sentry.Android.AssemblyReader.csproj",
"src\\Sentry.AspNet\\Sentry.AspNet.csproj",
"src\\Sentry.AspNetCore.Grpc\\Sentry.AspNetCore.Grpc.csproj",
"src\\Sentry.AspNetCore\\Sentry.AspNetCore.csproj",
Expand All @@ -33,7 +34,7 @@
"src\\Sentry.NLog\\Sentry.NLog.csproj",
"src\\Sentry.Serilog\\Sentry.Serilog.csproj",
"src\\Sentry\\Sentry.csproj",
"test\\Sentry.Android.Tests\\Sentry.Android.Tests.csproj",
"test\\Sentry.Android.AssemblyReader.Tests\\Sentry.Android.AssemblyReader.Tests.csproj",
"test\\Sentry.AspNet.Tests\\Sentry.AspNet.Tests.csproj",
"test\\Sentry.AspNetCore.Grpc.Tests\\Sentry.AspNetCore.Grpc.Tests.csproj",
"test\\Sentry.AspNetCore.Tests\\Sentry.AspNetCore.Tests.csproj",
Expand Down
3 changes: 2 additions & 1 deletion Sentry-CI-Build-macOS.slnf
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"samples\\Sentry.Samples.ME.Logging\\Sentry.Samples.ME.Logging.csproj",
"samples\\Sentry.Samples.NLog\\Sentry.Samples.NLog.csproj",
"samples\\Sentry.Samples.Serilog\\Sentry.Samples.Serilog.csproj",
"src\\Sentry.Android.AssemblyReader\\Sentry.Android.AssemblyReader.csproj",
"src\\Sentry.AspNet\\Sentry.AspNet.csproj",
"src\\Sentry.AspNetCore.Grpc\\Sentry.AspNetCore.Grpc.csproj",
"src\\Sentry.AspNetCore\\Sentry.AspNetCore.csproj",
Expand All @@ -36,7 +37,7 @@
"src\\Sentry.NLog\\Sentry.NLog.csproj",
"src\\Sentry.Serilog\\Sentry.Serilog.csproj",
"src\\Sentry\\Sentry.csproj",
"test\\Sentry.Android.Tests\\Sentry.Android.Tests.csproj",
"test\\Sentry.Android.AssemblyReader.Tests\\Sentry.Android.AssemblyReader.Tests.csproj",
"test\\Sentry.AspNet.Tests\\Sentry.AspNet.Tests.csproj",
"test\\Sentry.AspNetCore.Grpc.Tests\\Sentry.AspNetCore.Grpc.Tests.csproj",
"test\\Sentry.AspNetCore.Tests\\Sentry.AspNetCore.Tests.csproj",
Expand Down
1 change: 1 addition & 0 deletions Sentry-CI-CodeQL.slnf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"solution": {
"path": "Sentry.sln",
"projects": [
"src\\Sentry.Android.AssemblyReader\\Sentry.Android.AssemblyReader.csproj",
"src\\Sentry.AspNetCore.Grpc\\Sentry.AspNetCore.Grpc.csproj",
"src\\Sentry.AspNetCore\\Sentry.AspNetCore.csproj",
"src\\Sentry.AspNet\\Sentry.AspNet.csproj",
Expand Down
1 change: 1 addition & 0 deletions Sentry-CI-Pack.slnf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"solution": {
"path": "Sentry.sln",
"projects": [
"src\\Sentry.Android.AssemblyReader\\Sentry.Android.AssemblyReader.csproj",
"src\\Sentry.AspNetCore.Grpc\\Sentry.AspNetCore.Grpc.csproj",
"src\\Sentry.AspNetCore\\Sentry.AspNetCore.csproj",
"src\\Sentry.AspNet\\Sentry.AspNet.csproj",
Expand Down
2 changes: 1 addition & 1 deletion Sentry-CI-Test.slnf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"solution": {
"path": "Sentry.sln",
"projects": [
"test\\Sentry.Android.Tests\\Sentry.Android.Tests.csproj",
"test\\Sentry.Android.AssemblyReader.Tests\\Sentry.Android.AssemblyReader.Tests.csproj",
"test\\Sentry.AspNet.Tests\\Sentry.AspNet.Tests.csproj",
"test\\Sentry.AspNetCore.Grpc.Tests\\Sentry.AspNetCore.Grpc.Tests.csproj",
"test\\Sentry.AspNetCore.Tests\\Sentry.AspNetCore.Tests.csproj",
Expand Down
9 changes: 8 additions & 1 deletion Sentry.sln
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sentry.Bindings.Android", "
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sentry.Bindings.Cocoa", "src\Sentry.Bindings.Cocoa\Sentry.Bindings.Cocoa.csproj", "{F533FD6D-1E10-4F06-BE3A-3B3C713A75A6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sentry.Android.Tests", "test\Sentry.Android.Tests\Sentry.Android.Tests.csproj", "{5E12E053-22AF-4184-8581-3FCFD225617D}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sentry.Android.AssemblyReader.Tests", "test\Sentry.Android.AssemblyReader.Tests\Sentry.Android.AssemblyReader.Tests.csproj", "{5E12E053-22AF-4184-8581-3FCFD225617D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sentry.AspNetCore.TestUtils", "test\Sentry.AspNetCore.TestUtils\Sentry.AspNetCore.TestUtils.csproj", "{C96CB65D-3D2D-404E-85C0-69A3FC03B48F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sentry.Android.AssemblyReader", "src\Sentry.Android.AssemblyReader\Sentry.Android.AssemblyReader.csproj", "{ED5E4F7E-8267-4F3C-BD2A-779AC9BF3D7C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -409,6 +411,10 @@ Global
{C96CB65D-3D2D-404E-85C0-69A3FC03B48F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C96CB65D-3D2D-404E-85C0-69A3FC03B48F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C96CB65D-3D2D-404E-85C0-69A3FC03B48F}.Release|Any CPU.Build.0 = Release|Any CPU
{ED5E4F7E-8267-4F3C-BD2A-779AC9BF3D7C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{ED5E4F7E-8267-4F3C-BD2A-779AC9BF3D7C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{ED5E4F7E-8267-4F3C-BD2A-779AC9BF3D7C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{ED5E4F7E-8267-4F3C-BD2A-779AC9BF3D7C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -474,6 +480,7 @@ Global
{F533FD6D-1E10-4F06-BE3A-3B3C713A75A6} = {AF6AF4C7-8AA2-4D59-8064-2D79560904EB}
{5E12E053-22AF-4184-8581-3FCFD225617D} = {83263231-1A2A-4733-B759-EEFF14E8C5D5}
{C96CB65D-3D2D-404E-85C0-69A3FC03B48F} = {83263231-1A2A-4733-B759-EEFF14E8C5D5}
{ED5E4F7E-8267-4F3C-BD2A-779AC9BF3D7C} = {AF6AF4C7-8AA2-4D59-8064-2D79560904EB}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {0C652B1A-DF72-4EE5-A98B-194FE2C054F6}
Expand Down
3 changes: 2 additions & 1 deletion SentryMaui.slnf
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
"samples\\Sentry.Samples.Ios\\Sentry.Samples.Ios.csproj",
"samples\\Sentry.Samples.MacCatalyst\\Sentry.Samples.MacCatalyst.csproj",
"samples\\Sentry.Samples.Maui\\Sentry.Samples.Maui.csproj",
"src\\Sentry.Android.AssemblyReader\\Sentry.Android.AssemblyReader.csproj",
"src\\Sentry.Extensions.Logging\\Sentry.Extensions.Logging.csproj",
"src\\Sentry.Maui\\Sentry.Maui.csproj",
"src\\Sentry\\Sentry.csproj",
"test\\MauiTestUtils\\DeviceTests.Runners.SourceGen\\TestUtils.DeviceTests.Runners.SourceGen.csproj",
"test\\MauiTestUtils\\DeviceTests.Runners\\TestUtils.DeviceTests.Runners.csproj",
"test\\MauiTestUtils\\DeviceTests\\TestUtils.DeviceTests.csproj",
"test\\Sentry.Android.Tests\\Sentry.Android.Tests.csproj",
"test\\Sentry.Android.AssemblyReader.Tests\\Sentry.Android.AssemblyReader.Tests.csproj",
"test\\Sentry.Extensions.Logging.Tests\\Sentry.Extensions.Logging.Tests.csproj",
"test\\Sentry.Maui.Device.TestApp\\Sentry.Maui.Device.TestApp.csproj",
"test\\Sentry.Maui.Tests\\Sentry.Maui.Tests.csproj",
Expand Down
3 changes: 2 additions & 1 deletion SentryNoSamples.slnf
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"path": "Sentry.sln",
"projects": [
"benchmarks\\Sentry.Benchmarks\\Sentry.Benchmarks.csproj",
"src\\Sentry.Android.AssemblyReader\\Sentry.Android.AssemblyReader.csproj",
"src\\Sentry.AspNetCore.Grpc\\Sentry.AspNetCore.Grpc.csproj",
"src\\Sentry.AspNetCore\\Sentry.AspNetCore.csproj",
"src\\Sentry.AspNet\\Sentry.AspNet.csproj",
Expand All @@ -15,7 +16,7 @@
"src\\Sentry.NLog\\Sentry.NLog.csproj",
"src\\Sentry.Serilog\\Sentry.Serilog.csproj",
"src\\Sentry\\Sentry.csproj",
"test\\Sentry.Android.Tests\\Sentry.Android.Tests.csproj",
"test\\Sentry.Android.AssemblyReader.Tests\\Sentry.Android.AssemblyReader.Tests.csproj",
"test\\Sentry.AspNet.Tests\\Sentry.AspNet.Tests.csproj",
"test\\Sentry.AspNetCore.Grpc.Tests\\Sentry.AspNetCore.Grpc.Tests.csproj",
"test\\Sentry.AspNetCore.Tests\\Sentry.AspNetCore.Tests.csproj",
Expand Down
52 changes: 0 additions & 52 deletions scripts/update-test-apks.ps1

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
using System.Reflection.PortableExecutable;
using Sentry.Extensibility;

namespace Sentry.Android.AssemblyReader;

// The "Old" app type - where each DLL is placed in the 'assemblies' directory as an individual file.
internal sealed class AndroidAssemblyDirectoryReader : AndroidAssemblyReader, IAndroidAssemblyReader
{
public AndroidAssemblyDirectoryReader(ZipArchive zip, IList<string> supportedAbis, IDiagnosticLogger? logger)
public AndroidAssemblyDirectoryReader(ZipArchive zip, IList<string> supportedAbis, DebugLogger? logger)
: base(zip, supportedAbis, logger) { }

public PEReader? TryReadAssembly(string name)
{
var zipEntry = FindAssembly(name);
if (zipEntry is null)
{
Logger?.LogDebug("Couldn't find assembly {0} in the APK", name);
Logger?.Invoke("Couldn't find assembly {0} in the APK", name);
return null;
}

Logger?.LogDebug("Resolved assembly {0} in the APK at {1}", name, zipEntry.FullName);
Logger?.Invoke("Resolved assembly {0} in the APK at {1}", name, zipEntry.FullName);

// We need a seekable stream for the PEReader (or even to check whether the DLL is compressed), so make a copy.
var memStream = new MemoryStream((int)zipEntry.Length);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
using System.Reflection.PortableExecutable;
using Sentry.Extensibility;
using K4os.Compression.LZ4;

namespace Sentry.Android.AssemblyReader;

internal abstract class AndroidAssemblyReader : IDisposable
{
protected IDiagnosticLogger? Logger { get; }
protected DebugLogger? Logger { get; }
protected ZipArchive ZipArchive { get; }
protected IList<string> SupportedAbis { get; }

protected AndroidAssemblyReader(ZipArchive zip, IList<string> supportedAbis, IDiagnosticLogger? logger)
protected AndroidAssemblyReader(ZipArchive zip, IList<string> supportedAbis, DebugLogger? logger)
{
ZipArchive = zip;
Logger = logger;
Expand Down Expand Up @@ -55,7 +51,7 @@ protected PEReader CreatePEReader(string assemblyName, MemoryStream inputStream)
Debug.Assert(inputStream.Position == payloadOffset);
var inputLength = (int)(inputStream.Length - payloadOffset);

Logger?.LogDebug("Decompressing assembly ({0} bytes uncompressed) using LZ4", decompressedLength);
Logger?.Invoke("Decompressing assembly ({0} bytes uncompressed) using LZ4", decompressedLength);

var outputStream = new MemoryStream(decompressedLength);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
namespace Sentry.Android.AssemblyReader;

/// <summary>
/// A factory that creates an assembly reader for an Android APK.
/// </summary>
public static class AndroidAssemblyReaderFactory
{
/// <summary>
/// Opens an assembly reader.
/// </summary>
/// <param name="apkPath">The path to the APK</param>
/// <param name="supportedAbis">The supported ABIs</param>
/// <param name="logger">An optional logger for debugging</param>
/// <returns>The reader</returns>
public static IAndroidAssemblyReader Open(string apkPath, IList<string> supportedAbis, DebugLogger? logger = null)
{
logger?.Invoke("Opening APK: {0}", apkPath);
var zipArchive = ZipFile.Open(apkPath, ZipArchiveMode.Read);

if (zipArchive.GetEntry("assemblies/assemblies.manifest") is not null)
{
logger?.Invoke("APK uses AssemblyStore");
return new AndroidAssemblyStoreReader(zipArchive, supportedAbis, logger);
}

logger?.Invoke("APK doesn't use AssemblyStore");
return new AndroidAssemblyDirectoryReader(zipArchive, supportedAbis, logger);
}
}
Loading