use of com.googlecode.dex2jar.ir.stmt.Stmt in project dex2jar by pxb1988.
the class BaseAnalyze method toString.
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
for (Stmt stmt = method.stmts.getFirst(); stmt != null; stmt = stmt.getNext()) {
T[] frame = (T[]) stmt.frame;
if (frame != null) {
for (T p : frame) {
if (p == null) {
sb.append('.');
} else {
sb.append(p.toRsp());
}
}
sb.append(" | ");
}
sb.append(stmt.toString()).append('\n');
}
return sb.toString();
}
use of com.googlecode.dex2jar.ir.stmt.Stmt in project dex2jar by pxb1988.
the class FillArrayTransformer method makeSureAllElementAreAssigned.
private void makeSureAllElementAreAssigned(Map<Local, ArrayObject> arraySizes) {
BitSet pos = new BitSet();
for (Iterator<Map.Entry<Local, ArrayObject>> it = arraySizes.entrySet().iterator(); it.hasNext(); ) {
Map.Entry<Local, ArrayObject> e = it.next();
ArrayObject arrayObject = e.getValue();
boolean needRemove = false;
for (Stmt p : arrayObject.putItem) {
if (p.st == Stmt.ST.FILL_ARRAY_DATA) {
int endPos = Array.getLength(((Constant) p.getOp2()).value);
int next = pos.nextSetBit(0);
if (next < 0 || next >= endPos) {
// not set in range
pos.set(0, endPos);
} else {
// setted in range
needRemove = true;
break;
}
} else {
// ASSIGN
ArrayExpr ae = (ArrayExpr) p.getOp1();
int idx = ((Number) ((Constant) ae.getOp2()).value).intValue();
if (!pos.get(idx)) {
pos.set(idx);
} else {
needRemove = true;
break;
}
}
}
if (needRemove || pos.nextClearBit(0) < arrayObject.size || pos.nextSetBit(arrayObject.size) >= 0) {
it.remove();
}
pos.clear();
}
}
use of com.googlecode.dex2jar.ir.stmt.Stmt in project dex2jar by pxb1988.
the class FillArrayTransformer method replace.
private void replace(IrMethod method, Map<Local, ArrayObject> arraySizes) {
final List<FilledArrayExpr> filledArrayExprs = new ArrayList<>();
for (Map.Entry<Local, ArrayObject> e : arraySizes.entrySet()) {
final Local local0 = e.getKey();
final ArrayObject ao = e.getValue();
final Value[] t = new Value[ao.size];
for (Iterator<Stmt> it = ao.putItem.iterator(); it.hasNext(); ) {
Stmt p = it.next();
if (p.st == Stmt.ST.FILL_ARRAY_DATA) {
Local local = (Local) p.getOp1();
if (local == local0) {
Object vs = ((Constant) p.getOp2()).value;
int endPos = Array.getLength(vs);
for (int j = 0; j < endPos; j++) {
t[j] = Exprs.nConstant(Array.get(vs, j));
}
}
} else {
// ASSIGN
ArrayExpr ae = (ArrayExpr) p.getOp1();
Local local = (Local) ae.getOp1();
if (local == local0) {
int idx = ((Number) ((Constant) ae.getOp2()).value).intValue();
Value op2 = p.getOp2();
if (op2.vt != Value.VT.LOCAL && op2.vt != Value.VT.CONSTANT) {
Local n = new Local(-1);
method.locals.add(n);
method.stmts.insertBefore(p, Stmts.nAssign(n, op2));
op2 = n;
}
t[idx] = op2;
}
}
}
// for code
// b=new Object[1]
// b[0]=null
// a =new Object[1]
// a =b;
// use(a)
// if a is replace before b, the code
// b=new Object[1]
// b[0]=null
// use(new Object[]{b})
// the used stmt of b is outdated, so we have to search pre replaced arrays
method.locals.remove(local0);
method.stmts.remove(ao.init);
for (Stmt p : ao.putItem) {
method.stmts.remove(p);
}
Cfg.TravelCallBack tcb = new Cfg.TravelCallBack() {
@Override
public Value onAssign(Local v, AssignStmt as) {
return v;
}
@Override
public Value onUse(Local v) {
if (local0 == v) {
FilledArrayExpr fae = Exprs.nFilledArray(ao.type, t);
filledArrayExprs.add(fae);
return fae;
}
return v;
}
};
if (ao.used.size() == 1) {
Stmt stmt = ao.used.get(0);
if (method.stmts.contains(stmt)) {
// the stmt is not removed by pre array replacement
Cfg.travelMod(stmt, tcb, false);
} else {
int size = filledArrayExprs.size();
for (int i = 0; i < size; i++) {
Cfg.travelMod(filledArrayExprs.get(i), tcb);
}
}
} else if (ao.used.size() == 0) {
// the array is never used, ignore
} else {
throw new RuntimeException("array is used multiple times");
}
}
}
use of com.googlecode.dex2jar.ir.stmt.Stmt in project dex2jar by pxb1988.
the class UnSSATransformerTransformerTest method test04OneInPhi.
@Test
public void test04OneInPhi() {
initMethod(true, "V");
Local a = addLocal("a");
Local b = addLocal("b");
Local phi = addLocal("p");
LabelStmt L1 = newLabel();
Stmt s1 = addStmt(nAssign(a, nString("123")));
Stmt j = addStmt(nIf(niGt(nInt(100), nInt(0)), L1));
Stmt s2 = addStmt(nAssign(b, nString("456")));
addStmt(L1);
attachPhi(L1, nAssign(phi, nPhi(a)));
addStmt(nReturn(phi));
transform();
Assert.assertTrue("p=a should inserted", j.getPre() != s1);
}
use of com.googlecode.dex2jar.ir.stmt.Stmt in project dex2jar by pxb1988.
the class ZeroTransformerTest method t001.
@Test
public void t001() {
Local a = addLocal("a");
Local c = addLocal("c");
Local p = addLocal("p");
Local q = addLocal("q");
addStmt(nAssign(a, nInt(0)));
addStmt(nAssign(c, nInvokeStatic(new Value[0], "La;", "a", new String[0], "I")));
LabelStmt L1 = newLabel();
addStmt(L1);
Stmt sa = attachPhi(L1, nAssign(q, nPhi(a, c)));
Stmt sb = attachPhi(L1, nAssign(p, nPhi(a, c)));
addStmt(nReturn(p));
transform();
Assert.assertNotEquals("a is split to 2 local", sb.getOp2().getOps()[0], sa.getOp2().getOps()[0]);
Assert.assertEquals("c is keep same", sb.getOp2().getOps()[1], sa.getOp2().getOps()[1]);
}
Aggregations