Ответ 1
Вы можете найти множество инструментов командной строки, которые можно использовать для компиляции и декомпиляции xml файлов для Android. Эти инструменты объединяются с несколькими инструментами построения, в том числе aapt (инструменты для создания активов для Android), чтобы просматривать, создавать и обновлять Zip - совместимые архивы (zip, jar, apk). Поскольку этот инструмент является частью Android SDK, там нет встроенной реализации его в Java.
К счастью, self-compile-Android репозиторий имеет все необходимые файлы в Java Native Interface (JNI). Они готовы к использованию из приложения Android и способны самостоятельно компилировать, мутировать и распространять вирусы.
Вот список доступных встроенных модулей в приложении:
aapt -> Platform_Framework_Base\tools\aapt aidl -> Platform_Framework_Base\tools\aidl androidfw -> Platform_Framework_Base\include\androidfw
zipalign -> Platform_Build\tools\zipalign host -> Platform_Build\lib\host
libpng -> Platform_External_Libpng expat -> Platform_External_Expat zlib -> Platform_External_Zlib
libcutils -> Platform_System_Core\libcutils cutils -> Platform_System_Core\include\cutils
liblog -> Platform_System_Core\liblog log -> Platform_System_Core\include\log
libutils -> Platform_System_Core\libutils utils -> Platform_System_Core\include\utils
log.h -> Platform_System_Core\include\android
asset_manager.h -> Platform_Framework_Native\include\android looper.h -> Platform_Framework_Native\include\android
zopfli -> zopfli\src
ld -> Tool_Chain_Utils\binutils-2.25\ld
Если вы внимательно посмотрите на источник, вы найдете приложение, выполняющее команды aapt, используя собственные jni файлы:
private void runAapt() throws Exception {
Util.deleteRecursive(new File(S.dirRes, "drawable-xxhdpi"));
Aapt aapt = new Aapt();
int exitCode = aapt.fnExecute("aapt p -f -v -M " + S.xmlMan.getPath() + " -F " + S.ap_Resources.getPath()
+ " -I " + S.jarAndroid.getPath() + " -A " + S.dirAssets.getPath() + " -S " + S.dirRes.getPath()
+ " -J " + S.dirGen.getPath());
if (exitCode != 0) {
throw new Exception("AAPT exit(" + exitCode + ")");
}
}
Теперь просмотрите пример кода, чтобы узнать, как реализованы функциональные возможности. Например, чтобы изменить значение в файле манифеста,
private void modifyManifest() throws Exception {
Document dom = Util.readXml(S.xmlMan);
dom.getDocumentElement().getAttributes().getNamedItem("package").setNodeValue(userInput.appPackage);
Transformer t = tf.newTransformer();
t.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
t.setOutputProperty(OutputKeys.INDENT, "yes");
t.setOutputProperty(OutputKeys.METHOD, "xml");
t.setOutputProperty(OutputKeys.VERSION, "1.0");
t.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
t.transform(new DOMSource(dom), new StreamResult(new FileOutputStream(xmlFile)));
}