mirror of
https://github.com/revanced/Apktool.git
synced 2025-01-20 16:57:34 +01:00
parent
dc33533d76
commit
f0f87c844e
@ -124,6 +124,9 @@ public class Main {
|
||||
if (cli.hasOption("r") || cli.hasOption("no-res")) {
|
||||
decoder.setDecodeResources(ApkDecoder.DECODE_RESOURCES_NONE);
|
||||
}
|
||||
if (cli.hasOption("no-assets")) {
|
||||
decoder.setDecodeAssets(ApkDecoder.DECODE_ASSETS_NONE);
|
||||
}
|
||||
if (cli.hasOption("k") || cli.hasOption("keep-broken-res")) {
|
||||
decoder.setKeepBrokenResources(true);
|
||||
}
|
||||
@ -283,6 +286,11 @@ public class Main {
|
||||
.desc("Do not decode resources.")
|
||||
.build();
|
||||
|
||||
Option noAssetOption = Option.builder()
|
||||
.longOpt("no-assets")
|
||||
.desc("Do not decode assets.")
|
||||
.build();
|
||||
|
||||
Option debugDecOption = Option.builder("d")
|
||||
.longOpt("debug")
|
||||
.desc("REMOVED (DOES NOT WORK): Decode in debug mode.")
|
||||
@ -396,6 +404,7 @@ public class Main {
|
||||
DecodeOptions.addOption(keepResOption);
|
||||
DecodeOptions.addOption(analysisOption);
|
||||
DecodeOptions.addOption(apiLevelOption);
|
||||
DecodeOptions.addOption(noAssetOption);
|
||||
|
||||
BuildOptions.addOption(debugBuiOption);
|
||||
BuildOptions.addOption(aaptOption);
|
||||
@ -444,6 +453,7 @@ public class Main {
|
||||
allOptions.addOption(analysisOption);
|
||||
allOptions.addOption(debugDecOption);
|
||||
allOptions.addOption(noDbgOption);
|
||||
allOptions.addOption(noAssetOption);
|
||||
allOptions.addOption(keepResOption);
|
||||
allOptions.addOption(debugBuiOption);
|
||||
allOptions.addOption(aaptOption);
|
||||
|
@ -137,13 +137,16 @@ public class Androlib {
|
||||
mAndRes.decodeManifestWithResources(resTable, apkFile, outDir);
|
||||
}
|
||||
|
||||
public void decodeRawFiles(ExtFile apkFile, File outDir)
|
||||
public void decodeRawFiles(ExtFile apkFile, File outDir, short decodeAssetMode)
|
||||
throws AndrolibException {
|
||||
LOGGER.info("Copying assets and libs...");
|
||||
try {
|
||||
Directory in = apkFile.getDirectory();
|
||||
if (in.containsDir("assets")) {
|
||||
in.copyToDir(outDir, "assets");
|
||||
|
||||
if (decodeAssetMode == ApkDecoder.DECODE_ASSETS_FULL) {
|
||||
if (in.containsDir("assets")) {
|
||||
in.copyToDir(outDir, "assets");
|
||||
}
|
||||
}
|
||||
if (in.containsDir("lib")) {
|
||||
in.copyToDir(outDir, "lib");
|
||||
|
@ -161,7 +161,7 @@ public class ApkDecoder {
|
||||
}
|
||||
}
|
||||
|
||||
mAndrolib.decodeRawFiles(mApkFile, outDir);
|
||||
mAndrolib.decodeRawFiles(mApkFile, outDir, mDecodeAssets);
|
||||
mAndrolib.decodeUnknownFiles(mApkFile, outDir, mResTable);
|
||||
mUncompressedFiles = new ArrayList<String>();
|
||||
mAndrolib.recordUncompressedFiles(mApkFile, mUncompressedFiles);
|
||||
@ -190,6 +190,13 @@ public class ApkDecoder {
|
||||
mDecodeResources = mode;
|
||||
}
|
||||
|
||||
public void setDecodeAssets(short mode) throws AndrolibException {
|
||||
if (mode != DECODE_ASSETS_NONE && mode != DECODE_ASSETS_FULL) {
|
||||
throw new AndrolibException("Invalid decode asset mode");
|
||||
}
|
||||
mDecodeAssets = mode;
|
||||
}
|
||||
|
||||
public void setAnalysisMode(boolean mode, boolean pass) throws AndrolibException{
|
||||
mAnalysisMode = mode;
|
||||
|
||||
@ -299,6 +306,9 @@ public class ApkDecoder {
|
||||
public final static short DECODE_RESOURCES_NONE = 0x0100;
|
||||
public final static short DECODE_RESOURCES_FULL = 0x0101;
|
||||
|
||||
public final static short DECODE_ASSETS_NONE = 0x0000;
|
||||
public final static short DECODE_ASSETS_FULL = 0x0001;
|
||||
|
||||
private File getOutDir() throws AndrolibException {
|
||||
if (mOutDir == null) {
|
||||
throw new AndrolibException("Out dir not set");
|
||||
@ -407,6 +417,7 @@ public class ApkDecoder {
|
||||
private ResTable mResTable;
|
||||
private short mDecodeSources = DECODE_SOURCES_SMALI;
|
||||
private short mDecodeResources = DECODE_RESOURCES_FULL;
|
||||
private short mDecodeAssets = DECODE_ASSETS_FULL;
|
||||
private boolean mForceDelete = false;
|
||||
private boolean mKeepBrokenResources = false;
|
||||
private boolean mBakDeb = true;
|
||||
|
@ -0,0 +1,90 @@
|
||||
/**
|
||||
* Copyright (C) 2017 Ryszard Wiśniewski <brut.alll@gmail.com>
|
||||
* Copyright (C) 2017 Connor Tumbleson <connor.tumbleson@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package brut.androlib;
|
||||
|
||||
import brut.directory.ExtFile;
|
||||
import brut.common.BrutException;
|
||||
import brut.util.OS;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.junit.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class SkipAssetTest {
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass() throws Exception {
|
||||
TestUtils.cleanFrameworkFile();
|
||||
sTmpDir = new ExtFile(OS.createTempDirectory());
|
||||
TestUtils.copyResourceDir(SkipAssetTest.class, "brut/apktool/issue1605/", sTmpDir);
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void afterClass() throws BrutException {
|
||||
OS.rmdir(sTmpDir);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkIfEnablingSkipAssetWorks() throws BrutException, IOException {
|
||||
String apk = "issue1605.apk";
|
||||
|
||||
// decode issue1605.apk
|
||||
ApkDecoder apkDecoder = new ApkDecoder(new File(sTmpDir + File.separator + apk));
|
||||
sTestOrigDir = new ExtFile(sTmpDir + File.separator + apk + ".out");
|
||||
|
||||
apkDecoder.setOutDir(sTestOrigDir);
|
||||
apkDecoder.setDecodeAssets(ApkDecoder.DECODE_ASSETS_NONE);
|
||||
apkDecoder.setForceDelete(true);
|
||||
apkDecoder.decode();
|
||||
|
||||
checkFileDoesNotExist("assets" + File.separator + "kotlin.kotlin_builtins");
|
||||
checkFileDoesNotExist("assets" + File.separator + "ranges" + File.separator + "ranges.kotlin_builtins");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkControl() throws BrutException, IOException {
|
||||
String apk = "issue1605.apk";
|
||||
|
||||
// decode issue1605.apk
|
||||
ApkDecoder apkDecoder = new ApkDecoder(new File(sTmpDir + File.separator + apk));
|
||||
sTestOrigDir = new ExtFile(sTmpDir + File.separator + apk + ".out");
|
||||
|
||||
apkDecoder.setOutDir(sTestOrigDir);
|
||||
apkDecoder.setDecodeAssets(ApkDecoder.DECODE_ASSETS_FULL);
|
||||
apkDecoder.setForceDelete(true);
|
||||
apkDecoder.decode();
|
||||
|
||||
checkFileDoesExist("assets" + File.separator + "kotlin.kotlin_builtins");
|
||||
checkFileDoesExist("assets" + File.separator + "ranges" + File.separator + "ranges.kotlin_builtins");
|
||||
}
|
||||
|
||||
private void checkFileDoesNotExist(String path) throws BrutException {
|
||||
File f = new File(sTestOrigDir, path);
|
||||
|
||||
assertFalse(f.isFile());
|
||||
}
|
||||
|
||||
private void checkFileDoesExist(String path) throws BrutException {
|
||||
File f = new File(sTestOrigDir, path);
|
||||
|
||||
assertTrue(f.isFile());
|
||||
}
|
||||
|
||||
private static ExtFile sTmpDir;
|
||||
private static ExtFile sTestOrigDir;
|
||||
}
|
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user