use of jadx.core.dex.regions.conditions.IfInfo in project jadx by skylot.
the class IfMakerHelper method mergeTernaryConditions.
private static IfInfo mergeTernaryConditions(IfInfo currentIf, IfInfo nextThen, IfInfo nextElse) {
IfCondition newCondition = IfCondition.ternary(currentIf.getCondition(), nextThen.getCondition(), nextElse.getCondition());
IfInfo result = new IfInfo(newCondition, nextThen.getThenBlock(), nextThen.getElseBlock());
result.setIfBlock(currentIf.getIfBlock());
result.merge(currentIf, nextThen, nextElse);
confirmMerge(result);
return result;
}
use of jadx.core.dex.regions.conditions.IfInfo in project jadx by skylot.
the class IfMakerHelper method mergeIfInfo.
private static IfInfo mergeIfInfo(IfInfo first, IfInfo second, boolean followThenBranch) {
Mode mergeOperation = followThenBranch ? Mode.AND : Mode.OR;
IfCondition condition = IfCondition.merge(mergeOperation, first.getCondition(), second.getCondition());
// skip synthetic successor if both parts leads to same block
BlockNode thenBlock;
BlockNode elseBlock;
if (followThenBranch) {
thenBlock = second.getThenBlock();
elseBlock = getCrossBlock(first.getElseBlock(), second.getElseBlock());
} else {
thenBlock = getCrossBlock(first.getThenBlock(), second.getThenBlock());
elseBlock = second.getElseBlock();
}
IfInfo result = new IfInfo(condition, thenBlock, elseBlock);
result.setIfBlock(first.getIfBlock());
result.merge(first, second);
BlockNode otherPathBlock = followThenBranch ? first.getElseBlock() : first.getThenBlock();
skipSimplePath(otherPathBlock, result.getSkipBlocks());
return result;
}
use of jadx.core.dex.regions.conditions.IfInfo in project jadx by skylot.
the class IfMakerHelper method mergeNestedIfNodes.
static IfInfo mergeNestedIfNodes(IfInfo currentIf) {
BlockNode curThen = currentIf.getThenBlock();
BlockNode curElse = currentIf.getElseBlock();
if (curThen == curElse) {
return null;
}
boolean followThenBranch;
IfInfo nextIf = getNextIf(currentIf, curThen);
if (nextIf != null) {
followThenBranch = true;
} else {
nextIf = getNextIf(currentIf, curElse);
if (nextIf != null) {
followThenBranch = false;
} else {
return null;
}
}
if (isInversionNeeded(currentIf, nextIf)) {
// invert current node for match pattern
nextIf = IfInfo.invert(nextIf);
}
if (!isEqualPaths(curThen, nextIf.getThenBlock()) && !isEqualPaths(curElse, nextIf.getElseBlock())) {
// complex condition, run additional checks
if (checkConditionBranches(curThen, curElse) || checkConditionBranches(curElse, curThen)) {
return null;
}
BlockNode otherBranchBlock = followThenBranch ? curElse : curThen;
otherBranchBlock = BlockUtils.skipSyntheticSuccessor(otherBranchBlock);
if (!isPathExists(nextIf.getIfBlock(), otherBranchBlock)) {
return checkForTernaryInCondition(currentIf);
}
// this is nested conditions with different mode (i.e (a && b) || c),
// search next condition for merge, get null if failed
IfInfo tmpIf = mergeNestedIfNodes(nextIf);
if (tmpIf != null) {
nextIf = tmpIf;
if (isInversionNeeded(currentIf, nextIf)) {
nextIf = IfInfo.invert(nextIf);
}
if (!canMerge(currentIf, nextIf, followThenBranch)) {
return currentIf;
}
} else {
return currentIf;
}
}
IfInfo result = mergeIfInfo(currentIf, nextIf, followThenBranch);
// search next nested if block
return searchNestedIf(result);
}
Aggregations