• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2013, Google Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met:
8  *
9  *     * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *     * Redistributions in binary form must reproduce the above
12  * copyright notice, this list of conditions and the following disclaimer
13  * in the documentation and/or other materials provided with the
14  * distribution.
15  *     * Neither the name of Google Inc. nor the names of its
16  * contributors may be used to endorse or promote products derived from
17  * this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 package org.jf.dexlib2;
33 
34 import com.google.common.collect.Maps;
35 import org.jf.util.ExceptionWithContext;
36 
37 import javax.annotation.Nullable;
38 import java.util.HashMap;
39 
40 public class VerificationError {
41     public static final int GENERIC = 1;
42     public static final int NO_SUCH_CLASS = 2;
43     public static final int NO_SUCH_FIELD = 3;
44     public static final int NO_SUCH_METHOD = 4;
45     public static final int ILLEGAL_CLASS_ACCESS = 5;
46     public static final int ILLEGAL_FIELD_ACCESS = 6;
47     public static final int ILLEGAL_METHOD_ACCESS = 7;
48     public static final int CLASS_CHANGE_ERROR = 8;
49     public static final int INSTANTIATION_ERROR = 9;
50 
51     private static final HashMap<String, Integer> verificationErrorNames = Maps.newHashMap();
52 
53     static {
54         verificationErrorNames.put("generic-error", GENERIC);
55         verificationErrorNames.put("no-such-class", NO_SUCH_CLASS);
56         verificationErrorNames.put("no-such-field", NO_SUCH_FIELD);
57         verificationErrorNames.put("no-such-method", NO_SUCH_METHOD);
58         verificationErrorNames.put("illegal-class-access", ILLEGAL_CLASS_ACCESS);
59         verificationErrorNames.put("illegal-field-access", ILLEGAL_FIELD_ACCESS);
60         verificationErrorNames.put("illegal-method-access", ILLEGAL_METHOD_ACCESS);
61         verificationErrorNames.put("class-change-error", CLASS_CHANGE_ERROR);
62         verificationErrorNames.put("instantiation-error", INSTANTIATION_ERROR);
63     }
64 
65     @Nullable
getVerificationErrorName(int verificationError)66     public static String getVerificationErrorName(int verificationError) {
67         switch (verificationError) {
68             case GENERIC:
69                 return "generic-error";
70             case NO_SUCH_CLASS:
71                 return "no-such-class";
72             case NO_SUCH_FIELD:
73                 return "no-such-field";
74             case NO_SUCH_METHOD:
75                 return "no-such-method";
76             case ILLEGAL_CLASS_ACCESS:
77                 return "illegal-class-access";
78             case ILLEGAL_FIELD_ACCESS:
79                 return "illegal-field-access";
80             case ILLEGAL_METHOD_ACCESS:
81                 return "illegal-method-access";
82             case CLASS_CHANGE_ERROR:
83                 return "class-change-error";
84             case INSTANTIATION_ERROR:
85                 return "instantiation-error";
86             default:
87                 return null;
88         }
89     }
90 
getVerificationError(String verificationError)91     public static int getVerificationError(String verificationError) {
92         Integer ret = verificationErrorNames.get(verificationError);
93         if (ret == null) {
94             throw new ExceptionWithContext("Invalid verification error: %s", verificationError);
95         }
96         return ret;
97     }
98 
isValidVerificationError(int verificationError)99     public static boolean isValidVerificationError(int verificationError) {
100         return verificationError > 0 && verificationError < 10;
101     }
102 }
103