Fixed: #2486 decompilation timeout on infinite loop

This commit is contained in:
Jindra Petřík
2025-07-17 22:42:32 +02:00
parent 415a10502c
commit b471b48ba7
18 changed files with 344 additions and 266 deletions

View File

@@ -3652,6 +3652,13 @@ public class AVM2Code implements Cloneable {
cnt++;
}
}
if ((ins.definition instanceof LabelIns) || (ins.definition instanceof DebugLineIns)) {
ins.setIgnored(true, 0);
if (minChangedIp == -1 || minChangedIp > i) {
minChangedIp = i;
}
cnt++;
}
}
removeIgnored(body);
@@ -3660,6 +3667,25 @@ public class AVM2Code implements Cloneable {
return cnt;
}
/**
* Removes label and debugline instructions
* @param body Method body
* @return Number of removed instructions
* @throws InterruptedException
*/
public int removeLabelsAndDebugLine(MethodBody body) throws InterruptedException {
int cnt = 0;
for (int i = code.size() - 1; i >= 0; i--) {
AVM2Instruction ins = code.get(i);
if ((ins.definition instanceof LabelIns) || (ins.definition instanceof DebugLineIns)) {
ins.setIgnored(true, 0);
cnt++;
}
}
removeIgnored(body);
return cnt;
}
/**
* Replaces jumps to exit instructions (return, throw) with exit

View File

@@ -3263,39 +3263,5 @@ public class AVM2Graph extends Graph {
}
return ternar;
}
@Override
protected int checkIp(int ip) {
if (true) {
//return ip;
}
/*
Ignore label instructions
<pre>
locA:
label
locB:
pushbyte 1
=>
locAB:
pushbyte 1
</pre>
*/
while (ip < code.size()) {
GraphSourceItem ins = code.get(ip);
if (!(ins instanceof AVM2Instruction)) {
break;
}
AVM2Instruction ains = (AVM2Instruction) ins;
if (!(ains.definition instanceof LabelIns)) {
break;
}
ip++;
}
return ip;
}
}
}

View File

@@ -631,6 +631,7 @@ public final class MethodBody implements Cloneable {
if (deobfuscate) {
try {
code.removeTraps(trait, method_info, body, abc, scriptIndex, classIndex, isStatic, path);
code.removeLabelsAndDebugLine(body);
} catch (ThreadDeath | InterruptedException ex) {
throw ex;
} catch (Throwable ex) {

View File

@@ -4125,6 +4125,9 @@ public class Graph {
}
GraphPart nextPart = part.nextParts.get(0);
if (nextPart == part) {
continue;
}
for (GraphPart r : part.refs) {
while (true) {