com.googlecode.d2j.smali.Utils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gradle Show documentation
Show all versions of gradle Show documentation
fakeradnroid gradle builder
package com.googlecode.d2j.smali;
import com.googlecode.d2j.DexConstants;
import com.googlecode.d2j.Field;
import com.googlecode.d2j.Method;
import com.googlecode.d2j.Visibility;
import com.googlecode.d2j.reader.Op;
import com.googlecode.d2j.visitors.DexAnnotationVisitor;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class Utils implements DexConstants {
public static void doAccept(DexAnnotationVisitor dexAnnotationVisitor, String k, Object value) {
if (value instanceof ArrayList) {
DexAnnotationVisitor a = dexAnnotationVisitor.visitArray(k);
for (Object o : (ArrayList) value) {
doAccept(a, null, o);
}
a.visitEnd();
} else if (value instanceof Ann) {
Ann ann = (Ann) value;
DexAnnotationVisitor a = dexAnnotationVisitor.visitAnnotation(k, ann.name);
for (Map.Entry e : ann.elements) {
doAccept(a, e.getKey(), e.getValue());
}
a.visitEnd();
} else if (value instanceof Field) {
Field f = (Field) value;
dexAnnotationVisitor.visitEnum(k, f.getOwner(), f.getName());
} else {
dexAnnotationVisitor.visit(k, value);
}
}
public static int getAcc(String name) {
if (name.equals("public")) {
return ACC_PUBLIC;
} else if (name.equals("private")) {
return ACC_PRIVATE;
} else if (name.equals("protected")) {
return ACC_PROTECTED;
} else if (name.equals("static")) {
return ACC_STATIC;
} else if (name.equals("final")) {
return ACC_FINAL;
} else if (name.equals("synchronized")) {
return ACC_SYNCHRONIZED;
} else if (name.equals("volatile")) {
return ACC_VOLATILE;
} else if (name.equals("bridge")) {
return ACC_BRIDGE;
} else if (name.equals("varargs")) {
return ACC_VARARGS;
} else if (name.equals("transient")) {
return ACC_TRANSIENT;
} else if (name.equals("native")) {
return ACC_NATIVE;
} else if (name.equals("interface")) {
return ACC_INTERFACE;
} else if (name.equals("abstract")) {
return ACC_ABSTRACT;
} else if (name.equals("strict")) {
return ACC_STRICT;
} else if (name.equals("synthetic")) {
return ACC_SYNTHETIC;
} else if (name.equals("annotation")) {
return ACC_ANNOTATION;
} else if (name.equals("enum")) {
return ACC_ENUM;
} else if (name.equals("constructor")) {
return ACC_CONSTRUCTOR;
} else if (name.equals("declared-synchronized")) {
return ACC_DECLARED_SYNCHRONIZED;
}
return 0;
}
public static List listDesc(String desc) {
List list = new ArrayList(5);
if (desc == null) {
return list;
}
char[] chars = desc.toCharArray();
int i = 0;
while (i < chars.length) {
switch (chars[i]) {
case 'V':
case 'Z':
case 'C':
case 'B':
case 'S':
case 'I':
case 'F':
case 'J':
case 'D':
list.add(Character.toString(chars[i]));
i++;
break;
case '[': {
int count = 1;
while (chars[i + count] == '[') {
count++;
}
if (chars[i + count] == 'L') {
count++;
while (chars[i + count] != ';') {
count++;
}
}
count++;
list.add(new String(chars, i, count));
i += count;
break;
}
case 'L': {
int count = 1;
while (chars[i + count] != ';') {
++count;
}
count++;
list.add(new String(chars, i, count));
i += count;
break;
}
default:
throw new RuntimeException("can't parse type list: " + desc);
}
}
return list;
}
public static String[] toTypeList(String s) {
return listDesc(s).toArray(new String[0]);
}
static public Byte parseByte(String str) {
return Byte.valueOf((byte) parseInt(str.substring(0, str.length() - 1)));
}
static public Short parseShort(String str) {
return Short.valueOf((short) parseInt(str.substring(0, str.length() - 1)));
}
static public Long parseLong(String str) {
int sof = 0;
int end = str.length() - 1;
int x = 1;
if (str.charAt(sof) == '+') {
sof++;
} else if (str.charAt(sof) == '-') {
sof++;
x = -1;
}
BigInteger v;
if (str.charAt(sof) == '0') {
sof++;
if (sof >= end) {
return 0L;
}
char c = str.charAt(sof);
if (c == 'x' || c == 'X') {// hex
sof++;
v = new BigInteger(str.substring(sof, end), 16);
} else {// oct
v = new BigInteger(str.substring(sof, end), 8);
}
} else {
v = new BigInteger(str.substring(sof, end), 10);
}
if (x == -1) {
return v.negate().longValue();
} else {
return v.longValue();
}
}
static public float parseFloat(String str) {
str = str.toLowerCase();
int s = 0;
float x = 1f;
if (str.charAt(s) == '+') {
s++;
} else if (str.charAt(s) == '-') {
s++;
x = -1;
}
int e = str.length() - 1;
if (str.charAt(e) == 'f') {
e--;
}
str = str.substring(s, e + 1);
if (str.equals("nan")) {
return Float.NaN;
}
if (str.equals("infinity")) {
return x < 0 ? Float.NEGATIVE_INFINITY : Float.POSITIVE_INFINITY;
}
return (float) x * Float.parseFloat(str);
}
static public double parseDouble(String str) {
str = str.toLowerCase();
int s = 0;
double x = 1;
if (str.charAt(s) == '+') {
s++;
} else if (str.charAt(s) == '-') {
s++;
x = -1;
}
int e = str.length() - 1;
if (str.charAt(e) == 'd') {
e--;
}
str = str.substring(s, e + 1);
if (str.equals("nan")) {
return Double.NaN;
}
if (str.equals("infinity")) {
return x < 0 ? Double.NEGATIVE_INFINITY : Double.POSITIVE_INFINITY;
}
return x * Double.parseDouble(str);
}
static public int parseInt(String str, int start, int end) {
int sof = start;
int x = 1;
if (str.charAt(sof) == '+') {
sof++;
} else if (str.charAt(sof) == '-') {
sof++;
x = -1;
}
long v;
if (str.charAt(sof) == '0') {
sof++;
if (sof >= end) {
return 0;
}
char c = str.charAt(sof);
if (c == 'x' || c == 'X') {// hex
sof++;
v = Long.parseLong(str.substring(sof, end), 16);
} else {// oct
v = Long.parseLong(str.substring(sof, end), 8);
}
} else {
v = Long.parseLong(str.substring(sof, end), 10);
}
return (int) (v * x);
}
static public int parseInt(String str) {
return parseInt(str, 0, str.length());
}
public static String unescapeStr(String str) {
return unEscape(str);
}
public static Character unescapeChar(String str) {
return unEscape(str).charAt(0);
}
public static int[] toIntArray(List ss) {
int vs[] = new int[ss.size()];
for (int i = 0; i < ss.size(); i++) {
vs[i] = parseInt(ss.get(i));
}
return vs;
}
public static byte[] toByteArray(List