Пример #1
0
  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
  @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
  @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;")));
  }
Пример #5
0
  @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
  @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
 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
  @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
 protected MethodNode getMethod(ClassNode cls, String method) {
   for (MethodNode mth : cls.getMethods()) {
     if (mth.getName().equals(method)) {
       return mth;
     }
   }
   fail("Method not found " + method + " in class " + cls);
   return null;
 }
 public void run() {
   try {
     cls.load();
     for (IDexTreeVisitor pass : this.passes) {
       DepthTraversal.visit(pass, cls);
     }
   } catch (Exception e) {
     LOG.error("Decode exception: " + cls, e);
   }
 }
Пример #12
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()"));
  }
Пример #13
0
 private void decompileWithoutUnload(JadxDecompiler d, ClassNode cls) {
   cls.load();
   List<IDexTreeVisitor> passes = Jadx.getPassesList(d.getArgs(), new File(outDir));
   for (IDexTreeVisitor visitor : passes) {
     DepthTraversal.visit(visitor, cls);
   }
   try {
     new CodeGen(d.getArgs()).visit(cls);
   } catch (CodegenException e) {
     e.printStackTrace();
     fail(e.getMessage());
   }
   // don't unload class
 }