AS3: insert instruction fix for try

This commit is contained in:
Jindra Petřík
2015-06-21 07:31:36 +02:00
parent b286c45036
commit 18c295010a
2 changed files with 18 additions and 6 deletions

View File

@@ -1847,16 +1847,16 @@ public class AVM2Code implements Cloneable {
* @param pos
* @param instruction
*/
public void insertInstruction(int pos, AVM2Instruction instruction) {
insertInstruction(pos, instruction, true, false);
public void insertInstruction(int pos, AVM2Instruction instruction, MethodBody body) {
insertInstruction(pos, instruction, true, false, body);
}
public void replaceInstruction(int idx, AVM2Instruction ins, MethodBody body) {
insertInstruction(idx, ins, true, true);
insertInstruction(idx, ins, true, true, body);
removeInstruction(idx + 1, body);
}
public void insertInstruction(int pos, AVM2Instruction instruction, boolean preRefsToThis, boolean postRefsToThis) {
public void insertInstruction(int pos, AVM2Instruction instruction, boolean preRefsToThis, boolean postRefsToThis, MethodBody body) {
if (pos < 0) {
pos = 0;
}
@@ -1870,6 +1870,18 @@ public class AVM2Code implements Cloneable {
instruction.offset = code.get(pos).offset;
}
for (ABCException ex : body.exceptions) {
if (ex.start > instruction.offset) {
ex.start += byteCount;
}
if (ex.end > instruction.offset) {
ex.end += byteCount;
}
if (ex.target > instruction.offset) {
ex.target += byteCount;
}
}
{
for (int i = 0; i < pos; i++) {
if (code.get(i).definition instanceof LookupSwitchIns) {

View File

@@ -178,7 +178,7 @@ public class AVM2DeobfuscatorSimple implements SWFDecompilerListener {
}
AVM2Instruction ins = makePush(graphTargetItem.getResult(), cpool);
if (ins != null) {
code.insertInstruction(i + (idelta++), ins);
code.insertInstruction(i + (idelta++), ins, body);
//prevAction = ins;
} else {
throw new TranslateException("Cannot push: " + graphTargetItem);
@@ -188,7 +188,7 @@ public class AVM2DeobfuscatorSimple implements SWFDecompilerListener {
}
AVM2Instruction jump = new AVM2Instruction(0, new JumpIns(), new int[]{0});
code.insertInstruction(i + (idelta++), jump);
code.insertInstruction(i + (idelta++), jump, body);
jump.operands[0] = ((int) (target.offset - jump.offset - jump.getBytes().length));