Search in sources :

Example 1 with JavaSingleCatch

use of jadx.plugins.input.java.data.code.trycatch.JavaSingleCatch in project jadx by skylot.

the class JavaCodeReader method convertSingleCatches.

private static CatchData convertSingleCatches(List<JavaSingleCatch> list) {
    int allHandler = -1;
    for (JavaSingleCatch singleCatch : list) {
        if (singleCatch.getType() == null) {
            allHandler = singleCatch.getHandler();
            list.remove(singleCatch);
            break;
        }
    }
    int len = list.size();
    int[] handlers = new int[len];
    String[] types = new String[len];
    for (int i = 0; i < len; i++) {
        JavaSingleCatch singleCatch = list.get(i);
        handlers[i] = singleCatch.getHandler();
        types[i] = singleCatch.getType();
    }
    return new CatchData(handlers, types, allHandler);
}
Also used : CatchData(jadx.api.plugins.input.data.impl.CatchData) JavaSingleCatch(jadx.plugins.input.java.data.code.trycatch.JavaSingleCatch)

Example 2 with JavaSingleCatch

use of jadx.plugins.input.java.data.code.trycatch.JavaSingleCatch 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());
}
Also used : DebugInfo(jadx.api.plugins.input.data.impl.DebugInfo) JavaAttrType(jadx.plugins.input.java.data.attributes.JavaAttrType) JavaTryData(jadx.plugins.input.java.data.code.trycatch.JavaTryData) HashMap(java.util.HashMap) JavaSingleCatch(jadx.plugins.input.java.data.code.trycatch.JavaSingleCatch) ConstPoolReader(jadx.plugins.input.java.data.ConstPoolReader) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LocalVarsAttr(jadx.plugins.input.java.data.attributes.debuginfo.LocalVarsAttr) JavaAttrStorage(jadx.plugins.input.java.data.attributes.JavaAttrStorage) Map(java.util.Map) ICodeReader(jadx.api.plugins.input.data.ICodeReader) JavaClassParseException(jadx.plugins.input.java.utils.JavaClassParseException) IDebugInfo(jadx.api.plugins.input.data.IDebugInfo) JavaClassData(jadx.plugins.input.java.data.JavaClassData) Set(java.util.Set) Collectors(java.util.stream.Collectors) Consumer(java.util.function.Consumer) Nullable(org.jetbrains.annotations.Nullable) LocalVarTypesAttr(jadx.plugins.input.java.data.attributes.debuginfo.LocalVarTypesAttr) List(java.util.List) ILocalVar(jadx.api.plugins.input.data.ILocalVar) InsnData(jadx.api.plugins.input.insns.InsnData) DataReader(jadx.plugins.input.java.data.DataReader) CatchData(jadx.api.plugins.input.data.impl.CatchData) Collections(java.util.Collections) JavaLocalVar(jadx.plugins.input.java.data.attributes.debuginfo.JavaLocalVar) LineNumberTableAttr(jadx.plugins.input.java.data.attributes.debuginfo.LineNumberTableAttr) ITry(jadx.api.plugins.input.data.ITry) HashMap(java.util.HashMap) JavaSingleCatch(jadx.plugins.input.java.data.code.trycatch.JavaSingleCatch) JavaTryData(jadx.plugins.input.java.data.code.trycatch.JavaTryData) ArrayList(java.util.ArrayList) List(java.util.List) ConstPoolReader(jadx.plugins.input.java.data.ConstPoolReader)

Aggregations

CatchData (jadx.api.plugins.input.data.impl.CatchData)2 JavaSingleCatch (jadx.plugins.input.java.data.code.trycatch.JavaSingleCatch)2 ICodeReader (jadx.api.plugins.input.data.ICodeReader)1 IDebugInfo (jadx.api.plugins.input.data.IDebugInfo)1 ILocalVar (jadx.api.plugins.input.data.ILocalVar)1 ITry (jadx.api.plugins.input.data.ITry)1 DebugInfo (jadx.api.plugins.input.data.impl.DebugInfo)1 InsnData (jadx.api.plugins.input.insns.InsnData)1 ConstPoolReader (jadx.plugins.input.java.data.ConstPoolReader)1 DataReader (jadx.plugins.input.java.data.DataReader)1 JavaClassData (jadx.plugins.input.java.data.JavaClassData)1 JavaAttrStorage (jadx.plugins.input.java.data.attributes.JavaAttrStorage)1 JavaAttrType (jadx.plugins.input.java.data.attributes.JavaAttrType)1 JavaLocalVar (jadx.plugins.input.java.data.attributes.debuginfo.JavaLocalVar)1 LineNumberTableAttr (jadx.plugins.input.java.data.attributes.debuginfo.LineNumberTableAttr)1 LocalVarTypesAttr (jadx.plugins.input.java.data.attributes.debuginfo.LocalVarTypesAttr)1 LocalVarsAttr (jadx.plugins.input.java.data.attributes.debuginfo.LocalVarsAttr)1 JavaTryData (jadx.plugins.input.java.data.code.trycatch.JavaTryData)1 JavaClassParseException (jadx.plugins.input.java.utils.JavaClassParseException)1 ArrayList (java.util.ArrayList)1