Пример #1
1
  public void publicizeResources(File arscFile) throws AndrolibException {
    byte[] data = new byte[(int) arscFile.length()];

    InputStream in = null;
    OutputStream out = null;
    try {
      in = new FileInputStream(arscFile);
      in.read(data);

      publicizeResources(data);

      out = new FileOutputStream(arscFile);
      out.write(data);
    } catch (IOException ex) {
      throw new AndrolibException(ex);
    } finally {
      if (in != null) {
        try {
          in.close();
        } catch (IOException ex) {
        }
      }
      if (out != null) {
        try {
          out.close();
        } catch (IOException ex) {
        }
      }
    }
  }
Пример #2
0
 private File getFrameworkDir() throws AndrolibException {
   File dir =
       new File(
           System.getProperty("user.home")
               + File.separatorChar
               + "apktool"
               + File.separatorChar
               + "framework");
   if (!dir.exists()) {
     if (!dir.mkdirs()) {
       throw new AndrolibException("Can't create directory: " + dir);
     }
   }
   return dir;
 }
Пример #3
0
  public boolean detectWhetherAppIsFramework(File appDir) throws AndrolibException {
    File publicXml = new File(appDir, "res/values/public.xml");
    if (!publicXml.exists()) {
      return false;
    }

    Iterator<String> it;
    try {
      it = IOUtils.lineIterator(new FileReader(new File(appDir, "res/values/public.xml")));
    } catch (FileNotFoundException ex) {
      throw new AndrolibException("Could not detect whether app is framework one", ex);
    }
    it.next();
    it.next();
    return it.next().contains("0x01");
  }
Пример #4
0
  public File getFrameworkApk(int id, String frameTag) throws AndrolibException {
    File dir = getFrameworkDir();
    File apk;

    if (frameTag != null) {
      apk = new File(dir, String.valueOf(id) + '-' + frameTag + ".apk");
      if (apk.exists()) {
        return apk;
      }
    }

    apk = new File(dir, String.valueOf(id) + ".apk");
    if (apk.exists()) {
      return apk;
    }

    if (id == 1) {
      InputStream in = null;
      OutputStream out = null;
      try {
        in = AndrolibResources.class.getResourceAsStream("/brut/androlib/android-framework.jar");
        out = new FileOutputStream(apk);
        IOUtils.copy(in, out);
        return apk;
      } catch (IOException ex) {
        throw new AndrolibException(ex);
      } finally {
        if (in != null) {
          try {
            in.close();
          } catch (IOException ex) {
          }
        }
        if (out != null) {
          try {
            out.close();
          } catch (IOException ex) {
          }
        }
      }
    }

    throw new CantFindFrameworkResException(id);
  }
Пример #5
0
  public void aaptPackage(
      File apkFile,
      File manifest,
      File resDir,
      File rawDir,
      File assetDir,
      File[] include,
      boolean update,
      boolean framework)
      throws AndrolibException {
    List<String> cmd = new ArrayList<String>();

    cmd.add("aapt");
    cmd.add("p");
    cmd.add("-v"); // mega debug mode.@todo REMOVE ON FINAL
    if (update) {
      cmd.add("-u");
    }
    if (mMinSdkVersion != null) {
      cmd.add("--min-sdk-version");
      cmd.add(mMinSdkVersion);
    }
    if (mTargetSdkVersion != null) {
      cmd.add("--target-sdk-version");
      cmd.add(mTargetSdkVersion);
    }
    if (mMaxSdkVersion != null) {
      cmd.add("--max-sdk-version");
      cmd.add(mMaxSdkVersion);
    }
    cmd.add("-F");
    cmd.add(apkFile.getAbsolutePath());

    if (framework) {
      cmd.add("-x");
      //            cmd.add("-0");
      //            cmd.add("arsc");
    }

    if (include != null) {
      for (File file : include) {
        cmd.add("-I");
        cmd.add(file.getPath());
      }
    }
    if (resDir != null) {
      cmd.add("-S");
      cmd.add(resDir.getAbsolutePath());
    }
    if (manifest != null) {
      cmd.add("-M");
      cmd.add(manifest.getAbsolutePath());
    }
    if (assetDir != null) {
      cmd.add("-A");
      cmd.add(assetDir.getAbsolutePath());
    }
    if (rawDir != null) {
      cmd.add(rawDir.getAbsolutePath());
    }

    try {
      OS.exec(cmd.toArray(new String[0]));
    } catch (BrutException ex) {
      throw new AndrolibException(ex);
    }
  }