mirror of
https://github.com/BepInEx/BepInEx.git
synced 2026-10-20 01:46:13 +00:00
Make assembly resolve fully safe
This commit is contained in:
1 parent
7e687b6ef9
commit
68378b32b6
2 files changed
+23
-2
No files matched your search
@@ -31,12 +31,13 @@ namespace BepInEx.Preloader
|
||||
|
||||
private static Assembly LocalResolve(object sender, ResolveEventArgs args)
|
||||
{
|
||||
var assemblyName = new AssemblyName(args.Name);
|
||||
if (!Utility.TryParseAssemblyName(args.Name, out var assemblyName))
|
||||
return null;
|
||||
|
||||
// Use parse assembly name on managed side because native GetName() can fail on some locales
|
||||
// if the game path has "exotic" characters
|
||||
var foundAssembly = AppDomain.CurrentDomain.GetAssemblies()
|
||||
.FirstOrDefault(x => new AssemblyName(x.FullName).Name == assemblyName.Name);
|
||||
.FirstOrDefault(x => Utility.TryParseAssemblyName(x.FullName, out var name) && name.Name == assemblyName.Name);
|
||||
|
||||
if (foundAssembly != null)
|
||||
return foundAssembly;
|
||||
|
||||
@@ -274,6 +274,26 @@ namespace BepInEx
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Try to parse given string as an assembly name
|
||||
/// </summary>
|
||||
/// <param name="fullName">Fully qualified assembly name</param>
|
||||
/// <param name="assemblyName">Resulting <see cref="AssemblyName"/> instance</param>
|
||||
/// <returns><c>true</c>, if parsing was successful, otherwise <c>false</c></returns>
|
||||
public static bool TryParseAssemblyName(string fullName, out AssemblyName assemblyName)
|
||||
{
|
||||
try
|
||||
{
|
||||
assemblyName = new AssemblyName(fullName);
|
||||
return true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
assemblyName = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Adapted from https://github.com/MonoMod/MonoMod.Common/blob/master/Utils/PlatformHelper.cs#L13
|
||||
private static void CheckPlatform()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user