Tabnine Logo
ResXmlPatcher
Code IndexAdd Tabnine to your IDE (free)

How to use
ResXmlPatcher
in
brut.androlib.res.xml

Best Java code snippets using brut.androlib.res.xml.ResXmlPatcher (Showing top 12 results out of 315)

origin: iBotPeaches/Apktool

/**
 * Checks if the replacement was properly made to a node.
 *
 * @param file File we are searching for value
 * @param saved boolean on whether we need to save
 * @param provider Node we are attempting to replace
 * @return boolean
 * @throws AndrolibException setting node value failed
 */
private static boolean isSaved(File file, boolean saved, Node provider) throws AndrolibException {
  String reference = provider.getNodeValue();
  String replacement = pullValueFromStrings(file.getParentFile(), reference);
  if (replacement != null) {
    provider.setNodeValue(replacement);
    saved = true;
  }
  return saved;
}
origin: iBotPeaches/Apktool

private void buildManifestFile(File appDir, File manifest, File manifestOriginal)
    throws AndrolibException {
  // If we decoded in "raw", we cannot patch AndroidManifest
  if (new File(appDir, "resources.arsc").exists()) {
    return;
  }
  if (manifest.isFile() && manifest.exists()) {
    try {
      if (manifestOriginal.exists()) {
        manifestOriginal.delete();
      }
      FileUtils.copyFile(manifest, manifestOriginal);
      ResXmlPatcher.fixingPublicAttrsInProviderAttributes(manifest);
    } catch (IOException ex) {
      throw new AndrolibException(ex.getMessage());
    }
  }
}
origin: iBotPeaches/Apktool

if (file.exists()) {
  try {
    Document doc = loadDocument(file);
    XPath xPath = XPathFactory.newInstance().newXPath();
    XPathExpression expression = xPath.compile("/manifest/application/provider");
          saved = isSaved(file, saved, provider);
          saved = isSaved(file, saved, provider);
      saveDocument(file, doc);
origin: iBotPeaches/Apktool

/**
 * Replaces package value with passed packageOriginal string
 *
 * @param file File for AndroidManifest.xml
 * @param packageOriginal Package name to replace
 * @throws AndrolibException
 */
public static void renameManifestPackage(File file, String packageOriginal) throws AndrolibException {
  try {
    Document doc = loadDocument(file);
    // Get the manifest line
    Node manifest = doc.getFirstChild();
    // update package attribute
    NamedNodeMap attr = manifest.getAttributes();
    Node nodeAttr = attr.getNamedItem("package");
    nodeAttr.setNodeValue(packageOriginal);
    saveDocument(file, doc);
  } catch (SAXException | ParserConfigurationException | IOException | TransformerException ignored) {
  }
}
origin: iBotPeaches/Apktool

/**
 * Finds key in strings.xml file and returns text value
 *
 * @param directory Root directory of apk
 * @param key String reference (ie @string/foo)
 * @return String|null
 * @throws AndrolibException
 */
public static String pullValueFromStrings(File directory, String key) throws AndrolibException {
  if (key == null || ! key.contains("@")) {
    return null;
  }
  File file = new File(directory, "/res/values/strings.xml");
  key = key.replace("@string/", "");
  if (file.exists()) {
    try {
      Document doc = loadDocument(file);
      XPath xPath = XPathFactory.newInstance().newXPath();
      XPathExpression expression = xPath.compile("/resources/string[@name=" + '"' + key + "\"]/text()");
      Object result = expression.evaluate(doc, XPathConstants.STRING);
      if (result != null) {
        return (String) result;
      }
    }  catch (SAXException | ParserConfigurationException | IOException | XPathExpressionException ignored) {
    }
  }
  return null;
}
origin: iBotPeaches/Apktool

public void adjustPackageManifest(ResTable resTable, String filePath)
    throws AndrolibException {
  // compare resources.arsc package name to the one present in AndroidManifest
  ResPackage resPackage = resTable.getCurrentResPackage();
  String packageOriginal = resPackage.getName();
  mPackageRenamed = resTable.getPackageRenamed();
  resTable.setPackageId(resPackage.getId());
  resTable.setPackageOriginal(packageOriginal);
  // 1) Check if packageOriginal === mPackageRenamed
  // 2) Check if packageOriginal is ignored via IGNORED_PACKAGES
  // 2a) If its ignored, make sure the mPackageRenamed isn't explicitly allowed
  if (packageOriginal.equalsIgnoreCase(mPackageRenamed) ||
      (Arrays.asList(IGNORED_PACKAGES).contains(packageOriginal) &&
      ! Arrays.asList(ALLOWED_PACKAGES).contains(mPackageRenamed))) {
    LOGGER.info("Regular manifest package...");
  } else {
    LOGGER.info("Renamed manifest package found! Replacing " + mPackageRenamed + " with " + packageOriginal);
    ResXmlPatcher.renameManifestPackage(new File(filePath), packageOriginal);
  }
}
origin: iBotPeaches/Apktool

ResXmlPatcher.removeApplicationDebugTag(new File(appDir, "AndroidManifest.xml"));
origin: iBotPeaches/Apktool

public void decodeManifestWithResources(ResTable resTable, ExtFile apkFile, File outDir)
    throws AndrolibException {
  Duo<ResFileDecoder, AXmlResourceParser> duo = getResFileDecoder();
  ResFileDecoder fileDecoder = duo.m1;
  ResAttrDecoder attrDecoder = duo.m2.getAttrDecoder();
  attrDecoder.setCurrentPackage(resTable.listMainPackages().iterator().next());
  Directory inApk, in = null, out;
  try {
    inApk = apkFile.getDirectory();
    out = new FileDirectory(outDir);
    LOGGER.info("Decoding AndroidManifest.xml with resources...");
    fileDecoder.decodeManifest(inApk, "AndroidManifest.xml", out, "AndroidManifest.xml");
    // Remove versionName / versionCode (aapt API 16)
    if (!resTable.getAnalysisMode()) {
      // check for a mismatch between resources.arsc package and the package listed in AndroidManifest
      // also remove the android::versionCode / versionName from manifest for rebuild
      // this is a required change to prevent aapt warning about conflicting versions
      // it will be passed as a parameter to aapt like "--min-sdk-version" via apktool.yml
      adjustPackageManifest(resTable, outDir.getAbsolutePath() + File.separator + "AndroidManifest.xml");
      ResXmlPatcher.removeManifestVersions(new File(
          outDir.getAbsolutePath() + File.separator + "AndroidManifest.xml"));
      mPackageId = String.valueOf(resTable.getPackageId());
    }
  } catch (DirectoryException ex) {
    throw new AndrolibException(ex);
  }
}
origin: iBotPeaches/Apktool

/**
 * Removes "debug" tag from file
 *
 * @param file AndroidManifest file
 * @throws AndrolibException
 */
public static void removeApplicationDebugTag(File file) throws AndrolibException {
  if (file.exists()) {
    try {
      Document doc = loadDocument(file);
      Node application = doc.getElementsByTagName("application").item(0);
      // load attr
      NamedNodeMap attr = application.getAttributes();
      Node debugAttr = attr.getNamedItem("android:debuggable");
      // remove application:debuggable
      if (debugAttr != null) {
        attr.removeNamedItem("android:debuggable");
      }
      saveDocument(file, doc);
    } catch (SAXException | ParserConfigurationException | IOException | TransformerException ignored) {
    }
  }
}
origin: iBotPeaches/Apktool

private void putVersionInfo(MetaInfo meta) throws AndrolibException {
  VersionInfo info = getResTable().getVersionInfo();
  String refValue = ResXmlPatcher.pullValueFromStrings(mOutDir, info.versionName);
  if (refValue != null) {
    info.versionName = refValue;
  }
  meta.versionInfo = info;
}
origin: iBotPeaches/Apktool

/**
 * Removes attributes like "versionCode" and "versionName" from file.
 *
 * @param file File representing AndroidManifest.xml
 * @throws AndrolibException
 */
public static void removeManifestVersions(File file) throws AndrolibException {
  if (file.exists()) {
    try {
      Document doc = loadDocument(file);
      Node manifest = doc.getFirstChild();
      NamedNodeMap attr = manifest.getAttributes();
      Node vCode = attr.getNamedItem("android:versionCode");
      Node vName = attr.getNamedItem("android:versionName");
      if (vCode != null) {
        attr.removeNamedItem("android:versionCode");
      }
      if (vName != null) {
        attr.removeNamedItem("android:versionName");
      }
      saveDocument(file, doc);
    } catch (SAXException | ParserConfigurationException | IOException | TransformerException ignored) {
    }
  }
}
origin: droidefense/engine

private void putVersionInfo(MetaInfo meta) throws AndrolibException {
  VersionInfo info = getResTable().getVersionInfo();
  String refValue = ResXmlPatcher.pullValueFromStrings(mOutDir, info.versionName);
  if (refValue != null) {
    info.versionName = refValue;
  }
  meta.versionInfo = info;
}
brut.androlib.res.xmlResXmlPatcher

Most used methods

  • pullValueFromStrings
    Finds key in strings.xml file and returns text value
  • fixingPublicAttrsInProviderAttributes
    Any @string reference in a value in AndroidManifest.xml will break on build, thus preventing the app
  • isSaved
    Checks if the replacement was properly made to a node.
  • loadDocument
  • removeApplicationDebugTag
    Removes "debug" tag from file
  • removeManifestVersions
    Removes attributes like "versionCode" and "versionName" from file.
  • renameManifestPackage
    Replaces package value with passed packageOriginal string
  • saveDocument

Popular in Java

  • Start an intent from android
  • setScale (BigDecimal)
  • scheduleAtFixedRate (Timer)
  • startActivity (Activity)
  • Pointer (com.sun.jna)
    An abstraction for a native pointer data type. A Pointer instance represents, on the Java side, a na
  • PrintStream (java.io)
    Fake signature of an existing Java class.
  • Format (java.text)
    The base class for all formats. This is an abstract base class which specifies the protocol for clas
  • BitSet (java.util)
    The BitSet class implements abit array [http://en.wikipedia.org/wiki/Bit_array]. Each element is eit
  • Reference (javax.naming)
  • LogFactory (org.apache.commons.logging)
    Factory for creating Log instances, with discovery and configuration features similar to that employ
  • Top Vim plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now