handles manifests with missing named attributes.

- fixes #512
This commit is contained in:
Connor Tumbleson 2014-06-18 10:59:54 -05:00
parent a66e150fc1
commit e126a51b4b
3 changed files with 48 additions and 2 deletions

View File

@ -40,6 +40,7 @@ v2.0.0 (TBA)
-Fixed (issue #626) - Fixed handling strange characters with unknown files.
-Fixed (issue #630) - Fixed handling renamed manifests with ("com.lge")
-Fixed (issue #409) - Fixed array items incorrectly typed.
-Fixed (issue #512) - Fixed AndroidManifest missing attributes.
-Fixed issue with non-URI standard characters in apk name (Thanks rover12421)
-Added output to list Apktool version to help debugging.
-Updated known bytes for configurations to 38 (from addition of layout direction)

View File

@ -282,7 +282,22 @@ public class AXmlResourceParser implements XmlResourceParser {
if (namespace == -1) {
return "";
}
return m_strings.getString(namespace);
// hacky: if the attribute names are proguarded, then so are the namespace
// I don't know where these are located yet in the file, but it is always
// this.android_ns in testing, so we will default to that for now.
// @todo figure out where proguarded namespaces are stored.
String value = m_strings.getString(namespace);
if (value.length() == 0) {
int offsetName = getAttributeOffset(index);
int name = m_attributes[offsetName + ATTRIBUTE_IX_NAME];
if (m_strings.getString(name).length() == 0) {
value = android_ns;
}
}
return value;
}
@Override
@ -303,7 +318,21 @@ public class AXmlResourceParser implements XmlResourceParser {
if (name == -1) {
return "";
}
return m_strings.getString(name);
String value = m_strings.getString(name);
// some attributes will return "", we must rely on the resource_id and refer to the frameworks
// to match the resource id to the name. ex: 0x101021C = versionName
if (value.length() != 0) {
return value;
} else {
try {
value = mAttrDecoder.decodeManifestAttr(getAttributeNameResource(index));
} catch (AndrolibException e) {
value = "";
}
return value;
}
}
@Override
@ -941,6 +970,7 @@ public class AXmlResourceParser implements XmlResourceParser {
private StringBlock m_strings;
private int[] m_resourceIDs;
private NamespaceStack m_namespaces = new NamespaceStack();
private String android_ns = "http://schemas.android.com/apk/res/android";
private boolean m_decreaseDepth;
private int m_event;
private int m_lineNumber;

View File

@ -18,6 +18,7 @@ package brut.androlib.res.decoder;
import brut.androlib.AndrolibException;
import brut.androlib.res.data.ResPackage;
import brut.androlib.res.data.ResResSpec;
import brut.androlib.res.data.value.ResAttr;
import brut.androlib.res.data.value.ResScalarValue;
@ -40,6 +41,20 @@ public class ResAttrDecoder {
return decoded != null ? decoded : resValue.encodeAsResXmlAttr();
}
public String decodeManifestAttr(int attrResId)
throws AndrolibException {
if (attrResId != 0) {
ResResSpec resResSpec = getCurrentPackage().getResTable().getResSpec(attrResId);
if (resResSpec != null) {
return resResSpec.getName();
}
}
return null;
}
public ResPackage getCurrentPackage() throws AndrolibException {
if (mCurrentPackage == null) {
throw new AndrolibException("Current package not set");