mirror of
https://github.com/revanced/Apktool.git
synced 2025-05-01 14:44:26 +02: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 #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 #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 #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)
|
v1.5.3 (TBA)
|
||||||
-Updated to smali/baksmali to v1.4.2
|
-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.res.util.ExtFile;
|
||||||
import brut.androlib.src.SmaliBuilder;
|
import brut.androlib.src.SmaliBuilder;
|
||||||
import brut.androlib.src.SmaliDecoder;
|
import brut.androlib.src.SmaliDecoder;
|
||||||
|
import brut.androlib.src.TypeName;
|
||||||
import brut.common.BrutException;
|
import brut.common.BrutException;
|
||||||
import brut.directory.*;
|
import brut.directory.*;
|
||||||
import brut.util.BrutIO;
|
import brut.util.BrutIO;
|
||||||
import brut.util.OS;
|
import brut.util.OS;
|
||||||
import java.io.*;
|
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.*;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
import java.util.zip.ZipEntry;
|
import java.util.zip.ZipEntry;
|
||||||
|
import java.nio.file.Files;
|
||||||
import org.yaml.snakeyaml.DumperOptions;
|
import org.yaml.snakeyaml.DumperOptions;
|
||||||
import org.yaml.snakeyaml.Yaml;
|
import org.yaml.snakeyaml.Yaml;
|
||||||
|
|
||||||
@ -529,31 +535,53 @@ public class Androlib {
|
|||||||
|
|
||||||
public void buildUnknownFiles(File appDir, File outFile, Map<String, Object> meta)
|
public void buildUnknownFiles(File appDir, File outFile, Map<String, Object> meta)
|
||||||
throws AndrolibException {
|
throws AndrolibException {
|
||||||
|
File file;
|
||||||
|
mPath = Paths.get(appDir.getPath() + File.separatorChar + UNK_DIRNAME);
|
||||||
|
|
||||||
// confirm we have unknown files to inject
|
|
||||||
if (meta.containsKey("unknownFiles")) {
|
if (meta.containsKey("unknownFiles")) {
|
||||||
LOGGER.info("Copying unknown files/dir...");
|
LOGGER.info("Copying unknown files/dir...");
|
||||||
|
|
||||||
Map<String, String> files = (Map<String, String>)meta.get("unknownFiles");
|
Map<String, String> files = (Map<String, String>)meta.get("unknownFiles");
|
||||||
|
|
||||||
try {
|
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");
|
||||||
|
|
||||||
|
// create filesystem
|
||||||
|
URI apkFileSystem = URI.create("jar:file:" + outFile.getAbsolutePath());
|
||||||
|
try(FileSystem zipFS = FileSystems.newFileSystem(apkFileSystem, zip_properties)) {
|
||||||
|
|
||||||
// loop through files inside
|
// loop through files inside
|
||||||
for (Map.Entry<String,String> entry : files.entrySet()) {
|
for (Map.Entry<String,String> entry : files.entrySet()) {
|
||||||
|
|
||||||
// check if file exists
|
// check if file exists
|
||||||
if (new File(appDir,entry.getKey()).isFile()) {
|
file = new File(mPath.toFile(), entry.getKey());
|
||||||
|
if (file.isFile() && file.exists()) {
|
||||||
// @todo read ZipFile and inject file into
|
insertFile(zipFS, file, entry.getValue(),mPath.toAbsolutePath());
|
||||||
// might need to use Zip4j
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
apkZipFile.close();
|
zipFS.close();
|
||||||
|
}
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
throw new AndrolibException(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,
|
public void buildApk(File appDir, File outApk,
|
||||||
@ -652,6 +680,7 @@ public class Androlib {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String mAaptPath = null;
|
private String mAaptPath = null;
|
||||||
|
private Path mPath = null;
|
||||||
|
|
||||||
private final static Logger LOGGER = Logger.getLogger(Androlib.class
|
private final static Logger LOGGER = Logger.getLogger(Androlib.class
|
||||||
.getName());
|
.getName());
|
||||||
|
@ -1,3 +1,2 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<manifest android:versionCode="1" android:versionName="1.0" package="brut.apktool.testapp"
|
<manifest package="brut.apktool.testapp" xmlns:android="http://schemas.android.com/apk/res/android" />
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android" />
|
|
||||||
|
@ -1,6 +1,13 @@
|
|||||||
version: 1.5.0
|
version: 2.0.0
|
||||||
apkFileName: testapp.apk
|
apkFileName: testapp.apk
|
||||||
isFrameworkApk: false
|
isFrameworkApk: false
|
||||||
usesFramework:
|
usesFramework:
|
||||||
ids:
|
ids:
|
||||||
- 1
|
- 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…
x
Reference in New Issue
Block a user