Home | History | Annotate | Download | only in rawdex
      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.rawdex;
     18 
     19 import java.io.IOException;
     20 
     21 public class EncodedField implements RawDexObject {
     22   public int fieldIdxDiff;
     23   public int accessFlags;
     24 
     25   @Override
     26   public void read(DexRandomAccessFile file) throws IOException {
     27     fieldIdxDiff = file.readUleb128();
     28     accessFlags = file.readUleb128();
     29   }
     30 
     31   @Override
     32   public void write(DexRandomAccessFile file) throws IOException {
     33     file.writeUleb128(fieldIdxDiff);
     34     file.writeUleb128(accessFlags);
     35   }
     36 
     37   @Override
     38   public void incrementIndex(IndexUpdateKind kind, int insertedIdx) {
     39     // Do nothing.
     40     // NB: our idx_diff is handled in ClassDataItem...
     41   }
     42 
     43   public boolean isVolatile() {
     44     return ((accessFlags & Flag.ACC_VOLATILE.getValue()) != 0);
     45   }
     46 
     47   /**
     48    * Set/unset the volatile flag for this EncodedField.
     49    */
     50   public void setVolatile(boolean turnOn) {
     51     if (turnOn) {
     52       accessFlags |= Flag.ACC_VOLATILE.getValue();
     53     } else {
     54       accessFlags &= ~(Flag.ACC_VOLATILE.getValue());
     55     }
     56   }
     57 
     58   private static enum Flag {
     59     ACC_PUBLIC(0x1),
     60     ACC_PRIVATE(0x2),
     61     ACC_PROTECTED(0x4),
     62     ACC_STATIC(0x8),
     63     ACC_FINAL(0x10),
     64     ACC_VOLATILE(0x40),
     65     ACC_TRANSIENT(0x80),
     66     ACC_SYNTHETIC(0x1000),
     67     ACC_ENUM(0x4000);
     68 
     69     private int value;
     70 
     71     private Flag(int value) {
     72       this.value = value;
     73     }
     74 
     75     public int getValue() {
     76       return value;
     77     }
     78   }
     79 }
     80