mirror of
https://github.com/revanced/Apktool.git
synced 2025-01-21 01:07:34 +01:00
Remove previous android:debuggable value to allow changing
- adds unit test - normalizeNewlines moved to TestUtils
This commit is contained in:
parent
032a3e5e25
commit
87315af36e
@ -409,6 +409,10 @@ public class Androlib {
|
|||||||
newFiles(APK_RESOURCES_FILENAMES, apkDir))) {
|
newFiles(APK_RESOURCES_FILENAMES, apkDir))) {
|
||||||
LOGGER.info("Building resources...");
|
LOGGER.info("Building resources...");
|
||||||
|
|
||||||
|
if (apkOptions.debugMode) {
|
||||||
|
ResXmlPatcher.removeApplicationDebugTag(new File(appDir, "AndroidManifest.xml"));
|
||||||
|
}
|
||||||
|
|
||||||
File apkFile = File.createTempFile("APKTOOL", null);
|
File apkFile = File.createTempFile("APKTOOL", null);
|
||||||
apkFile.delete();
|
apkFile.delete();
|
||||||
|
|
||||||
@ -476,7 +480,6 @@ public class Androlib {
|
|||||||
|
|
||||||
Directory tmpDir = new ExtFile(apkFile).getDirectory();
|
Directory tmpDir = new ExtFile(apkFile).getDirectory();
|
||||||
tmpDir.copyToDir(apkDir, APK_MANIFEST_FILENAMES);
|
tmpDir.copyToDir(apkDir, APK_MANIFEST_FILENAMES);
|
||||||
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} catch (IOException | DirectoryException ex) {
|
} catch (IOException | DirectoryException ex) {
|
||||||
|
@ -40,6 +40,35 @@ import java.io.IOException;
|
|||||||
* @author Connor Tumbleson <connor.tumbleson@gmail.com>
|
* @author Connor Tumbleson <connor.tumbleson@gmail.com>
|
||||||
*/
|
*/
|
||||||
public final class ResXmlPatcher {
|
public final class ResXmlPatcher {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes "debug" tag from file
|
||||||
|
*
|
||||||
|
* @param file AndroidManifest file
|
||||||
|
* @throws AndrolibException
|
||||||
|
*/
|
||||||
|
public static void removeApplicationDebugTag(File file) throws AndrolibException {
|
||||||
|
if (file.exists()) {
|
||||||
|
try {
|
||||||
|
Document doc = loadDocument(file);
|
||||||
|
Node application = doc.getElementsByTagName("application").item(0);
|
||||||
|
|
||||||
|
// load attr
|
||||||
|
NamedNodeMap attr = application.getAttributes();
|
||||||
|
Node debugAttr = attr.getNamedItem("android:debuggable");
|
||||||
|
|
||||||
|
// remove application:debuggable
|
||||||
|
if (debugAttr != null) {
|
||||||
|
attr.removeNamedItem("android:debuggable");
|
||||||
|
}
|
||||||
|
|
||||||
|
saveDocument(file, doc);
|
||||||
|
|
||||||
|
} catch (SAXException | ParserConfigurationException | IOException | TransformerException ignored) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Any @string reference in a <provider> value in AndroidManifest.xml will break on
|
* Any @string reference in a <provider> value in AndroidManifest.xml will break on
|
||||||
* build, thus preventing the application from installing. This is from a bug/error
|
* build, thus preventing the application from installing. This is from a bug/error
|
||||||
|
@ -0,0 +1,90 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2014 Ryszard Wiśniewski <brut.alll@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.androlib.res.util.ExtFile;
|
||||||
|
import brut.common.BrutException;
|
||||||
|
import brut.util.OS;
|
||||||
|
import org.junit.AfterClass;
|
||||||
|
import org.junit.BeforeClass;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Connor Tumbleson <connor.tumbleson@gmail.com>
|
||||||
|
*/
|
||||||
|
public class DebugTagRetainedTest {
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public static void beforeClass() throws Exception, BrutException {
|
||||||
|
TestUtils.cleanFrameworkFile();
|
||||||
|
sTmpDir = new ExtFile(OS.createTempDirectory());
|
||||||
|
sTestOrigDir = new ExtFile(sTmpDir, "issue1235-orig");
|
||||||
|
sTestNewDir = new ExtFile(sTmpDir, "issue1235-new");
|
||||||
|
LOGGER.info("Unpacking issue1235...");
|
||||||
|
TestUtils.copyResourceDir(BuildAndDecodeJarTest.class, "brut/apktool/issue1235/", sTestOrigDir);
|
||||||
|
|
||||||
|
LOGGER.info("Building issue1235.apk...");
|
||||||
|
ApkOptions apkOptions = new ApkOptions();
|
||||||
|
apkOptions.debugMode = true;
|
||||||
|
|
||||||
|
File testApk = new File(sTmpDir, "issue1235.apk");
|
||||||
|
new Androlib(apkOptions).build(sTestOrigDir, testApk);
|
||||||
|
|
||||||
|
LOGGER.info("Decoding issue1235.apk...");
|
||||||
|
ApkDecoder apkDecoder = new ApkDecoder(testApk);
|
||||||
|
apkDecoder.setOutDir(sTestNewDir);
|
||||||
|
apkDecoder.decode();
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterClass
|
||||||
|
public static void afterClass() throws BrutException {
|
||||||
|
OS.rmdir(sTmpDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void buildAndDecodeTest() throws BrutException {
|
||||||
|
assertTrue(sTestNewDir.isDirectory());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void DebugIsTruePriorToBeingFalseTest() throws BrutException, IOException {
|
||||||
|
String apk = "issue1235-new";
|
||||||
|
|
||||||
|
String expected = TestUtils.replaceNewlines("<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n" +
|
||||||
|
"<manifest xmlns:android=\"http://schemas.android.com/apk/res/android\" package=\"com.ibotpeaches.issue1235\" platformBuildVersionCode=\"23\" platformBuildVersionName=\"6.0-2438415\">\n" +
|
||||||
|
" <application android:debuggable=\"true\"/>" +
|
||||||
|
"</manifest>");
|
||||||
|
|
||||||
|
byte[] encoded = Files.readAllBytes(Paths.get(sTmpDir + File.separator + apk + File.separator + "AndroidManifest.xml"));
|
||||||
|
String obtained = TestUtils.replaceNewlines(new String(encoded));
|
||||||
|
assertEquals(expected, obtained);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ExtFile sTmpDir;
|
||||||
|
private static ExtFile sTestOrigDir;
|
||||||
|
private static ExtFile sTestNewDir;
|
||||||
|
|
||||||
|
private final static Logger LOGGER = Logger.getLogger(BuildAndDecodeJarTest.class.getName());
|
||||||
|
}
|
@ -66,7 +66,7 @@ public class ProviderAttributeTest {
|
|||||||
apkDecoder.setOutDir(new File(sTmpDir + File.separator + apk + ".out.two"));
|
apkDecoder.setOutDir(new File(sTmpDir + File.separator + apk + ".out.two"));
|
||||||
apkDecoder.decode();
|
apkDecoder.decode();
|
||||||
|
|
||||||
String expected = replaceNewlines("<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n" +
|
String expected = TestUtils.replaceNewlines("<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n" +
|
||||||
"<manifest xmlns:android=\"http://schemas.android.com/apk/res/android\" package=\"com.ibotpeaches.issue636\" platformBuildVersionCode=\"23\" platformBuildVersionName=\"6.0-2438415\">\n" +
|
"<manifest xmlns:android=\"http://schemas.android.com/apk/res/android\" package=\"com.ibotpeaches.issue636\" platformBuildVersionCode=\"23\" platformBuildVersionName=\"6.0-2438415\">\n" +
|
||||||
" <application android:allowBackup=\"true\" android:debuggable=\"true\" android:icon=\"@mipmap/ic_launcher\" android:label=\"@string/app_name\" android:theme=\"@style/AppTheme\">\n" +
|
" <application android:allowBackup=\"true\" android:debuggable=\"true\" android:icon=\"@mipmap/ic_launcher\" android:label=\"@string/app_name\" android:theme=\"@style/AppTheme\">\n" +
|
||||||
" <provider android:authorities=\"com.ibotpeaches.issue636.Provider\" android:exported=\"false\" android:grantUriPermissions=\"true\" android:label=\"@string/app_name\" android:multiprocess=\"false\" android:name=\"com.ibotpeaches.issue636.Provider\"/>\n" +
|
" <provider android:authorities=\"com.ibotpeaches.issue636.Provider\" android:exported=\"false\" android:grantUriPermissions=\"true\" android:label=\"@string/app_name\" android:multiprocess=\"false\" android:name=\"com.ibotpeaches.issue636.Provider\"/>\n" +
|
||||||
@ -76,7 +76,7 @@ public class ProviderAttributeTest {
|
|||||||
|
|
||||||
|
|
||||||
byte[] encoded = Files.readAllBytes(Paths.get(sTmpDir + File.separator + apk + ".out.two" + File.separator + "AndroidManifest.xml"));
|
byte[] encoded = Files.readAllBytes(Paths.get(sTmpDir + File.separator + apk + ".out.two" + File.separator + "AndroidManifest.xml"));
|
||||||
String obtained = replaceNewlines(new String(encoded));
|
String obtained = TestUtils.replaceNewlines(new String(encoded));
|
||||||
assertEquals(expected, obtained);
|
assertEquals(expected, obtained);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,9 +84,5 @@ public class ProviderAttributeTest {
|
|||||||
return Files.exists(Paths.get(sTmpDir.getAbsolutePath() + File.separator + filepath));
|
return Files.exists(Paths.get(sTmpDir.getAbsolutePath() + File.separator + filepath));
|
||||||
}
|
}
|
||||||
|
|
||||||
private String replaceNewlines(String value) {
|
|
||||||
return value.replace("\n", "").replace("\r", "");
|
|
||||||
}
|
|
||||||
|
|
||||||
private static ExtFile sTmpDir;
|
private static ExtFile sTmpDir;
|
||||||
}
|
}
|
||||||
|
@ -159,4 +159,8 @@ public abstract class TestUtils {
|
|||||||
return controlType.equals(testType) && control.getAttribute("name").equals(test.getAttribute("name"));
|
return controlType.equals(testType) && control.getAttribute("name").equals(test.getAttribute("name"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String replaceNewlines(String value) {
|
||||||
|
return value.replace("\n", "").replace("\r", "");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,4 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<manifest package="com.ibotpeaches.issue1235" xmlns:android="http://schemas.android.com/apk/res/android" platformBuildVersionCode="20" platformBuildVersionName="4.4W.2-1537038">
|
||||||
|
<application android:debuggable="false"/>
|
||||||
|
</manifest>
|
@ -0,0 +1,12 @@
|
|||||||
|
version: 2.0.0
|
||||||
|
apkFileName: issue1235.apk
|
||||||
|
isFrameworkApk: false
|
||||||
|
usesFramework:
|
||||||
|
ids:
|
||||||
|
- 1
|
||||||
|
packageInfo:
|
||||||
|
forced-package-id: '127'
|
||||||
|
versionInfo:
|
||||||
|
versionCode: '1'
|
||||||
|
versionName: '1.0'
|
||||||
|
compressionType: false
|
@ -0,0 +1,4 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
<string name="hello_world">Hello World</string>
|
||||||
|
</resources>
|
Loading…
x
Reference in New Issue
Block a user