use of jadx.core.dex.attributes.nodes.PhiListAttr in project jadx by skylot.
the class SSATransform method addPhi.
public static PhiInsn addPhi(MethodNode mth, BlockNode block, int regNum) {
PhiListAttr phiList = block.get(AType.PHI_LIST);
if (phiList == null) {
phiList = new PhiListAttr();
block.addAttr(phiList);
}
int size = block.getPredecessors().size();
if (mth.getEnterBlock() == block) {
RegisterArg thisArg = mth.getThisArg();
if (thisArg != null && thisArg.getRegNum() == regNum) {
size++;
} else {
for (RegisterArg arg : mth.getArgRegs()) {
if (arg.getRegNum() == regNum) {
size++;
break;
}
}
}
}
PhiInsn phiInsn = new PhiInsn(regNum, size);
phiList.getList().add(phiInsn);
phiInsn.setOffset(block.getStartOffset());
block.getInstructions().add(0, phiInsn);
return phiInsn;
}
use of jadx.core.dex.attributes.nodes.PhiListAttr in project jadx by skylot.
the class SSATransform method fixUselessPhi.
private static boolean fixUselessPhi(MethodNode mth) {
boolean changed = false;
List<PhiInsn> insnToRemove = new ArrayList<>();
for (SSAVar var : mth.getSVars()) {
// phi result not used
if (var.getUseCount() == 0) {
InsnNode assignInsn = var.getAssign().getParentInsn();
if (assignInsn != null && assignInsn.getType() == InsnType.PHI) {
insnToRemove.add((PhiInsn) assignInsn);
changed = true;
}
}
}
for (BlockNode block : mth.getBasicBlocks()) {
PhiListAttr phiList = block.get(AType.PHI_LIST);
if (phiList == null) {
continue;
}
Iterator<PhiInsn> it = phiList.getList().iterator();
while (it.hasNext()) {
PhiInsn phi = it.next();
if (fixPhiWithSameArgs(mth, block, phi)) {
it.remove();
changed = true;
}
}
}
removePhiList(mth, insnToRemove);
return changed;
}
use of jadx.core.dex.attributes.nodes.PhiListAttr in project jadx by skylot.
the class SSATransform method renameVarsInBlock.
private static void renameVarsInBlock(MethodNode mth, RenameState state) {
BlockNode block = state.getBlock();
for (InsnNode insn : block.getInstructions()) {
if (insn.getType() != InsnType.PHI) {
for (InsnArg arg : insn.getArguments()) {
if (!arg.isRegister()) {
continue;
}
RegisterArg reg = (RegisterArg) arg;
int regNum = reg.getRegNum();
SSAVar var = state.getVar(regNum);
if (var == null) {
// TODO: in most cases issue in incorrectly attached exception handlers
mth.addWarnComment("Not initialized variable reg: " + regNum + ", insn: " + insn + ", block:" + block);
var = state.startVar(reg);
}
var.use(reg);
}
}
RegisterArg result = insn.getResult();
if (result != null) {
state.startVar(result);
}
}
for (BlockNode s : block.getSuccessors()) {
PhiListAttr phiList = s.get(AType.PHI_LIST);
if (phiList == null) {
continue;
}
for (PhiInsn phiInsn : phiList.getList()) {
bindPhiArg(state, phiInsn);
}
}
}
use of jadx.core.dex.attributes.nodes.PhiListAttr in project jadx by skylot.
the class SSATransform method removeBlockerInsns.
private static boolean removeBlockerInsns(MethodNode mth) {
boolean removed = false;
for (BlockNode block : mth.getBasicBlocks()) {
PhiListAttr phiList = block.get(AType.PHI_LIST);
if (phiList == null) {
continue;
}
// check if args must be removed
for (PhiInsn phi : phiList.getList()) {
for (int i = 0; i < phi.getArgsCount(); i++) {
RegisterArg arg = phi.getArg(i);
InsnNode parentInsn = arg.getAssignInsn();
if (parentInsn != null && parentInsn.contains(AFlag.REMOVE)) {
phi.removeArg(arg);
InsnRemover.remove(mth, block, parentInsn);
removed = true;
}
}
}
}
return removed;
}
use of jadx.core.dex.attributes.nodes.PhiListAttr in project jadx by skylot.
the class SSATransform method initPhiInEnterBlock.
private static void initPhiInEnterBlock(SSAVar[] vars, BlockNode enterBlock) {
PhiListAttr phiList = enterBlock.get(AType.PHI_LIST);
if (phiList != null) {
for (PhiInsn phiInsn : phiList.getList()) {
int regNum = phiInsn.getResult().getRegNum();
SSAVar var = vars[regNum];
if (var == null) {
continue;
}
RegisterArg arg = phiInsn.bindArg(enterBlock);
var.use(arg);
var.setUsedInPhi(phiInsn);
}
}
}
Aggregations