This repository has been archived by the owner on Jul 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added warning when module is installed in /Modules and subscribed on …
…Workshop at the same time
- Loading branch information
Showing
4 changed files
with
91 additions
and
71 deletions.
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
60 changes: 60 additions & 0 deletions
60
src/Bannerlord.BUTRLoader.LauncherEx/Helpers/ModuleChecker.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,60 @@ | ||
using Bannerlord.BUTR.Shared.Helpers; | ||
using Bannerlord.ModuleManager; | ||
|
||
using Mono.Cecil; | ||
using Mono.Cecil.Rocks; | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
|
||
using TaleWorlds.Library; | ||
using TaleWorlds.MountAndBlade; | ||
|
||
namespace Bannerlord.BUTRLoader.Helpers | ||
{ | ||
internal static class ModuleChecker | ||
{ | ||
private static readonly HashSet<string> MainModules = ModuleInfoHelper.GetPhysicalModules().Select(x => x.Id).ToHashSet(); | ||
private static readonly HashSet<string> ExternalModules = ModuleInfoHelper.GetPlatformModules().Select(x => x.Id).ToHashSet(); | ||
|
||
public static bool IsInstalledInMainAndExternalModuleDirectory(ModuleInfoExtendedWithMetadata moduleInfoExtended) => | ||
MainModules.Contains(moduleInfoExtended.Id) && ExternalModules.Contains(moduleInfoExtended.Id); | ||
|
||
public static bool IsObfuscated(ModuleInfoExtendedWithMetadata moduleInfoExtended) | ||
{ | ||
static bool CanBeLoaded(SubModuleInfoExtended x) => | ||
ModuleInfoHelper.CheckIfSubModuleCanBeLoaded(x, ApplicationPlatform.CurrentPlatform, ApplicationPlatform.CurrentRuntimeLibrary, DedicatedServerType.None, false); | ||
|
||
foreach (var subModule in moduleInfoExtended.SubModules.Where(CanBeLoaded)) | ||
{ | ||
var asm = Path.GetFullPath(Path.Combine(moduleInfoExtended.Path, "bin", "Win64_Shipping_Client", subModule.DLLName)); | ||
|
||
try | ||
{ | ||
using var moduleDefinition = ModuleDefinition.ReadModule(asm); | ||
|
||
var hasObfuscationAttributeUsed = moduleDefinition.GetCustomAttributes().Any(x => x.Constructor.DeclaringType.Name switch | ||
{ | ||
"ConfusedByAttribute" => true, | ||
_ => false | ||
}); | ||
var hasObfuscationAttributeDeclared = moduleDefinition.Types.Any(x => x.Name switch | ||
{ | ||
"ConfusedByAttribute" => true, | ||
_ => false | ||
}); | ||
// Every module should have a module initializer. If it's missing, someone is hiding it | ||
var hasModuleInitializer = moduleDefinition.GetAllTypes().Any(x => x.Name == "<Module>"); | ||
|
||
return hasObfuscationAttributeUsed || hasObfuscationAttributeDeclared || !hasModuleInitializer; | ||
} | ||
// Failing to read the metadata is a direct sign of metadata manipulation | ||
catch (Exception) { return true; } | ||
} | ||
|
||
return false; | ||
} | ||
} | ||
} |
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