Exemplo n.º 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;
  }
Exemplo n.º 2
0
  public static void main(String[] args) throws IOException, DecodeException {
    if (args.length < 2) {
      usage();
      System.exit(1);
    }
    File output = new File(args[0]);

    List<InputFile> inputFiles = new ArrayList<InputFile>(args.length - 1);
    for (int i = 1; i < args.length; i++) {
      File f = new File(args[i]);
      if (f.isDirectory()) {
        addFilesFromDirectory(f, inputFiles);
      } else {
        inputFiles.add(new InputFile(f));
      }
    }
    for (InputFile inputFile : inputFiles) {
      LOG.info("Loaded: {}", inputFile.getFile());
    }

    RootNode root = new RootNode();
    root.load(inputFiles);

    ClsSet set = new ClsSet();
    set.load(root);
    set.save(output);
    LOG.info("Output: {}", output);
    LOG.info("done");
  }
Exemplo n.º 3
0
  public BinaryXMLParser(RootNode root) {
    try {
      try {
        Class<?> rStyleCls = Class.forName(ANDROID_R_STYLE_CLS);
        for (Field f : rStyleCls.getFields()) {
          styleMap.put(f.getInt(f.getType()), f.getName());
        }
      } catch (Throwable th) {
        LOG.error("R class loading failed", th);
      }
      // add application constants
      for (DexNode dexNode : root.getDexNodes()) {
        for (Map.Entry<Object, FieldNode> entry : dexNode.getConstFields().entrySet()) {
          Object key = entry.getKey();
          FieldNode field = entry.getValue();
          if (field.getType().equals(ArgType.INT) && key instanceof Integer) {
            localStyleMap.put((Integer) key, field);
          }
        }
      }

      resNames = root.getResourcesNames();

      attributes = new ManifestAttributes();
      attributes.parse();
    } catch (Exception e) {
      throw new JadxRuntimeException("BinaryXMLParser init error", e);
    }
  }