ApkDecoder +hasSources() +hasResources().

This commit is contained in:
Ryszard Wiśniewski 2010-06-12 17:11:00 +02:00
parent 80c9806214
commit b15179c8bc

View File

@ -21,7 +21,6 @@ import brut.androlib.res.data.ResPackage;
import brut.androlib.res.data.ResTable; import brut.androlib.res.data.ResTable;
import brut.androlib.res.util.ExtFile; import brut.androlib.res.util.ExtFile;
import brut.common.BrutException; import brut.common.BrutException;
import brut.directory.Directory;
import brut.directory.DirectoryException; import brut.directory.DirectoryException;
import brut.util.OS; import brut.util.OS;
import java.io.File; import java.io.File;
@ -71,14 +70,7 @@ public class ApkDecoder {
} }
outDir.mkdirs(); outDir.mkdirs();
Directory apk = null; if (hasSources()) {
try {
apk = mApkFile.getDirectory();
} catch (DirectoryException ex) {
throw new AndrolibException(ex);
}
if (apk.containsFile("classes.dex")) {
switch (mDecodeSources) { switch (mDecodeSources) {
case DECODE_SOURCES_NONE: case DECODE_SOURCES_NONE:
mAndrolib.decodeSourcesRaw(mApkFile, outDir, mDebug); mAndrolib.decodeSourcesRaw(mApkFile, outDir, mDebug);
@ -91,7 +83,7 @@ public class ApkDecoder {
break; break;
} }
} }
if (apk.containsFile("resources.arsc")) { if (hasResources()) {
switch (mDecodeResources) { switch (mDecodeResources) {
case DECODE_RESOURCES_NONE: case DECODE_RESOURCES_NONE:
mAndrolib.decodeResourcesRaw(mApkFile, outDir); mAndrolib.decodeResourcesRaw(mApkFile, outDir);
@ -138,12 +130,31 @@ public class ApkDecoder {
public ResTable getResTable() throws AndrolibException { public ResTable getResTable() throws AndrolibException {
if (mResTable == null) { if (mResTable == null) {
if (! hasResources()) {
throw new AndrolibException(
"Apk doesn't containt resources.arsc file");
}
mResTable = mAndrolib.getResTable(mApkFile); mResTable = mAndrolib.getResTable(mApkFile);
mResTable.setFrameTag(mFrameTag); mResTable.setFrameTag(mFrameTag);
} }
return mResTable; return mResTable;
} }
public boolean hasSources() throws AndrolibException {
try {
return mApkFile.getDirectory().containsFile("classes.dex");
} catch (DirectoryException ex) {
throw new AndrolibException(ex);
}
}
public boolean hasResources() throws AndrolibException {
try {
return mApkFile.getDirectory().containsFile("resources.arsc");
} catch (DirectoryException ex) {
throw new AndrolibException(ex);
}
}
public final static short DECODE_SOURCES_NONE = 0x0000; public final static short DECODE_SOURCES_NONE = 0x0000;
public final static short DECODE_SOURCES_SMALI = 0x0001; public final static short DECODE_SOURCES_SMALI = 0x0001;