Browse Source

Fix #1443: ProxyCallReplacer replacing non-proxy-calls with arbitrary calls.

pull/1464/head
Siegfried Pammer 6 years ago
parent
commit
5dfc6132d9
  1. 20
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.cs
  2. 7
      ICSharpCode.Decompiler/IL/Transforms/ProxyCallReplacer.cs

20
ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.cs

@ -1,5 +1,6 @@ @@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
namespace ICSharpCode.Decompiler.Tests.TestCases.ILPretty
@ -62,6 +63,25 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.ILPretty @@ -62,6 +63,25 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.ILPretty
}
}
[CompilerGenerated]
internal class FalsePositive_Issue1443
{
private static void WrongMethod()
{
Console.WriteLine("Wrong!");
}
private void CorrectMethod()
{
WrongMethod();
}
private void Use()
{
CorrectMethod();
}
}
internal class G
{
protected internal virtual void Test(string test)

7
ICSharpCode.Decompiler/IL/Transforms/ProxyCallReplacer.cs

@ -57,11 +57,12 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -57,11 +57,12 @@ namespace ICSharpCode.Decompiler.IL.Transforms
if (!returnValue.MatchNop())
return;
}
if (call == null) {
if (call == null || call.Method.IsConstructor) {
return;
}
if (call.Method.IsConstructor)
if (call.Method.IsStatic != inst.Method.IsStatic || call.Method.Parameters.Count != inst.Method.Parameters.Count) {
return;
}
// check if original arguments are only correct ldloc calls
for (int i = 0; i < call.Arguments.Count; i++) {
@ -72,7 +73,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -72,7 +73,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
return;
}
}
context.Step("Replace proxy: " + inst.Method.Name + " with " + call.Method.Name, inst);
Call newInst = (Call)call.Clone();
newInst.Arguments.ReplaceList(inst.Arguments);

Loading…
Cancel
Save