AS3: Lookupswitch offsets deobfuscation fix

This commit is contained in:
Jindra Petřík
2015-06-21 07:26:27 +02:00
parent 84398eaccf
commit b286c45036
3 changed files with 50 additions and 12 deletions
@@ -1872,30 +1872,68 @@ public class AVM2Code implements Cloneable {
{
for (int i = 0; i < pos; i++) {
for (int j = 0; j < code.get(i).definition.operands.length; j++) {
if (code.get(i).definition.operands[j] == AVM2Code.DAT_OFFSET) {
long target = code.get(i).offset + code.get(i).getBytes().length + code.get(i).operands[j];
if (code.get(i).definition instanceof LookupSwitchIns) {
long target = code.get(i).offset + code.get(i).operands[0];
if (target > instruction.offset) {
code.get(i).operands[0] += byteCount;
}
if (target == instruction.offset && !preRefsToThis) {
code.get(i).operands[0] += byteCount;
}
for (int k = 2; k < code.get(i).operands.length; k++) {
target = code.get(i).offset + code.get(i).operands[k];
if (target > instruction.offset) {
code.get(i).operands[j] += byteCount;
code.get(i).operands[k] += byteCount;
}
if (target == instruction.offset && !preRefsToThis) {
code.get(i).operands[j] += byteCount;
code.get(i).operands[k] += byteCount;
}
}
} else {
for (int j = 0; j < code.get(i).definition.operands.length; j++) {
if (code.get(i).definition.operands[j] == AVM2Code.DAT_OFFSET) {
long target = code.get(i).offset + code.get(i).getBytes().length + code.get(i).operands[j];
if (target > instruction.offset) {
code.get(i).operands[j] += byteCount;
}
if (target == instruction.offset && !preRefsToThis) {
code.get(i).operands[j] += byteCount;
}
}
}
}
}
}
{
for (int i = pos; i < code.size(); i++) {
for (int j = 0; j < code.get(i).definition.operands.length; j++) {
if (code.get(i).definition.operands[j] == AVM2Code.DAT_OFFSET) {
long target = code.get(i).offset + code.get(i).getBytes().length + code.get(i).operands[j];
if (code.get(i).definition instanceof LookupSwitchIns) {
long target = code.get(i).offset + code.get(i).operands[0];
if (target < instruction.offset) {
code.get(i).operands[0] -= byteCount;
}
if (target == instruction.offset && postRefsToThis) {
code.get(i).operands[0] -= byteCount;
}
for (int k = 2; k < code.get(i).operands.length; k++) {
target = code.get(i).offset + code.get(i).operands[k];
if (target < instruction.offset) {
code.get(i).operands[j] -= byteCount;
code.get(i).operands[k] -= byteCount;
}
if (target == instruction.offset && postRefsToThis) {
code.get(i).operands[j] -= byteCount;
code.get(i).operands[k] -= byteCount;
}
}
} else {
for (int j = 0; j < code.get(i).definition.operands.length; j++) {
if (code.get(i).definition.operands[j] == AVM2Code.DAT_OFFSET) {
long target = code.get(i).offset + code.get(i).getBytes().length + code.get(i).operands[j];
if (target < instruction.offset) {
code.get(i).operands[j] -= byteCount;
}
if (target == instruction.offset && postRefsToThis) {
code.get(i).operands[j] -= byteCount;
}
}
}
}
@@ -528,7 +528,7 @@ public class AVM2Graph extends Graph {
GraphTargetItem nt = sstack.peek();
if (!(nt instanceof IntegerValueAVM2Item)) {
throw new RuntimeException("Invalid integer value in Switch");
throw new RuntimeException("Invalid integer value in Switch:" + nt);
}
IntegerValueAVM2Item iv = (IntegerValueAVM2Item) nt;
caseValuesMap.put((int) (long) iv.value, tar);
@@ -49,7 +49,7 @@ public class IntegerValueAVM2Item extends NumberValueAVM2Item {
@Override
public Object getResult() {
return (Double) (double) (long) value;
return value;//(Double) (double) (long) value;
}
@Override