do not check valid offsets on every removeInstruction call.. check it only once after deobfuscation

This commit is contained in:
honfika@gmail.com
2015-07-05 15:03:58 +02:00
parent 5553d3f046
commit afc7229f97
3 changed files with 17 additions and 15 deletions

View File

@@ -1956,7 +1956,7 @@ public class AVM2Code implements Cloneable {
}, body);
}
private void checkValidOffsets(MethodBody body) {
public void checkValidOffsets(MethodBody body) {
updateOffsets(new OffsetUpdater() {
@Override
@@ -1978,14 +1978,15 @@ public class AVM2Code implements Cloneable {
if ((pos < 0) || (pos >= code.size())) {
throw new IndexOutOfBoundsException();
}
checkValidOffsets(body);
//checkValidOffsets(body);
AVM2Instruction ins = code.get(pos);
final long remOffset = ins.offset;
int bc;
if (pos < code.size() - 1) {
// Checking the instuction length is not enough because in some
// obfuscated files the length of the lookupswitch is not the same
// as the diference of the offsets
// as the difference of the offsets
bc = (int) (code.get(pos + 1).offset - remOffset);
} else {
bc = ins.getBytesLength();
@@ -2014,9 +2015,7 @@ public class AVM2Code implements Cloneable {
}, body);
code.remove(pos);
invalidateCache();
checkValidOffsets(body);
//System.exit(0);
//checkValidOffsets(body);
}
/**

View File

@@ -332,24 +332,27 @@ public final class MethodBody implements Cloneable {
}
public MethodBody convertMethodBody(String path, boolean isStatic, int scriptIndex, int classIndex, ABC abc, Trait trait, AVM2ConstantPool constants, List<MethodInfo> method_info, ScopeStack scopeStack, boolean isStaticInitializer, List<String> fullyQualifiedNames, Traits initTraits) throws InterruptedException {
MethodBody b = clone();
b.getCode().markMappedOffsets();
MethodBody body = clone();
body.getCode().markMappedOffsets();
if (Configuration.autoDeobfuscate.get()) {
if (Configuration.deobfuscationOldMode.get()) {
try {
b.getCode().removeTraps(constants, trait, method_info.get(this.method_info), b, abc, scriptIndex, classIndex, isStatic, path);
body.getCode().removeTraps(constants, trait, method_info.get(this.method_info), body, abc, scriptIndex, classIndex, isStatic, path);
} catch (Throwable ex) {
logger.log(Level.SEVERE, "Error during old deobfuscation: " + path, ex);
}
} else {
new AVM2DeobfuscatorSimple().deobfuscate(path, classIndex, isStatic, scriptIndex, abc, constants, trait, method_info.get(this.method_info), b);
new AVM2DeobfuscatorRegisters().deobfuscate(path, classIndex, isStatic, scriptIndex, abc, constants, trait, method_info.get(this.method_info), b);
new AVM2DeobfuscatorJumps().deobfuscate(path, classIndex, isStatic, scriptIndex, abc, constants, trait, method_info.get(this.method_info), b);
new AVM2DeobfuscatorSimple().deobfuscate(path, classIndex, isStatic, scriptIndex, abc, constants, trait, method_info.get(this.method_info), body);
new AVM2DeobfuscatorRegisters().deobfuscate(path, classIndex, isStatic, scriptIndex, abc, constants, trait, method_info.get(this.method_info), body);
new AVM2DeobfuscatorJumps().deobfuscate(path, classIndex, isStatic, scriptIndex, abc, constants, trait, method_info.get(this.method_info), body);
}
// todo: only for debugging. checkValidOffsets can be made private later
body.getCode().checkValidOffsets(body);
}
return b;
return body;
}
@Override

View File

@@ -1053,7 +1053,7 @@ public class Helper {
writer.appendNoHilight(" * ").appendNoHilight(AppResources.translate("decompilationError")).newLine();
writer.appendNoHilight(" * ").appendNoHilight(MessageFormat.format(AppResources.translate("decompilationError.timeout"), Helper.formatTimeToText(timeout))).newLine();
if (actionCount > 0) {
writer.appendNoHilight(" * ").appendNoHilight(AppResources.translate("decompilationError.instructionCount") + " " + actionCount).newLine();
writer.appendNoHilight(" * ").appendNoHilight(AppResources.translate("decompilationError.actionCount") + " " + actionCount).newLine();
}
writer.appendNoHilight(" */").newLine();
@@ -1067,7 +1067,7 @@ public class Helper {
writer.appendNoHilight(" * ").appendNoHilight(AppResources.translate("decompilationError")).newLine();
writer.appendNoHilight(" * ").appendNoHilight(MessageFormat.format(AppResources.translate("decompilationError.timeout"), Helper.formatTimeToText(timeout))).newLine();
if (instructionCount > 0) {
writer.appendNoHilight(" * ").appendNoHilight(AppResources.translate("decompilationError.actionCount") + " " + instructionCount).newLine();
writer.appendNoHilight(" * ").appendNoHilight(AppResources.translate("decompilationError.instructionCount") + " " + instructionCount).newLine();
}
writer.appendNoHilight(" */").newLine();