Using zipj4 for adding stuff back into original apk

This commit is contained in:
Connor Tumbleson 2012-09-17 22:26:10 -05:00
parent 53e7ffd9a2
commit 75ad01c60a
5 changed files with 55 additions and 11 deletions

View File

@ -38,6 +38,7 @@
<include>org.antlr:antlr-runtime</include>
<include>com.google.*</include>
<include>org.apache.*</include>
<include>net.lingala.*</include>
</includes>
</dependencySet>
</dependencySets>

View File

@ -23,6 +23,7 @@ import brut.androlib.ApktoolProperties;
import brut.androlib.err.CantFindFrameworkResException;
import brut.androlib.err.InFileNotFoundException;
import brut.androlib.err.OutDirExistsException;
import brut.androlib.res.util.ExtFile;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
@ -165,7 +166,7 @@ public class Main {
int i;
int skip = 0;
File mOrigApk = null;
ExtFile mOrigApk = null;
for (i = 0; i < args.length; i++) {
String opt = args[i];
if (! opt.startsWith("-")) {
@ -182,7 +183,7 @@ public class Main {
throw new InvalidArgsError();
} else {
flags.put("injectOriginal", true);
mOrigApk = new File(args[i + 1]);
mOrigApk = new ExtFile(args[i + 1]);
skip = 1;
}
} else {
@ -205,7 +206,7 @@ public class Main {
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)

View File

@ -137,6 +137,11 @@
<artifactId>smali</artifactId>
<version>1.3.4-ibot8</version>
</dependency>
<dependency>
<groupId>net.lingala.zip4j</groupId>
<artifactId>zip4j</artifactId>
<version>1.3.1</version>
</dependency>
</dependencies>
<pluginRepositories>
<pluginRepository>

View File

@ -33,6 +33,10 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
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.Yaml;
@ -172,16 +176,25 @@ public class Androlib {
}
public void build(File appDir, File outFile,
HashMap<String, Boolean> flags) throws AndrolibException {
build(new ExtFile(appDir), outFile, flags);
HashMap<String, Boolean> flags, ExtFile origApk) throws AndrolibException {
build(new ExtFile(appDir), outFile, flags, origApk);
}
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);
Object t1 = meta.get("isFrameworkApk");
flags.put("framework", t1 == null ? false : (Boolean) t1);
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) {
String outFileName = (String) meta.get("apkFileName");
@ -439,9 +452,32 @@ public class Androlib {
/* check for re-insert */
if (flags.get("injectOriginal")) {
// if (!mApkFile.isFile() || !mApkFile.canRead()) {
// throw new InFileNotFoundException();
//}
try {
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 =
Logger.getLogger(Androlib.class.getName());

View File

@ -45,7 +45,8 @@ public class BuildAndDecodeTest {
"brut/apktool/testapp/", sTestOrigDir);
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...");
ApkDecoder apkDecoder = new ApkDecoder(testApk);