Skip to content

Commit

Permalink
Merge branch 'iBotPeaches:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
b4byhuey authored Aug 15, 2023
2 parents 23e9470 + 225c908 commit 57f967d
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -407,28 +407,13 @@ public String getAttributeValue(int index) {
String stringBlockValue = valueRaw == -1 ? null : ResXmlEncoders.escapeXmlChars(mStringBlock.getString(valueRaw));
String resourceMapValue = null;

// Ensure we only track down obfuscated values for reference/attribute type values. Otherwise we might
// Ensure we only track down obfuscated values for reference/attribute type values. Otherwise, we might
// spam lookups against resource table for invalid ids.
if (valueType == TypedValue.TYPE_REFERENCE || valueType == TypedValue.TYPE_DYNAMIC_REFERENCE ||
valueType == TypedValue.TYPE_ATTRIBUTE || valueType == TypedValue.TYPE_DYNAMIC_ATTRIBUTE) {
resourceMapValue = decodeFromResourceId(valueData);
}
String value = stringBlockValue;

if (stringBlockValue != null && resourceMapValue != null) {
int slashPos = stringBlockValue.lastIndexOf("/");
int colonPos = stringBlockValue.lastIndexOf(":");

// Handle a value with a format of "@yyy/xxx", but avoid "@yyy/zzz:xxx"
if (slashPos != -1) {
if (colonPos == -1) {
String type = stringBlockValue.substring(0, slashPos);
value = type + "/" + resourceMapValue;
}
} else if (! stringBlockValue.equals(resourceMapValue)) {
value = resourceMapValue;
}
}
String value = getPreferredString(stringBlockValue, resourceMapValue);

// try to decode from resource table
int attrResId = getAttributeNameResource(index);
Expand Down Expand Up @@ -662,6 +647,26 @@ private int findAttribute(String namespace, String attribute) {
return -1;
}

private static String getPreferredString(String stringBlockValue, String resourceMapValue) {
String value = stringBlockValue;

if (stringBlockValue != null && resourceMapValue != null) {
int slashPos = stringBlockValue.lastIndexOf("/");
int colonPos = stringBlockValue.lastIndexOf(":");

// Handle a value with a format of "@yyy/xxx", but avoid "@yyy/zzz:xxx"
if (slashPos != -1) {
if (colonPos == -1) {
String type = stringBlockValue.substring(0, slashPos);
value = type + "/" + resourceMapValue;
}
} else if (! stringBlockValue.equals(resourceMapValue)) {
value = resourceMapValue;
}
}
return value;
}

private void resetEventInfo() {
mEvent = -1;
mLineNumber = -1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,18 +157,6 @@ public void copyRaw(Directory inDir, Directory outDir, String inFilename,
}
}

public void decodeManifest(Directory inDir, String inFileName,
Directory outDir, String outFileName) throws AndrolibException {
try (
InputStream in = inDir.getFileInput(inFileName);
OutputStream out = outDir.getFileOutput(outFileName)
) {
((XmlPullStreamDecoder) mDecoders.getDecoder("xml")).decodeManifest(in, out);
} catch (DirectoryException | IOException ex) {
throw new AndrolibException(ex);
}
}

private final static Logger LOGGER = Logger.getLogger(ResFileDecoder.class.getName());

private final static String[] RAW_IMAGE_EXTENSIONS = new String[] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,13 @@ public void checkControl() throws BrutException, IOException {
checkFileDoesExist("assets" + File.separator + "ranges" + File.separator + "ranges.kotlin_builtins");
}

private void checkFileDoesNotExist(String path) throws BrutException {
private void checkFileDoesNotExist(String path) {
File f = new File(sTestOrigDir, path);

assertFalse(f.isFile());
}

private void checkFileDoesExist(String path) throws BrutException {
private void checkFileDoesExist(String path) {
File f = new File(sTestOrigDir, path);

assertTrue(f.isFile());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import brut.common.BrutException;
import brut.directory.ExtFile;
import brut.util.OS;
import org.custommonkey.xmlunit.XMLUnit;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
Expand All @@ -34,10 +33,7 @@
import javax.xml.parsers.ParserConfigurationException;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;

import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
import static org.junit.Assert.*;

public class BuildAndDecodeTest extends BaseTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void checkifAndResDecodeRemapsRFolder() throws BrutException, IOException
}

@Test
public void checkifAndResDecodeRemapsRFolderInRawMode() throws BrutException, IOException {
public void checkIfAndResDecodeRemapsRFolderInRawMode() throws BrutException, IOException {

Config config = Config.getDefaultConfig();
config.forceDelete = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/
package brut.androlib.decode;

import brut.androlib.ApkDecoder;
import brut.androlib.BaseTest;
import brut.androlib.Config;
import brut.androlib.TestUtils;
Expand All @@ -32,9 +31,7 @@
import org.junit.BeforeClass;
import org.junit.Test;

import java.io.File;

import static junit.framework.Assert.assertTrue;
import static org.junit.Assert.assertTrue;

public class DecodeArrayTest extends BaseTest {

Expand All @@ -54,7 +51,6 @@ public static void afterClass() throws BrutException {
public void decodeStringArray() throws BrutException {
ExtFile apkFile = new ExtFile(sTmpDir, "issue1994.apk");
ApkInfo apkInfo = new ApkInfo(apkFile);
//ApkDecoder apkDecoder = new ApkDecoder(apkFile);
ResourcesDecoder resourcesDecoder = new ResourcesDecoder(Config.getDefaultConfig(), apkInfo);

resourcesDecoder.loadMainPkg();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,6 @@ public void kotlinFolderExistsTest() {
public void kotlinDecodeTest() throws IOException {
File kotlinActivity = new File(sTestNewDir, "smali/org/example/kotlin/mixed/KotlinActivity.smali");

assertTrue(FileUtils.readFileToString(kotlinActivity).contains("KotlinActivity.kt"));
assertTrue(FileUtils.readFileToString(kotlinActivity, "UTF-8").contains("KotlinActivity.kt"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import java.io.File;
import java.io.IOException;


public class DuplicateDexTest extends BaseTest {

@Before
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ public static void afterClass() throws BrutException {

@Test
public void doctypeTest() throws IOException {

String expected = TestUtils.replaceNewlines("<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<manifest android:versionCode=\"1\" android:versionName=\"1.0\" android:compileSdkVersion=\"23\" android:compileSdkVersionCodename=\"6.0-2438415\" " +
"hardwareAccelerated=\"true\" package=\"com.ibotpeaches.doctype\" platformBuildVersionCode=\"24\" platformBuildVersionName=\"6.0-2456767\" " +
Expand Down

0 comments on commit 57f967d

Please sign in to comment.