From 4fa8e676d8a16307c006565ec9e79538e70b519c Mon Sep 17 00:00:00 2001 From: REAndroid Date: Fri, 2 Aug 2024 18:58:49 +0200 Subject: [PATCH] Fix: Decode apks without resource table #66 --- .../java/com/reandroid/apk/ApkModule.java | 28 ++++++++++++++++++- .../com/reandroid/apk/ApkModuleDecoder.java | 9 ++---- .../com/reandroid/arsc/chunk/TableBlock.java | 6 ++++ 3 files changed, 35 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/reandroid/apk/ApkModule.java b/src/main/java/com/reandroid/apk/ApkModule.java index cffd36360..71a4182d6 100644 --- a/src/main/java/com/reandroid/apk/ApkModule.java +++ b/src/main/java/com/reandroid/apk/ApkModule.java @@ -765,6 +765,13 @@ public void setTableBlock(TableBlock tableBlock){ updateExternalFramework(); ensureLoadedManifestLinked(); } + public boolean ensureTableBlock() { + if(!hasTableBlock()) { + setTableBlock(TableBlock.createEmpty()); + return true; + } + return false; + } /** * Use getAndroidManifest() * */ @@ -845,8 +852,9 @@ private void ensureLoadedManifestLinked() { } if(packageBlock != null) { manifestBlock.setPackageBlock(packageBlock); - manifestBlock.setApkFile(this); } + manifestBlock.setApkFile(this); + ensureFrameworkLinked(); } private void unlinkLoadedManifest() { AndroidManifestBlock manifestBlock = this.mManifestBlock; @@ -856,6 +864,24 @@ private void unlinkLoadedManifest() { manifestBlock.setPackageBlock(null); manifestBlock.setApkFile(null); } + private void ensureFrameworkLinked() { + if(mDisableLoadFramework) { + return; + } + TableBlock tableBlock = this.mTableBlock; + if(tableBlock == null || + tableBlock instanceof FrameworkTable || + isAndroid(tableBlock)) { + return; + } + Integer preferred = this.preferredFramework; + if(preferred != null || (mManifestBlock != null && !tableBlock.hasFramework())) { + try { + initializeAndroidFramework(tableBlock, preferred); + } catch (IOException ignored) { + } + } + } private void updateExternalFramework(){ TableBlock tableBlock = mTableBlock; if(tableBlock == null){ diff --git a/src/main/java/com/reandroid/apk/ApkModuleDecoder.java b/src/main/java/com/reandroid/apk/ApkModuleDecoder.java index bd69be161..d980dc132 100644 --- a/src/main/java/com/reandroid/apk/ApkModuleDecoder.java +++ b/src/main/java/com/reandroid/apk/ApkModuleDecoder.java @@ -229,14 +229,9 @@ void initialize(){ } private void ensureTableBlock(){ ApkModule apkModule = getApkModule(); - if(apkModule.hasTableBlock()){ - return; + if(apkModule.ensureTableBlock()){ + logMessage("Missing " + TableBlock.FILE_NAME + ", created empty"); } - TableBlock tableBlock = new TableBlock(); - tableBlock.pickOrEmptyPackage(); - apkModule.setTableBlock(tableBlock); - tableBlock.setNull(true); - logMessage("Missing " + TableBlock.FILE_NAME + ", created empty"); } public boolean isLogErrors() { diff --git a/src/main/java/com/reandroid/arsc/chunk/TableBlock.java b/src/main/java/com/reandroid/arsc/chunk/TableBlock.java index fbd9020f6..9741c2fc1 100755 --- a/src/main/java/com/reandroid/arsc/chunk/TableBlock.java +++ b/src/main/java/com/reandroid/arsc/chunk/TableBlock.java @@ -843,6 +843,12 @@ public static TableBlock load(InputStream inputStream) throws IOException{ tableBlock.readBytes(inputStream); return tableBlock; } + public static TableBlock createEmpty() { + TableBlock tableBlock = new TableBlock(); + tableBlock.pickOrEmptyPackage(); + tableBlock.setNull(true); + return tableBlock; + } public static boolean isResTableBlock(InputStream inputStream){ try {