Skip to content

Commit

Permalink
Merge pull request #125 from sunnamed434/dev
Browse files Browse the repository at this point in the history
Bump new version 0.15.1-alpha.28
  • Loading branch information
sunnamed434 committed Apr 28, 2023
2 parents 494bfed + dfbfd93 commit 463ba90
Show file tree
Hide file tree
Showing 34 changed files with 326 additions and 259 deletions.
398 changes: 233 additions & 165 deletions CHANGELOG.md

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions props/SharedProjectProps.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/sunnamed434/BitMono</PackageProjectUrl>
<PackageOwners>sunnamed434</PackageOwners>
<PackageVersion>0.15.0-alpha.27</PackageVersion>
<PackageVersion>0.15.1-alpha.28</PackageVersion>
<RepositoryUrl>https://github.com/sunnamed434/BitMono</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<Authors>sunnamed434</Authors>
<Version>0.15.0-alpha.27</Version>
<InformationalVersion>0.15.0-alpha.27</InformationalVersion>
<Version>0.15.1-alpha.28</Version>
<InformationalVersion>0.15.1-alpha.28</InformationalVersion>
<Company>BitMono</Company>
<Copyright>sunnamed434</Copyright>
<LangVersion>10</LangVersion>
Expand Down
4 changes: 0 additions & 4 deletions src/BitMono.API/BitMono.API.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,4 @@
<ProjectReference Include="..\BitMono.Shared\BitMono.Shared.csproj" />
</ItemGroup>

<ItemGroup>
<Folder Include="Services\" />
</ItemGroup>

</Project>
1 change: 1 addition & 0 deletions src/BitMono.API/GlobalUsings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
global using System.Collections.Generic;
global using System.Diagnostics.CodeAnalysis;
global using System.Threading.Tasks;
global using BitMono.API.Protections;
global using IModule = Autofac.Core.IModule;
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace BitMono.API;
namespace BitMono.API.Protections;

public interface IPacker : IProtection
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace BitMono.API.Pipeline;
namespace BitMono.API.Protections;

public interface IPhaseProtection : IProtection
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace BitMono.API.Pipeline;
namespace BitMono.API.Protections;

public interface IPipelineProtection : IProtection
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace BitMono.API;
namespace BitMono.API.Protections;

public interface IProtection
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace BitMono.API.Contexts;
namespace BitMono.API.Protections;

[SuppressMessage("ReSharper", "UnusedType.Global")]
public class ProtectionParameters
Expand Down
2 changes: 2 additions & 0 deletions src/BitMono.CLI/GlobalUsings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
global using System.Threading.Tasks;
global using BitMono.Host.Extensions;
global using BitMono.Obfuscation.Files;
global using BitMono.Obfuscation.Starter;
global using BitMono.Shared.Models;
global using BitMono.Utilities.Paths;
global using CommandLine;
global using Microsoft.Extensions.DependencyInjection;
global using Microsoft.Extensions.Options;
global using Pocket.Extensions;
global using Serilog;
Expand Down
9 changes: 4 additions & 5 deletions src/BitMono.CLI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@ private static async Task<int> Main(string[] args)
.RegisterModule(module)
.Build();

var lifetimeScope = serviceProvider.LifetimeScope;
var obfuscation = lifetimeScope.Resolve<IOptions<ObfuscationSettings>>().Value;
var logger = lifetimeScope
.Resolve<ILogger>()
var obfuscation = serviceProvider.GetRequiredService<IOptions<ObfuscationSettings>>().Value;
var logger = serviceProvider
.GetRequiredService<ILogger>()
.ForContext<Program>();
var needs = new ObfuscationNeedsFactory(args, logger).Create();
if (needs == null)
Expand All @@ -48,7 +47,7 @@ private static async Task<int> Main(string[] args)
logger.Information(AsciiArt);

var info = new IncompleteFileInfo(needs.FileName, needs.ReferencesDirectoryName, needs.OutputPath);
var engine = new BitMonoEngine(serviceProvider);
var engine = new BitMonoStarter(serviceProvider);
var succeed = await engine.StartAsync(info, CancellationTokenSource.Token);
if (succeed == false)
{
Expand Down
2 changes: 1 addition & 1 deletion src/BitMono.Core/Attributes/RuntimeMonikerAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace BitMono.Core.Attributes;
/// <remarks>i.e if you see this attribute on protection then only specified attributes are the supported runtime monikers.
/// If you don't see any of the attributes then it works everywhere, also, users will get message via <see cref="GetMessage"/></remarks>
/// </summary>
[AttributeUsage(AttributeTargets.Class, Inherited = false)]
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = true)]
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
public abstract class RuntimeMonikerAttribute : Attribute
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace BitMono.Core.Contexts;

[SuppressMessage("ReSharper", "UnusedAutoPropertyAccessor.Global")]
public class EngineContext
public class StarterContext
{
#pragma warning disable CS8618
public ModuleDefinition Module { get; set; }
Expand Down
17 changes: 8 additions & 9 deletions src/BitMono.Core/Extensions/ProtectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,17 @@ public static bool TryGetDoNotResolveAttribute(this IPacker source, out DoNotRes
{
return typeof(TProtection).TryGetDoNotResolveAttribute(out attribute);
}
public static bool TryGetRuntimeMonikerAttribute(this Type source, out RuntimeMonikerAttribute? attribute, bool inherit = false)
public static RuntimeMonikerAttribute[] GetRuntimeMonikerAttributes(this Type source, bool inherit = false)
{
attribute = source.GetCustomAttribute<RuntimeMonikerAttribute>(inherit);
if (attribute == null)
{
return false;
}
return true;
return source
.GetCustomAttributes<RuntimeMonikerAttribute>(inherit)
.ToArray();
}
public static bool TryGetRuntimeMonikerAttribute(this IProtection source, out RuntimeMonikerAttribute? attribute)
public static RuntimeMonikerAttribute[] GetRuntimeMonikerAttributes(this IProtection source)
{
return source.GetType().TryGetRuntimeMonikerAttribute(out attribute);
return source
.GetType()
.GetRuntimeMonikerAttributes();
}
public static bool TryGetObsoleteAttribute(this Type source, out ObsoleteAttribute? attribute, bool inherit = false)
{
Expand Down
3 changes: 1 addition & 2 deletions src/BitMono.Core/GlobalUsings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
global using AsmResolver.PE.File.Headers;
global using BitMono.API;
global using BitMono.API.Analyzing;
global using BitMono.API.Contexts;
global using BitMono.API.Pipeline;
global using BitMono.API.Protections;
global using BitMono.API.Resolvers;
global using BitMono.Core.Analyzing;
global using BitMono.Core.Attributes;
Expand Down
2 changes: 1 addition & 1 deletion src/BitMono.Core/Resolvers/AssemblyResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ namespace BitMono.Core.Resolvers;

public static class AssemblyResolver
{
public static AssemblyResolve Resolve(IEnumerable<byte[]> dependenciesData, EngineContext context)
public static AssemblyResolve Resolve(IEnumerable<byte[]> dependenciesData, StarterContext context)
{
context.ThrowIfCancellationRequested();

Expand Down
2 changes: 1 addition & 1 deletion src/BitMono.Core/Services/EngineContextAccessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

public class EngineContextAccessor : IEngineContextAccessor
{
public EngineContext Instance { get; set; }
public StarterContext Instance { get; set; }
}
2 changes: 1 addition & 1 deletion src/BitMono.Core/Services/IEngineContextAccessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ namespace BitMono.Core.Services;

public interface IEngineContextAccessor
{
EngineContext Instance { get; set; }
StarterContext Instance { get; set; }
}
1 change: 1 addition & 0 deletions src/BitMono.GUI/GlobalUsings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
global using BitMono.GUI.Utilities.Extensions;
global using BitMono.Host.Extensions;
global using BitMono.Obfuscation.Files;
global using BitMono.Obfuscation.Starter;
global using CommunityToolkit.Maui;
global using Microsoft.Extensions.Options;
global using static BitMono.Utilities.Collections.CollectionExtensions;
Expand Down
5 changes: 2 additions & 3 deletions src/BitMono.GUI/Pages/Obfuscation/Protect.razor.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using BitMono.Core.Contexts;
using BitMono.Obfuscation;
using BitMono.API.Protections;

namespace BitMono.GUI.Pages.Obfuscation;

Expand Down Expand Up @@ -39,7 +38,7 @@ await _obfuscationFile
var fileData = memoryStream.ToArray();

//var info = new CompleteFileInfo(_obfuscationFile.Name, fileData, _dependenciesDirectoryName, _outputDirectoryName)
var engine = new BitMonoEngine(ServiceProvider);
var engine = new BitMonoStarter(ServiceProvider);
await engine.StartAsync(new IncompleteFileInfo("", "", ""), _cancellationToken);
}
catch (Exception ex)
Expand Down
2 changes: 2 additions & 0 deletions src/BitMono.GUI/Pages/Obfuscation/Protections.razor.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using BitMono.API.Protections;

namespace BitMono.GUI.Pages.Obfuscation;

public partial class Protections
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace BitMono.Host.Extensions;

[SuppressMessage("ReSharper", "UnusedMethodReturnValue.Global")]
[SuppressMessage("ReSharper", "IdentifierTypo")]
public static class AutofacServiceProviderExtensions
public static class AutofacContainerBuilderExtensions
{
private const string ProtectionsFileName = "BitMono.Protections.dll";

Expand Down
2 changes: 1 addition & 1 deletion src/BitMono.Host/GlobalUsings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
global using System.Text.RegularExpressions;
global using BitMono.API;
global using BitMono.API.Analyzing;
global using BitMono.API.Pipeline;
global using BitMono.API.Protections;
global using BitMono.API.Resolvers;
global using BitMono.Core.Configuration;
global using BitMono.Core.Factories;
Expand Down
10 changes: 0 additions & 10 deletions src/BitMono.Host/README.md

This file was deleted.

9 changes: 6 additions & 3 deletions src/BitMono.Obfuscation/BitMonoObfuscator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
public class BitMonoObfuscator
{
private readonly IServiceProvider _serviceProvider;
private readonly EngineContext _context;
private readonly StarterContext _context;
private readonly IDataWriter _dataWriter;
private readonly ObfuscationSettings _obfuscationSettings;
private readonly InvokablePipeline _invokablePipeline;
Expand All @@ -22,7 +22,7 @@ public class BitMonoObfuscator

public BitMonoObfuscator(
IServiceProvider serviceProvider,
EngineContext context,
StarterContext context,
IDataWriter dataWriter,
ObfuscationSettings obfuscationSettings,
ILogger logger)
Expand Down Expand Up @@ -121,6 +121,7 @@ private Task<bool> ResolveDependenciesAsync()
var reference = failedToResolveReferences[i];
_logger.Warning("Failed to resolve dependency: {0}", reference.FullName);
}
_logger.Information("References resolve have been completed!");
if (assemblyResolve.Succeed == false)
{
if (_obfuscationSettings.FailOnNoRequiredDependency)
Expand All @@ -144,6 +145,7 @@ private Task<bool> ExpandMacrosAsync()
}
private async Task<bool> RunProtectionsAsync()
{
_logger.Information("Executing Protections... this could take for a while...");
foreach (var protection in _protectionsSort!.SortedProtections)
{
_context.ThrowIfCancellationRequested();
Expand Down Expand Up @@ -227,7 +229,7 @@ private async Task<bool> WriteModuleAsync()
.CreateFile(_imageBuild!.ConstructedImage!)
.Write(memoryStream);
await _dataWriter.WriteAsync(_context.BitMonoContext.OutputFile, memoryStream.ToArray());
_logger.Information("Protected module`s saved in {0}", _context.BitMonoContext.OutputDirectoryName);
_logger.Information("The protected module was saved in {0}", _context.BitMonoContext.OutputDirectoryName);
}
catch (Exception ex)
{
Expand All @@ -245,6 +247,7 @@ private async Task<bool> PackAsync()
await packer.ExecuteAsync();
_protectionExecutionNotifier.Notify(packer);
}
_logger.Information("Protections have been executed!");
return true;
}
private Task<bool> OutputElapsedTimeAsync()
Expand Down
3 changes: 1 addition & 2 deletions src/BitMono.Obfuscation/GlobalUsings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@
global using AsmResolver.PE.DotNet;
global using AsmResolver.PE.File.Headers;
global using BitMono.API;
global using BitMono.API.Pipeline;
global using BitMono.API.Protections;
global using BitMono.Core.Contexts;
global using BitMono.Core.Pipeline;
global using BitMono.Core.Resolvers;
global using BitMono.Core.Services;
global using BitMono.Obfuscation.Engine;
global using BitMono.Obfuscation.Files;
global using BitMono.Obfuscation.Logging;
global using BitMono.Obfuscation.Modules;
Expand Down
25 changes: 14 additions & 11 deletions src/BitMono.Obfuscation/Notifiers/ProtectionsNotifier.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
#pragma warning disable CS8602
namespace BitMono.Obfuscation.Notifiers;
namespace BitMono.Obfuscation.Notifiers;

public class ProtectionsNotifier
{
private readonly ObfuscationSettings _obfuscationSettings;
private readonly ILogger m_Logger;
private readonly ILogger _logger;

public ProtectionsNotifier(ObfuscationSettings obfuscationSettings, ILogger logger)
{
_obfuscationSettings = obfuscationSettings;
m_Logger = logger.ForContext<ProtectionsNotifier>();
_logger = logger.ForContext<ProtectionsNotifier>();
}

[SuppressMessage("ReSharper", "InvertIf")]
Expand All @@ -21,7 +20,7 @@ public void Notify(ProtectionsSort protectionsSort)
if (protectionsSort.HasProtections)
{
var stringBuilder = new StringBuilder();
stringBuilder.Append(string.Join(", ", protectionsSort.SortedProtections.Select(p => $"{p.GetName()}")));
stringBuilder.Append(string.Join(", ", protectionsSort.SortedProtections.Select(p => p.GetName())));
if (protectionsSort.Pipelines.Any())
{
stringBuilder.Append(", ");
Expand All @@ -32,25 +31,29 @@ public void Notify(ProtectionsSort protectionsSort)
stringBuilder.Append(", ");
stringBuilder.Append(string.Join(", ", protectionsSort.Packers.Select(p => p.GetName())));
}
m_Logger.Information("Enabled protections: {0}", stringBuilder.ToString());
var runtimeMonikerNotifier = new ProtectionsRuntimeMonikerNotifier(_obfuscationSettings, m_Logger);
var enabledProtectionsCount = protectionsSort.SortedProtections.Count()
+ protectionsSort.Pipelines.Count()
+ protectionsSort.Packers.Count();
_logger.Information("({0}) Enabled protection(s): {1}", enabledProtectionsCount, stringBuilder.ToString());
var runtimeMonikerNotifier = new ProtectionsRuntimeMonikerNotifier(_obfuscationSettings, _logger);
runtimeMonikerNotifier.Notify(protectionsSort);
}
if (protectionsSort.DeprecatedProtections.Any())
{
m_Logger.Warning("Skip deprecated protections: {0}", string.Join(", ", protectionsSort.DeprecatedProtections.Select(p => p?.GetName())));
_logger.Warning("Skip deprecated protection(s): {0}", string.Join(", ", protectionsSort.DeprecatedProtections.Select(p => p?.GetName())));
}
if (protectionsSort.ProtectionsResolve.DisabledProtections.Any())
{
m_Logger.Warning("Disabled protections: {0}", string.Join(", ", protectionsSort.ProtectionsResolve.DisabledProtections.Select(p => p ?? "Unnamed Protection")));
var disabledProtectionsCount = protectionsSort.ProtectionsResolve.DisabledProtections.Count;
_logger.Warning("({0}) Disabled protection(s): {1}", disabledProtectionsCount, string.Join(", ", protectionsSort.ProtectionsResolve.DisabledProtections.Select(p => p ?? "Unnamed Protection")));
}
if (protectionsSort.ProtectionsResolve.UnknownProtections.Any())
{
m_Logger.Warning("Unknown protections: {0}", string.Join(", ", protectionsSort.ProtectionsResolve.UnknownProtections.Select(p => p ?? "Unnamed Protection")));
_logger.Warning("Unknown protection(s): {0}", string.Join(", ", protectionsSort.ProtectionsResolve.UnknownProtections.Select(p => p ?? "Unnamed Protection")));
}
if (protectionsSort.ObfuscationAttributeExcludeProtections.Any())
{
m_Logger.Warning("Skip protections with obfuscation attribute: {0}", string.Join(", ", protectionsSort.ObfuscationAttributeExcludeProtections.Select(p => p?.GetName())));
_logger.Warning("Skip protection(s) with obfuscation attribute: {0}", string.Join(", ", protectionsSort.ObfuscationAttributeExcludeProtections.Select(p => p?.GetName())));
}
}
}
Expand Down

0 comments on commit 463ba90

Please sign in to comment.