public ClassNode getClassNodeFromFile(File file, String clsName) { JadxDecompiler d = new JadxDecompiler(getArgs()); try { d.loadFile(file); } catch (JadxException e) { e.printStackTrace(); fail(e.getMessage()); } RootNode root = JadxInternalAccess.getRoot(d); root.getResourcesNames().putAll(resMap); ClassNode cls = root.searchClassByName(clsName); assertThat("Class not found: " + clsName, cls, notNullValue()); assertThat(clsName, is(cls.getClassInfo().getFullName())); if (unloadCls) { decompile(d, cls); } else { decompileWithoutUnload(d, cls); } System.out.println("-----------------------------------------------------------"); System.out.println(cls.getCode()); System.out.println("-----------------------------------------------------------"); checkCode(cls); compile(cls); runAutoCheck(clsName); return cls; }
@Test public void test() { ClassNode cls = getClassNode(TestCls.class); String code = cls.getCode().toString(); assertThat(code, containsString("Class<?>[] a =")); assertThat(code, not(containsString("Class[] a ="))); }
@Test public void test() { noDebugInfo(); ClassNode cls = getClassNode(TestCls.class); String code = cls.getCode().toString(); assertThat(code, containsOne("try {")); }
@Test public void test() { ClassNode cls = getClassNode(TestCls.class); String code = cls.getCode().toString(); assertThat(code, containsOne(indent(3) + "for (IDexTreeVisitor pass : this.passes) {")); assertThat(code, not(containsString("iterator;"))); }
@Test public void test() { ClassNode cls = getClassNode(TestCls.class); String code = cls.getCode().toString(); assertThat(code, containsString("try {")); assertThat(code, containsString("Thread.sleep(50);")); assertThat(code, containsString("} catch (InterruptedException e) {")); assertThat(code, not(containsString("return"))); }
@Test public void test() { ClassNode cls = getClassNode(TestCls.class); String code = cls.getCode().toString(); assertThat(code, containsOne("public Runnable test(final double d) {")); assertThat(code, containsOne("return new Runnable() {")); assertThat(code, containsOne("public void run() {")); assertThat(code, containsOne("System.out.println(d);")); assertThat(code, not(containsString("synthetic"))); }
private static void checkCode(ClassNode cls) { assertTrue( "Inconsistent cls: " + cls, !cls.contains(AFlag.INCONSISTENT_CODE) && !cls.contains(AType.JADX_ERROR)); for (MethodNode mthNode : cls.getMethods()) { assertTrue( "Inconsistent method: " + mthNode, !mthNode.contains(AFlag.INCONSISTENT_CODE) && !mthNode.contains(AType.JADX_ERROR)); } assertThat(cls.getCode().toString(), not(containsString("inconsistent"))); }
@Test public void test() { ClassNode cls = getClassNode(TestCls.class); String code = cls.getCode().toString(); System.out.println(code); assertThat(code, containsOne("i < this.f.length()")); assertThat(code, containsOne("list.set(i, \"ABC\")")); assertThat(code, containsOne("list.set(i, \"DEF\")")); assertThat(code, containsOne("if (j == 2) {")); assertThat(code, containsOne("setEnabled(true);")); assertThat(code, containsOne("setEnabled(false);")); }
@Test public void test() { disableCompilation(); ClassNode cls = getClassNode(TestCls.class); String code = cls.getCode().toString(); assertThat(code, containsString(indent(4) + "public void run() {")); assertThat(code, containsString(indent(3) + "}.start();")); // assertThat(code, not(containsString("synthetic"))); // assertThat(code, not(containsString("AnonymousClass_"))); // assertThat(code, containsString("a = f--;")); }
@Test public void test() { ClassNode cls = getClassNode(TestCls.class); String code = cls.getCode().toString(); System.out.println(code); assertThat(code, not(containsString("(-1)"))); assertThat(code, not(containsString("return;"))); assertThat(code, containsString("return obj instanceof String ? ((String) obj).length() : 0;")); assertThat(code, containsString("if (a + b < 10)")); assertThat(code, containsString("if ((a & b) != 0)")); assertThat(code, containsString("if (num == 4 || num == 6 || num == 8 || num == 10)")); assertThat(code, containsString("a[1] = n * 2;")); assertThat(code, containsString("a[n - 1] = 1;")); // argument type not changed to String assertThat(code, containsString("public int method2(Object obj) {")); // cast not eliminated assertThat(code, containsString("((String) obj).length()")); }