mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-06-07 15:55:12 +00:00
deobfuscation fixes
This commit is contained in:
@@ -114,6 +114,7 @@ public class AVM2GraphTargetDialect extends GraphTargetDialect {
|
||||
public GraphTextWriter writeTemporaryDeclaration(GraphTextWriter writer, LocalData localData, String suffix, int tempIndex, GraphTargetItem value) throws InterruptedException {
|
||||
writer.append("var ");
|
||||
writer.append("_temp");
|
||||
writer.append(suffix);
|
||||
writer.append("_").append(tempIndex).append(":*");
|
||||
if (value != null) {
|
||||
writer.append(" = ");
|
||||
|
||||
@@ -19,10 +19,14 @@ package com.jpexs.decompiler.flash.abc.avm2.instructions;
|
||||
import com.jpexs.decompiler.flash.abc.ABC;
|
||||
import com.jpexs.decompiler.flash.abc.AVM2LocalData;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.instructions.stack.PopIns;
|
||||
import com.jpexs.decompiler.graph.AbstractGraphTargetVisitor;
|
||||
import com.jpexs.decompiler.graph.GraphTargetItem;
|
||||
import com.jpexs.decompiler.graph.TranslateStack;
|
||||
import com.jpexs.decompiler.graph.model.DuplicateItem;
|
||||
import com.jpexs.decompiler.graph.model.DuplicateSourceItem;
|
||||
import com.jpexs.decompiler.graph.model.HasTempIndex;
|
||||
import com.jpexs.decompiler.graph.model.SetTemporaryItem;
|
||||
import com.jpexs.decompiler.graph.model.TemporaryItem;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -70,15 +74,40 @@ public class DeobfuscatePopIns extends PopIns {
|
||||
@Override
|
||||
public void translate(AVM2LocalData localData, TranslateStack stack, AVM2Instruction ins, List<GraphTargetItem> output, String path) {
|
||||
GraphTargetItem item = stack.pop();
|
||||
if (item instanceof DuplicateSourceItem) {
|
||||
DuplicateSourceItem ds = (DuplicateSourceItem) item;
|
||||
if (!output.isEmpty() && output.get(output.size() - 1) instanceof SetTemporaryItem) {
|
||||
SetTemporaryItem st = (SetTemporaryItem) output.get(output.size() - 1);
|
||||
if (st.tempIndex == ds.tempIndex) {
|
||||
output.remove(output.size() - 1);
|
||||
AbstractGraphTargetVisitor visitor = new AbstractGraphTargetVisitor() {
|
||||
@Override
|
||||
public boolean visit(GraphTargetItem subItem) {
|
||||
if ((subItem instanceof DuplicateSourceItem) || (subItem instanceof DuplicateItem)) {
|
||||
int tempIndex = ((HasTempIndex) subItem).getTempIndex();
|
||||
if (!output.isEmpty() && output.get(output.size() - 1) instanceof SetTemporaryItem) {
|
||||
SetTemporaryItem st = (SetTemporaryItem) output.get(output.size() - 1);
|
||||
if (st.tempIndex == tempIndex) {
|
||||
st.refCount--;
|
||||
if (st.refCount <= 0) {
|
||||
output.remove(output.size() - 1);
|
||||
stack.moveToStack(output);
|
||||
} else if (st.refCount == 1) {
|
||||
for (int i = 0; i < stack.size(); i++) {
|
||||
if (stack.get(i) instanceof HasTempIndex) {
|
||||
HasTempIndex ht = (HasTempIndex) stack.get(i);
|
||||
if (ht.getTempIndex() == tempIndex) {
|
||||
stack.set(i, st.value);
|
||||
st.refCount--;
|
||||
output.remove(output.size() - 1);
|
||||
stack.moveToStack(output);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
visitor.visit(item);
|
||||
item.visitRecursively(visitor);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -72,7 +72,7 @@ public class DupIns extends InstructionDefinition {
|
||||
temp = localData.maxTempIndex.getVal() + 1;
|
||||
localData.maxTempIndex.setVal(temp);
|
||||
stack.finishBlock(output);
|
||||
stack.addToOutput(new SetTemporaryItem(AVM2GraphTargetDialect.INSTANCE, ins, localData.lineStartInstruction, v, temp, "dup"));
|
||||
stack.addToOutput(new SetTemporaryItem(AVM2GraphTargetDialect.INSTANCE, ins, localData.lineStartInstruction, v, temp, "dup", 2));
|
||||
stack.finishBlock(output);
|
||||
|
||||
stack.push(new DuplicateSourceItem(AVM2GraphTargetDialect.INSTANCE, ins, localData.lineStartInstruction, v, temp));
|
||||
|
||||
@@ -153,7 +153,7 @@ public class SwapIns extends InstructionDefinition {
|
||||
int temp = localData.maxTempIndex.getVal() + 1;
|
||||
localData.maxTempIndex.setVal(temp);
|
||||
stack.finishBlock(output);
|
||||
stack.addToOutput(new SetTemporaryItem(AVM2GraphTargetDialect.INSTANCE, ins, localData.lineStartInstruction, o2, temp, "swap"));
|
||||
stack.addToOutput(new SetTemporaryItem(AVM2GraphTargetDialect.INSTANCE, ins, localData.lineStartInstruction, o2, temp, "swap", 1));
|
||||
stack.push(o1);
|
||||
stack.push(new TemporaryItem(AVM2GraphTargetDialect.INSTANCE, ins, localData.lineStartInstruction, o2, temp));
|
||||
stack.finishBlock(output);
|
||||
|
||||
@@ -119,6 +119,7 @@ public class ActionGraphTargetDialect extends GraphTargetDialect {
|
||||
public GraphTextWriter writeTemporaryDeclaration(GraphTextWriter writer, LocalData localData, String suffix, int tempIndex, GraphTargetItem value) throws InterruptedException {
|
||||
writer.append("var ");
|
||||
writer.append("_temp");
|
||||
writer.append(suffix);
|
||||
writer.append("_").append(tempIndex);
|
||||
if (value != null) {
|
||||
writer.append(" = ");
|
||||
|
||||
@@ -1057,7 +1057,7 @@ public class Graph {
|
||||
public void visit(GraphTargetItem item, Stack<GraphTargetItem> parentStack) {
|
||||
if (item instanceof SetTemporaryItem) {
|
||||
SetTemporaryItem st = (SetTemporaryItem) item;
|
||||
SetTemporaryItem dec = new SetTemporaryItem(dialect, null, null, null, st.tempIndex, st.getSuffix());
|
||||
SetTemporaryItem dec = new SetTemporaryItem(dialect, null, null, null, st.tempIndex, st.getSuffix(), st.refCount);
|
||||
dec.declaration = true;
|
||||
items.add(iRef.getVal(), dec);
|
||||
iRef.setVal(iRef.getVal() + 1);
|
||||
|
||||
@@ -27,12 +27,10 @@ import com.jpexs.decompiler.graph.model.ContinueItem;
|
||||
import com.jpexs.decompiler.graph.model.DuplicateItem;
|
||||
import com.jpexs.decompiler.graph.model.DuplicateSourceItem;
|
||||
import com.jpexs.decompiler.graph.model.ExitItem;
|
||||
import com.jpexs.decompiler.graph.model.HasTempIndex;
|
||||
import com.jpexs.decompiler.graph.model.PopItem;
|
||||
import com.jpexs.decompiler.graph.model.PushItem;
|
||||
import com.jpexs.decompiler.graph.model.ScriptEndItem;
|
||||
import com.jpexs.decompiler.graph.model.SetTemporaryItem;
|
||||
import com.jpexs.decompiler.graph.model.SwapItem;
|
||||
import com.jpexs.decompiler.graph.model.TemporaryItem;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@@ -106,10 +104,8 @@ public class TranslateStack extends Stack<GraphTargetItem> {
|
||||
return super.push(item);
|
||||
}
|
||||
|
||||
private boolean isDupsOnly() {
|
||||
if (true) {
|
||||
return false;
|
||||
}
|
||||
//for #116
|
||||
private boolean isDupsOnly() {
|
||||
for (GraphTargetItem item : this) {
|
||||
if (item instanceof DuplicateItem) {
|
||||
continue;
|
||||
@@ -280,7 +276,7 @@ public class TranslateStack extends Stack<GraphTargetItem> {
|
||||
} else {
|
||||
int temp = localData.maxTempIndex.getVal() + 1;
|
||||
localData.maxTempIndex.setVal(temp);
|
||||
connectedOutput.set(i, new SetTemporaryItem(pi.dialect, pi.value.getSrc(), pi.value.getLineStartItem(), pi.value, temp, "push"));
|
||||
connectedOutput.set(i, new SetTemporaryItem(pi.dialect, pi.value.getSrc(), pi.value.getLineStartItem(), pi.value, temp, "push", 1));
|
||||
return new TemporaryItem(pi.dialect, pi.value.getSrc(), pi.value.getLineStartItem(), pi.value, temp);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,6 +39,7 @@ public class SetTemporaryItem extends GraphTargetItem implements SimpleValue, Ha
|
||||
|
||||
public int tempIndex;
|
||||
public boolean declaration = false;
|
||||
public int refCount = 0;
|
||||
|
||||
private final String suffix;
|
||||
|
||||
@@ -54,10 +55,11 @@ public class SetTemporaryItem extends GraphTargetItem implements SimpleValue, Ha
|
||||
* @param lineStartIns Line start item
|
||||
* @param value Value
|
||||
*/
|
||||
public SetTemporaryItem(GraphTargetDialect dialect, GraphSourceItem src, GraphSourceItem lineStartIns, GraphTargetItem value, int tempIndex, String suffix) {
|
||||
public SetTemporaryItem(GraphTargetDialect dialect, GraphSourceItem src, GraphSourceItem lineStartIns, GraphTargetItem value, int tempIndex, String suffix, int refCount) {
|
||||
super(dialect, src, lineStartIns, PRECEDENCE_ASSIGNMENT, value);
|
||||
this.tempIndex = tempIndex;
|
||||
this.suffix = suffix;
|
||||
this.refCount = refCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user