Improved handling of dup instruction (#127)

The trace service handles the duplicate instruction properly now.
This commit is contained in:
Martin Karing 2020-02-25 11:27:45 +01:00 коммит произвёл GitHub
Родитель 2e32fcd309
Коммит 82f340490c
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
1 изменённых файлов: 18 добавлений и 3 удалений

Просмотреть файл

@ -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.