Don't inline method if ldarga is used
This commit is contained in:
parent
3e70d1fa63
commit
221dcc3cc9
|
@ -137,7 +137,9 @@ namespace de4dot.blocks.cflow {
|
||||||
bool inlineOtherMethod(int patchIndex, MethodDefinition method, Instruction instr, int instrIndex) {
|
bool inlineOtherMethod(int patchIndex, MethodDefinition method, Instruction instr, int instrIndex) {
|
||||||
int loadIndex = 0;
|
int loadIndex = 0;
|
||||||
int methodArgsCount = DotNetUtils.getArgsCount(method);
|
int methodArgsCount = DotNetUtils.getArgsCount(method);
|
||||||
|
bool foundLdarga = false;
|
||||||
while (instr != null && loadIndex < methodArgsCount) {
|
while (instr != null && loadIndex < methodArgsCount) {
|
||||||
|
bool isLdarg = true;
|
||||||
switch (instr.OpCode.Code) {
|
switch (instr.OpCode.Code) {
|
||||||
case Code.Ldarg:
|
case Code.Ldarg:
|
||||||
case Code.Ldarg_S:
|
case Code.Ldarg_S:
|
||||||
|
@ -145,20 +147,29 @@ namespace de4dot.blocks.cflow {
|
||||||
case Code.Ldarg_1:
|
case Code.Ldarg_1:
|
||||||
case Code.Ldarg_2:
|
case Code.Ldarg_2:
|
||||||
case Code.Ldarg_3:
|
case Code.Ldarg_3:
|
||||||
|
break;
|
||||||
case Code.Ldarga:
|
case Code.Ldarga:
|
||||||
case Code.Ldarga_S:
|
case Code.Ldarga_S:
|
||||||
if (DotNetUtils.getArgIndex(method, instr) != loadIndex)
|
foundLdarga = true;
|
||||||
return false;
|
break;
|
||||||
loadIndex++;
|
default:
|
||||||
instr = DotNetUtils.getInstruction(method.Body.Instructions, ref instrIndex);
|
isLdarg = false;
|
||||||
continue;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
if (!isLdarg)
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (DotNetUtils.getArgIndex(method, instr) != loadIndex)
|
||||||
|
return false;
|
||||||
|
loadIndex++;
|
||||||
|
instr = DotNetUtils.getInstruction(method.Body.Instructions, ref instrIndex);
|
||||||
}
|
}
|
||||||
if (instr == null || loadIndex != methodArgsCount)
|
if (instr == null || loadIndex != methodArgsCount)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (instr.OpCode.Code == Code.Call || instr.OpCode.Code == Code.Callvirt) {
|
if (instr.OpCode.Code == Code.Call || instr.OpCode.Code == Code.Callvirt) {
|
||||||
|
if (foundLdarga)
|
||||||
|
return false;
|
||||||
var callInstr = instr;
|
var callInstr = instr;
|
||||||
var calledMethod = callInstr.Operand as MethodReference;
|
var calledMethod = callInstr.Operand as MethodReference;
|
||||||
if (calledMethod == null)
|
if (calledMethod == null)
|
||||||
|
@ -184,6 +195,8 @@ namespace de4dot.blocks.cflow {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if (instr.OpCode.Code == Code.Newobj) {
|
else if (instr.OpCode.Code == Code.Newobj) {
|
||||||
|
if (foundLdarga)
|
||||||
|
return false;
|
||||||
var newobjInstr = instr;
|
var newobjInstr = instr;
|
||||||
var ctor = newobjInstr.Operand as MethodReference;
|
var ctor = newobjInstr.Operand as MethodReference;
|
||||||
if (ctor == null)
|
if (ctor == null)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user