コード例 #1
0
ファイル: IntegrationTest.java プロジェクト: arteme/jadx
  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;
  }
コード例 #2
0
ファイル: TestGenerics4.java プロジェクト: CarGuo/jadx
  @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 =")));
  }
コード例 #3
0
ファイル: TestTryCatch6.java プロジェクト: CarGuo/jadx
  @Test
  public void test() {
    noDebugInfo();
    ClassNode cls = getClassNode(TestCls.class);
    String code = cls.getCode().toString();

    assertThat(code, containsOne("try {"));
  }
コード例 #4
0
  @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;")));
  }
コード例 #5
0
ファイル: TestTryCatch.java プロジェクト: CarGuo/jadx
  @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")));
  }
コード例 #6
0
ファイル: TestAnonymousClass6.java プロジェクト: CarGuo/jadx
  @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")));
  }
コード例 #7
0
ファイル: IntegrationTest.java プロジェクト: arteme/jadx
 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")));
 }
コード例 #8
0
  @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);"));
  }
コード例 #9
0
ファイル: TestAnonymousClass3.java プロジェクト: CarGuo/jadx
  @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--;"));
  }
コード例 #10
0
  @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()"));
  }