use of jadx.core.utils.exceptions.JadxRuntimeException in project jadx by skylot.
the class BlockProcessor method computeDominanceFrontier.
static void computeDominanceFrontier(MethodNode mth) {
mth.getExitBlock().setDomFrontier(EMPTY);
List<BlockNode> domSortedBlocks = new ArrayList<>(mth.getBasicBlocks().size());
Deque<BlockNode> stack = new LinkedList<>();
stack.push(mth.getEnterBlock());
while (!stack.isEmpty()) {
BlockNode node = stack.pop();
for (BlockNode dominated : node.getDominatesOn()) {
stack.push(dominated);
}
domSortedBlocks.add(node);
}
Collections.reverse(domSortedBlocks);
for (BlockNode block : domSortedBlocks) {
try {
computeBlockDF(mth, block);
} catch (Exception e) {
throw new JadxRuntimeException("Failed compute block dominance frontier", e);
}
}
}
use of jadx.core.utils.exceptions.JadxRuntimeException in project jadx by skylot.
the class ProcessInstructionsVisitor method initJumps.
private static void initJumps(MethodNode mth, InsnNode[] insnByOffset) {
for (int offset = 0; offset < insnByOffset.length; offset++) {
InsnNode insn = insnByOffset[offset];
if (insn == null) {
continue;
}
switch(insn.getType()) {
case SWITCH:
SwitchInsn sw = (SwitchInsn) insn;
if (sw.needData()) {
attachSwitchData(insnByOffset, offset, sw);
}
int defCaseOffset = sw.getDefaultCaseOffset();
if (defCaseOffset != -1) {
addJump(mth, insnByOffset, offset, defCaseOffset);
}
for (int target : sw.getTargets()) {
addJump(mth, insnByOffset, offset, target);
}
break;
case IF:
int next = getNextInsnOffset(insnByOffset, offset);
if (next != -1) {
addJump(mth, insnByOffset, offset, next);
}
addJump(mth, insnByOffset, offset, ((IfNode) insn).getTarget());
break;
case GOTO:
addJump(mth, insnByOffset, offset, ((GotoNode) insn).getTarget());
break;
case INVOKE:
if (insn.getResult() == null) {
ArgType retType = ((BaseInvokeNode) insn).getCallMth().getReturnType();
mergeMoveResult(insnByOffset, offset, insn, retType);
}
break;
case STR_CONCAT:
// invoke-custom with string concatenation translated directly to STR_CONCAT, merge next move-result
if (insn.getResult() == null) {
mergeMoveResult(insnByOffset, offset, insn, ArgType.STRING);
}
break;
case FILLED_NEW_ARRAY:
ArgType arrType = ((FilledNewArrayNode) insn).getArrayType();
mergeMoveResult(insnByOffset, offset, insn, arrType);
break;
case FILL_ARRAY:
FillArrayInsn fillArrayInsn = (FillArrayInsn) insn;
int target = fillArrayInsn.getTarget();
InsnNode arrDataInsn = getInsnAtOffset(insnByOffset, target);
if (arrDataInsn != null && arrDataInsn.getType() == InsnType.FILL_ARRAY_DATA) {
fillArrayInsn.setArrayData((FillArrayData) arrDataInsn);
removeInsn(insnByOffset, arrDataInsn);
} else {
throw new JadxRuntimeException("Payload for fill-array not found at " + InsnUtils.formatOffset(target));
}
break;
default:
break;
}
}
}
use of jadx.core.utils.exceptions.JadxRuntimeException in project jadx by skylot.
the class OverrideMethodVisitor method processMth.
private void processMth(MethodNode mth, SuperTypesData superData) {
if (mth.isConstructor() || mth.getAccessFlags().isStatic() || mth.getAccessFlags().isPrivate()) {
return;
}
MethodOverrideAttr attr = processOverrideMethods(mth, superData);
if (attr != null) {
if (attr.getBaseMethods().isEmpty()) {
throw new JadxRuntimeException("No base methods for override attribute: " + attr.getOverrideList());
}
mth.addAttr(attr);
IMethodDetails baseMth = Utils.getOne(attr.getBaseMethods());
if (baseMth != null) {
boolean updated = fixMethodReturnType(mth, baseMth, superData);
updated |= fixMethodArgTypes(mth, baseMth, superData);
if (updated) {
// check if new signature cause method collisions
checkMethodSignatureCollisions(mth, mth.root().getArgs().isRenameValid());
}
}
}
}
use of jadx.core.utils.exceptions.JadxRuntimeException in project jadx by skylot.
the class BlockExceptionHandler method searchTopBlock.
private static BlockNode searchTopBlock(MethodNode mth, List<BlockNode> blocks) {
BlockNode top = BlockUtils.getTopBlock(blocks);
if (top != null) {
return adjustTopBlock(top);
}
BlockNode topDom = BlockUtils.getCommonDominator(mth, blocks);
if (topDom != null) {
return adjustTopBlock(topDom);
}
throw new JadxRuntimeException("Failed to find top block for try-catch from: " + blocks);
}
use of jadx.core.utils.exceptions.JadxRuntimeException in project jadx by skylot.
the class BlockExceptionHandler method sortHandlers.
private static void sortHandlers(MethodNode mth, List<TryCatchBlockAttr> tryBlocks) {
TypeCompare typeCompare = mth.root().getTypeCompare();
Comparator<ArgType> comparator = typeCompare.getReversedComparator();
for (TryCatchBlockAttr tryBlock : tryBlocks) {
for (ExceptionHandler handler : tryBlock.getHandlers()) {
handler.getCatchTypes().sort((first, second) -> compareByTypeAndName(comparator, first, second));
}
tryBlock.getHandlers().sort((first, second) -> {
if (first.equals(second)) {
throw new JadxRuntimeException("Same handlers in try block: " + tryBlock);
}
if (first.isCatchAll()) {
return 1;
}
if (second.isCatchAll()) {
return -1;
}
return compareByTypeAndName(comparator, ListUtils.first(first.getCatchTypes()), ListUtils.first(second.getCatchTypes()));
});
}
}
Aggregations