mirror of
https://github.com/revanced/Apktool.git
synced 2025-05-01 06:34:25 +02:00
Added possibility to not decode resources.
This commit is contained in:
parent
5577654105
commit
03a98d6a1c
@ -20,14 +20,10 @@ package brut.androlib;
|
|||||||
import brut.androlib.res.AndrolibResources;
|
import brut.androlib.res.AndrolibResources;
|
||||||
import brut.androlib.res.data.ResTable;
|
import brut.androlib.res.data.ResTable;
|
||||||
import brut.common.BrutException;
|
import brut.common.BrutException;
|
||||||
import brut.directory.Directory;
|
import brut.directory.*;
|
||||||
import brut.directory.DirectoryException;
|
|
||||||
import brut.directory.FileDirectory;
|
|
||||||
import brut.directory.Util;
|
|
||||||
import brut.directory.ZipRODirectory;
|
|
||||||
import brut.util.OS;
|
import brut.util.OS;
|
||||||
import java.io.File;
|
import java.io.*;
|
||||||
import java.io.IOException;
|
import org.apache.commons.io.IOUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Ryszard Wiśniewski <brut.alll@gmail.com>
|
* @author Ryszard Wiśniewski <brut.alll@gmail.com>
|
||||||
@ -36,12 +32,12 @@ public class Androlib {
|
|||||||
private final AndrolibResources mAndRes = new AndrolibResources();
|
private final AndrolibResources mAndRes = new AndrolibResources();
|
||||||
private final AndrolibSmali mSmali = new AndrolibSmali();
|
private final AndrolibSmali mSmali = new AndrolibSmali();
|
||||||
|
|
||||||
public void decode(String apkFileName, String outDirName)
|
public void decode(String apkFileName, String outDirName, boolean resources)
|
||||||
throws AndrolibException {
|
throws AndrolibException {
|
||||||
decode(new File(apkFileName), new File(outDirName));
|
decode(new File(apkFileName), new File(outDirName), resources);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void decode(File apkFile, File outDir)
|
public void decode(File apkFile, File outDir, boolean resources)
|
||||||
throws AndrolibException {
|
throws AndrolibException {
|
||||||
try {
|
try {
|
||||||
OS.rmdir(outDir);
|
OS.rmdir(outDir);
|
||||||
@ -50,13 +46,14 @@ public class Androlib {
|
|||||||
}
|
}
|
||||||
outDir.mkdirs();
|
outDir.mkdirs();
|
||||||
|
|
||||||
ResTable resTable = mAndRes.getResTable(apkFile);
|
|
||||||
|
|
||||||
mAndRes.decode(resTable, apkFile, outDir);
|
|
||||||
|
|
||||||
File smaliDir = new File(outDir.getPath() + "/smali");
|
File smaliDir = new File(outDir.getPath() + "/smali");
|
||||||
mSmali.baksmali(apkFile, smaliDir);
|
mSmali.baksmali(apkFile, smaliDir);
|
||||||
|
|
||||||
|
if(resources) {
|
||||||
|
ResTable resTable = mAndRes.getResTable(apkFile);
|
||||||
|
mAndRes.decode(resTable, apkFile, outDir);
|
||||||
mAndRes.tagSmaliResIDs(resTable, smaliDir);
|
mAndRes.tagSmaliResIDs(resTable, smaliDir);
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Directory in = new ZipRODirectory(apkFile);
|
Directory in = new ZipRODirectory(apkFile);
|
||||||
@ -67,6 +64,15 @@ public class Androlib {
|
|||||||
if (in.containsDir("lib")) {
|
if (in.containsDir("lib")) {
|
||||||
Util.copyFiles(in.getDir("lib"), out.createDir("lib"));
|
Util.copyFiles(in.getDir("lib"), out.createDir("lib"));
|
||||||
}
|
}
|
||||||
|
if (! resources) {
|
||||||
|
Util.copyFiles(in.getDir("res"), out.createDir("res"));
|
||||||
|
IOUtils.copy(in.getFileInput("resources.arsc"),
|
||||||
|
out.getFileOutput("resources.arsc"));
|
||||||
|
IOUtils.copy(in.getFileInput("AndroidManifest.xml"),
|
||||||
|
out.getFileOutput("AndroidManifest.xml"));
|
||||||
|
}
|
||||||
|
} catch (IOException ex) {
|
||||||
|
throw new AndrolibException("Could not decode apk", ex);
|
||||||
} catch (DirectoryException ex) {
|
} catch (DirectoryException ex) {
|
||||||
throw new AndrolibException("Could not decode apk", ex);
|
throw new AndrolibException("Could not decode apk", ex);
|
||||||
}
|
}
|
||||||
@ -104,6 +110,23 @@ public class Androlib {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void buildResources() throws AndrolibException {
|
public void buildResources() throws AndrolibException {
|
||||||
|
if (new File("resources.arsc").exists()) {
|
||||||
|
try {
|
||||||
|
new File("build/apk/res").mkdirs();
|
||||||
|
Util.copyFiles(new FileDirectory("res"),
|
||||||
|
new FileDirectory("build/apk/res"));
|
||||||
|
IOUtils.copy(new FileInputStream("resources.arsc"),
|
||||||
|
new FileOutputStream("build/apk/resources.arsc"));
|
||||||
|
IOUtils.copy(new FileInputStream("AndroidManifest.xml"),
|
||||||
|
new FileOutputStream("build/apk/AndroidManifest.xml"));
|
||||||
|
} catch (IOException ex) {
|
||||||
|
throw new AndrolibException(ex);
|
||||||
|
} catch (DirectoryException ex) {
|
||||||
|
throw new AndrolibException(ex);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
File apkFile;
|
File apkFile;
|
||||||
try {
|
try {
|
||||||
apkFile = File.createTempFile("APKTOOL", null);
|
apkFile = File.createTempFile("APKTOOL", null);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user