use of com.googlecode.dex2jar.ir.expr.Value in project dex2jar by pxb1988.
the class DeadCodeTransformer method transform.
@Override
public void transform(IrMethod method) {
Cfg.createCFG(method);
Cfg.dfsVisit(method, null);
if (method.traps != null) {
for (Iterator<Trap> it = method.traps.iterator(); it.hasNext(); ) {
Trap t = it.next();
boolean allNotThrow = true;
for (Stmt p = t.start; p != t.end; p = p.getNext()) {
if (p.visited && Cfg.isThrow(p)) {
allNotThrow = false;
break;
}
}
if (allNotThrow) {
it.remove();
continue;
}
boolean allNotVisited = true;
boolean allVisited = true;
for (LabelStmt labelStmt : t.handlers) {
if (labelStmt.visited) {
allNotVisited = false;
} else {
allVisited = false;
}
}
if (allNotVisited) {
it.remove();
} else {
// keep start and end
t.start.visited = true;
t.end.visited = true;
if (!allVisited) {
// part visited
List<String> types = new ArrayList<>(t.handlers.length);
List<LabelStmt> labelStmts = new ArrayList<>(t.handlers.length);
for (int i = 0; i < t.handlers.length; i++) {
labelStmts.add(t.handlers[i]);
types.add(t.types[i]);
}
t.handlers = labelStmts.toArray(new LabelStmt[labelStmts.size()]);
t.types = types.toArray(new String[types.size()]);
}
}
}
}
Set<Local> definedLocals = new HashSet<>();
for (Iterator<Stmt> it = method.stmts.iterator(); it.hasNext(); ) {
Stmt p = it.next();
if (!p.visited) {
it.remove();
continue;
}
if (p.st == Stmt.ST.ASSIGN || p.st == Stmt.ST.IDENTITY) {
if (p.getOp1().vt == Value.VT.LOCAL) {
definedLocals.add((Local) p.getOp1());
}
}
}
if (method.phiLabels != null) {
for (Iterator<LabelStmt> it = method.phiLabels.iterator(); it.hasNext(); ) {
LabelStmt labelStmt = it.next();
if (!labelStmt.visited) {
it.remove();
continue;
}
if (labelStmt.phis != null) {
for (AssignStmt phi : labelStmt.phis) {
definedLocals.add((Local) phi.getOp1());
}
}
}
}
method.locals.clear();
method.locals.addAll(definedLocals);
Set<Value> tmp = new HashSet<>();
if (method.phiLabels != null) {
for (Iterator<LabelStmt> it = method.phiLabels.iterator(); it.hasNext(); ) {
LabelStmt labelStmt = it.next();
if (labelStmt.phis != null) {
for (AssignStmt phi : labelStmt.phis) {
PhiExpr phiExpr = (PhiExpr) phi.getOp2();
boolean needRebuild = false;
for (Value v : phiExpr.getOps()) {
if (!definedLocals.contains(v)) {
needRebuild = true;
break;
}
}
if (needRebuild) {
for (Value v : phiExpr.getOps()) {
if (definedLocals.contains(v)) {
tmp.add(v);
}
}
phiExpr.setOps(tmp.toArray(new Value[tmp.size()]));
tmp.clear();
}
}
}
}
}
}
use of com.googlecode.dex2jar.ir.expr.Value in project dex2jar by pxb1988.
the class FixVar method transform.
@Override
public void transform(IrMethod irMethod) {
int i = 0;
for (LocalVar var : irMethod.vars) {
if (var.reg.trim().vt != VT.LOCAL) {
if (var.reg.trim().vt == VT.CONSTANT) {
Local n = new Local(i++);
Value old = var.reg.trim();
irMethod.stmts.insertBefore(var.start, Stmts.nAssign(n, old));
var.reg = n;
irMethod.locals.add(n);
} else {
// throw new DexExcpeption("not support");
}
}
}
}
use of com.googlecode.dex2jar.ir.expr.Value in project dex2jar by pxb1988.
the class Ir2JRegAssignTransformer method genGraph.
private Reg[] genGraph(IrMethod method, final Reg[] regs) {
Reg[] args;
if (method.isStatic) {
args = new Reg[method.args.length];
} else {
args = new Reg[method.args.length + 1];
}
Set<Stmt> tos = new HashSet<>();
for (Stmt stmt : method.stmts) {
if (stmt.st == ST.ASSIGN || stmt.st == ST.IDENTITY) {
if (stmt.getOp1().vt == VT.LOCAL) {
Local left = (Local) stmt.getOp1();
Value op2 = stmt.getOp2();
int idx = left._ls_index;
Reg leftReg = regs[idx];
// a new local can't effect next value live in next frame
Cfg.collectTos(stmt, tos);
for (Stmt next : tos) {
SimpleLiveValue[] frame = (SimpleLiveValue[]) next.frame;
if (frame == null) {
continue;
}
for (int i = 0; i < frame.length; i++) {
if (i == idx) {
continue;
}
SimpleLiveValue v = frame[i];
if (v != null && v.used) {
Reg rightReg = regs[i];
leftReg.excludes.add(rightReg);
rightReg.excludes.add(leftReg);
}
}
}
tos.clear();
// Preferred same reg can save load-store
if (op2.vt == VT.LOCAL) {
Reg rightReg = regs[((Local) op2)._ls_index];
leftReg.prefers.add(rightReg);
rightReg.prefers.add(leftReg);
}
// record @this @parameter_x
if (op2.vt == VT.THIS_REF) {
args[0] = leftReg;
} else if (op2.vt == VT.PARAMETER_REF) {
RefExpr refExpr = (RefExpr) op2;
if (method.isStatic) {
args[refExpr.parameterIndex] = leftReg;
} else {
args[refExpr.parameterIndex + 1] = leftReg;
}
}
}
}
}
// remove the link between itself
for (Reg reg : regs) {
reg.excludes.remove(reg);
reg.prefers.remove(reg);
}
return args;
}
use of com.googlecode.dex2jar.ir.expr.Value in project dex2jar by pxb1988.
the class StmtSearcher method travel.
public void travel(Stmt stmt) {
switch(stmt.et) {
case E0:
break;
case E1:
travel(stmt.getOp());
break;
case E2:
travel(stmt.getOp1());
travel(stmt.getOp2());
break;
case En:
Value[] ops = stmt.getOps();
for (Value op : ops) {
travel(op);
}
break;
}
}
use of com.googlecode.dex2jar.ir.expr.Value in project dex2jar by pxb1988.
the class AggTransformer method localCanExecFirst.
/**
* dfs searching, if local is appear before first location-insensitive value, throws SUCCESS, or throws FAIL
*/
private static void localCanExecFirst(Local local, Value op) throws MergeResult {
switch(op.et) {
case E0:
if (local.vt == Value.VT.LOCAL) {
if (op == local) {
throw SUCCESS;
}
}
break;
case E1:
localCanExecFirst(local, op.getOp());
break;
case E2:
localCanExecFirst(local, op.getOp1());
localCanExecFirst(local, op.getOp2());
break;
case En:
for (Value v : op.getOps()) {
localCanExecFirst(local, v);
}
}
boolean shouldExclude = false;
if (op.vt == Value.VT.INVOKE_STATIC) {
InvokeExpr ie = (InvokeExpr) op;
if (ie.name.equals("valueOf") && ie.owner.startsWith("Ljava/lang/") && ie.args.length == 1 && ie.args[0].length() == 1) {
shouldExclude = true;
}
}
if (!isLocationInsensitive(op.vt) && !shouldExclude) {
// this is the first insensitive Value
throw FAIL;
}
}
Aggregations