use of com.googlecode.dex2jar.ir.IrMethod in project dex2jar by pxb1988.
the class ArrayElementTransformer method main.
public static void main(String... args) {
IrMethod m = new IrMethod();
m.isStatic = true;
m.name = "a";
m.args = new String[0];
m.ret = "[Ljava/lang/String;";
m.owner = "La;";
Local array = Exprs.nLocal(1);
m.locals.add(array);
m.stmts.add(Stmts.nAssign(array, Exprs.nNewArray("Ljava/lang/String;", Exprs.nInt(2))));
m.stmts.add(Stmts.nAssign(Exprs.nArray(array, Exprs.nInt(1), "Ljava/lang/String;"), Exprs.nString("123")));
m.stmts.add(Stmts.nAssign(Exprs.nArray(array, Exprs.nInt(0), "Ljava/lang/String;"), Exprs.nString("456")));
m.stmts.add(Stmts.nReturn(array));
new ArrayElementTransformer().transform(m);
}
use of com.googlecode.dex2jar.ir.IrMethod in project dex2jar by pxb1988.
the class FillArrayTransformer method main.
public static void main(String... args) {
IrMethod m = new IrMethod();
m.isStatic = true;
m.name = "a";
m.args = new String[0];
m.ret = "[Ljava/lang/String;";
m.owner = "La;";
Local array = Exprs.nLocal(1);
m.locals.add(array);
m.stmts.add(Stmts.nAssign(array, Exprs.nNewArray("Ljava/lang/String;", Exprs.nInt(2))));
m.stmts.add(Stmts.nAssign(Exprs.nArray(array, Exprs.nInt(1), "Ljava/lang/String;"), Exprs.nString("123")));
m.stmts.add(Stmts.nAssign(Exprs.nArray(array, Exprs.nInt(0), "Ljava/lang/String;"), Exprs.nString("456")));
m.stmts.add(Stmts.nReturn(array));
new FillArrayTransformer().transform(m);
System.out.println(m);
}
use of com.googlecode.dex2jar.ir.IrMethod in project dex2jar by pxb1988.
the class ConstTransformerTest method test04.
@Test
public void test04() {
IrMethod jm = new IrMethod();
Local a = nLocal("a");
Local b = nLocal("b");
Local p = nLocal("p");
jm.locals.add(a);
jm.locals.add(b);
jm.locals.add(p);
jm.stmts.add(nAssign(a, nString(new String("a String"))));
jm.stmts.add(nAssign(b, nString(new String("a String"))));
jm.stmts.add(nAssign(p, Exprs.nPhi(a, b)));
UnopStmt retStmt = nReturn(p);
jm.stmts.add(retStmt);
new ConstTransformer().transform(jm);
Assert.assertTrue(jm.locals.size() == 3);
Assert.assertTrue(jm.stmts.getSize() == 4);
Assert.assertEquals(VT.CONSTANT, retStmt.op.vt);
}
use of com.googlecode.dex2jar.ir.IrMethod in project dex2jar by pxb1988.
the class DecryptStringCmd method decryptByIr.
private boolean decryptByIr(ClassNode cn, Map<MethodConfig, MethodConfig> map) {
MethodConfig key = this.key;
boolean changed = false;
for (Iterator<MethodNode> it = cn.methods.iterator(); it.hasNext(); ) {
MethodNode m = it.next();
if (m.instructions == null) {
continue;
}
key.owner = cn.name;
key.name = m.name;
key.desc = m.desc;
if (map.containsKey(key)) {
if (deleteMethod) {
it.remove();
}
continue;
}
if (false && verbose) {
System.out.println();
System.out.println("===============");
System.out.println("on method " + cn.name + ";->" + m.name + m.desc);
}
boolean find = false;
// search for the decrypt method
for (AbstractInsnNode p = m.instructions.getFirst(); p != null; p = p.getNext()) {
if (p.getOpcode() == Opcodes.INVOKESTATIC) {
MethodInsnNode mn = (MethodInsnNode) p;
key.owner = mn.owner;
key.name = mn.name;
key.desc = mn.desc;
MethodConfig config = map.get(key);
if (config != null) {
find = true;
}
}
}
if (find) {
try {
// copy m to m2 for cleanup debug info
MethodNode m2 = new MethodNode();
m2.tryCatchBlocks = new ArrayList<>();
m2.name = m.name;
m2.access = m.access;
m2.desc = m.desc;
m.accept(m2);
cleanDebug(m2);
// convert m2 to ir
IrMethod irMethod = J2IRConverter.convert(cn.name, m2);
// opt and decrypt
optAndDecrypt(irMethod, map);
// convert ir to m3
MethodNode m3 = new MethodNode();
m3.tryCatchBlocks = new ArrayList<>();
new IR2JConverter(true).convert(irMethod, m3);
// copy back m3 to m
m.maxLocals = -1;
m.maxLocals = -1;
m.instructions = m3.instructions;
m.tryCatchBlocks = m3.tryCatchBlocks;
m.localVariables = null;
changed = true;
} catch (Exception ex) {
if (verbose) {
ex.printStackTrace();
}
}
}
}
return changed;
}
use of com.googlecode.dex2jar.ir.IrMethod in project dex2jar by pxb1988.
the class ConstTransformerTest method test00.
@Test
public void test00() {
IrMethod jm = new IrMethod();
Local a = nLocal("a");
jm.locals.add(a);
jm.stmts.add(nAssign(a, nString("a String")));
UnopStmt retStmt = nReturn(a);
jm.stmts.add(retStmt);
new ConstTransformer().transform(jm);
Assert.assertTrue(jm.locals.size() == 1);
Assert.assertTrue(jm.stmts.getSize() == 2);
Assert.assertEquals("a String", ((Constant) retStmt.op.trim()).value);
}
Aggregations