use of com.googlecode.dex2jar.ir.IrMethod in project dex2jar by pxb1988.
the class ConstTransformerTest method test01.
@Test
public void test01() {
// local in phi
IrMethod jm = new IrMethod();
Local a = nLocal("a");
Local p = nLocal("p");
jm.locals.add(a);
jm.locals.add(p);
jm.stmts.add(nAssign(a, nString("a String")));
jm.stmts.add(nAssign(p, Exprs.nPhi(a)));
UnopStmt retStmt = nReturn(p);
jm.stmts.add(retStmt);
new ConstTransformer().transform(jm);
Assert.assertTrue(jm.locals.size() == 2);
Assert.assertTrue(jm.stmts.getSize() == 3);
Assert.assertEquals("a String", ((Constant) retStmt.op.trim()).value);
}
use of com.googlecode.dex2jar.ir.IrMethod in project dex2jar by pxb1988.
the class Dex2IRConverter method convert.
public IrMethod convert(boolean isStatic, Method method, DexCodeNode dexCodeNode) {
this.dexCodeNode = dexCodeNode;
IrMethod irMethod = new IrMethod();
irMethod.args = method.getParameterTypes();
irMethod.ret = method.getReturnType();
irMethod.owner = method.getOwner();
irMethod.name = method.getName();
irMethod.isStatic = isStatic;
target = irMethod;
insnList = dexCodeNode.stmts;
for (int i = 0; i < insnList.size(); i++) {
DexStmtNode stmtNode = insnList.get(i);
stmtNode.__index = i;
if (stmtNode instanceof DexLabelStmtNode) {
DexLabelStmtNode dexLabelStmtNode = (DexLabelStmtNode) stmtNode;
labelMap.put(dexLabelStmtNode.label, dexLabelStmtNode);
}
}
fixExceptionHandlers();
BitSet[] exBranch = new BitSet[insnList.size()];
parentCount = new int[insnList.size()];
initParentCount(parentCount);
BitSet handlers = new BitSet(insnList.size());
initExceptionHandlers(dexCodeNode, exBranch, handlers);
DvmInterpreter<DvmValue> interpreter = buildInterpreter();
frames = new Dex2IrFrame[insnList.size()];
emitStmts = new ArrayList[insnList.size()];
BitSet access = new BitSet(insnList.size());
dfs(exBranch, handlers, access, interpreter);
StmtList stmts = target.stmts;
stmts.addAll(preEmit);
for (int i = 0; i < insnList.size(); i++) {
DexStmtNode p = insnList.get(i);
if (access.get(i)) {
List<Stmt> es = emitStmts[i];
if (es != null) {
stmts.addAll(es);
}
} else {
if (p instanceof DexLabelStmtNode) {
stmts.add(getLabel(((DexLabelStmtNode) p).label));
}
}
}
emitStmts = null;
Queue<DvmValue> queue = new LinkedList<>();
for (int i1 = 0; i1 < frames.length; i1++) {
Dex2IrFrame frame = frames[i1];
if (parentCount[i1] > 1 && frame != null && access.get(i1)) {
for (int j = 0; j < frame.getTotalRegisters(); j++) {
DvmValue v = frame.getReg(j);
addToQueue(queue, v);
}
}
}
while (!queue.isEmpty()) {
DvmValue v = queue.poll();
getLocal(v);
if (v.parent != null) {
if (v.parent.local == null) {
queue.add(v.parent);
}
}
if (v.otherParent != null) {
for (DvmValue v2 : v.otherParent) {
if (v2.local == null) {
queue.add(v2);
}
}
}
}
Set<com.googlecode.dex2jar.ir.expr.Value> phiValues = new HashSet<>();
List<LabelStmt> phiLabels = new ArrayList<>();
for (int i = 0; i < frames.length; i++) {
Dex2IrFrame frame = frames[i];
if (parentCount[i] > 1 && frame != null && access.get(i)) {
DexStmtNode p = insnList.get(i);
LabelStmt labelStmt = getLabel(((DexLabelStmtNode) p).label);
List<AssignStmt> phis = new ArrayList<>();
for (int j = 0; j < frame.getTotalRegisters(); j++) {
DvmValue v = frame.getReg(j);
addPhi(v, phiValues, phis);
}
labelStmt.phis = phis;
phiLabels.add(labelStmt);
}
}
if (phiLabels.size() > 0) {
target.phiLabels = phiLabels;
}
return target;
}
use of com.googlecode.dex2jar.ir.IrMethod in project dex2jar by pxb1988.
the class J2IRConverter method populate.
IrMethod populate(String owner, MethodNode source) {
IrMethod target = new IrMethod();
target.name = source.name;
target.owner = "L" + owner + ";";
target.ret = Type.getReturnType(source.desc).getDescriptor();
Type[] args = Type.getArgumentTypes(source.desc);
String[] sArgs = new String[args.length];
target.args = sArgs;
for (int i = 0; i < args.length; i++) {
sArgs[i] = args[i].getDescriptor();
}
target.isStatic = 0 != (source.access & Opcodes.ACC_STATIC);
return target;
}
use of com.googlecode.dex2jar.ir.IrMethod in project dex2jar by pxb1988.
the class Dex2Asm method convertCode.
public void convertCode(DexMethodNode methodNode, MethodVisitor mv) {
IrMethod irMethod = dex2ir(methodNode);
optimize(irMethod);
ir2j(irMethod, mv);
}
use of com.googlecode.dex2jar.ir.IrMethod in project dex2jar by pxb1988.
the class DecryptStringCmd method optAndDecrypt.
public void optAndDecrypt(IrMethod irMethod, final Map<MethodConfig, MethodConfig> map) {
T_deadCode.transform(irMethod);
T_cleanLabel.transform(irMethod);
T_removeLocal.transform(irMethod);
T_removeConst.transform(irMethod);
T_zero.transform(irMethod);
if (T_npe.transformReportChanged(irMethod)) {
T_deadCode.transform(irMethod);
T_removeLocal.transform(irMethod);
T_removeConst.transform(irMethod);
}
T_new.transform(irMethod);
T_fillArray.transform(irMethod);
T_agg.transform(irMethod);
T_voidInvoke.transform(irMethod);
new StmtTraveler() {
@Override
public Value travel(Value op) {
op = super.travel(op);
if (op.vt == Value.VT.INVOKE_STATIC) {
InvokeExpr ie = (InvokeExpr) op;
MethodConfig key = DecryptStringCmd.this.key;
key.owner = ie.owner.substring(1, ie.owner.length() - 1);
key.name = ie.name;
key.desc = buildMethodDesc(ie.args, ie.ret);
MethodConfig c = map.get(key);
if (c != null) {
try {
Method jmethod = c.jmethod;
if (ie.args.length != jmethod.getParameterTypes().length) {
throw new RuntimeException();
}
Object[] args = new Object[ie.args.length];
for (int i = 0; i < args.length; i++) {
args[i] = convertIr2Jobj(ie.getOps()[i], ie.args[i]);
}
if (verbose) {
System.out.println(" > calling " + jmethod + " with arguments " + v(args));
}
String str = (String) jmethod.invoke(null, args);
if (verbose) {
System.out.println(" -> " + Escape.v(str));
}
return Exprs.nString(str);
} catch (Exception e) {
e.printStackTrace();
}
}
}
return op;
}
}.travel(irMethod.stmts);
T_type.transform(irMethod);
T_unssa.transform(irMethod);
T_trimEx.transform(irMethod);
T_ir2jRegAssign.transform(irMethod);
}
Aggregations