Browse Source

Added anti-malware related config options

pull/72/head
Anairkoen Schno 3 years ago
parent
commit
53f94fcb80
Signed by: DaNike GPG Key ID: BEFB74D5F3FC4387
3 changed files with 40 additions and 31 deletions
  1. +15
    -23
      IPA.Injector/Injector.cs
  2. +6
    -7
      IPA.Loader/AntiMalware/AntiMalwareEngine.cs
  3. +19
    -1
      IPA.Loader/Config/SelfConfig.cs

+ 15
- 23
IPA.Injector/Injector.cs View File

@ -1,4 +1,6 @@
using IPA.Config;
#nullable enable
using IPA.AntiMalware;
using IPA.Config;
using IPA.Injector.Backups;
using IPA.Loader;
using IPA.Logging;
@ -29,8 +31,8 @@ namespace IPA.Injector
// ReSharper disable once UnusedMember.Global
internal static class Injector
{
private static Task pluginAsyncLoadTask;
private static Task permissionFixTask;
private static Task? pluginAsyncLoadTask;
private static Task? permissionFixTask;
//private static string otherNewtonsoftJson = null;
// ReSharper disable once UnusedParameter.Global
@ -40,7 +42,7 @@ namespace IPA.Injector
// and since this class doesn't have any static fields that
// aren't defined in mscorlib, we can control exactly what
// gets loaded.
_ = args;
try
{
if (Environment.GetCommandLineArgs().Contains("--verbose"))
@ -48,16 +50,6 @@ namespace IPA.Injector
SetupLibraryLoading();
/*var otherNewtonsoft = Path.Combine(
Directory.EnumerateDirectories(Environment.CurrentDirectory, "*_Data").First(),
"Managed",
"Newtonsoft.Json.dll");
if (File.Exists(otherNewtonsoft))
{ // this game ships its own Newtonsoft; force load ours and flag loading theirs
LibLoader.LoadLibrary(new AssemblyName("Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed"));
otherNewtonsoftJson = otherNewtonsoft;
}*/
EnsureDirectories();
// this is weird, but it prevents Mono from having issues loading the type.
@ -93,6 +85,9 @@ namespace IPA.Injector
GameVersionEarly.Load();
// load the anti-malware engine
_ = AntiMalwareEngine.Engine;
Updates.InstallPendingUpdates();
LibLoader.SetupAssemblyFilenames(true);
@ -110,9 +105,9 @@ namespace IPA.Injector
{
string path;
if (!Directory.Exists(path = Path.Combine(Environment.CurrentDirectory, "UserData")))
Directory.CreateDirectory(path);
_ = Directory.CreateDirectory(path);
if (!Directory.Exists(path = Path.Combine(Environment.CurrentDirectory, "Plugins")))
Directory.CreateDirectory(path);
_ = Directory.CreateDirectory(path);
}
private static void SetupLibraryLoading()
@ -184,7 +179,7 @@ namespace IPA.Injector
goto endPatchCoreModule;
}
MethodDefinition cctor = null;
MethodDefinition? cctor = null;
foreach (var m in application.Methods)
if (m.IsRuntimeSpecialName && m.Name == ".cctor")
cctor = m;
@ -311,9 +306,6 @@ namespace IPA.Injector
if (bootstrapped) return;
bootstrapped = true;
/*if (otherNewtonsoftJson != null)
Assembly.LoadFrom(otherNewtonsoftJson);*/
Application.logMessageReceived += delegate (string condition, string stackTrace, LogType type)
{
@ -336,12 +328,12 @@ namespace IPA.Injector
private static void Bootstrapper_Destroyed()
{
// wait for plugins to finish loading
pluginAsyncLoadTask.Wait();
permissionFixTask.Wait();
pluginAsyncLoadTask?.Wait();
permissionFixTask?.Wait();
log.Debug("Plugins loaded");
log.Debug(string.Join(", ", PluginLoader.PluginsMetadata.StrJP()));
PluginComponent.Create();
_ = PluginComponent.Create();
}
}
}

+ 6
- 7
IPA.Loader/AntiMalware/AntiMalwareEngine.cs View File

@ -1,10 +1,6 @@
#nullable enable
using IPA.Config;
using IPA.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace IPA.AntiMalware
{
@ -23,10 +19,13 @@ namespace IPA.AntiMalware
private static IAntiMalware InitializeEngine()
{
IAntiMalware? engine = null;
if (SelfConfig.AntiMalware_.UseIfAvailable_)
{
#if !NET35
engine = WindowsCOMAntiMalware.TryInitialize();
engine = WindowsCOMAntiMalware.TryInitialize();
#endif
engine ??= WindowsWin32AntiMalware.TryInitialize();
engine ??= WindowsWin32AntiMalware.TryInitialize();
}
engine ??= new NoopAntiMalware();
Logger.AntiMalware.Debug($"Antimalware engine initialized with {engine.GetType()}");


+ 19
- 1
IPA.Loader/Config/SelfConfig.cs View File

@ -79,6 +79,9 @@ namespace IPA.Config
// Debug.CondenseModLogs
internal static SelfConfig CommandLineValues = new();
// For readability's sake, I want the default values to be visible in source.
#pragma warning disable CA1805 // Do not initialize unnecessarily
// END: section ignore
public virtual bool Regenerate { get; set; } = true;
@ -149,7 +152,22 @@ namespace IPA.Config
// LINE: ignore
[NonNullable]
public virtual Debug_ Debug { get; set; } = new Debug_();
public virtual Debug_ Debug { get; set; } = new();
public class AntiMalware_
{
public virtual bool UseIfAvailable { get; set; } = true;
// LINE: ignore
public static bool UseIfAvailable_ => Instance?.AntiMalware?.UseIfAvailable ?? true;
public virtual bool LoadPartialThreatPlugins { get; set; } = false;
// LINE: ignore
public static bool LoadPartialThreatPlugins_ => Instance?.AntiMalware?.LoadPartialThreatPlugins ?? true;
}
// LINE: ignore
[NonNullable]
public virtual AntiMalware_ AntiMalware { get; set; } = new();
public virtual bool YeetMods { get; set; } = true;
// LINE: ignore 2


Loading…
Cancel
Save