• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2014 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;
18 
19 import dexfuzz.rawdex.Instruction;
20 
21 /**
22  * Base class that is a thin wrapper for Instructions currently, also tracking location
23  * as the instruction is moved around.
24  */
25 public class MInsn {
26   /**
27    * The raw DEX instruction that this instruction represents.
28    */
29   public Instruction insn;
30 
31 
32   /**
33    * The location of this instruction, as an offset in code words from the beginning.
34    * May become invalid if instructions around it are mutated.
35    */
36   public int location;
37 
38   /**
39    * Denotes if the currently associated location can be trusted.
40    */
41   public boolean locationUpdated;
42 
43   /**
44    * Clone this MInsn, and clone the wrapped Instruction.
45    */
clone()46   public MInsn clone() {
47     MInsn newInsn = new MInsn();
48     newInsn.insn = insn.clone();
49     // It is the responsibility of the cloner to update these values.
50     newInsn.location = location;
51     newInsn.locationUpdated = locationUpdated;
52     return newInsn;
53   }
54 
55   /**
56    * Get the String representation of an instruction.
57    */
toString()58   public String toString() {
59     return String.format("{0x%04x%s: %s}",
60         location,
61         (locationUpdated) ? "!" : "",
62             insn.toString());
63   }
64 }
65