Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I checked a fix for the missing AndroidManifest.xml issue, please pull it into the master repository if you think it's ok #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions apktool-lib/src/main/java/brut/androlib/Androlib.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,22 @@ public void decodeSourcesJava(ExtFile apkFile, File outDir, boolean debug)
new AndrolibJava().decode(apkFile, outDir);
}

public void decodeManifestRaw(ExtFile apkFile, File outDir)
throws AndrolibException {
try {
Directory apk = apkFile.getDirectory();
LOGGER.info("Copying raw manifest...");
apkFile.getDirectory().copyToDir(outDir, APK_MANIFEST_FILENAME);
} catch (DirectoryException ex) {
throw new AndrolibException(ex);
}
}

public void decodeManifestFull(ExtFile apkFile, File outDir)
throws AndrolibException {
mAndRes.decodeManifest(apkFile, outDir);
}

public void decodeResourcesRaw(ExtFile apkFile, File outDir)
throws AndrolibException {
try {
Expand Down Expand Up @@ -436,5 +452,6 @@ private File[] newFiles(String[] names, File dir) {
new String[]{"resources.arsc", "AndroidManifest.xml"};
private final static String[] APP_RESOURCES_FILENAMES =
new String[]{"AndroidManifest.xml", "res"};
private final static String APK_MANIFEST_FILENAME = "AndroidManifest.xml";
private final static String VERSION = "1.3.2";
}
23 changes: 23 additions & 0 deletions apktool-lib/src/main/java/brut/androlib/ApkDecoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public void decode() throws AndrolibException {
break;
}
}

if (hasResources()) {
switch (mDecodeResources) {
case DECODE_RESOURCES_NONE:
Expand All @@ -99,7 +100,21 @@ public void decode() throws AndrolibException {
getResTable());
break;
}
} else {
// if there's no resources.asrc, decode the manifest without looking up
// attribute references
if (hasManifest()) {
switch (mDecodeResources) {
case DECODE_RESOURCES_NONE:
mAndrolib.decodeManifestRaw(mApkFile, outDir);
break;
case DECODE_RESOURCES_FULL:
mAndrolib.decodeManifestFull(mApkFile, outDir);
break;
}
}
}

mAndrolib.decodeRawFiles(mApkFile, outDir);
writeMetaFile();
}
Expand Down Expand Up @@ -159,6 +174,14 @@ public boolean hasSources() throws AndrolibException {
}
}

public boolean hasManifest() throws AndrolibException {
try {
return mApkFile.getDirectory().containsFile("AndroidManifest.xml");
} catch (DirectoryException ex) {
throw new AndrolibException(ex);
}
}

public boolean hasResources() throws AndrolibException {
try {
return mApkFile.getDirectory().containsFile("resources.arsc");
Expand Down
35 changes: 35 additions & 0 deletions apktool-lib/src/main/java/brut/androlib/res/AndrolibResources.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,27 @@ public ResPackage loadFrameworkPkg(ResTable resTable, int id,
return pkg;
}

public void decodeManifest(ExtFile apkFile, File outDir)
throws AndrolibException {

Duo<ResFileDecoder, AXmlResourceParser> duo = getManifestFileDecoder();
ResFileDecoder fileDecoder = duo.m1;

Directory inApk, out;
try {
inApk = apkFile.getDirectory();
out = new FileDirectory(outDir);

LOGGER.info("Decoding AndroidManifest.xml without resources...");
fileDecoder.decode(
inApk, "AndroidManifest.xml", out, "AndroidManifest.xml",
"xml");

} catch (DirectoryException ex) {
throw new AndrolibException(ex);
}
}

public void decode(ResTable resTable, ExtFile apkFile, File outDir)
throws AndrolibException {
Duo<ResFileDecoder, AXmlResourceParser> duo = getResFileDecoder();
Expand All @@ -111,6 +132,7 @@ public void decode(ResTable resTable, ExtFile apkFile, File outDir)
inApk = apkFile.getDirectory();
out = new FileDirectory(outDir);

LOGGER.info("Decoding AndroidManifest.xml with resources...");
fileDecoder.decode(
inApk, "AndroidManifest.xml", out, "AndroidManifest.xml",
"xml");
Expand Down Expand Up @@ -238,6 +260,19 @@ public Duo<ResFileDecoder, AXmlResourceParser> getResFileDecoder() {
new ResFileDecoder(decoders), axmlParser);
}

public Duo<ResFileDecoder, AXmlResourceParser> getManifestFileDecoder() {
ResStreamDecoderContainer decoders =
new ResStreamDecoderContainer();

AXmlResourceParser axmlParser = new AXmlResourceParser();

decoders.setDecoder("xml",
new XmlPullStreamDecoder(axmlParser, getResXmlSerializer()));

return new Duo<ResFileDecoder, AXmlResourceParser>(
new ResFileDecoder(decoders), axmlParser);
}

public ExtMXSerializer getResXmlSerializer() {
ExtMXSerializer serial = new ExtMXSerializer();
serial.setProperty(ExtXmlSerializer.PROPERTY_SERIALIZER_INDENTATION
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,10 @@ public String getAttributeValue(int index) {
valueData
), ex);
}
} else {
if (valueType==TypedValue.TYPE_STRING) {
return m_strings.getString(valueRaw);
}
}

return TypedValue.coerceToString(valueType, valueData);
Expand Down Expand Up @@ -370,7 +374,7 @@ public int getAttributeResourceValue(int index, int defaultValue) {
public String getAttributeValue(String namespace, String attribute) {
int index = findAttribute(namespace, attribute);
if (index == -1) {
return null;
return "";
}
return getAttributeValue(index);
}
Expand Down