mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-07-04 23:04:21 +00:00
unnecessarry try-catch removed from deobfuscarot methods 2 + small fixes
This commit is contained in:
@@ -578,6 +578,8 @@ public class ABC {
|
||||
SWFDecompilerPlugin.fireMethodBodyParsed(mb, swf);
|
||||
}
|
||||
|
||||
createBodyIdxFromMethodIdxMap();
|
||||
|
||||
/*for(int i=0;i<script_count;i++){
|
||||
MethodBody bod=bodies.get(bodyIdxFromMethodIdx.get(script_info.get(i).init_index));
|
||||
GraphTextWriter t=new HighlightedTextWriter(Configuration.getCodeFormatting(),false);
|
||||
@@ -843,17 +845,20 @@ public class ABC {
|
||||
return deobfuscation;
|
||||
}
|
||||
|
||||
private Map<Integer, Integer> getBodyIdxFromMethodIdx() {
|
||||
if (bodyIdxFromMethodIdx == null) {
|
||||
Map<Integer, Integer> map = new HashMap<>(bodies.size());
|
||||
for (int i = 0; i < bodies.size(); i++) {
|
||||
MethodBody mb = bodies.get(i);
|
||||
map.put(mb.method_info, i);
|
||||
}
|
||||
|
||||
bodyIdxFromMethodIdx = map;
|
||||
public final void createBodyIdxFromMethodIdxMap() {
|
||||
Map<Integer, Integer> map = new HashMap<>(bodies.size());
|
||||
for (int i = 0; i < bodies.size(); i++) {
|
||||
MethodBody mb = bodies.get(i);
|
||||
map.put(mb.method_info, i);
|
||||
}
|
||||
|
||||
bodyIdxFromMethodIdx = map;
|
||||
}
|
||||
|
||||
private Map<Integer, Integer> getBodyIdxFromMethodIdx() {
|
||||
if (bodyIdxFromMethodIdx == null) {
|
||||
createBodyIdxFromMethodIdxMap();
|
||||
}
|
||||
return bodyIdxFromMethodIdx;
|
||||
}
|
||||
|
||||
@@ -1305,5 +1310,7 @@ public class ABC {
|
||||
m--;
|
||||
}
|
||||
}
|
||||
|
||||
createBodyIdxFromMethodIdxMap();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,8 @@ public class ClassPath {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return packageStr.isEmpty() ? className : packageStr.toPrintableString(true) + "." + IdentifiersDeobfuscation.printIdentifier(true, className);
|
||||
return packageStr.isEmpty() ? IdentifiersDeobfuscation.printIdentifier(true, className)
|
||||
: packageStr.toPrintableString(true) + "." + IdentifiersDeobfuscation.printIdentifier(true, className);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -180,132 +180,129 @@ public class AVM2DeobfuscatorRegisters extends AVM2DeobfuscatorSimple {
|
||||
while (!toVisit.isEmpty()) {
|
||||
idx = toVisit.remove(0);
|
||||
stack = toVisitStacks.remove(0);
|
||||
try {
|
||||
while (true) {
|
||||
if (idx > endIdx) {
|
||||
break;
|
||||
}
|
||||
if (visited.contains(idx)) {
|
||||
break;
|
||||
}
|
||||
visited.add(idx);
|
||||
|
||||
AVM2Instruction ins = code.code.get(idx);
|
||||
InstructionDefinition def = ins.definition;
|
||||
while (true) {
|
||||
if (idx > endIdx) {
|
||||
break;
|
||||
}
|
||||
if (visited.contains(idx)) {
|
||||
break;
|
||||
}
|
||||
visited.add(idx);
|
||||
|
||||
AVM2Instruction ins = code.code.get(idx);
|
||||
InstructionDefinition def = ins.definition;
|
||||
//System.err.println("" + idx + ": " + ins + " stack:" + stack.size());
|
||||
|
||||
// do not throw EmptyStackException, much faster
|
||||
int requiredStackSize = ins.getStackPopCount(localData);
|
||||
if (stack.size() < requiredStackSize) {
|
||||
continue outer;
|
||||
// do not throw EmptyStackException, much faster
|
||||
int requiredStackSize = ins.getStackPopCount(localData);
|
||||
if (stack.size() < requiredStackSize) {
|
||||
continue outer;
|
||||
}
|
||||
|
||||
ins.translate(localData, stack, output, Graph.SOP_USE_STATIC, "");
|
||||
|
||||
//if (!(def instanceof KillIns))
|
||||
if (def instanceof SetLocalTypeIns) {
|
||||
int regId = ((SetLocalTypeIns) def).getRegisterId(ins);
|
||||
if (!ignored.contains(regId)) {
|
||||
assignment.setVal(ins);
|
||||
return regId;
|
||||
}
|
||||
|
||||
ins.translate(localData, stack, output, Graph.SOP_USE_STATIC, "");
|
||||
|
||||
//if (!(def instanceof KillIns))
|
||||
if (def instanceof SetLocalTypeIns) {
|
||||
int regId = ((SetLocalTypeIns) def).getRegisterId(ins);
|
||||
if (!ignored.contains(regId)) {
|
||||
assignment.setVal(ins);
|
||||
return regId;
|
||||
}
|
||||
} else if (def instanceof GetLocalTypeIns) {
|
||||
int regId = ((GetLocalTypeIns) def).getRegisterId(ins);
|
||||
if (!ignored.contains(regId) && !ignoredGets.contains(regId)) {
|
||||
assignment.setVal(ins);
|
||||
return regId;
|
||||
}
|
||||
} else {
|
||||
for (int p = 0; p < ins.definition.operands.length; p++) {
|
||||
int op = ins.definition.operands[p];
|
||||
if (op == AVM2Code.DAT_REGISTER_INDEX) {
|
||||
int regId = ins.operands[p];
|
||||
if (!ignored.contains(regId)) {
|
||||
assignment.setVal(ins);
|
||||
return regId;
|
||||
}
|
||||
} else if (def instanceof GetLocalTypeIns) {
|
||||
int regId = ((GetLocalTypeIns) def).getRegisterId(ins);
|
||||
if (!ignored.contains(regId) && !ignoredGets.contains(regId)) {
|
||||
assignment.setVal(ins);
|
||||
return regId;
|
||||
}
|
||||
} else {
|
||||
for (int p = 0; p < ins.definition.operands.length; p++) {
|
||||
int op = ins.definition.operands[p];
|
||||
if (op == AVM2Code.DAT_REGISTER_INDEX) {
|
||||
int regId = ins.operands[p];
|
||||
if (!ignored.contains(regId)) {
|
||||
assignment.setVal(ins);
|
||||
return regId;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
idx++;
|
||||
|
||||
if (ins.definition instanceof JumpIns) {
|
||||
|
||||
long address = ins.offset + 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);
|
||||
}
|
||||
}
|
||||
|
||||
if (ins.isBranch()) {
|
||||
List<Integer> branches = ins.getBranches(new GraphSource() {
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public GraphSourceItem get(int pos) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<GraphTargetItem> translatePart(GraphPart part, BaseLocalData localData, TranslateStack stack, int start, int end, int staticOperation, String path) throws InterruptedException {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public int adr2pos(long adr) {
|
||||
return code.adr2pos(adr);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long pos2adr(int pos) {
|
||||
return code.pos2adr(pos);
|
||||
}
|
||||
});
|
||||
idx = branches.get(0);
|
||||
for (int n = 1; n < branches.size(); n++) {
|
||||
//visitCode(visited, (TranslateStack) stack.clone(), classIndex, isStatic, body, scriptIndex, abc, code, branches.get(n), endIdx, result);
|
||||
int nidx = branches.get(n);
|
||||
if (visited.contains(nidx)) {
|
||||
continue;
|
||||
}
|
||||
toVisit.add(nidx);
|
||||
toVisitStacks.add((TranslateStack) stack.clone());
|
||||
}
|
||||
}
|
||||
/*if (ins.definition instanceof IfTypeIns) {
|
||||
long address = ins.offset + ins.getBytes().length + ins.operands[0];
|
||||
int newIdx = code.adr2pos(address);
|
||||
if (newIdx == -1) {
|
||||
throw new TranslateException("If target not found: " + address);
|
||||
}
|
||||
visitCode(visited, (TranslateStack) stack.clone(), classIndex, isStatic, body, scriptIndex, abc, code, newIdx, endIdx, result);
|
||||
}*/
|
||||
|
||||
if (ins.definition instanceof ReturnValueIns) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (ins.definition instanceof ThrowIns) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (ins.definition instanceof ReturnVoidIns) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (ThreadDeath | InterruptedException ex) {
|
||||
throw ex;
|
||||
|
||||
idx++;
|
||||
|
||||
if (ins.definition instanceof JumpIns) {
|
||||
|
||||
long address = ins.offset + 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);
|
||||
}
|
||||
}
|
||||
|
||||
if (ins.isBranch()) {
|
||||
List<Integer> branches = ins.getBranches(new GraphSource() {
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public GraphSourceItem get(int pos) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<GraphTargetItem> translatePart(GraphPart part, BaseLocalData localData, TranslateStack stack, int start, int end, int staticOperation, String path) throws InterruptedException {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public int adr2pos(long adr) {
|
||||
return code.adr2pos(adr);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long pos2adr(int pos) {
|
||||
return code.pos2adr(pos);
|
||||
}
|
||||
});
|
||||
idx = branches.get(0);
|
||||
for (int n = 1; n < branches.size(); n++) {
|
||||
//visitCode(visited, (TranslateStack) stack.clone(), classIndex, isStatic, body, scriptIndex, abc, code, branches.get(n), endIdx, result);
|
||||
int nidx = branches.get(n);
|
||||
if (visited.contains(nidx)) {
|
||||
continue;
|
||||
}
|
||||
toVisit.add(nidx);
|
||||
toVisitStacks.add((TranslateStack) stack.clone());
|
||||
}
|
||||
}
|
||||
/*if (ins.definition instanceof IfTypeIns) {
|
||||
long address = ins.offset + ins.getBytes().length + ins.operands[0];
|
||||
int newIdx = code.adr2pos(address);
|
||||
if (newIdx == -1) {
|
||||
throw new TranslateException("If target not found: " + address);
|
||||
}
|
||||
visitCode(visited, (TranslateStack) stack.clone(), classIndex, isStatic, body, scriptIndex, abc, code, newIdx, endIdx, result);
|
||||
}*/
|
||||
|
||||
if (ins.definition instanceof ReturnValueIns) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (ins.definition instanceof ThrowIns) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (ins.definition instanceof ReturnVoidIns) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
|
||||
@@ -254,169 +254,165 @@ public class AVM2DeobfuscatorSimple implements SWFDecompilerListener {
|
||||
FixItemCounterTranslateStack stack = new FixItemCounterTranslateStack("");
|
||||
int instructionsProcessed = 0;
|
||||
|
||||
try {
|
||||
while (true) {
|
||||
if (idx > endIdx) {
|
||||
break;
|
||||
}
|
||||
while (true) {
|
||||
if (idx > endIdx) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (instructionsProcessed > executionLimit) {
|
||||
break;
|
||||
}
|
||||
if (instructionsProcessed > executionLimit) {
|
||||
break;
|
||||
}
|
||||
|
||||
AVM2Instruction ins = code.code.get(idx);
|
||||
if (ins.definition 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);
|
||||
continue;
|
||||
}
|
||||
AVM2Instruction ins = code.code.get(idx);
|
||||
if (ins.definition 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);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// do not throw EmptyStackException, much faster
|
||||
int requiredStackSize = ins.getStackPopCount(localData);
|
||||
if (stack.size() < requiredStackSize) {
|
||||
return;
|
||||
}
|
||||
|
||||
ins.translate(localData, stack, output, Graph.SOP_USE_STATIC, "");
|
||||
}
|
||||
|
||||
InstructionDefinition def = ins.definition;
|
||||
|
||||
if (inlineIns.contains(ins)) {
|
||||
if (def instanceof SetLocalTypeIns) {
|
||||
int regId = ((SetLocalTypeIns) def).getRegisterId(ins);
|
||||
staticRegs.put(regId, localData.localRegs.get(regId).getNotCoerced());
|
||||
code.replaceInstruction(idx, new AVM2Instruction(0, new DeobfuscatePopIns(), null), body);
|
||||
}
|
||||
}
|
||||
if (def instanceof GetLocalTypeIns) {
|
||||
int regId = ((GetLocalTypeIns) def).getRegisterId(ins);
|
||||
if (staticRegs.containsKey(regId)) {
|
||||
stack.pop();
|
||||
AVM2Instruction pushins = makePush(abc.constants, staticRegs.get(regId));
|
||||
code.replaceInstruction(idx, pushins, body);
|
||||
stack.push(staticRegs.get(regId));
|
||||
ins = pushins;
|
||||
def = ins.definition;
|
||||
}
|
||||
}
|
||||
|
||||
boolean ok = false;
|
||||
if (def instanceof PushByteIns
|
||||
|| def instanceof PushShortIns
|
||||
|| def instanceof PushIntIns
|
||||
|| def instanceof PushDoubleIns
|
||||
|| def instanceof PushStringIns
|
||||
|| def instanceof PushNullIns
|
||||
|| def instanceof PushUndefinedIns
|
||||
|| def instanceof PushFalseIns
|
||||
|| def instanceof PushTrueIns
|
||||
|| def instanceof DupIns
|
||||
|| def instanceof SwapIns
|
||||
|| def instanceof AddIns
|
||||
|| def instanceof AddIIns
|
||||
|| def instanceof SubtractIns
|
||||
|| def instanceof SubtractIIns
|
||||
|| def instanceof ModuloIns
|
||||
|| def instanceof MultiplyIns
|
||||
|| def instanceof BitAndIns
|
||||
|| def instanceof BitXorIns
|
||||
|| def instanceof BitOrIns
|
||||
|| def instanceof LShiftIns
|
||||
|| def instanceof RShiftIns
|
||||
|| def instanceof URShiftIns
|
||||
|| def instanceof EqualsIns
|
||||
|| def instanceof NotIns
|
||||
|| def instanceof IfTypeIns
|
||||
|| def instanceof JumpIns
|
||||
|| def instanceof EqualsIns
|
||||
|| def instanceof LessEqualsIns
|
||||
|| def instanceof GreaterEqualsIns
|
||||
|| def instanceof GreaterThanIns
|
||||
|| def instanceof LessThanIns
|
||||
|| def instanceof StrictEqualsIns
|
||||
|| def instanceof PopIns
|
||||
|| def instanceof GetLocalTypeIns
|
||||
|| def instanceof NewFunctionIns
|
||||
|| def instanceof CoerceOrConvertTypeIns) {
|
||||
ok = true;
|
||||
}
|
||||
|
||||
if (!ok) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (def instanceof GetLocalTypeIns) {
|
||||
int regId = ((GetLocalTypeIns) def).getRegisterId(ins);
|
||||
if (staticRegs.containsKey(regId)) {
|
||||
stack.pop();
|
||||
stack.push(staticRegs.get(regId));
|
||||
} else {
|
||||
// do not throw EmptyStackException, much faster
|
||||
int requiredStackSize = ins.getStackPopCount(localData);
|
||||
if (stack.size() < requiredStackSize) {
|
||||
return;
|
||||
}
|
||||
|
||||
ins.translate(localData, stack, output, Graph.SOP_USE_STATIC, "");
|
||||
}
|
||||
|
||||
InstructionDefinition def = ins.definition;
|
||||
|
||||
if (inlineIns.contains(ins)) {
|
||||
if (def instanceof SetLocalTypeIns) {
|
||||
int regId = ((SetLocalTypeIns) def).getRegisterId(ins);
|
||||
staticRegs.put(regId, localData.localRegs.get(regId).getNotCoerced());
|
||||
code.replaceInstruction(idx, new AVM2Instruction(0, new DeobfuscatePopIns(), null), body);
|
||||
}
|
||||
}
|
||||
if (def instanceof GetLocalTypeIns) {
|
||||
int regId = ((GetLocalTypeIns) def).getRegisterId(ins);
|
||||
if (staticRegs.containsKey(regId)) {
|
||||
stack.pop();
|
||||
AVM2Instruction pushins = makePush(abc.constants, staticRegs.get(regId));
|
||||
code.replaceInstruction(idx, pushins, body);
|
||||
stack.push(staticRegs.get(regId));
|
||||
ins = pushins;
|
||||
def = ins.definition;
|
||||
}
|
||||
}
|
||||
|
||||
boolean ok = false;
|
||||
if (def instanceof PushByteIns
|
||||
|| def instanceof PushShortIns
|
||||
|| def instanceof PushIntIns
|
||||
|| def instanceof PushDoubleIns
|
||||
|| def instanceof PushStringIns
|
||||
|| def instanceof PushNullIns
|
||||
|| def instanceof PushUndefinedIns
|
||||
|| def instanceof PushFalseIns
|
||||
|| def instanceof PushTrueIns
|
||||
|| def instanceof DupIns
|
||||
|| def instanceof SwapIns
|
||||
|| def instanceof AddIns
|
||||
|| def instanceof AddIIns
|
||||
|| def instanceof SubtractIns
|
||||
|| def instanceof SubtractIIns
|
||||
|| def instanceof ModuloIns
|
||||
|| def instanceof MultiplyIns
|
||||
|| def instanceof BitAndIns
|
||||
|| def instanceof BitXorIns
|
||||
|| def instanceof BitOrIns
|
||||
|| def instanceof LShiftIns
|
||||
|| def instanceof RShiftIns
|
||||
|| def instanceof URShiftIns
|
||||
|| def instanceof EqualsIns
|
||||
|| def instanceof NotIns
|
||||
|| def instanceof IfTypeIns
|
||||
|| def instanceof JumpIns
|
||||
|| def instanceof EqualsIns
|
||||
|| def instanceof LessEqualsIns
|
||||
|| def instanceof GreaterEqualsIns
|
||||
|| def instanceof GreaterThanIns
|
||||
|| def instanceof LessThanIns
|
||||
|| def instanceof StrictEqualsIns
|
||||
|| def instanceof PopIns
|
||||
|| def instanceof GetLocalTypeIns
|
||||
|| def instanceof NewFunctionIns
|
||||
|| def instanceof CoerceOrConvertTypeIns) {
|
||||
ok = true;
|
||||
}
|
||||
|
||||
if (!ok) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (def instanceof GetLocalTypeIns) {
|
||||
int regId = ((GetLocalTypeIns) def).getRegisterId(ins);
|
||||
if (staticRegs.containsKey(regId)) {
|
||||
stack.pop();
|
||||
stack.push(staticRegs.get(regId));
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
boolean ifed = false;
|
||||
if (def instanceof JumpIns) {
|
||||
long address = ins.offset + ins.getBytesLength() + ins.operands[0];
|
||||
idx = code.adr2pos(address);
|
||||
|
||||
if (idx == -1) {
|
||||
throw new TranslateException("Jump target not found: " + address);
|
||||
}
|
||||
} else if (def instanceof IfTypeIns) {
|
||||
GraphTargetItem top = stack.pop();
|
||||
Object res = top.getResult();
|
||||
long address = ins.offset + ins.getBytesLength() + ins.operands[0];
|
||||
int nidx = code.adr2pos(address);//code.indexOf(code.getByAddress(address));
|
||||
AVM2Instruction tarIns = code.code.get(nidx);
|
||||
|
||||
//Some IfType instructions need more than 1 operand, we must pop out all of them
|
||||
int stackCount = -def.getStackDelta(ins, abc);
|
||||
|
||||
if (EcmaScript.toBoolean(res)) {
|
||||
//System.err.println("replacing " + ins + " on " + idx + " with jump");
|
||||
AVM2Instruction jumpIns = new AVM2Instruction(0, new JumpIns(), 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());
|
||||
for (int s = 0; s < stackCount; s++) {
|
||||
code.insertInstruction(idx, new AVM2Instruction(ins.offset, new DeobfuscatePopIns(), null), true, body);
|
||||
}
|
||||
|
||||
idx = code.adr2pos(jumpIns.offset + jumpIns.getBytesLength() + jumpIns.operands[0]);
|
||||
} else {
|
||||
//System.err.println("replacing " + ins + " on " + idx + " with pop");
|
||||
code.replaceInstruction(idx, new AVM2Instruction(ins.offset, new DeobfuscatePopIns(), null), body);
|
||||
for (int s = 1 /*first is replaced*/; s < stackCount; s++) {
|
||||
code.insertInstruction(idx, new AVM2Instruction(ins.offset, new DeobfuscatePopIns(), null), true, body);
|
||||
}
|
||||
//ins.definition = new DeobfuscatePopIns();
|
||||
idx++;
|
||||
}
|
||||
ifed = true;
|
||||
//break;
|
||||
} else {
|
||||
idx++;
|
||||
}
|
||||
|
||||
instructionsProcessed++;
|
||||
|
||||
if (stack.allItemsFixed()) {
|
||||
result.idx = idx == code.code.size() ? idx - 1 : idx;
|
||||
result.instructionsProcessed = instructionsProcessed;
|
||||
result.stack.clear();
|
||||
result.stack.addAll(stack);
|
||||
}
|
||||
if (ifed) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (InterruptedException ex) {
|
||||
throw ex;
|
||||
|
||||
boolean ifed = false;
|
||||
if (def instanceof JumpIns) {
|
||||
long address = ins.offset + ins.getBytesLength() + ins.operands[0];
|
||||
idx = code.adr2pos(address);
|
||||
|
||||
if (idx == -1) {
|
||||
throw new TranslateException("Jump target not found: " + address);
|
||||
}
|
||||
} else if (def instanceof IfTypeIns) {
|
||||
GraphTargetItem top = stack.pop();
|
||||
Object res = top.getResult();
|
||||
long address = ins.offset + ins.getBytesLength() + ins.operands[0];
|
||||
int nidx = code.adr2pos(address);//code.indexOf(code.getByAddress(address));
|
||||
AVM2Instruction tarIns = code.code.get(nidx);
|
||||
|
||||
//Some IfType instructions need more than 1 operand, we must pop out all of them
|
||||
int stackCount = -def.getStackDelta(ins, abc);
|
||||
|
||||
if (EcmaScript.toBoolean(res)) {
|
||||
//System.err.println("replacing " + ins + " on " + idx + " with jump");
|
||||
AVM2Instruction jumpIns = new AVM2Instruction(0, new JumpIns(), 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());
|
||||
for (int s = 0; s < stackCount; s++) {
|
||||
code.insertInstruction(idx, new AVM2Instruction(ins.offset, new DeobfuscatePopIns(), null), true, body);
|
||||
}
|
||||
|
||||
idx = code.adr2pos(jumpIns.offset + jumpIns.getBytesLength() + jumpIns.operands[0]);
|
||||
} else {
|
||||
//System.err.println("replacing " + ins + " on " + idx + " with pop");
|
||||
code.replaceInstruction(idx, new AVM2Instruction(ins.offset, new DeobfuscatePopIns(), null), body);
|
||||
for (int s = 1 /*first is replaced*/; s < stackCount; s++) {
|
||||
code.insertInstruction(idx, new AVM2Instruction(ins.offset, new DeobfuscatePopIns(), null), true, body);
|
||||
}
|
||||
//ins.definition = new DeobfuscatePopIns();
|
||||
idx++;
|
||||
}
|
||||
ifed = true;
|
||||
//break;
|
||||
} else {
|
||||
idx++;
|
||||
}
|
||||
|
||||
instructionsProcessed++;
|
||||
|
||||
if (stack.allItemsFixed()) {
|
||||
result.idx = idx == code.code.size() ? idx - 1 : idx;
|
||||
result.instructionsProcessed = instructionsProcessed;
|
||||
result.stack.clear();
|
||||
result.stack.addAll(stack);
|
||||
}
|
||||
if (ifed) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2445,6 +2445,7 @@ public class ActionScript3Parser {
|
||||
abc.class_info = originalAbc.class_info;
|
||||
abc.script_info = originalAbc.script_info;
|
||||
abc.bodies = originalAbc.bodies;
|
||||
abc.createBodyIdxFromMethodIdxMap();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -235,11 +235,12 @@ public final class MethodBody implements Cloneable {
|
||||
}
|
||||
|
||||
public int getLocalReservedCount() {
|
||||
int pos = abc.method_info.get(this.method_info).param_types.length + 1;
|
||||
if (abc.method_info.get(this.method_info).flagNeed_arguments()) {
|
||||
MethodInfo methodInfo = abc.method_info.get(this.method_info);
|
||||
int pos = methodInfo.param_types.length + 1;
|
||||
if (methodInfo.flagNeed_arguments()) {
|
||||
pos++;
|
||||
}
|
||||
if (abc.method_info.get(this.method_info).flagNeed_rest()) {
|
||||
if (methodInfo.flagNeed_rest()) {
|
||||
pos++;
|
||||
}
|
||||
return pos;
|
||||
|
||||
@@ -171,7 +171,7 @@ public class ActionListReader {
|
||||
|
||||
if (deobfuscationMode == 0) {
|
||||
try {
|
||||
actions = deobfuscateActionList(listeners, actions, version, 0, path);
|
||||
actions = deobfuscateActionListOld(listeners, actions, version, 0, path);
|
||||
updateActionLengths(actions, version);
|
||||
} catch (OutOfMemoryError | StackOverflowError | TranslateException ex) {
|
||||
// keep orignal (not deobfuscated) actions
|
||||
@@ -259,7 +259,7 @@ public class ActionListReader {
|
||||
* @throws IOException
|
||||
* @throws java.lang.InterruptedException
|
||||
*/
|
||||
private static ActionList deobfuscateActionList(List<DisassemblyListener> listeners, ActionList actions, int version, int ip, String path) throws IOException, InterruptedException {
|
||||
private static ActionList deobfuscateActionListOld(List<DisassemblyListener> listeners, ActionList actions, int version, int ip, String path) throws IOException, InterruptedException {
|
||||
if (actions.isEmpty()) {
|
||||
return actions;
|
||||
}
|
||||
@@ -292,7 +292,7 @@ public class ActionListReader {
|
||||
}
|
||||
}
|
||||
|
||||
deobfustaceActionListAtPosRecursive(listeners,
|
||||
deobfustaceActionListAtPosRecursiveOld(listeners,
|
||||
new ArrayList<>(),
|
||||
new HashMap<>(),
|
||||
new ActionLocalData(),
|
||||
@@ -875,7 +875,7 @@ public class ActionListReader {
|
||||
}
|
||||
}
|
||||
|
||||
private static void deobfustaceActionListAtPosRecursive(List<DisassemblyListener> listeners, List<GraphTargetItem> output, HashMap<Long, List<GraphSourceItemContainer>> containers, ActionLocalData localData, TranslateStack stack, ConstantPool cpool, List<Action> actions, int ip, List<Action> ret, int startIp, int endip, String path, Map<Integer, Integer> visited, boolean indeterminate, Map<Integer, HashMap<String, GraphTargetItem>> decisionStates, int version, int recursionLevel, int maxRecursionLevel) throws IOException, InterruptedException {
|
||||
private static void deobfustaceActionListAtPosRecursiveOld(List<DisassemblyListener> listeners, List<GraphTargetItem> output, HashMap<Long, List<GraphSourceItemContainer>> containers, ActionLocalData localData, TranslateStack stack, ConstantPool cpool, List<Action> actions, int ip, List<Action> ret, int startIp, int endip, String path, Map<Integer, Integer> visited, boolean indeterminate, Map<Integer, HashMap<String, GraphTargetItem>> decisionStates, int version, int recursionLevel, int maxRecursionLevel) throws IOException, InterruptedException {
|
||||
boolean debugMode = false;
|
||||
boolean decideBranch = false;
|
||||
|
||||
@@ -1040,7 +1040,7 @@ public class ActionListReader {
|
||||
} else {
|
||||
localData2 = localData;
|
||||
}
|
||||
deobfustaceActionListAtPosRecursive(listeners, output2, containers, localData2, new TranslateStack(path), cpool, actions, (int) endAddr, ret, startIp, (int) (endAddr + size), path + (cntName == null ? "" : "/" + cntName), visited, indeterminate, decisionStates, version, recursionLevel + 1, maxRecursionLevel);
|
||||
deobfustaceActionListAtPosRecursiveOld(listeners, output2, containers, localData2, new TranslateStack(path), cpool, actions, (int) endAddr, ret, startIp, (int) (endAddr + size), path + (cntName == null ? "" : "/" + cntName), visited, indeterminate, decisionStates, version, recursionLevel + 1, maxRecursionLevel);
|
||||
output2s.add(output2);
|
||||
endAddr += size;
|
||||
}
|
||||
@@ -1101,7 +1101,7 @@ public class ActionListReader {
|
||||
TranslateStack subStack = (TranslateStack) stack.clone();
|
||||
ActionLocalData subLocalData = new ActionLocalData(new HashMap<>(localData.regNames),
|
||||
new HashMap<>(localData.variables), new HashMap<>(localData.functions));
|
||||
deobfustaceActionListAtPosRecursive(listeners, output, containers, subLocalData, subStack, cpool, actions, ip + actionLen + aif.getJumpOffset(), ret, startIp, endip, path, visited, indeterminate, decisionStates, version, recursionLevel + 1, maxRecursionLevel);
|
||||
deobfustaceActionListAtPosRecursiveOld(listeners, output, containers, subLocalData, subStack, cpool, actions, ip + actionLen + aif.getJumpOffset(), ret, startIp, endip, path, visited, indeterminate, decisionStates, version, recursionLevel + 1, maxRecursionLevel);
|
||||
}
|
||||
|
||||
if (newip > -1) {
|
||||
|
||||
Reference in New Issue
Block a user