Fixed error in opcode parameter that only shows itself in mono under 6.x
This commit is contained in:
parent
0ef28e5786
commit
6b7566fed8
|
@ -46,10 +46,12 @@ namespace NzbDrone.RuntimePatches.Mono
|
|||
|
||||
var patchable = codes.Matches(OpCodes.Ldstr, OpCodes.Ldc_I4_1, OpCodes.Call, OpCodes.Ret);
|
||||
|
||||
Instance.DebugOpcodes("Before", codes);
|
||||
|
||||
var targetType = method.DeclaringType;
|
||||
var copyMethod = targetType.GetMethod("Copy");
|
||||
var disposeMethod = targetType.GetMethod("Dispose");
|
||||
var setFlagsMethod = targetType.GetMethod("SetFlags");
|
||||
var copyMethod = targetType.GetMethod("Copy", new Type[0]);
|
||||
var disposeMethod = targetType.GetMethod("Dispose", new Type[0]);
|
||||
var setFlagsMethod = targetType.GetMethod("SetFlags", new[] { typeof(ulong) });
|
||||
|
||||
if (patchable && copyMethod != null && disposeMethod != null && setFlagsMethod != null)
|
||||
{
|
||||
|
@ -64,10 +66,12 @@ namespace NzbDrone.RuntimePatches.Mono
|
|||
codes.Add(new CodeInstruction(OpCodes.Callvirt, disposeMethod)); // Dispose the original
|
||||
codes.Add(new CodeInstruction(OpCodes.Ldloc, copy));
|
||||
codes.Add(new CodeInstruction(OpCodes.Dup));
|
||||
codes.Add(new CodeInstruction(OpCodes.Ldc_I4, 0x8000)); // X509_V_FLAG_TRUSTED_FIRST
|
||||
codes.Add(new CodeInstruction(OpCodes.Ldc_I8, 0x8000L)); // X509_V_FLAG_TRUSTED_FIRST
|
||||
codes.Add(new CodeInstruction(OpCodes.Call, setFlagsMethod)); // SetFlags is an or-operation
|
||||
codes.Add(new CodeInstruction(OpCodes.Ret));
|
||||
|
||||
Instance.DebugOpcodes("After", codes);
|
||||
|
||||
Instance.Debug($"Patch applied to method {method.GetSimplifiedName()}");
|
||||
}
|
||||
else
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using HarmonyLib;
|
||||
|
||||
|
@ -8,6 +9,8 @@ namespace NzbDrone.RuntimePatches
|
|||
{
|
||||
private Harmony _harmony;
|
||||
|
||||
internal static bool IsDebug;
|
||||
|
||||
public virtual bool ShouldPatch() => true;
|
||||
protected abstract void Patch();
|
||||
|
||||
|
@ -101,11 +104,24 @@ namespace NzbDrone.RuntimePatches
|
|||
return null;
|
||||
}
|
||||
|
||||
protected void DebugOpcodes(string prefix, List<CodeInstruction> codes)
|
||||
{
|
||||
if (IsDebug)
|
||||
{
|
||||
Log($"Opcodes {prefix}:");
|
||||
foreach (var code in codes)
|
||||
{
|
||||
Console.WriteLine($" {code}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void Debug(string log)
|
||||
{
|
||||
#if DEBUG
|
||||
Log(log);
|
||||
#endif
|
||||
if (IsDebug)
|
||||
{
|
||||
Log(log);
|
||||
}
|
||||
}
|
||||
|
||||
protected void Error(string log)
|
||||
|
|
|
@ -9,9 +9,26 @@ namespace NzbDrone.RuntimePatches
|
|||
{
|
||||
public static void Initialize()
|
||||
{
|
||||
var env = Environment.GetEnvironmentVariable("DISABLE_RUNTIMEPATCHES");
|
||||
if (env != "1")
|
||||
var envDisableRuntimePatches = Environment.GetEnvironmentVariable("DISABLE_RUNTIMEPATCHES");
|
||||
var envDebugRuntimePatches = Environment.GetEnvironmentVariable("DEBUG_RUNTIMEPATCHES");
|
||||
|
||||
if (envDisableRuntimePatches != "1")
|
||||
{
|
||||
if (envDebugRuntimePatches == "1")
|
||||
{
|
||||
RuntimePatchBase.IsDebug = true;
|
||||
}
|
||||
else if (envDebugRuntimePatches == "0")
|
||||
{
|
||||
RuntimePatchBase.IsDebug = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
#if DEBUG
|
||||
RuntimePatchBase.IsDebug = true;
|
||||
#endif
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
ApplyPatches();
|
||||
|
|
Loading…
Reference in New Issue