Browse Source

Add support for MSC 2.6.4 pinned region with string variable

pull/3015/head
ElektroKill 3 years ago
parent
commit
915c0310c4
No known key found for this signature in database
GPG Key ID: 7E3C5C084E40E3EC
  1. 30
      ICSharpCode.Decompiler/IL/ControlFlow/DetectPinnedRegions.cs

30
ICSharpCode.Decompiler/IL/ControlFlow/DetectPinnedRegions.cs

@ -1,4 +1,4 @@
// Copyright (c) 2016 Daniel Grunwald // Copyright (c) 2016 Daniel Grunwald
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy of this // Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software // software and associated documentation files (the "Software"), to deal in the Software
@ -878,27 +878,43 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow
} }
return; return;
} }
if (body.EntryPoint.Instructions.Count != 3) if (nativeVar.Type.GetStackType() != StackType.I)
{
return; return;
}
if (nativeVar.Type.GetStackType() != StackType.I) Block targetBlock;
Block adjustOffsetToStringData = null;
if (body.EntryPoint.Instructions.Count == 2)
{
if (!initInst.MatchBinaryNumericInstruction(BinaryNumericOperator.Add, out ILInstruction left, out ILInstruction right))
return;
if (!left.UnwrapConv(ConversionKind.StopGCTracking).MatchLdLoc(pinnedRegion.Variable))
return;
if (!IsOffsetToStringDataCall(right))
return; return;
if (!body.EntryPoint.Instructions[1].MatchBranch(out targetBlock))
return;
}
else if (body.EntryPoint.Instructions.Count == 3)
{
if (!initInst.UnwrapConv(ConversionKind.StopGCTracking).MatchLdLoc(pinnedRegion.Variable)) if (!initInst.UnwrapConv(ConversionKind.StopGCTracking).MatchLdLoc(pinnedRegion.Variable))
return; return;
if (!IsBranchOnNull(body.EntryPoint.Instructions[1], nativeVar, out Block targetBlock)) if (!IsBranchOnNull(body.EntryPoint.Instructions[1], nativeVar, out targetBlock))
return; return;
if (!body.EntryPoint.Instructions[2].MatchBranch(out Block adjustOffsetToStringData)) if (!body.EntryPoint.Instructions[2].MatchBranch(out adjustOffsetToStringData))
return; return;
if (!(adjustOffsetToStringData.Parent == body && adjustOffsetToStringData.IncomingEdgeCount == 1 if (!(adjustOffsetToStringData.Parent == body && adjustOffsetToStringData.IncomingEdgeCount == 1
&& IsOffsetToStringDataBlock(adjustOffsetToStringData, nativeVar, targetBlock))) && IsOffsetToStringDataBlock(adjustOffsetToStringData, nativeVar, targetBlock)))
return; return;
}
else
return;
context.Step("Handle pinned string (with adjustOffsetToStringData)", pinnedRegion); context.Step("Handle pinned string (with adjustOffsetToStringData)", pinnedRegion);
if (targetBlock.Parent == body) if (targetBlock.Parent == body)
{ {
// remove old entry point // remove old entry point
body.Blocks.RemoveAt(0); body.Blocks.RemoveAt(0);
if (adjustOffsetToStringData is not null)
body.Blocks.RemoveAt(adjustOffsetToStringData.ChildIndex); body.Blocks.RemoveAt(adjustOffsetToStringData.ChildIndex);
// make targetBlock the new entry point // make targetBlock the new entry point
body.Blocks.RemoveAt(targetBlock.ChildIndex); body.Blocks.RemoveAt(targetBlock.ChildIndex);

Loading…
Cancel
Save