Skip to content

Commit

Permalink
Fix: Decode apks without resource table #66
Browse files Browse the repository at this point in the history
  • Loading branch information
REAndroid committed Aug 2, 2024
1 parent f1e40f7 commit 4fa8e67
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 8 deletions.
28 changes: 27 additions & 1 deletion src/main/java/com/reandroid/apk/ApkModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -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()
* */
Expand Down Expand Up @@ -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;
Expand All @@ -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){
Expand Down
9 changes: 2 additions & 7 deletions src/main/java/com/reandroid/apk/ApkModuleDecoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/com/reandroid/arsc/chunk/TableBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 4fa8e67

Please sign in to comment.