Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.saev.deob.trans;
- import org.saev.deob.*;
- import java.util.*;
- import org.apache.bcel.generic.*;
- import org.apache.bcel.classfile.*;
- import org.apache.bcel.util.*;
- public class UnconditionalBranchFolder extends ApplicationTransformer {
- private static final boolean DEBUG = false;
- public UnconditionalBranchFolder() {
- super();
- }
- protected Method internalTransform(MethodGen mg) {
- int n = 0;
- InstructionList il = mg.getInstructionList();
- Iterator<InstructionHandle[]> it = new InstructionFinder(il).search("IfInstruction");
- while(it.hasNext()) {
- InstructionHandle ih = it.next() [0];
- InstructionHandle target = ((BranchHandle) ih).getTarget();
- if(target.getInstruction() instanceof GOTO) {
- n++;
- ((BranchHandle) ih).setTarget(((BranchHandle) target).getTarget());
- }
- }
- if(DEBUG && n > 0) {
- System.out.println("[ " + new org.saev.deob.util.MethodID(mg) +
- " ] retargeted " + n + " instructions");
- }
- it = new InstructionFinder(il).search("GOTO GOTO");
- while(it.hasNext()) {
- InstructionHandle[] match = it.next();
- try {
- il.delete(match[0]);
- } catch(TargetLostException e) {
- InstructionHandle[] targets = e.getTargets();
- for(int j = 0; j < targets.length; j++) {
- InstructionTargeter[] targeters = targets[j].getTargeters();
- for(int k = 0; k < targeters.length; k++) {
- targeters[k].updateTarget(targets[j], match[1]);
- }
- }
- }
- }
- mg.setInstructionList(il);
- return mg.getMethod();
- }
- public String getName() {
- return "ub-folder";
- }
- public String getDescription() {
- return "folds unconditional branches, ie. if instructions\n" +
- "\tthat target goto instructions are modified to target the\n" +
- "\ttarget of the goto. in some cases the goto can be removed.\n" +
- "\tyes, i realize that description sucks, but its the best i\n" +
- "\tcould come up with.";
- }
- public String getAuthor() {
- return "saevion <saevion at gmail dot com>";
- }
- }
Add Comment
Please, Sign In to add comment