mirror of
https://github.com/revanced/Apktool.git
synced 2025-01-27 12:17:35 +01:00
Using zipj4 for adding stuff back into original apk
This commit is contained in:
parent
53e7ffd9a2
commit
75ad01c60a
@ -38,6 +38,7 @@
|
|||||||
<include>org.antlr:antlr-runtime</include>
|
<include>org.antlr:antlr-runtime</include>
|
||||||
<include>com.google.*</include>
|
<include>com.google.*</include>
|
||||||
<include>org.apache.*</include>
|
<include>org.apache.*</include>
|
||||||
|
<include>net.lingala.*</include>
|
||||||
</includes>
|
</includes>
|
||||||
</dependencySet>
|
</dependencySet>
|
||||||
</dependencySets>
|
</dependencySets>
|
||||||
|
@ -23,6 +23,7 @@ import brut.androlib.ApktoolProperties;
|
|||||||
import brut.androlib.err.CantFindFrameworkResException;
|
import brut.androlib.err.CantFindFrameworkResException;
|
||||||
import brut.androlib.err.InFileNotFoundException;
|
import brut.androlib.err.InFileNotFoundException;
|
||||||
import brut.androlib.err.OutDirExistsException;
|
import brut.androlib.err.OutDirExistsException;
|
||||||
|
import brut.androlib.res.util.ExtFile;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@ -165,7 +166,7 @@ public class Main {
|
|||||||
|
|
||||||
int i;
|
int i;
|
||||||
int skip = 0;
|
int skip = 0;
|
||||||
File mOrigApk = null;
|
ExtFile mOrigApk = null;
|
||||||
for (i = 0; i < args.length; i++) {
|
for (i = 0; i < args.length; i++) {
|
||||||
String opt = args[i];
|
String opt = args[i];
|
||||||
if (! opt.startsWith("-")) {
|
if (! opt.startsWith("-")) {
|
||||||
@ -182,7 +183,7 @@ public class Main {
|
|||||||
throw new InvalidArgsError();
|
throw new InvalidArgsError();
|
||||||
} else {
|
} else {
|
||||||
flags.put("injectOriginal", true);
|
flags.put("injectOriginal", true);
|
||||||
mOrigApk = new File(args[i + 1]);
|
mOrigApk = new ExtFile(args[i + 1]);
|
||||||
skip = 1;
|
skip = 1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -205,7 +206,7 @@ public class Main {
|
|||||||
throw new InvalidArgsError();
|
throw new InvalidArgsError();
|
||||||
}
|
}
|
||||||
|
|
||||||
new Androlib().build(new File(appDirName), outFile, flags);
|
new Androlib().build(new File(appDirName), outFile, flags, mOrigApk);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void cmdInstallFramework(String[] args)
|
private static void cmdInstallFramework(String[] args)
|
||||||
|
@ -137,6 +137,11 @@
|
|||||||
<artifactId>smali</artifactId>
|
<artifactId>smali</artifactId>
|
||||||
<version>1.3.4-ibot8</version>
|
<version>1.3.4-ibot8</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.lingala.zip4j</groupId>
|
||||||
|
<artifactId>zip4j</artifactId>
|
||||||
|
<version>1.3.1</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<pluginRepositories>
|
<pluginRepositories>
|
||||||
<pluginRepository>
|
<pluginRepository>
|
||||||
|
@ -33,6 +33,10 @@ import java.util.HashMap;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
import net.lingala.zip4j.core.ZipFile;
|
||||||
|
import net.lingala.zip4j.exception.ZipException;
|
||||||
|
import net.lingala.zip4j.model.ZipParameters;
|
||||||
|
import net.lingala.zip4j.util.Zip4jConstants;
|
||||||
import org.yaml.snakeyaml.DumperOptions;
|
import org.yaml.snakeyaml.DumperOptions;
|
||||||
import org.yaml.snakeyaml.Yaml;
|
import org.yaml.snakeyaml.Yaml;
|
||||||
|
|
||||||
@ -172,17 +176,26 @@ public class Androlib {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void build(File appDir, File outFile,
|
public void build(File appDir, File outFile,
|
||||||
HashMap<String, Boolean> flags) throws AndrolibException {
|
HashMap<String, Boolean> flags, ExtFile origApk) throws AndrolibException {
|
||||||
build(new ExtFile(appDir), outFile, flags);
|
build(new ExtFile(appDir), outFile, flags, origApk);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void build(ExtFile appDir, File outFile,
|
public void build(ExtFile appDir, File outFile,
|
||||||
HashMap<String, Boolean> flags) throws AndrolibException {
|
HashMap<String, Boolean> flags, ExtFile origApk) throws AndrolibException {
|
||||||
Map<String, Object> meta = readMetaFile(appDir);
|
Map<String, Object> meta = readMetaFile(appDir);
|
||||||
Object t1 = meta.get("isFrameworkApk");
|
Object t1 = meta.get("isFrameworkApk");
|
||||||
flags.put("framework", t1 == null ? false : (Boolean) t1);
|
flags.put("framework", t1 == null ? false : (Boolean) t1);
|
||||||
mAndRes.setSdkInfo((Map<String, String>) meta.get("sdkInfo"));
|
mAndRes.setSdkInfo((Map<String, String>) meta.get("sdkInfo"));
|
||||||
|
|
||||||
|
// check the orig apk
|
||||||
|
if (flags.get("injectOriginal")) {
|
||||||
|
if (!origApk.isFile() || !origApk.canRead()) {
|
||||||
|
throw new InFileNotFoundException();
|
||||||
|
} else {
|
||||||
|
mOrigApkFile = origApk;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (outFile == null) {
|
if (outFile == null) {
|
||||||
String outFileName = (String) meta.get("apkFileName");
|
String outFileName = (String) meta.get("apkFileName");
|
||||||
outFile = new File(appDir, "dist" + File.separator +
|
outFile = new File(appDir, "dist" + File.separator +
|
||||||
@ -439,9 +452,32 @@ public class Androlib {
|
|||||||
|
|
||||||
/* check for re-insert */
|
/* check for re-insert */
|
||||||
if (flags.get("injectOriginal")) {
|
if (flags.get("injectOriginal")) {
|
||||||
// if (!mApkFile.isFile() || !mApkFile.canRead()) {
|
try {
|
||||||
// throw new InFileNotFoundException();
|
LOGGER.info("Building resources into original apk file...");
|
||||||
//}
|
ZipFile editOrig = new ZipFile(mOrigApkFile.getAbsoluteFile());
|
||||||
|
|
||||||
|
// no compression levels, paras
|
||||||
|
ZipParameters parameters = new ZipParameters();
|
||||||
|
parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);
|
||||||
|
parameters.setCompressionLevel(0);
|
||||||
|
parameters.setIncludeRootFolder(true);
|
||||||
|
parameters.setRootFolderInZip("/");
|
||||||
|
|
||||||
|
// add res folder
|
||||||
|
editOrig.addFolder(new File(appDir, APK_DIRNAME + "/res").getAbsolutePath(), parameters);
|
||||||
|
|
||||||
|
// add assets, if there
|
||||||
|
if (assetDir.exists()) {
|
||||||
|
//editOrig.addFolder(new File(appDir, APK_DIRNAME + "/assets").getAbsolutePath(), parameters);
|
||||||
|
}
|
||||||
|
|
||||||
|
// add resources.arsc
|
||||||
|
parameters.setFileNameInZip("resources.arsc");
|
||||||
|
// editOrig.addFile(new File(appDir, "resources.arsc"), parameters);
|
||||||
|
} catch(ZipException e) {
|
||||||
|
LOGGER.warning(e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -522,7 +558,7 @@ public class Androlib {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private ExtFile mOrigApkFile;
|
private ExtFile mOrigApkFile = null;
|
||||||
|
|
||||||
private final static Logger LOGGER =
|
private final static Logger LOGGER =
|
||||||
Logger.getLogger(Androlib.class.getName());
|
Logger.getLogger(Androlib.class.getName());
|
||||||
|
@ -45,7 +45,8 @@ public class BuildAndDecodeTest {
|
|||||||
"brut/apktool/testapp/", sTestOrigDir);
|
"brut/apktool/testapp/", sTestOrigDir);
|
||||||
|
|
||||||
LOGGER.info("Building testapp.apk...");
|
LOGGER.info("Building testapp.apk...");
|
||||||
new Androlib().build(sTestOrigDir, testApk, BuildAndDecodeTest.returnStock());
|
ExtFile blank = null;
|
||||||
|
new Androlib().build(sTestOrigDir, testApk, BuildAndDecodeTest.returnStock(),blank);
|
||||||
|
|
||||||
LOGGER.info("Decoding testapp.apk...");
|
LOGGER.info("Decoding testapp.apk...");
|
||||||
ApkDecoder apkDecoder = new ApkDecoder(testApk);
|
ApkDecoder apkDecoder = new ApkDecoder(testApk);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user