use of jadx.plugins.input.java.data.ConstPoolReader in project jadx by skylot.
the class JavaAnnotationsAttr method readAnnotation.
public static JadxAnnotation readAnnotation(AnnotationVisibility visibility, JavaClassData clsData, DataReader reader) {
ConstPoolReader constPool = clsData.getConstPoolReader();
String type = constPool.getUtf8(reader.readU2());
int pairsCount = reader.readU2();
Map<String, EncodedValue> pairs = new LinkedHashMap<>(pairsCount);
for (int j = 0; j < pairsCount; j++) {
String name = constPool.getUtf8(reader.readU2());
EncodedValue value = EncodedValueReader.read(clsData, reader);
pairs.put(name, value);
}
return new JadxAnnotation(visibility, type, pairs);
}
use of jadx.plugins.input.java.data.ConstPoolReader in project jadx by skylot.
the class JavaCodeReader method getTries.
@Override
public List<ITry> getTries() {
skipToTries();
int excTableLen = reader.readU2();
if (excTableLen == 0) {
return Collections.emptyList();
}
ConstPoolReader constPool = clsData.getConstPoolReader();
Map<JavaTryData, List<JavaSingleCatch>> tries = new HashMap<>(excTableLen);
for (int i = 0; i < excTableLen; i++) {
int start = reader.readU2();
int end = reader.readU2();
int handler = reader.readU2();
int type = reader.readU2();
JavaTryData tryData = new JavaTryData(start, end);
List<JavaSingleCatch> catches = tries.computeIfAbsent(tryData, k -> new ArrayList<>());
if (type == 0) {
catches.add(new JavaSingleCatch(handler, null));
} else {
catches.add(new JavaSingleCatch(handler, constPool.getClass(type)));
}
}
return tries.entrySet().stream().map(e -> {
JavaTryData tryData = e.getKey();
tryData.setCatch(convertSingleCatches(e.getValue()));
return tryData;
}).collect(Collectors.toList());
}
use of jadx.plugins.input.java.data.ConstPoolReader in project jadx by skylot.
the class LoadConstDecoder method decode.
@Override
public void decode(CodeDecodeState state) {
DataReader reader = state.reader();
JavaInsnData insn = state.insn();
int index;
if (wide) {
index = reader.readU2();
} else {
index = reader.readU1();
}
ConstPoolReader constPoolReader = insn.constPoolReader();
ConstantType constType = constPoolReader.jumpToConst(index);
switch(constType) {
case INTEGER:
case FLOAT:
insn.setLiteral(constPoolReader.readU4());
insn.setOpcode(Opcode.CONST);
state.push(0, SVType.NARROW);
break;
case LONG:
case DOUBLE:
insn.setLiteral(constPoolReader.readU8());
insn.setOpcode(Opcode.CONST_WIDE);
state.push(0, SVType.WIDE);
break;
case STRING:
insn.setIndex(constPoolReader.readU2());
insn.setOpcode(Opcode.CONST_STRING);
state.push(0, SVType.NARROW);
break;
case UTF8:
insn.setIndex(index);
insn.setOpcode(Opcode.CONST_STRING);
state.push(0, SVType.NARROW);
break;
case CLASS:
insn.setIndex(index);
insn.setOpcode(Opcode.CONST_CLASS);
state.push(0, SVType.NARROW);
break;
default:
throw new JavaClassParseException("Unsupported constant type: " + constType);
}
}
use of jadx.plugins.input.java.data.ConstPoolReader in project jadx by skylot.
the class EncodedValueReader method read.
public static EncodedValue read(JavaClassData clsData, DataReader reader) {
ConstPoolReader constPool = clsData.getConstPoolReader();
char tag = (char) reader.readU1();
switch(tag) {
case 'B':
return new EncodedValue(EncodedType.ENCODED_BYTE, (byte) constPool.getInt(reader.readU2()));
case 'C':
return new EncodedValue(EncodedType.ENCODED_CHAR, (char) constPool.getInt(reader.readU2()));
case 'D':
return new EncodedValue(EncodedType.ENCODED_DOUBLE, constPool.getDouble(reader.readU2()));
case 'F':
return new EncodedValue(EncodedType.ENCODED_FLOAT, constPool.getFloat(reader.readU2()));
case 'I':
return new EncodedValue(EncodedType.ENCODED_INT, constPool.getInt(reader.readU2()));
case 'J':
return new EncodedValue(EncodedType.ENCODED_LONG, constPool.getLong(reader.readU2()));
case 'S':
return new EncodedValue(EncodedType.ENCODED_SHORT, (short) constPool.getInt(reader.readU2()));
case 'Z':
return new EncodedValue(EncodedType.ENCODED_BOOLEAN, 1 == constPool.getInt(reader.readU2()));
case 's':
return new EncodedValue(EncodedType.ENCODED_STRING, constPool.getUtf8(reader.readU2()));
case 'e':
String cls = constPool.getUtf8(reader.readU2());
String name = constPool.getUtf8(reader.readU2());
return new EncodedValue(EncodedType.ENCODED_ENUM, new JadxFieldRef(cls, name, cls));
case 'c':
return new EncodedValue(EncodedType.ENCODED_TYPE, constPool.getUtf8(reader.readU2()));
case '@':
return new EncodedValue(EncodedType.ENCODED_ANNOTATION, JavaAnnotationsAttr.readAnnotation(AnnotationVisibility.RUNTIME, clsData, reader));
case '[':
int len = reader.readU2();
List<EncodedValue> values = new ArrayList<>(len);
for (int i = 0; i < len; i++) {
values.add(read(clsData, reader));
}
return new EncodedValue(EncodedType.ENCODED_ARRAY, values);
default:
throw new JavaClassParseException("Unknown element value tag: " + tag);
}
}
Aggregations