Search in sources :

Example 1 with ITry

use of jadx.api.plugins.input.data.ITry 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)

Example 2 with ITry

use of jadx.api.plugins.input.data.ITry in project jadx by skylot.

the class DexCodeReader method getTries.

@Override
public List<ITry> getTries() {
    int triesOffset = getTriesOffset();
    if (triesOffset == -1) {
        return Collections.emptyList();
    }
    int triesCount = getTriesCount();
    Map<Integer, ICatch> catchHandlers = getCatchHandlers(triesOffset + 8 * triesCount, in.copy());
    in.pos(triesOffset);
    List<ITry> triesList = new ArrayList<>(triesCount);
    for (int i = 0; i < triesCount; i++) {
        int startAddr = in.readInt();
        int insnsCount = in.readUShort();
        int handlerOff = in.readUShort();
        ICatch catchHandler = catchHandlers.get(handlerOff);
        if (catchHandler == null) {
            throw new DexException("Catch handler not found by byte offset: " + handlerOff);
        }
        triesList.add(new TryData(startAddr, startAddr + insnsCount - 1, catchHandler));
    }
    return triesList;
}
Also used : ITry(jadx.api.plugins.input.data.ITry) DexException(jadx.plugins.input.dex.DexException) ArrayList(java.util.ArrayList) TryData(jadx.api.plugins.input.data.impl.TryData) ICatch(jadx.api.plugins.input.data.ICatch)

Example 3 with ITry

use of jadx.api.plugins.input.data.ITry in project jadx by skylot.

the class Smali method writeTries.

private void writeTries(ICodeReader codeReader, LineInfo line) {
    List<ITry> tries = codeReader.getTries();
    for (ITry aTry : tries) {
        int end = aTry.getEndOffset();
        String tryEndTip = String.format(FMT_TRY_END_TAG, end);
        String tryStartTip = String.format(FMT_TRY_TAG, aTry.getStartOffset());
        String tryStartTipExtra = " # :" + tryStartTip.substring(0, tryStartTip.length() - 1);
        line.addTip(aTry.getStartOffset(), tryStartTip, " # :" + tryEndTip.substring(0, tryEndTip.length() - 1));
        line.addTip(end, tryEndTip, tryStartTipExtra);
        ICatch iCatch = aTry.getCatch();
        int[] addresses = iCatch.getHandlers();
        int addr;
        for (int i = 0; i < addresses.length; i++) {
            addr = addresses[i];
            String catchTip = String.format(FMT_CATCH_TAG, addr);
            line.addTip(addr, catchTip, " # " + iCatch.getTypes()[i]);
            line.addTip(addr, catchTip, tryStartTipExtra);
            line.addTip(aTry.getStartOffset(), tryStartTip, " # :" + catchTip.substring(0, catchTip.length() - 1));
        }
        addr = iCatch.getCatchAllHandler();
        if (addr > -1) {
            String catchAllTip = String.format(FMT_CATCH_ALL_TAG, addr);
            line.addTip(addr, catchAllTip, tryStartTipExtra);
            line.addTip(aTry.getStartOffset(), tryStartTip, " # :" + catchAllTip.substring(0, catchAllTip.length() - 1));
        }
    }
}
Also used : ITry(jadx.api.plugins.input.data.ITry) ICatch(jadx.api.plugins.input.data.ICatch)

Example 4 with ITry

use of jadx.api.plugins.input.data.ITry in project jadx by skylot.

the class AttachTryCatchVisitor method initTryCatches.

private static void initTryCatches(MethodNode mth, InsnNode[] insnByOffset, List<ITry> tries) {
    if (tries.isEmpty()) {
        return;
    }
    if (Consts.DEBUG_EXC_HANDLERS) {
        LOG.debug("Raw try blocks in {}", mth);
        tries.forEach(tryData -> LOG.debug(" - {}", tryData));
    }
    for (ITry tryData : tries) {
        List<ExceptionHandler> handlers = convertToHandlers(mth, tryData.getCatch(), insnByOffset);
        if (handlers.isEmpty()) {
            continue;
        }
        markTryBounds(insnByOffset, tryData, CatchAttr.build(handlers));
    }
}
Also used : ITry(jadx.api.plugins.input.data.ITry) ExceptionHandler(jadx.core.dex.trycatch.ExceptionHandler)

Aggregations

ITry (jadx.api.plugins.input.data.ITry)4 ICatch (jadx.api.plugins.input.data.ICatch)2 ArrayList (java.util.ArrayList)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 CatchData (jadx.api.plugins.input.data.impl.CatchData)1 DebugInfo (jadx.api.plugins.input.data.impl.DebugInfo)1 TryData (jadx.api.plugins.input.data.impl.TryData)1 InsnData (jadx.api.plugins.input.insns.InsnData)1 ExceptionHandler (jadx.core.dex.trycatch.ExceptionHandler)1 DexException (jadx.plugins.input.dex.DexException)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