mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-07-19 03:18:19 +00:00
using a function which calculates the target address of the IfType instructions
This commit is contained in:
@@ -733,14 +733,14 @@ public class AVM2Code implements Cloneable {
|
||||
}
|
||||
if (ins.definition instanceof JumpIns) {
|
||||
try {
|
||||
pos = adr2pos(pos2adr(pos) + ins.getBytesLength() + ins.operands[0]);
|
||||
pos = adr2pos(ins.getTargetAddress());
|
||||
continue;
|
||||
} catch (ConvertException ex) {
|
||||
return false;
|
||||
}
|
||||
} else if (ins.definition instanceof IfTypeIns) {
|
||||
try {
|
||||
int newpos = adr2pos(pos2adr(pos) + ins.getBytesLength() + ins.operands[0]);
|
||||
int newpos = adr2pos(ins.getTargetAddress());
|
||||
calculateDebugFileLine(debugFile, debugLine, newpos, abc, seen);
|
||||
} catch (ConvertException ex) {
|
||||
return false;
|
||||
@@ -1978,8 +1978,8 @@ public class AVM2Code implements Cloneable {
|
||||
}
|
||||
}*/
|
||||
//Faster, but not so universal
|
||||
if ((ins.definition instanceof JumpIns) || (ins.definition instanceof IfTypeIns)) {
|
||||
long target = ins.getOffset() + ins.getBytesLength() + ins.operands[0];
|
||||
if (ins.definition instanceof IfTypeIns) {
|
||||
long target = ins.getTargetAddress();
|
||||
try {
|
||||
ins.operands[0] = updater.updateOperandOffset(ins.getOffset(), target, ins.operands[0]);
|
||||
} catch (ConvertException cex) {
|
||||
@@ -2322,14 +2322,14 @@ public class AVM2Code implements Cloneable {
|
||||
}
|
||||
if (ins.definition instanceof JumpIns) {
|
||||
try {
|
||||
pos = adr2pos(pos2adr(pos) + ins.getBytesLength() + ins.operands[0]);
|
||||
pos = adr2pos(ins.getTargetAddress());
|
||||
continue;
|
||||
} catch (ConvertException ex) {
|
||||
return false;
|
||||
}
|
||||
} else if (ins.definition instanceof IfTypeIns) {
|
||||
try {
|
||||
int newpos = adr2pos(pos2adr(pos) + ins.getBytesLength() + ins.operands[0]);
|
||||
int newpos = adr2pos(ins.getTargetAddress());
|
||||
walkCode(stats, newpos, stack, scope, abc);
|
||||
} catch (ConvertException ex) {
|
||||
return false;
|
||||
@@ -2459,14 +2459,14 @@ public class AVM2Code implements Cloneable {
|
||||
}
|
||||
if (ins.definition instanceof JumpIns) {
|
||||
try {
|
||||
ip = adr2pos(pos2adr(ip) + ins.getBytesLength() + ins.operands[0]);
|
||||
ip = adr2pos(ins.getTargetAddress());
|
||||
continue;
|
||||
} catch (ConvertException ex) {
|
||||
logger.log(Level.FINE, null, ex);
|
||||
}
|
||||
} else if (ins.definition instanceof IfTypeIns) {
|
||||
try {
|
||||
toVisit.add(adr2pos(pos2adr(ip) + ins.getBytesLength() + ins.operands[0]));
|
||||
toVisit.add(adr2pos(ins.getTargetAddress()));
|
||||
toVisitLast.add(ip);
|
||||
} catch (ConvertException ex) {
|
||||
logger.log(Level.FINE, null, ex);
|
||||
|
||||
@@ -185,7 +185,7 @@ public class AVM2DeobfuscatorGetSet extends SWFDecompilerAdapter {
|
||||
|
||||
boolean ifed = false;
|
||||
if (def instanceof JumpIns) {
|
||||
long address = ins.getOffset() + ins.getBytesLength() + ins.operands[0];
|
||||
long address = ins.getTargetAddress();
|
||||
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.getOffset() + ins.operands[0] + ins.getBytesLength();
|
||||
long targetAddr = ins.getTargetAddress();
|
||||
{
|
||||
for (int r : refs.get(i)) {
|
||||
if (r >= 0) { //Not Exception start/end
|
||||
|
||||
@@ -264,7 +264,7 @@ public class AVM2DeobfuscatorRegisters extends AVM2DeobfuscatorSimple {
|
||||
|
||||
if (ins.definition instanceof JumpIns) {
|
||||
|
||||
long address = ins.getOffset() + ins.getBytesLength() + ins.operands[0];
|
||||
long address = ins.getTargetAddress();
|
||||
idx = code.adr2pos(address);//code.indexOf(code.getByAddress(address));
|
||||
if (idx == -1) {
|
||||
throw new TranslateException("Jump target not found: " + address);
|
||||
|
||||
@@ -228,7 +228,7 @@ public class AVM2DeobfuscatorRegistersOld extends AVM2DeobfuscatorSimpleOld {
|
||||
|
||||
if (ins.definition instanceof JumpIns) {
|
||||
|
||||
long address = ins.getOffset() + ins.getBytesLength() + ins.operands[0];
|
||||
long address = ins.getTargetAddress();
|
||||
idx = code.adr2pos(address);//code.indexOf(code.getByAddress(address));
|
||||
if (idx == -1) {
|
||||
throw new TranslateException("Jump target not found: " + address);
|
||||
|
||||
@@ -303,7 +303,7 @@ public class AVM2DeobfuscatorSimple extends SWFDecompilerAdapter {
|
||||
|
||||
boolean ifed = false;
|
||||
if (def instanceof IfTypeIns && !(def instanceof JumpIns)) {
|
||||
long address = ins.getOffset() + ins.getBytesLength() + ins.operands[0];
|
||||
long address = ins.getTargetAddress();
|
||||
int nidx = code.adr2pos(address);
|
||||
AVM2Instruction tarIns = code.code.get(nidx);
|
||||
|
||||
@@ -320,7 +320,7 @@ public class AVM2DeobfuscatorSimple extends SWFDecompilerAdapter {
|
||||
code.insertInstruction(idx, new AVM2Instruction(ins.getOffset(), DeobfuscatePopIns.getInstance(), null), true, body);
|
||||
}
|
||||
|
||||
idx = code.adr2pos(jumpIns.getOffset() + jumpIns.getBytesLength() + jumpIns.operands[0]);
|
||||
idx = code.adr2pos(jumpIns.getTargetAddress());
|
||||
} else {
|
||||
//System.err.println("replacing " + ins + " on " + idx + " with pop");
|
||||
code.replaceInstruction(idx, new AVM2Instruction(ins.getOffset(), DeobfuscatePopIns.getInstance(), null), body);
|
||||
|
||||
@@ -342,7 +342,7 @@ public class AVM2DeobfuscatorSimpleOld extends SWFDecompilerAdapter {
|
||||
|
||||
boolean ifed = false;
|
||||
if (def instanceof JumpIns) {
|
||||
long address = ins.getOffset() + ins.getBytesLength() + ins.operands[0];
|
||||
long address = ins.getTargetAddress();
|
||||
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.getOffset() + ins.getBytesLength() + ins.operands[0];
|
||||
long address = ins.getTargetAddress();
|
||||
int nidx = code.adr2pos(address);//code.indexOf(code.getByAddress(address));
|
||||
AVM2Instruction tarIns = code.code.get(nidx);
|
||||
|
||||
@@ -372,7 +372,7 @@ public class AVM2DeobfuscatorSimpleOld extends SWFDecompilerAdapter {
|
||||
code.insertInstruction(idx, new AVM2Instruction(ins.getOffset(), DeobfuscatePopIns.getInstance(), null), true, body);
|
||||
}
|
||||
|
||||
idx = code.adr2pos(jumpIns.getOffset() + jumpIns.getBytesLength() + jumpIns.operands[0]);
|
||||
idx = code.adr2pos(jumpIns.getTargetAddress());
|
||||
} else {
|
||||
//System.err.println("replacing " + ins + " on " + idx + " with pop");
|
||||
code.replaceInstruction(idx, new AVM2Instruction(ins.getOffset(), DeobfuscatePopIns.getInstance(), null), body);
|
||||
|
||||
@@ -379,12 +379,16 @@ public class AVM2Instruction implements Cloneable, GraphSourceItem {
|
||||
this.offset = offset;
|
||||
}
|
||||
|
||||
public long getTargetAddress() {
|
||||
return offset + 4 /*getBytesLength()*/ + operands[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Integer> getBranches(GraphSource code) {
|
||||
List<Integer> ret = new ArrayList<>();
|
||||
if (definition instanceof IfTypeIns) {
|
||||
|
||||
ret.add(code.adr2pos(offset + getBytesLength() + operands[0]));
|
||||
ret.add(code.adr2pos(getTargetAddress()));
|
||||
if (!(definition instanceof JumpIns)) {
|
||||
ret.add(code.adr2pos(offset + getBytesLength()));
|
||||
}
|
||||
|
||||
@@ -126,10 +126,11 @@ public class ActionIf extends Action {
|
||||
public List<Integer> getBranches(GraphSource code) {
|
||||
List<Integer> ret = super.getBranches(code);
|
||||
int length = getTotalActionLength();
|
||||
int jmp = code.adr2pos(getAddress() + length + offset);
|
||||
long targetAddress = getTargetAddress();
|
||||
int jmp = code.adr2pos(targetAddress);
|
||||
int after = code.adr2pos(getAddress() + length);
|
||||
if (jmp == -1) {
|
||||
Logger.getLogger(ActionIf.class.getName()).log(Level.SEVERE, "Invalid IF jump to ofs" + Helper.formatAddress(getAddress() + length + offset));
|
||||
Logger.getLogger(ActionIf.class.getName()).log(Level.SEVERE, "Invalid IF jump to ofs" + Helper.formatAddress(targetAddress));
|
||||
ret.add(after);
|
||||
} else {
|
||||
ret.add(jmp);
|
||||
|
||||
@@ -117,11 +117,12 @@ public class ActionJump extends Action {
|
||||
@Override
|
||||
public List<Integer> getBranches(GraphSource code) {
|
||||
List<Integer> ret = super.getBranches(code);
|
||||
int length = getBytesLength();
|
||||
int ofs = code.adr2pos(getAddress() + length + offset);
|
||||
long targetAddress = getTargetAddress();
|
||||
int ofs = code.adr2pos(targetAddress);
|
||||
if (ofs == -1) {
|
||||
int length = getBytesLength();
|
||||
ofs = code.adr2pos(getAddress() + length);
|
||||
Logger.getLogger(ActionJump.class.getName()).log(Level.SEVERE, "Invalid jump to ofs" + Helper.formatAddress(getAddress() + length + offset) + " from ofs" + Helper.formatAddress(getAddress()));
|
||||
Logger.getLogger(ActionJump.class.getName()).log(Level.SEVERE, "Invalid jump to ofs" + Helper.formatAddress(targetAddress) + " from ofs" + Helper.formatAddress(getAddress()));
|
||||
}
|
||||
ret.add(ofs);
|
||||
return ret;
|
||||
|
||||
Reference in New Issue
Block a user