Improved handling of dup instruction (#127)
The trace service handles the duplicate instruction properly now.
This commit is contained in:
Родитель
2e32fcd309
Коммит
82f340490c
|
@ -223,8 +223,20 @@ namespace Confuser.Core.Services {
|
||||||
while (working.Count > 0) {
|
while (working.Count > 0) {
|
||||||
int index = working.Dequeue();
|
int index = working.Dequeue();
|
||||||
while (index >= 0) {
|
while (index >= 0) {
|
||||||
if (BeforeStackDepths[index] == targetStack)
|
if (BeforeStackDepths[index] == targetStack) {
|
||||||
|
if (method.Body.Instructions[index].OpCode.Code != Code.Dup) {
|
||||||
|
// It's not a duplicate instruction, this is an acceptable start point.
|
||||||
break;
|
break;
|
||||||
|
} else {
|
||||||
|
var prevInstr = method.Body.Instructions[index - 1];
|
||||||
|
prevInstr.CalculateStackUsage(out push, out _);
|
||||||
|
if (push > 0) {
|
||||||
|
// A duplicate instruction is an acceptable start point in case the preceeding instruction
|
||||||
|
// pushes a value.
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (fromInstrs.ContainsKey(index))
|
if (fromInstrs.ContainsKey(index))
|
||||||
foreach (Instruction fromInstr in fromInstrs[index]) {
|
foreach (Instruction fromInstr in fromInstrs[index]) {
|
||||||
|
@ -270,7 +282,10 @@ namespace Confuser.Core.Services {
|
||||||
evalStack.Push(lastIdx);
|
evalStack.Push(lastIdx);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
// Removing values from the stack. If the stack is already empty, the poped values are of no relevance.
|
||||||
|
Debug.Assert(evalStack.Count >= pop);
|
||||||
for (var i = 0; i < pop; i++) {
|
for (var i = 0; i < pop; i++) {
|
||||||
|
if (evalStack.Count > 0)
|
||||||
evalStack.Pop();
|
evalStack.Pop();
|
||||||
}
|
}
|
||||||
Debug.Assert(push <= 1); // Instructions shouldn't put more than one value on the stack.
|
Debug.Assert(push <= 1); // Instructions shouldn't put more than one value on the stack.
|
||||||
|
|
Загрузка…
Ссылка в новой задаче