Add ability to force decoding of manifest

This commit is contained in:
Ruben Anagua
2017-12-07 11:33:04 +00:00
parent 2b9728e9f3
commit dd81dbfc9c
2 changed files with 36 additions and 8 deletions

View File

@ -104,6 +104,15 @@ public class ApkDecoder {
switch (mDecodeResources) {
case DECODE_RESOURCES_NONE:
mAndrolib.decodeResourcesRaw(mApkFile, outDir);
if (mForceDecodeManifest == FORCE_DECODE_MANIFEST_FULL) {
setTargetSdkVersion();
setAnalysisMode(mAnalysisMode, true);
// done after raw decoding of resources because copyToDir overwrites dest files
if (hasManifest()) {
mAndrolib.decodeManifestWithResources(mApkFile, outDir, getResTable());
}
}
break;
case DECODE_RESOURCES_FULL:
setTargetSdkVersion();
@ -119,14 +128,12 @@ public class ApkDecoder {
// 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,
getResTable());
break;
if (mDecodeResources == DECODE_RESOURCES_FULL
|| mForceDecodeManifest == FORCE_DECODE_MANIFEST_FULL) {
mAndrolib.decodeManifestFull(mApkFile, outDir, getResTable());
}
else {
mAndrolib.decodeManifestRaw(mApkFile, outDir);
}
}
}
@ -190,6 +197,13 @@ public class ApkDecoder {
mDecodeResources = mode;
}
public void setForceDecodeManifest(short mode) throws AndrolibException {
if (mode != FORCE_DECODE_MANIFEST_NONE && mode != FORCE_DECODE_MANIFEST_FULL) {
throw new AndrolibException("Invalid force decode manifest mode");
}
mForceDecodeManifest = mode;
}
public void setDecodeAssets(short mode) throws AndrolibException {
if (mode != DECODE_ASSETS_NONE && mode != DECODE_ASSETS_FULL) {
throw new AndrolibException("Invalid decode asset mode");
@ -306,6 +320,9 @@ public class ApkDecoder {
public final static short DECODE_RESOURCES_NONE = 0x0100;
public final static short DECODE_RESOURCES_FULL = 0x0101;
public final static short FORCE_DECODE_MANIFEST_NONE = 0x0000;
public final static short FORCE_DECODE_MANIFEST_FULL = 0x0001;
public final static short DECODE_ASSETS_NONE = 0x0000;
public final static short DECODE_ASSETS_FULL = 0x0001;
@ -417,6 +434,7 @@ public class ApkDecoder {
private ResTable mResTable;
private short mDecodeSources = DECODE_SOURCES_SMALI;
private short mDecodeResources = DECODE_RESOURCES_FULL;
private short mForceDecodeManifest = FORCE_DECODE_MANIFEST_NONE;
private short mDecodeAssets = DECODE_ASSETS_FULL;
private boolean mForceDelete = false;
private boolean mKeepBrokenResources = false;