1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package dexfuzz.program.mutators; 18 19 import dexfuzz.Log; 20 import dexfuzz.MutationStats; 21 import dexfuzz.program.MInsn; 22 import dexfuzz.program.Mutation; 23 import dexfuzz.rawdex.Opcode; 24 import java.util.List; 25 import java.util.Random; 26 27 public class OppositeBranchChanger extends IfBranchChanger { 28 OppositeBranchChanger(Random rng, MutationStats stats, List<Mutation> mutations)29 public OppositeBranchChanger(Random rng, MutationStats stats, List<Mutation> mutations) { 30 super(rng, stats, mutations); 31 likelihood = 40; 32 } 33 34 @Override getModifiedOpcode(MInsn mInsn)35 protected Opcode getModifiedOpcode(MInsn mInsn) { 36 Opcode opcode = mInsn.insn.info.opcode; 37 switch (opcode) { 38 case IF_EQ: 39 return Opcode.IF_NE; 40 case IF_NE: 41 return Opcode.IF_EQ; 42 case IF_LT: 43 return Opcode.IF_GE; 44 case IF_GT: 45 return Opcode.IF_LE; 46 case IF_GE: 47 return Opcode.IF_LT; 48 case IF_LE: 49 return Opcode.IF_GT; 50 case IF_EQZ: 51 return Opcode.IF_NEZ; 52 case IF_NEZ: 53 return Opcode.IF_EQZ; 54 case IF_LTZ: 55 return Opcode.IF_GEZ; 56 case IF_GTZ: 57 return Opcode.IF_LEZ; 58 case IF_GEZ: 59 return Opcode.IF_LTZ; 60 case IF_LEZ: 61 return Opcode.IF_GTZ; 62 default: 63 Log.errorAndQuit("Could not find if branch."); 64 return opcode; 65 } 66 } 67 68 @Override getMutationTag()69 protected String getMutationTag() { 70 return "opposite"; 71 } 72 }