Skip to content

Commit 4fa8e67

Browse files
committed
Fix: Decode apks without resource table #66
1 parent f1e40f7 commit 4fa8e67

File tree

3 files changed

+35
-8
lines changed

3 files changed

+35
-8
lines changed

src/main/java/com/reandroid/apk/ApkModule.java

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -765,6 +765,13 @@ public void setTableBlock(TableBlock tableBlock){
765765
updateExternalFramework();
766766
ensureLoadedManifestLinked();
767767
}
768+
public boolean ensureTableBlock() {
769+
if(!hasTableBlock()) {
770+
setTableBlock(TableBlock.createEmpty());
771+
return true;
772+
}
773+
return false;
774+
}
768775
/**
769776
* Use getAndroidManifest()
770777
* */
@@ -845,8 +852,9 @@ private void ensureLoadedManifestLinked() {
845852
}
846853
if(packageBlock != null) {
847854
manifestBlock.setPackageBlock(packageBlock);
848-
manifestBlock.setApkFile(this);
849855
}
856+
manifestBlock.setApkFile(this);
857+
ensureFrameworkLinked();
850858
}
851859
private void unlinkLoadedManifest() {
852860
AndroidManifestBlock manifestBlock = this.mManifestBlock;
@@ -856,6 +864,24 @@ private void unlinkLoadedManifest() {
856864
manifestBlock.setPackageBlock(null);
857865
manifestBlock.setApkFile(null);
858866
}
867+
private void ensureFrameworkLinked() {
868+
if(mDisableLoadFramework) {
869+
return;
870+
}
871+
TableBlock tableBlock = this.mTableBlock;
872+
if(tableBlock == null ||
873+
tableBlock instanceof FrameworkTable ||
874+
isAndroid(tableBlock)) {
875+
return;
876+
}
877+
Integer preferred = this.preferredFramework;
878+
if(preferred != null || (mManifestBlock != null && !tableBlock.hasFramework())) {
879+
try {
880+
initializeAndroidFramework(tableBlock, preferred);
881+
} catch (IOException ignored) {
882+
}
883+
}
884+
}
859885
private void updateExternalFramework(){
860886
TableBlock tableBlock = mTableBlock;
861887
if(tableBlock == null){

src/main/java/com/reandroid/apk/ApkModuleDecoder.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -229,14 +229,9 @@ void initialize(){
229229
}
230230
private void ensureTableBlock(){
231231
ApkModule apkModule = getApkModule();
232-
if(apkModule.hasTableBlock()){
233-
return;
232+
if(apkModule.ensureTableBlock()){
233+
logMessage("Missing " + TableBlock.FILE_NAME + ", created empty");
234234
}
235-
TableBlock tableBlock = new TableBlock();
236-
tableBlock.pickOrEmptyPackage();
237-
apkModule.setTableBlock(tableBlock);
238-
tableBlock.setNull(true);
239-
logMessage("Missing " + TableBlock.FILE_NAME + ", created empty");
240235
}
241236

242237
public boolean isLogErrors() {

src/main/java/com/reandroid/arsc/chunk/TableBlock.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -843,6 +843,12 @@ public static TableBlock load(InputStream inputStream) throws IOException{
843843
tableBlock.readBytes(inputStream);
844844
return tableBlock;
845845
}
846+
public static TableBlock createEmpty() {
847+
TableBlock tableBlock = new TableBlock();
848+
tableBlock.pickOrEmptyPackage();
849+
tableBlock.setNull(true);
850+
return tableBlock;
851+
}
846852

847853
public static boolean isResTableBlock(InputStream inputStream){
848854
try {

0 commit comments

Comments
 (0)