mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-05-22 18:25:51 +00:00
using existing getOffset method everywhere, made offset is privete
This commit is contained in:
@@ -312,7 +312,7 @@ public class AVM2Code implements Cloneable {
|
||||
|
||||
public static int toSourceLimit = -1;
|
||||
|
||||
public List<AVM2Instruction> code = new ArrayList<>();
|
||||
public List<AVM2Instruction> code;
|
||||
|
||||
public static boolean DEBUG_REWRITE = false;
|
||||
|
||||
@@ -640,6 +640,15 @@ public class AVM2Code implements Cloneable {
|
||||
public static final String IDENTCLOSE = "/*IDENTCLOSE*/";
|
||||
|
||||
public AVM2Code() {
|
||||
code = new ArrayList<>();
|
||||
}
|
||||
|
||||
public AVM2Code(int capacity) {
|
||||
code = new ArrayList<>(capacity);
|
||||
}
|
||||
|
||||
public AVM2Code(ArrayList<AVM2Instruction> instructions) {
|
||||
code = instructions;
|
||||
}
|
||||
|
||||
public Object execute(HashMap<Integer, Object> arguments, AVM2ConstantPool constants) throws AVM2ExecutionException {
|
||||
@@ -993,6 +1002,7 @@ public class AVM2Code implements Cloneable {
|
||||
diParent.sortChildren();
|
||||
}
|
||||
|
||||
code = new ArrayList<>(codeMap.size());
|
||||
AVM2Instruction prev = null;
|
||||
for (int i = 0; i < availableBytes; i++) {
|
||||
AVM2Instruction ins = codeMap.get((long) i);
|
||||
@@ -1035,7 +1045,7 @@ public class AVM2Code implements Cloneable {
|
||||
public void markOffsets() {
|
||||
long offset = 0;
|
||||
for (int i = 0; i < code.size(); i++) {
|
||||
code.get(i).offset = offset;
|
||||
code.get(i).setOffset(offset);
|
||||
offset += code.get(i).getBytesLength();
|
||||
}
|
||||
}
|
||||
@@ -1230,7 +1240,7 @@ public class AVM2Code implements Cloneable {
|
||||
Helper.byteArrayToHexWithHeader(writer, getBytes());
|
||||
} else if (exportMode == ScriptExportMode.PCODE || exportMode == ScriptExportMode.PCODE_HEX) {
|
||||
for (AVM2Instruction ins : code) {
|
||||
long ofs = ins.offset;
|
||||
long ofs = ins.getOffset();
|
||||
if (exportMode == ScriptExportMode.PCODE_HEX) {
|
||||
writer.appendNoHilight("; ");
|
||||
writer.appendNoHilight(Helper.bytesToHexString(ins.getBytes()));
|
||||
@@ -1275,7 +1285,7 @@ public class AVM2Code implements Cloneable {
|
||||
if (body != null) {
|
||||
for (ABCException exception : body.exceptions) {
|
||||
ret.add((long) exception.start);
|
||||
ret.add((long) exception.end);
|
||||
// ret.add((long) exception.end); // end is not important
|
||||
ret.add((long) exception.target);
|
||||
}
|
||||
}
|
||||
@@ -1308,7 +1318,7 @@ public class AVM2Code implements Cloneable {
|
||||
|
||||
while (max >= min) {
|
||||
int mid = (min + max) / 2;
|
||||
long midValue = code.get(mid).offset;
|
||||
long midValue = code.get(mid).getOffset();
|
||||
if (midValue == address) {
|
||||
return mid;
|
||||
} else if (midValue < address) {
|
||||
@@ -1329,7 +1339,7 @@ public class AVM2Code implements Cloneable {
|
||||
if (pos == code.size()) {
|
||||
return getEndOffset();
|
||||
}
|
||||
return (int) code.get(pos).offset;
|
||||
return (int) code.get(pos).getOffset();
|
||||
}
|
||||
|
||||
public long getEndOffset() {
|
||||
@@ -1338,7 +1348,7 @@ public class AVM2Code implements Cloneable {
|
||||
}
|
||||
|
||||
AVM2Instruction ins = code.get(code.size() - 1);
|
||||
return (int) (ins.offset + ins.getBytesLength());
|
||||
return (int) (ins.getOffset() + ins.getBytesLength());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1954,11 +1964,11 @@ public class AVM2Code implements Cloneable {
|
||||
for (int i = 0; i < code.size(); i++) {
|
||||
AVM2Instruction ins = code.get(i);
|
||||
if (ins.definition instanceof LookupSwitchIns) {
|
||||
long target = ins.offset + ins.operands[0];
|
||||
ins.operands[0] = updater.updateOperandOffset(ins.offset, target, ins.operands[0]);
|
||||
long target = ins.getOffset() + ins.operands[0];
|
||||
ins.operands[0] = updater.updateOperandOffset(ins.getOffset(), target, ins.operands[0]);
|
||||
for (int k = 2; k < ins.operands.length; k++) {
|
||||
target = ins.offset + ins.operands[k];
|
||||
ins.operands[k] = updater.updateOperandOffset(ins.offset, target, ins.operands[k]);
|
||||
target = ins.getOffset() + ins.operands[k];
|
||||
ins.operands[k] = updater.updateOperandOffset(ins.getOffset(), target, ins.operands[k]);
|
||||
}
|
||||
} else {
|
||||
/*for (int j = 0; j < ins.definition.operands.length; j++) {
|
||||
@@ -1969,15 +1979,15 @@ public class AVM2Code implements Cloneable {
|
||||
}*/
|
||||
//Faster, but not so universal
|
||||
if ((ins.definition instanceof JumpIns) || (ins.definition instanceof IfTypeIns)) {
|
||||
long target = ins.offset + ins.getBytesLength() + ins.operands[0];
|
||||
long target = ins.getOffset() + ins.getBytesLength() + ins.operands[0];
|
||||
try {
|
||||
ins.operands[0] = updater.updateOperandOffset(ins.offset, target, ins.operands[0]);
|
||||
ins.operands[0] = updater.updateOperandOffset(ins.getOffset(), target, ins.operands[0]);
|
||||
} catch (ConvertException cex) {
|
||||
throw new ConvertException("Invalid offset (" + ins + ")", i);
|
||||
}
|
||||
}
|
||||
}
|
||||
ins.offset = updater.updateInstructionOffset(ins.offset);
|
||||
ins.setOffset(updater.updateInstructionOffset(ins.getOffset()));
|
||||
}
|
||||
|
||||
for (ABCException ex : body.exceptions) {
|
||||
@@ -2051,7 +2061,7 @@ public class AVM2Code implements Cloneable {
|
||||
}
|
||||
|
||||
AVM2Instruction ins = code.get(pos);
|
||||
final long remOffset = ins.offset;
|
||||
final long remOffset = ins.getOffset();
|
||||
int bc = ins.getBytesLength();
|
||||
|
||||
final int byteCount = bc;
|
||||
@@ -2116,7 +2126,7 @@ public class AVM2Code implements Cloneable {
|
||||
*/
|
||||
public void replaceInstruction(int pos, AVM2Instruction instruction, MethodBody body) {
|
||||
AVM2Instruction oldInstruction = code.get(pos);
|
||||
instruction.offset = oldInstruction.offset;
|
||||
instruction.setOffset(oldInstruction.getOffset());
|
||||
int oldByteCount = oldInstruction.getBytesLength();
|
||||
int newByteCount = instruction.getBytesLength();
|
||||
int byteDelta = newByteCount - oldByteCount;
|
||||
@@ -2126,7 +2136,7 @@ public class AVM2Code implements Cloneable {
|
||||
|
||||
@Override
|
||||
public long updateInstructionOffset(long address) {
|
||||
if (address > instruction.offset) {
|
||||
if (address > instruction.getOffset()) {
|
||||
return address + byteDelta;
|
||||
}
|
||||
return address;
|
||||
@@ -2134,10 +2144,10 @@ public class AVM2Code implements Cloneable {
|
||||
|
||||
@Override
|
||||
public int updateOperandOffset(long insAddr, long targetAddress, int offset) {
|
||||
if (targetAddress > instruction.offset && insAddr <= instruction.offset) {
|
||||
if (targetAddress > instruction.getOffset() && insAddr <= instruction.getOffset()) {
|
||||
return offset + byteDelta;
|
||||
}
|
||||
if (targetAddress <= instruction.offset && insAddr > instruction.offset) {
|
||||
if (targetAddress <= instruction.getOffset() && insAddr > instruction.getOffset()) {
|
||||
return offset - byteDelta;
|
||||
}
|
||||
return offset;
|
||||
@@ -2168,11 +2178,11 @@ public class AVM2Code implements Cloneable {
|
||||
}
|
||||
final int byteCount = instruction.getBytesLength();
|
||||
if (pos == code.size()) {
|
||||
instruction.offset = code.get(pos - 1).offset + code.get(pos - 1).getBytesLength();
|
||||
instruction.setOffset(code.get(pos - 1).getOffset() + code.get(pos - 1).getBytesLength());
|
||||
} else {
|
||||
instruction.offset = code.get(pos).offset;
|
||||
instruction.setOffset(code.get(pos).getOffset());
|
||||
}
|
||||
final long x = instruction.offset;
|
||||
final long x = instruction.getOffset();
|
||||
updateOffsets(new OffsetUpdater() {
|
||||
|
||||
@Override
|
||||
@@ -2220,7 +2230,7 @@ public class AVM2Code implements Cloneable {
|
||||
return offset_jt;
|
||||
}
|
||||
}, body);
|
||||
instruction.offset = x;
|
||||
instruction.setOffset(x);
|
||||
code.add(pos, instruction);
|
||||
//checkValidOffsets(body);
|
||||
}
|
||||
|
||||
@@ -149,7 +149,7 @@ public class AVM2DeobfuscatorGetSet extends SWFDecompilerAdapter {
|
||||
int regId = ((SetLocalTypeIns) def).getRegisterId(ins);
|
||||
if (!stack.isEmpty() && (stack.peek() instanceof LocalRegAVM2Item) && (((LocalRegAVM2Item) stack.peek()).regIndex == regId)) {
|
||||
stack.pop();
|
||||
code.replaceInstruction(idx, new AVM2Instruction(ins.offset, DeobfuscatePopIns.getInstance(), null), body);
|
||||
code.replaceInstruction(idx, new AVM2Instruction(ins.getOffset(), DeobfuscatePopIns.getInstance(), null), body);
|
||||
idx++;
|
||||
continue;
|
||||
}
|
||||
@@ -185,7 +185,7 @@ public class AVM2DeobfuscatorGetSet extends SWFDecompilerAdapter {
|
||||
|
||||
boolean ifed = false;
|
||||
if (def instanceof JumpIns) {
|
||||
long address = ins.offset + ins.getBytesLength() + ins.operands[0];
|
||||
long address = ins.getOffset() + ins.getBytesLength() + ins.operands[0];
|
||||
idx = code.adr2pos(address);
|
||||
|
||||
if (idx == -1) {
|
||||
|
||||
@@ -50,7 +50,7 @@ public class AVM2DeobfuscatorJumps extends SWFDecompilerAdapter {
|
||||
for (int i = 0; i < code.code.size(); i++) {
|
||||
AVM2Instruction ins = code.code.get(i);
|
||||
if (ins.definition instanceof JumpIns) {
|
||||
long targetAddr = ins.offset + ins.operands[0] + ins.getBytesLength();
|
||||
long targetAddr = ins.getOffset() + ins.operands[0] + ins.getBytesLength();
|
||||
{
|
||||
for (int r : refs.get(i)) {
|
||||
if (r >= 0) { //Not Exception start/end
|
||||
@@ -58,7 +58,7 @@ public class AVM2DeobfuscatorJumps extends SWFDecompilerAdapter {
|
||||
|
||||
if ((srcIns.definition instanceof JumpIns) || ((srcIns.definition instanceof IfTypeIns) && (r != i - 1))) {
|
||||
int oldop = srcIns.operands[0];
|
||||
srcIns.operands[0] = (int) (targetAddr - (srcIns.offset + srcIns.getBytesLength()));
|
||||
srcIns.operands[0] = (int) (targetAddr - (srcIns.getOffset() + srcIns.getBytesLength()));
|
||||
if (srcIns.operands[0] != oldop) {
|
||||
found = true;
|
||||
}
|
||||
|
||||
@@ -167,7 +167,7 @@ public class AVM2DeobfuscatorRegisters extends AVM2DeobfuscatorSimple {
|
||||
SetLocalTypeIns slt = (SetLocalTypeIns) ins.definition;
|
||||
int regId = slt.getRegisterId(ins);
|
||||
if (singleRegisters.containsKey(regId)) {
|
||||
code.replaceInstruction(i, new AVM2Instruction(ins.offset, DeobfuscatePopIns.getInstance(), null), body);
|
||||
code.replaceInstruction(i, new AVM2Instruction(ins.getOffset(), DeobfuscatePopIns.getInstance(), null), body);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -264,7 +264,7 @@ public class AVM2DeobfuscatorRegisters extends AVM2DeobfuscatorSimple {
|
||||
|
||||
if (ins.definition instanceof JumpIns) {
|
||||
|
||||
long address = ins.offset + ins.getBytesLength() + ins.operands[0];
|
||||
long address = ins.getOffset() + ins.getBytesLength() + ins.operands[0];
|
||||
idx = code.adr2pos(address);//code.indexOf(code.getByAddress(address));
|
||||
if (idx == -1) {
|
||||
throw new TranslateException("Jump target not found: " + address);
|
||||
|
||||
@@ -20,9 +20,7 @@ import com.jpexs.decompiler.flash.BaseLocalData;
|
||||
import com.jpexs.decompiler.flash.abc.ABC;
|
||||
import com.jpexs.decompiler.flash.abc.AVM2LocalData;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.AVM2Code;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.AVM2ConstantPool;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.instructions.DeobfuscatePopIns;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.instructions.InstructionDefinition;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.instructions.debug.DebugIns;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.instructions.jumps.JumpIns;
|
||||
@@ -35,7 +33,6 @@ import com.jpexs.decompiler.flash.abc.avm2.instructions.other.ThrowIns;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.model.NullAVM2Item;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.parser.script.Reference;
|
||||
import com.jpexs.decompiler.flash.abc.types.MethodBody;
|
||||
import com.jpexs.decompiler.flash.abc.types.MethodInfo;
|
||||
import com.jpexs.decompiler.flash.abc.types.traits.Trait;
|
||||
import com.jpexs.decompiler.graph.Graph;
|
||||
import com.jpexs.decompiler.graph.GraphPart;
|
||||
@@ -48,7 +45,6 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
@@ -232,7 +228,7 @@ public class AVM2DeobfuscatorRegistersOld extends AVM2DeobfuscatorSimpleOld {
|
||||
|
||||
if (ins.definition instanceof JumpIns) {
|
||||
|
||||
long address = ins.offset + ins.getBytesLength() + ins.operands[0];
|
||||
long address = ins.getOffset() + ins.getBytesLength() + ins.operands[0];
|
||||
idx = code.adr2pos(address);//code.indexOf(code.getByAddress(address));
|
||||
if (idx == -1) {
|
||||
throw new TranslateException("Jump target not found: " + address);
|
||||
|
||||
@@ -170,7 +170,7 @@ public class AVM2DeobfuscatorSimple extends SWFDecompilerAdapter {
|
||||
}
|
||||
|
||||
AVM2Instruction ins = code.code.get(idx);
|
||||
if (instructionsProcessed > 0 && refs.contains(ins.offset)) {
|
||||
if (instructionsProcessed > 0 && refs.contains(ins.getOffset())) {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -199,51 +199,13 @@ public class AVM2DeobfuscatorSimple extends SWFDecompilerAdapter {
|
||||
}
|
||||
}
|
||||
|
||||
if (def instanceof NewFunctionIns) {
|
||||
if (idx + 1 < code.code.size()) {
|
||||
if (code.code.get(idx + 1).definition instanceof PopIns) {
|
||||
code.removeInstruction(idx + 1, body);
|
||||
code.removeInstruction(idx, body);
|
||||
modified = true;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// do not throw EmptyStackException, much faster
|
||||
int requiredStackSize = def.getStackPopCount(ins, abc);
|
||||
if (stack.size() < requiredStackSize) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (requiredStackSize > 0 && !def.isNotCompileTimeSupported()) {
|
||||
boolean notCompileTime = false;
|
||||
for (int i = 0; i < requiredStackSize; i++) {
|
||||
if (stack.peek(i + 1) == NotCompileTime.INSTANCE) {
|
||||
notCompileTime = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (notCompileTime) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (localData.scopeStack.size() < -def.getScopeStackDelta(ins, abc)) {
|
||||
break;
|
||||
}
|
||||
|
||||
boolean supported;
|
||||
try {
|
||||
localData.jump = null;
|
||||
supported = def.execute(localData, abc.constants, ins);
|
||||
} catch (AVM2ExecutionException ex) {
|
||||
supported = false;
|
||||
}
|
||||
|
||||
if (!supported) {
|
||||
break;
|
||||
}
|
||||
if (def instanceof NewFunctionIns
|
||||
&& idx + 1 < code.code.size()
|
||||
&& code.code.get(idx + 1).definition instanceof PopIns) {
|
||||
code.removeInstruction(idx + 1, body);
|
||||
code.removeInstruction(idx, body);
|
||||
modified = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
boolean ok = false;
|
||||
@@ -301,9 +263,47 @@ public class AVM2DeobfuscatorSimple extends SWFDecompilerAdapter {
|
||||
break;
|
||||
}
|
||||
|
||||
if (!(def instanceof NewFunctionIns)) {
|
||||
// do not throw EmptyStackException, much faster
|
||||
int requiredStackSize = def.getStackPopCount(ins, abc);
|
||||
if (stack.size() < requiredStackSize) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (requiredStackSize > 0 && !def.isNotCompileTimeSupported()) {
|
||||
boolean notCompileTime = false;
|
||||
for (int i = 0; i < requiredStackSize; i++) {
|
||||
if (stack.peek(i + 1) == NotCompileTime.INSTANCE) {
|
||||
notCompileTime = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (notCompileTime) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (localData.scopeStack.size() < -def.getScopeStackDelta(ins, abc)) {
|
||||
break;
|
||||
}
|
||||
|
||||
boolean supported;
|
||||
try {
|
||||
localData.jump = null;
|
||||
supported = def.execute(localData, abc.constants, ins);
|
||||
} catch (AVM2ExecutionException ex) {
|
||||
supported = false;
|
||||
}
|
||||
|
||||
if (!supported) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
boolean ifed = false;
|
||||
if (def instanceof IfTypeIns && !(def instanceof JumpIns)) {
|
||||
long address = ins.offset + ins.getBytesLength() + ins.operands[0];
|
||||
long address = ins.getOffset() + ins.getBytesLength() + ins.operands[0];
|
||||
int nidx = code.adr2pos(address);
|
||||
AVM2Instruction tarIns = code.code.get(nidx);
|
||||
|
||||
@@ -315,17 +315,17 @@ public class AVM2DeobfuscatorSimple extends SWFDecompilerAdapter {
|
||||
AVM2Instruction jumpIns = new AVM2Instruction(0, AVM2Instructions.Jump, new int[]{0});
|
||||
//jumpIns.operands[0] = ins.operands[0] /*- ins.getBytes().length*/ + jumpIns.getBytes().length;
|
||||
code.replaceInstruction(idx, jumpIns, body);
|
||||
jumpIns.operands[0] = (int) (tarIns.offset - jumpIns.offset - jumpIns.getBytesLength());
|
||||
jumpIns.operands[0] = (int) (tarIns.getOffset() - jumpIns.getOffset() - jumpIns.getBytesLength());
|
||||
for (int s = 0; s < stackCount; s++) {
|
||||
code.insertInstruction(idx, new AVM2Instruction(ins.offset, DeobfuscatePopIns.getInstance(), null), true, body);
|
||||
code.insertInstruction(idx, new AVM2Instruction(ins.getOffset(), DeobfuscatePopIns.getInstance(), null), true, body);
|
||||
}
|
||||
|
||||
idx = code.adr2pos(jumpIns.offset + jumpIns.getBytesLength() + jumpIns.operands[0]);
|
||||
idx = code.adr2pos(jumpIns.getOffset() + jumpIns.getBytesLength() + jumpIns.operands[0]);
|
||||
} else {
|
||||
//System.err.println("replacing " + ins + " on " + idx + " with pop");
|
||||
code.replaceInstruction(idx, new AVM2Instruction(ins.offset, DeobfuscatePopIns.getInstance(), null), body);
|
||||
code.replaceInstruction(idx, new AVM2Instruction(ins.getOffset(), DeobfuscatePopIns.getInstance(), null), body);
|
||||
for (int s = 1 /*first is replaced*/; s < stackCount; s++) {
|
||||
code.insertInstruction(idx, new AVM2Instruction(ins.offset, DeobfuscatePopIns.getInstance(), null), true, body);
|
||||
code.insertInstruction(idx, new AVM2Instruction(ins.getOffset(), DeobfuscatePopIns.getInstance(), null), true, body);
|
||||
}
|
||||
//ins.definition = DeobfuscatePopIns.getInstance();
|
||||
idx++;
|
||||
|
||||
@@ -342,7 +342,7 @@ public class AVM2DeobfuscatorSimpleOld extends SWFDecompilerAdapter {
|
||||
|
||||
boolean ifed = false;
|
||||
if (def instanceof JumpIns) {
|
||||
long address = ins.offset + ins.getBytesLength() + ins.operands[0];
|
||||
long address = ins.getOffset() + ins.getBytesLength() + ins.operands[0];
|
||||
idx = code.adr2pos(address);
|
||||
|
||||
if (idx == -1) {
|
||||
@@ -355,7 +355,7 @@ public class AVM2DeobfuscatorSimpleOld extends SWFDecompilerAdapter {
|
||||
|
||||
GraphTargetItem top = stack.pop();
|
||||
Object res = top.getResult();
|
||||
long address = ins.offset + ins.getBytesLength() + ins.operands[0];
|
||||
long address = ins.getOffset() + ins.getBytesLength() + ins.operands[0];
|
||||
int nidx = code.adr2pos(address);//code.indexOf(code.getByAddress(address));
|
||||
AVM2Instruction tarIns = code.code.get(nidx);
|
||||
|
||||
@@ -367,17 +367,17 @@ public class AVM2DeobfuscatorSimpleOld extends SWFDecompilerAdapter {
|
||||
AVM2Instruction jumpIns = new AVM2Instruction(0, AVM2Instructions.Jump, new int[]{0});
|
||||
//jumpIns.operands[0] = ins.operands[0] /*- ins.getBytes().length*/ + jumpIns.getBytes().length;
|
||||
code.replaceInstruction(idx, jumpIns, body);
|
||||
jumpIns.operands[0] = (int) (tarIns.offset - jumpIns.offset - jumpIns.getBytesLength());
|
||||
jumpIns.operands[0] = (int) (tarIns.getOffset() - jumpIns.getOffset() - jumpIns.getBytesLength());
|
||||
for (int s = 0; s < stackCount; s++) {
|
||||
code.insertInstruction(idx, new AVM2Instruction(ins.offset, DeobfuscatePopIns.getInstance(), null), true, body);
|
||||
code.insertInstruction(idx, new AVM2Instruction(ins.getOffset(), DeobfuscatePopIns.getInstance(), null), true, body);
|
||||
}
|
||||
|
||||
idx = code.adr2pos(jumpIns.offset + jumpIns.getBytesLength() + jumpIns.operands[0]);
|
||||
idx = code.adr2pos(jumpIns.getOffset() + jumpIns.getBytesLength() + jumpIns.operands[0]);
|
||||
} else {
|
||||
//System.err.println("replacing " + ins + " on " + idx + " with pop");
|
||||
code.replaceInstruction(idx, new AVM2Instruction(ins.offset, DeobfuscatePopIns.getInstance(), null), body);
|
||||
code.replaceInstruction(idx, new AVM2Instruction(ins.getOffset(), DeobfuscatePopIns.getInstance(), null), body);
|
||||
for (int s = 1 /*first is replaced*/; s < stackCount; s++) {
|
||||
code.insertInstruction(idx, new AVM2Instruction(ins.offset, DeobfuscatePopIns.getInstance(), null), true, body);
|
||||
code.insertInstruction(idx, new AVM2Instruction(ins.getOffset(), DeobfuscatePopIns.getInstance(), null), true, body);
|
||||
}
|
||||
//ins.definition = DeobfuscatePopIns.getInstance();
|
||||
idx++;
|
||||
|
||||
@@ -47,7 +47,7 @@ public class AVM2Instruction implements Cloneable, GraphSourceItem {
|
||||
|
||||
public int[] operands;
|
||||
|
||||
public long offset;
|
||||
private long offset;
|
||||
|
||||
public String comment;
|
||||
|
||||
@@ -375,6 +375,10 @@ public class AVM2Instruction implements Cloneable, GraphSourceItem {
|
||||
return offset;
|
||||
}
|
||||
|
||||
public void setOffset(long offset) {
|
||||
this.offset = offset;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Integer> getBranches(GraphSource code) {
|
||||
List<Integer> ret = new ArrayList<>();
|
||||
|
||||
@@ -238,7 +238,7 @@ public abstract class InstructionDefinition implements Serializable {
|
||||
if (constants.getMultiname(multinameIndex).needsName()) {
|
||||
name = stack.get(pos).toString();
|
||||
} else {
|
||||
name = GraphTextWriter.hilighOffset(constants.getMultiname(multinameIndex).getName(constants, fullyQualifiedNames, false), ins.offset);
|
||||
name = GraphTextWriter.hilighOffset(constants.getMultiname(multinameIndex).getName(constants, fullyQualifiedNames, false), ins.getOffset());
|
||||
}
|
||||
return name + ns;
|
||||
}
|
||||
|
||||
@@ -969,9 +969,9 @@ public class ASM3Parser {
|
||||
AVM2Instruction ins = code.code.get((int) oi.insPosition);
|
||||
int relOffset;
|
||||
if (oi instanceof CaseOffsetItem) {
|
||||
relOffset = li.offset - (int) ins.offset;
|
||||
relOffset = li.offset - (int) ins.getOffset();
|
||||
} else {
|
||||
relOffset = li.offset - ((int) ins.offset + ins.getBytesLength());
|
||||
relOffset = li.offset - ((int) ins.getOffset() + ins.getBytesLength());
|
||||
}
|
||||
ins.operands[oi.insOperandIndex] = relOffset;
|
||||
}
|
||||
|
||||
@@ -201,8 +201,8 @@ public class AVM2SourceGenerator implements SourceGenerator {
|
||||
return ret;
|
||||
}
|
||||
|
||||
public List<AVM2Instruction> toInsList(List<GraphSourceItem> items) {
|
||||
List<AVM2Instruction> ret = new ArrayList<>();
|
||||
public ArrayList<AVM2Instruction> toInsList(List<GraphSourceItem> items) {
|
||||
ArrayList<AVM2Instruction> ret = new ArrayList<>();
|
||||
for (GraphSourceItem s : items) {
|
||||
if (s instanceof AVM2Instruction) {
|
||||
ret.add((AVM2Instruction) s);
|
||||
@@ -1675,9 +1675,8 @@ public class AVM2SourceGenerator implements SourceGenerator {
|
||||
|
||||
mbody.method_info = abcIndex.getSelectedAbc().addMethodInfo(mi);
|
||||
mi.setBody(mbody);
|
||||
List<AVM2Instruction> mbodyCode = toInsList(src);
|
||||
mbody.setCode(new AVM2Code());
|
||||
mbody.getCode().code = mbodyCode;
|
||||
ArrayList<AVM2Instruction> mbodyCode = toInsList(src);
|
||||
mbody.setCode(new AVM2Code(mbodyCode));
|
||||
|
||||
if (needsActivation) {
|
||||
if (localData.traitUsages.containsKey(mbody)) {
|
||||
|
||||
@@ -122,6 +122,7 @@ public abstract class Action implements GraphSourceItem {
|
||||
*/
|
||||
public int actionLength;
|
||||
|
||||
// todo: honfika: rename to offset to be similar with AS3
|
||||
private long address;
|
||||
|
||||
@Override
|
||||
@@ -208,6 +209,7 @@ public abstract class Action implements GraphSourceItem {
|
||||
}
|
||||
|
||||
public int getTotalActionLength() {
|
||||
// honfika: todo rename to getBytesLength to match the name with the similar method in AS3
|
||||
return actionLength + 1 + (actionCode >= 0x80 ? 2 : 0);
|
||||
}
|
||||
|
||||
|
||||
@@ -672,7 +672,7 @@ public class FastActionList implements Collection<ActionItem> {
|
||||
if (o instanceof ActionItem) {
|
||||
item = (ActionItem) o;
|
||||
} else if (o instanceof Action) {
|
||||
item = actionItemMap.get(o);
|
||||
item = actionItemMap.get((Action) o);
|
||||
}
|
||||
|
||||
if (item == null) {
|
||||
|
||||
@@ -31,7 +31,6 @@ import com.jpexs.decompiler.flash.tags.Tag;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
@@ -90,7 +89,6 @@ public class ActionScript3ExecuteTest {
|
||||
runBody.max_stack = 10;
|
||||
|
||||
AVM2Code ccode = new AVM2Code();
|
||||
ccode.code = new ArrayList<>();
|
||||
List<AVM2Instruction> code = ccode.code;
|
||||
code.add(new AVM2Instruction(0, AVM2Instructions.GetLocal0, null));
|
||||
code.add(new AVM2Instruction(0, AVM2Instructions.PushScope, null));
|
||||
@@ -98,7 +96,6 @@ public class ActionScript3ExecuteTest {
|
||||
|
||||
for (int testMethodId = 1; testMethodId < 10; testMethodId++) {
|
||||
AVM2Code ccode2 = new AVM2Code();
|
||||
ccode2.code = new ArrayList<>();
|
||||
List<AVM2Instruction> code2 = ccode2.code;
|
||||
code2.add(new AVM2Instruction(0, AVM2Instructions.GetLocal0, null));
|
||||
code2.add(new AVM2Instruction(0, AVM2Instructions.PushScope, null));
|
||||
|
||||
@@ -301,7 +301,6 @@ public class AdobeFlashExecutor {
|
||||
int multinameId = abc.constants.getMultinameId(multiname, true);
|
||||
|
||||
AVM2Code ccode = new AVM2Code();
|
||||
ccode.code = new ArrayList<>();
|
||||
List<AVM2Instruction> code = ccode.code;
|
||||
code.add(new AVM2Instruction(0, AVM2Instructions.GetLocal0, null));
|
||||
code.add(new AVM2Instruction(0, AVM2Instructions.PushScope, null));
|
||||
|
||||
@@ -84,7 +84,6 @@ import java.util.Random;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
import static org.testng.Assert.fail;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -109,7 +108,6 @@ public class FlashPlayerTest {
|
||||
List<AS3ExecuteTask> tasks = new ArrayList<>();
|
||||
for (int p1 = 0; p1 < pushes.length; p1++) {
|
||||
AVM2Code ccode = new AVM2Code();
|
||||
ccode.code = new ArrayList<>();
|
||||
List<AVM2Instruction> code = ccode.code;
|
||||
code.add(new AVM2Instruction(0, AVM2Instructions.GetLocal0, null));
|
||||
code.add(new AVM2Instruction(0, AVM2Instructions.PushScope, null));
|
||||
@@ -213,7 +211,6 @@ public class FlashPlayerTest {
|
||||
}
|
||||
|
||||
AVM2Code ccode = new AVM2Code();
|
||||
ccode.code = new ArrayList<>();
|
||||
List<AVM2Instruction> code = ccode.code;
|
||||
code.add(new AVM2Instruction(0, AVM2Instructions.GetLocal0, null));
|
||||
code.add(new AVM2Instruction(0, AVM2Instructions.PushScope, null));
|
||||
|
||||
Reference in New Issue
Block a user