-
Notifications
You must be signed in to change notification settings - Fork 0
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
feat: Portable Debug Data images #56
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
c17c71e
solution structure
miquelbeltran 5d3abdb
wip
miquelbeltran c26ea00
code simplification
miquelbeltran 9768df7
Add stacktrace and image tests
miquelbeltran bd96f92
Update README.md
miquelbeltran 76da870
Update README.md
miquelbeltran 9389009
Merge branch 'main' into 15-PEDebug-data
miquelbeltran ace3dc4
include ImageSignature in stacktrace if available
miquelbeltran 7a64ca8
Merge branch '15-PEDebug-data' of https://github.com/MindscapeHQ/rayg…
miquelbeltran 7e08972
add Android assembly reader
miquelbeltran 3c67f47
format
miquelbeltran File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
src/Raygun.Blazor.Maui/Platforms/Android/AndroidUtilities.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
using System.IO.Compression; | ||
using System.Runtime.InteropServices; | ||
using System.Text; | ||
|
||
namespace Raygun.Blazor.Maui; | ||
|
||
internal static class AndroidUtilities | ||
{ | ||
/// <summary> | ||
/// Factory method to create the correct assembly reader for the current application | ||
/// </summary> | ||
/// <returns></returns> | ||
public static IAssemblyReader? CreateAssemblyReader() | ||
{ | ||
var apkPath = Android.App.Application.Context.ApplicationInfo?.SourceDir; | ||
var supportedAbis = new List<string>(); | ||
|
||
if (Android.OS.Build.SupportedAbis != null) | ||
{ | ||
supportedAbis.AddRange(Android.OS.Build.SupportedAbis); | ||
} | ||
|
||
if (!File.Exists(apkPath)) | ||
{ | ||
// No apk, so return nothing | ||
return null; | ||
} | ||
|
||
if (!IsAndroidArchive(apkPath)) | ||
{ | ||
// Not a valid android archive so nothing to return | ||
return null; | ||
} | ||
|
||
// Open the apk file, and see if it has a manifest, if it does, | ||
// we are using the new assembly store method, | ||
// else it's just a normal zip with assemblies as archive entries | ||
using var zipArchive = ZipFile.Open(apkPath, ZipArchiveMode.Read); | ||
|
||
if (zipArchive.GetEntry("assemblies/assemblies.manifest") != null) | ||
{ | ||
return new AssemblyBlobStoreReader(zipArchive, supportedAbis); | ||
} | ||
|
||
return new AssemblyZipEntryReader(zipArchive, supportedAbis); | ||
} | ||
|
||
public static bool IsAndroidArchive(string filePath) | ||
{ | ||
return filePath.EndsWith(".aab", StringComparison.OrdinalIgnoreCase) || | ||
filePath.EndsWith(".apk", StringComparison.OrdinalIgnoreCase) || | ||
filePath.EndsWith(".zip", StringComparison.OrdinalIgnoreCase); | ||
} | ||
|
||
public static ReadOnlyMemory<byte> AsReadOnlyMemory(this Stream stream) | ||
{ | ||
ArgumentNullException.ThrowIfNull(stream); | ||
|
||
using var memoryStream = new MemoryStream(); | ||
stream.CopyTo(memoryStream); | ||
return new ReadOnlyMemory<byte>(memoryStream.ToArray()); | ||
} | ||
|
||
public static byte[] ToArray(this ReadOnlyMemory<byte> memory) | ||
{ | ||
if (!MemoryMarshal.TryGetArray(memory, out var segment)) | ||
{ | ||
throw new InvalidOperationException("Could not get array segment from ReadOnlyMemory."); | ||
} | ||
|
||
return segment.Array!; | ||
} | ||
|
||
public static BinaryReader GetBinaryReader(this ReadOnlyMemory<byte> memory, Encoding? encoding = null) | ||
{ | ||
return new BinaryReader(memory.AsStream(), encoding ?? Encoding.UTF8, false); | ||
} | ||
|
||
|
||
public static MemoryStream AsStream(this ReadOnlyMemory<byte> memory) | ||
{ | ||
return new MemoryStream(memory.ToArray(), writable: false); | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...this exception was captured...