Skip to content
New issue

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

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

Already on GitHub? # to your account

Support loading compressed Xamarin assemblies, see #2137 #2471

Conversation

cpraehaus
Copy link
Contributor

Fixes #2137.

Problem

Assemblies included in mobile Android apps created with Xamarin can be compressed. This PR detects compressed assemblies and attempts to decompress them in order to correctly load the assembly. This is handy when analyzing mobile apps created with Xamarin using ILSpy.

Solution

  • Extend class LoadedAssembly to detect and load compressed Xamarin assemblies if direct loading of assembly fails.
  • Requires Nuget pkg K4os.Compression.LZ4 for LZ4 decompression.

Extend class LoadedAssembly to detect and load compressed Xamarin assemblies if direct loading of assembly fails.

Requires Nuget pkg K4os.Compression.LZ4 for LZ4 decompression.
var descIdx = fileReader.ReadUInt32();
var uncLen = fileReader.ReadUInt32();
// fileReader stream position is now at compressed module data
var src = fileReader.ReadBytes((int)uncLen); // compressed length must be smaller than uncompressed length
Copy link

@Falco20019 Falco20019 Aug 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would read the complete rest of the file instead of relying on an assumption here. Like using fileStream.Length - 12.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, now using fileStream.Length to read all remaining data. Not accounting for compressed header length since ReadBytes() will stop at stream end anyway. We also save us from having a new constant and checking for (theoretical case) fileStream.Length < 12

@dgrunwald
Copy link
Member

The K4os.Compression.LZ4 license should be added to doc/third-party-notices.txt

@cpraehaus
Copy link
Contributor Author

The K4os.Compression.LZ4 license should be added to doc/third-party-notices.txt

Added license notice for K4os.Compression.LZ4.

@siegfriedpammer
Copy link
Member

Thank you for your contribution!

@siegfriedpammer siegfriedpammer merged commit 7473ff2 into icsharpcode:master Aug 7, 2021
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Could not decompile dll from apk of Xamarin.Android
4 participants