Search in sources :

Example 1 with ICatch

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

the class DexCodeReader method getCatchHandlers.

private Map<Integer, ICatch> getCatchHandlers(int offset, SectionReader ext) {
    in.pos(offset);
    int byteOffsetStart = in.getAbsPos();
    int size = in.readUleb128();
    Map<Integer, ICatch> map = new HashMap<>(size);
    for (int i = 0; i < size; i++) {
        int byteIndex = in.getAbsPos() - byteOffsetStart;
        int sizeAndType = in.readSleb128();
        int handlersLen = Math.abs(sizeAndType);
        int[] addr = new int[handlersLen];
        String[] types = new String[handlersLen];
        for (int h = 0; h < handlersLen; h++) {
            types[h] = ext.getType(in.readUleb128());
            addr[h] = in.readUleb128();
        }
        int catchAllAddr;
        if (sizeAndType <= 0) {
            catchAllAddr = in.readUleb128();
        } else {
            catchAllAddr = -1;
        }
        map.put(byteIndex, new CatchData(addr, types, catchAllAddr));
    }
    return map;
}
Also used : CatchData(jadx.api.plugins.input.data.impl.CatchData) HashMap(java.util.HashMap) ICatch(jadx.api.plugins.input.data.ICatch)

Example 2 with ICatch

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

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

Aggregations

ICatch (jadx.api.plugins.input.data.ICatch)3 ITry (jadx.api.plugins.input.data.ITry)2 CatchData (jadx.api.plugins.input.data.impl.CatchData)1 TryData (jadx.api.plugins.input.data.impl.TryData)1 DexException (jadx.plugins.input.dex.DexException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1