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());
}
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;
}
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));
}
}
}
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));
}
}
Aggregations