Skip to content

Commit

Permalink
TargetFrameworks net35;net40
Browse files Browse the repository at this point in the history
  • Loading branch information
Aigio Li committed Feb 8, 2018
1 parent 3952e76 commit d7c3e89
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# unpack.libmonodroid_bundle_app.so
Unpack *.apk\lib\{ABI}\libmonodroid_bundle_app.so
Unpack *.apk\lib\\{ABI\}\libmonodroid_bundle_app.so
18 changes: 11 additions & 7 deletions unpack.libmonodroid_bundle_app.so/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,18 @@ void Main()
// ReSharper disable PossibleNullReferenceException
var entryAssembly = Assembly.GetEntryAssembly();
var title = entryAssembly.FullName.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).FirstOrDefault();
if (!string.IsNullOrWhiteSpace(title)) Console.Title = title;
// ReSharper disable once AssignNullToNotNullAttribute
if (!title.IsNullOrWhiteSpace()) Console.Title = title;
var rootPath = Path.GetDirectoryName(entryAssembly.Location);
if (rootPath == null) throw new ArgumentNullException(nameof(rootPath));
var sofilepaths = Directory.GetFiles(rootPath).Where(x =>
Path.GetExtension(x).Equals(GetSoFileExtension(), StringComparison.OrdinalIgnoreCase)).ToArray();
var sofilepath =
sofilepaths.FirstOrDefault(x => Path.GetFileName(x).Equals(GetSoDefaultFileName(), StringComparison.OrdinalIgnoreCase)) ??
sofilepaths.FirstOrDefault();
var sofilepath = args?.FirstOrDefault(x => x != null && File.Exists(x) && Path.GetExtension(x).Equals(GetSoFileExtension(), StringComparison.OrdinalIgnoreCase));
if (sofilepath == null)
{
var sofilepaths = Directory.GetFiles(rootPath).Where(x => Path.GetExtension(x).Equals(GetSoFileExtension(), StringComparison.OrdinalIgnoreCase)).ToArray();
sofilepath =
sofilepaths.FirstOrDefault(x => Path.GetFileName(x).Equals(GetSoDefaultFileName(), StringComparison.OrdinalIgnoreCase)) ??
sofilepaths.FirstOrDefault();
}
if (sofilepath == null) ReadLineAndExit("Can not find the .so file.");
// ReSharper disable once AssignNullToNotNullAttribute
var bytes = File.ReadAllBytes(sofilepath);
Expand All @@ -71,7 +75,7 @@ void Main()
addr += i;

var name = GetString(bytes, addr);
if (string.IsNullOrWhiteSpace(name))
if (name.IsNullOrWhiteSpace())
break;

//We only care about dlls
Expand Down
13 changes: 12 additions & 1 deletion unpack.libmonodroid_bundle_app.so/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
using System.Runtime.CompilerServices;
using System.Reflection;
using System.Runtime.CompilerServices;

[assembly: SuppressIldasm]

[assembly: AssemblyTitle("unpack.libmonodroid_bundle_app.so " +
#if NET35
".NET Framework 3.5"
#elif NET40
".NET Framework 4.0"
#else
""
#endif
)]
42 changes: 42 additions & 0 deletions unpack.libmonodroid_bundle_app.so/StreamExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#if NET35

// ReSharper disable once CheckNamespace
namespace System.IO
{
/// <summary>
/// CopyTo .NET Framework 3.5
/// </summary>
public static class StreamExtension
{
public static void CopyTo(this Stream source, Stream destination) => CopyTo(source, destination, 81920);

public static void CopyTo(this Stream source, Stream destination, int bufferSize)
{
if (source == null)
throw new ArgumentNullException(nameof(source));
if (destination == null)
throw new ArgumentNullException(nameof(destination));
if (bufferSize <= 0)
throw new ArgumentOutOfRangeException(nameof(bufferSize), "ArgumentOutOfRange_NeedPosNum");
if (!source.CanRead && !source.CanWrite)
throw new ObjectDisposedException(nameof(source), "ObjectDisposed_StreamClosed");
if (!destination.CanRead && !destination.CanWrite)
throw new ObjectDisposedException(nameof(destination), "ObjectDisposed_StreamClosed");
if (!source.CanRead)
throw new NotSupportedException(nameof(source) + "_NotSupported_UnreadableStream");
if (!destination.CanWrite)
throw new NotSupportedException(nameof(destination) + "_NotSupported_UnwritableStream");
InternalCopyTo(source, destination, bufferSize);
}

private static void InternalCopyTo(Stream source, Stream destination, int bufferSize)
{
byte[] buffer = new byte[bufferSize];
int count;
while ((count = source.Read(buffer, 0, buffer.Length)) != 0)
destination.Write(buffer, 0, count);
}
}
}

#endif
43 changes: 43 additions & 0 deletions unpack.libmonodroid_bundle_app.so/StringExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// ReSharper disable once CheckNamespace
namespace System
{
/// <summary>
/// System.String Extension
/// </summary>
public static partial class StringExtension
{
#if NET35
/// <summary>
/// 指示指定的字符串是 <see langword="null" />、空还是仅由空白字符组成。
/// </summary>
/// <param name="value">要测试的字符串。</param>
/// <returns>
/// 如果 <see langword="true" /> 参数为 <paramref name="value" /> 或 <see langword="null" />,或者如果 <see cref="F:System.String.Empty" /> 仅由空白字符组成,则为 <paramref name="value" />。
/// </returns>
public static bool IsNullOrWhiteSpace(this string value)
{
if (value == null)
return true;
for (int index = 0; index < value.Length; ++index)
{
if (!char.IsWhiteSpace(value[index]))
return false;
}
return true;
}

#else

/// <summary>
/// 指示指定的字符串是 <see langword="null" />、空还是仅由空白字符组成。
/// </summary>
/// <param name="value">要测试的字符串。</param>
/// <returns>
/// 如果 <see langword="true" /> 参数为 <paramref name="value" /> 或 <see langword="null" />,或者如果 <see cref="F:System.String.Empty" /> 仅由空白字符组成,则为 <paramref name="value" />。
/// </returns>
public static bool IsNullOrWhiteSpace(this string value) => string.IsNullOrWhiteSpace(value);

#endif

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,22 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net45</TargetFramework>
<SignAssembly>false</SignAssembly>
<TargetFrameworks>net35;net40</TargetFrameworks>
<SignAssembly>true</SignAssembly>
<LangVersion>latest</LangVersion>
<PlatformTarget>AnyCPU</PlatformTarget>
<ApplicationManifest>Properties\app.manifest</ApplicationManifest>
<GenerateAssemblyTitleAttribute>false</GenerateAssemblyTitleAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyCopyrightAttribute>false</GenerateAssemblyCopyrightAttribute>
<DelaySign>false</DelaySign>
<AssemblyOriginatorKeyFile>unpack.libmonodroid_bundle_app.so.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)'=='Release'">
<DebugType>none</DebugType>
<DebugSymbols>false</DebugSymbols>
</PropertyGroup>

<ItemGroup>
Expand Down
Binary file not shown.

0 comments on commit d7c3e89

Please sign in to comment.