mirror of
https://github.com/revanced/Apktool.git
synced 2024-12-05 02:22:55 +01:00
add unit-test and support for handling unknown files
This commit is contained in:
parent
150a95f14a
commit
a7236053bf
1
CHANGES
1
CHANGES
@ -5,6 +5,7 @@ v2.0.0 (TBA)
|
||||
-Fixed (issue #401) - Uses versionInfo meta to correctly parse versionName and versionCode
|
||||
-Fixed (issue #440) - Include aapt binaries within Apktool to have closer control over build.
|
||||
-Fixed (issue #439) - Correctly handles apk's that have have the general access bit enabled for encryption
|
||||
-Fixed (issue #63) - Correctly handles apk's that have unknown files outside of the standard aapt allowed resources.
|
||||
|
||||
v1.5.3 (TBA)
|
||||
-Updated to smali/baksmali to v1.4.2
|
||||
|
@ -23,15 +23,21 @@ import brut.androlib.res.data.ResTable;
|
||||
import brut.androlib.res.util.ExtFile;
|
||||
import brut.androlib.src.SmaliBuilder;
|
||||
import brut.androlib.src.SmaliDecoder;
|
||||
import brut.androlib.src.TypeName;
|
||||
import brut.common.BrutException;
|
||||
import brut.directory.*;
|
||||
import brut.util.BrutIO;
|
||||
import brut.util.OS;
|
||||
import java.io.*;
|
||||
import java.net.URI;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.file.*;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.attribute.BasicFileAttributes;
|
||||
import java.util.*;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.zip.ZipEntry;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import org.yaml.snakeyaml.DumperOptions;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
|
||||
@ -529,31 +535,53 @@ public class Androlib {
|
||||
|
||||
public void buildUnknownFiles(File appDir, File outFile, Map<String, Object> meta)
|
||||
throws AndrolibException {
|
||||
File file;
|
||||
mPath = Paths.get(appDir.getPath() + File.separatorChar + UNK_DIRNAME);
|
||||
|
||||
// confirm we have unknown files to inject
|
||||
if (meta.containsKey("unknownFiles")) {
|
||||
LOGGER.info("Copying unknown files/dir...");
|
||||
|
||||
Map<String, String> files = (Map<String, String>)meta.get("unknownFiles");
|
||||
|
||||
try {
|
||||
ZipExtFile apkZipFile = new ZipExtFile(outFile.getAbsolutePath());
|
||||
// set our filesystem options
|
||||
Map<String, String> zip_properties = new HashMap<>();
|
||||
zip_properties.put("create", "false");
|
||||
zip_properties.put("encoding", "UTF-8");
|
||||
|
||||
// loop through files inside
|
||||
for (Map.Entry<String,String> entry : files.entrySet()) {
|
||||
// create filesystem
|
||||
URI apkFileSystem = URI.create("jar:file:" + outFile.getAbsolutePath());
|
||||
try(FileSystem zipFS = FileSystems.newFileSystem(apkFileSystem, zip_properties)) {
|
||||
|
||||
// check if file exists
|
||||
if (new File(appDir,entry.getKey()).isFile()) {
|
||||
// loop through files inside
|
||||
for (Map.Entry<String,String> entry : files.entrySet()) {
|
||||
|
||||
// @todo read ZipFile and inject file into
|
||||
// might need to use Zip4j
|
||||
// check if file exists
|
||||
file = new File(mPath.toFile(), entry.getKey());
|
||||
if (file.isFile() && file.exists()) {
|
||||
insertFile(zipFS, file, entry.getValue(),mPath.toAbsolutePath());
|
||||
}
|
||||
}
|
||||
zipFS.close();
|
||||
}
|
||||
apkZipFile.close();
|
||||
} catch (IOException ex) {
|
||||
throw new AndrolibException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void insertFile(FileSystem zipfs, File insert, String method, Path root)
|
||||
throws AndrolibException, IOException {
|
||||
Path zipRoot = zipfs.getPath(zipfs.getSeparator());
|
||||
Path zipPath = zipfs.getPath(zipRoot + insert.getAbsolutePath().replace(root.toString(),""));
|
||||
Path tmp = zipPath.normalize().getParent();
|
||||
|
||||
if (!Files.isDirectory(tmp, LinkOption.NOFOLLOW_LINKS)) {
|
||||
Files.createDirectories(tmp);
|
||||
}
|
||||
Path newFile = Paths.get(insert.getAbsolutePath());
|
||||
Files.copy(newFile,zipPath, StandardCopyOption.REPLACE_EXISTING);
|
||||
}
|
||||
|
||||
public void buildApk(File appDir, File outApk,
|
||||
@ -652,6 +680,7 @@ public class Androlib {
|
||||
}
|
||||
|
||||
private String mAaptPath = null;
|
||||
private Path mPath = null;
|
||||
|
||||
private final static Logger LOGGER = Logger.getLogger(Androlib.class
|
||||
.getName());
|
||||
|
@ -1,3 +1,2 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest android:versionCode="1" android:versionName="1.0" package="brut.apktool.testapp"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android" />
|
||||
<manifest package="brut.apktool.testapp" xmlns:android="http://schemas.android.com/apk/res/android" />
|
||||
|
@ -1,6 +1,13 @@
|
||||
version: 1.5.0
|
||||
version: 2.0.0
|
||||
apkFileName: testapp.apk
|
||||
isFrameworkApk: false
|
||||
usesFramework:
|
||||
ids:
|
||||
- 1
|
||||
versionInfo:
|
||||
versionCode: '1'
|
||||
versionName: '1.0'
|
||||
compressionType: false
|
||||
unknownFiles:
|
||||
hidden.file: '8'
|
||||
unk_folder/unknown_file: '8'
|
@ -0,0 +1 @@
|
||||
This file is unknown.
|
@ -0,0 +1 @@
|
||||
I am a hidden file. Put here by a developer to make recompilation difficult.
|
Loading…
Reference in New Issue
Block a user