use of com.googlecode.dex2jar.ir.stmt.Stmt in project dex2jar by pxb1988.
the class StmtTraveler method travel.
public void travel(StmtList stmts) {
for (Iterator<Stmt> it = stmts.iterator(); it.hasNext(); ) {
Stmt stmt = it.next();
Stmt n = travel(stmt);
if (n != stmt) {
stmts.insertBefore(stmt, n);
it.remove();
}
}
}
use of com.googlecode.dex2jar.ir.stmt.Stmt in project dex2jar by pxb1988.
the class AggTransformer method simpleMergeLocals.
/**
* if a local is only used in one place, and the value is isLocationInsensitive,
* remove the local and replace it with its value
* <pre>
* a=b+c
* d=a+e
* </pre>
* to
* <pre>
* d=(b+c)+e
* </pre>
*/
private boolean simpleMergeLocals(IrMethod method, boolean changed, Set<Stmt> locationSensitiveStmts) {
if (method.locals.size() == 0) {
return false;
}
final int[] readCounts = Cfg.countLocalReads(method);
Set<Local> useInPhi = collectLocalUsedInPhi(method);
final Map<Local, Value> toReplace = new HashMap<>();
for (Iterator<Stmt> it = method.stmts.iterator(); it.hasNext(); ) {
Stmt p = it.next();
if (p.st == Stmt.ST.ASSIGN && p.getOp1().vt == Value.VT.LOCAL) {
Local local = (Local) p.getOp1();
if (useInPhi.contains(local)) {
continue;
}
if (readCounts[local._ls_index] < 2) {
Value op2 = p.getOp2();
if (isLocationInsensitive(op2)) {
method.locals.remove(local);
toReplace.put(local, op2);
it.remove();
changed = true;
} else {
locationSensitiveStmts.add(p);
}
}
}
}
Cfg.TravelCallBack tcb = new Cfg.TravelCallBack() {
@Override
public Value onAssign(Local v, AssignStmt as) {
return v;
}
@Override
public Value onUse(Local v) {
Value v2 = toReplace.get(v);
if (v2 != null) {
return v2;
}
return v;
}
};
modReplace(toReplace, tcb);
Cfg.travelMod(method.stmts, tcb, false);
return changed;
}
use of com.googlecode.dex2jar.ir.stmt.Stmt in project dex2jar by pxb1988.
the class ConstTransformer method collect.
private void collect(IrMethod m) {
for (Stmt p = m.stmts.getFirst(); p != null; p = p.getNext()) {
if (p.st == ST.ASSIGN || p.st == ST.IDENTITY) {
E2Stmt e2 = (E2Stmt) p;
Value op1 = e2.op1.trim();
Value op2 = e2.op2.trim();
if (op1.vt == VT.LOCAL) {
ConstAnalyzeValue cav = (ConstAnalyzeValue) ((Local) op1).tag;
if (op2.vt == VT.CONSTANT) {
Constant c = (Constant) op2;
cav.isConst = true;
cav.cst = c.value;
} else if (op2.vt == VT.LOCAL) {
Local local2 = (Local) op2;
ConstAnalyzeValue zaf2 = (ConstAnalyzeValue) local2.tag;
cav.assignFrom.add(zaf2);
zaf2.assignTo.add(cav);
} else if (op2.vt == VT.PHI) {
PhiExpr pe = (PhiExpr) op2;
for (Value v : pe.ops) {
ConstAnalyzeValue zaf2 = (ConstAnalyzeValue) ((Local) v.trim()).tag;
cav.assignFrom.add(zaf2);
zaf2.assignTo.add(cav);
}
} else {
cav.isConst = Boolean.FALSE;
}
}
}
}
}
use of com.googlecode.dex2jar.ir.stmt.Stmt in project dex2jar by pxb1988.
the class UnSSATransformer method insertAssignPath.
private void insertAssignPath(IrMethod method, Collection<LabelStmt> phiLabels) {
// FIXME the phi in Exception handler is buggy
List<AssignStmt> buff = new ArrayList<>();
for (LabelStmt labelStmt : phiLabels) {
List<AssignStmt> phis = (List<AssignStmt>) labelStmt.phis;
LiveV[] frame = (LiveV[]) labelStmt.frame;
for (Stmt from : labelStmt._cfg_froms) {
if (from.visited) {
// at lease it is reached by cfg
for (AssignStmt phi : phis) {
Local a = (Local) phi.getOp1();
LiveV v = frame[a._ls_index];
Local local = v.stmt2regMap.get(from);
if (local != a) {
buff.add(Stmts.nAssign(a, local));
}
}
insertAssignPath(method.stmts, from, labelStmt, buff);
buff.clear();
}
}
}
}
use of com.googlecode.dex2jar.ir.stmt.Stmt in project dex2jar by pxb1988.
the class ZeroTransformer method transformReportChanged.
@Override
public boolean transformReportChanged(IrMethod method) {
boolean changed = false;
List<AssignStmt> assignStmtList = new ArrayList<>();
for (Stmt p = method.stmts.getFirst(); p != null; p = p.getNext()) {
if (p.st == Stmt.ST.ASSIGN) {
AssignStmt as = (AssignStmt) p;
if (as.getOp1().vt == Value.VT.LOCAL && as.getOp2().vt == Value.VT.CONSTANT) {
Constant cst = (Constant) as.getOp2();
Object value = cst.value;
if (value instanceof Number && !((value instanceof Long) || (value instanceof Double))) {
int v = ((Number) value).intValue();
if (v == 0 || v == 1) {
assignStmtList.add(as);
}
}
}
}
}
if (assignStmtList.size() == 0) {
return false;
}
List<LabelStmt> phiLabels = method.phiLabels;
if (phiLabels != null) {
for (AssignStmt as : assignStmtList) {
Local local = (Local) as.getOp1();
boolean first = true;
for (LabelStmt labelStmt : phiLabels) {
for (AssignStmt phi : labelStmt.phis) {
Value[] vs = phi.getOp2().getOps();
for (int i = 0; i < vs.length; i++) {
Value v = vs[i];
if (v == local) {
if (first) {
first = false;
} else {
Local nLocal = Exprs.nLocal(-1);
method.locals.add(nLocal);
changed = true;
method.stmts.insertBefore(as, Stmts.nAssign(nLocal, as.getOp2().clone()));
vs[i] = nLocal;
}
}
}
}
}
}
}
return changed;
}
Aggregations