disable entry group mapping when not necessary

This commit is contained in:
REAndroid 2023-04-28 11:57:47 +02:00
parent fd0ef31cb3
commit 6fce5ad5ed
5 changed files with 145 additions and 97 deletions

View File

@ -1,4 +1,4 @@
/*
/*
* Copyright (C) 2022 github.com/REAndroid
*
* Licensed under the Apache License, Version 2.0 (the "License");
@ -38,8 +38,9 @@ public class ApkBundle {
if(moduleList.size()==0){
throw new FileNotFoundException("Nothing to merge, empty modules");
}
ApkModule result=new ApkModule(generateMergedModuleName(), new APKArchive());
ApkModule result = new ApkModule(generateMergedModuleName(), new APKArchive());
result.setAPKLogger(apkLogger);
result.setDisableEntryGroupMap(true);
result.setLoadDefaultFramework(false);
mergeStringPools(result);
@ -157,15 +158,16 @@ public class ApkBundle {
logMessage("Found apk files: "+apkList.size());
for(File file:apkList){
logVerbose("Loading: "+file.getName());
String name=ApkUtil.toModuleName(file);
ApkModule module=ApkModule.loadApkFile(file, name);
String name = ApkUtil.toModuleName(file);
ApkModule module = ApkModule.loadApkFile(file, name);
module.setAPKLogger(apkLogger);
addModule(module);
}
}
public void addModule(ApkModule apkModule){
apkModule.setLoadDefaultFramework(false);
String name=apkModule.getModuleName();
apkModule.setDisableEntryGroupMap(true);
String name = apkModule.getModuleName();
mModulesMap.remove(name);
mModulesMap.put(name, apkModule);
}

View File

@ -1,4 +1,4 @@
/*
/*
* Copyright (C) 2022 github.com/REAndroid
*
* Licensed under the Apache License, Version 2.0 (the "License");
@ -57,6 +57,8 @@ public class ApkModule implements ApkFile {
private Decoder mDecoder;
private ApkType mApkType;
private ApkSignatureBlock apkSignatureBlock;
private boolean disableEntryGroupMap;
public ApkModule(String moduleName, APKArchive apkArchive){
this.moduleName=moduleName;
this.apkArchive=apkArchive;
@ -64,6 +66,16 @@ public class ApkModule implements ApkFile {
this.mUncompressedFiles.addPath(apkArchive);
}
public boolean isDisableEntryGroupMap() {
return disableEntryGroupMap;
}
public void setDisableEntryGroupMap(boolean disable) {
this.disableEntryGroupMap = disable;
TableBlock tableBlock = this.mTableBlock;
if(tableBlock != null){
tableBlock.setDisableEntryGroupMap(disable);
}
}
public ApkSignatureBlock getApkSignatureBlock() {
return apkSignatureBlock;
}
@ -525,6 +537,7 @@ public class ApkModule implements ApkFile {
new BlockInputSource<>(TableBlock.FILE_NAME, tableBlock);
archive.add(source);
mTableBlock = tableBlock;
tableBlock.setDisableEntryGroupMap(isDisableEntryGroupMap());
}
@Override
public AndroidManifestBlock getAndroidManifestBlock() {
@ -563,6 +576,7 @@ public class ApkModule implements ApkFile {
}
try {
mTableBlock = loadTableBlock();
mTableBlock.setDisableEntryGroupMap(isDisableEntryGroupMap());
if(initFramework && loadDefaultFramework){
Integer version = getAndroidFrameworkVersion();
initializeAndroidFramework(mTableBlock, version);

View File

@ -1,4 +1,4 @@
/*
/*
* Copyright (C) 2022 github.com/REAndroid
*
* Licensed under the Apache License, Version 2.0 (the "License");
@ -18,6 +18,7 @@ package com.reandroid.arsc.array;
import com.reandroid.arsc.base.Block;
import com.reandroid.arsc.base.BlockArray;
import com.reandroid.arsc.chunk.PackageBlock;
import com.reandroid.arsc.chunk.TableBlock;
import com.reandroid.arsc.io.BlockLoad;
import com.reandroid.arsc.io.BlockReader;
import com.reandroid.arsc.item.IntegerItem;
@ -84,13 +85,17 @@ public class PackageArray extends BlockArray<PackageBlock>
return getOrCreate(0xff & pkgId);
}
public PackageBlock getOrCreate(int pkgId){
PackageBlock packageBlock=getPackageBlockById(pkgId);
if(packageBlock!=null){
PackageBlock packageBlock = getPackageBlockById(pkgId);
if(packageBlock != null){
return packageBlock;
}
packageBlock=createNext();
packageBlock = createNext();
packageBlock.setId(pkgId);
packageBlock.setName("PACKAGE NAME");
TableBlock tableBlock = getParentInstance(TableBlock.class);
if(tableBlock != null){
packageBlock.setDisableEntryGroupMap(tableBlock.isDisableEntryGroupMap());
}
return packageBlock;
}
public PackageBlock getPackageBlockById(byte pkgId){
@ -126,8 +131,13 @@ public class PackageArray extends BlockArray<PackageBlock>
@Override
public void onBlockLoaded(BlockReader reader, Block sender) throws IOException {
if(sender==mPackageCount){
setChildesCount(mPackageCount.get());
if(sender != mPackageCount){
return;
}
setChildesCount(mPackageCount.get());
TableBlock tableBlock = getParentInstance(TableBlock.class);
if(tableBlock != null){
tableBlock.setDisableEntryGroupMap(tableBlock.isDisableEntryGroupMap());
}
}
@Override

View File

@ -1,48 +1,48 @@
/*
* Copyright (C) 2022 github.com/REAndroid
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* Copyright (C) 2022 github.com/REAndroid
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.reandroid.arsc.chunk;
import com.reandroid.arsc.BuildInfo;
import com.reandroid.arsc.array.LibraryInfoArray;
import com.reandroid.arsc.array.SpecTypePairArray;
import com.reandroid.arsc.base.Block;
import com.reandroid.arsc.container.BlockList;
import com.reandroid.arsc.container.PackageBody;
import com.reandroid.arsc.container.SpecTypePair;
import com.reandroid.arsc.group.EntryGroup;
import com.reandroid.arsc.header.PackageHeader;
import com.reandroid.arsc.list.OverlayableList;
import com.reandroid.arsc.list.StagedAliasList;
import com.reandroid.arsc.pool.SpecStringPool;
import com.reandroid.arsc.pool.TypeStringPool;
import com.reandroid.arsc.value.Entry;
import com.reandroid.arsc.value.LibraryInfo;
import com.reandroid.arsc.value.ResConfig;
import com.reandroid.arsc.value.StagedAliasEntry;
import com.reandroid.json.JSONArray;
import com.reandroid.json.JSONConvert;
import com.reandroid.json.JSONObject;
import com.reandroid.arsc.BuildInfo;
import com.reandroid.arsc.array.LibraryInfoArray;
import com.reandroid.arsc.array.SpecTypePairArray;
import com.reandroid.arsc.base.Block;
import com.reandroid.arsc.container.BlockList;
import com.reandroid.arsc.container.PackageBody;
import com.reandroid.arsc.container.SpecTypePair;
import com.reandroid.arsc.group.EntryGroup;
import com.reandroid.arsc.header.PackageHeader;
import com.reandroid.arsc.list.OverlayableList;
import com.reandroid.arsc.list.StagedAliasList;
import com.reandroid.arsc.pool.SpecStringPool;
import com.reandroid.arsc.pool.TypeStringPool;
import com.reandroid.arsc.value.Entry;
import com.reandroid.arsc.value.LibraryInfo;
import com.reandroid.arsc.value.ResConfig;
import com.reandroid.arsc.value.StagedAliasEntry;
import com.reandroid.json.JSONArray;
import com.reandroid.json.JSONConvert;
import com.reandroid.json.JSONObject;
import java.util.*;
import java.util.*;
public class PackageBlock extends Chunk<PackageHeader>
public class PackageBlock extends Chunk<PackageHeader>
implements ParentChunk,
JSONConvert<JSONObject>,
Comparable<PackageBlock> {
JSONConvert<JSONObject>,
Comparable<PackageBlock> {
private final TypeStringPool mTypeStringPool;
private final SpecStringPool mSpecStringPool;
@ -50,6 +50,7 @@ package com.reandroid.arsc.chunk;
private final PackageBody mBody;
private final Map<Integer, EntryGroup> mEntriesGroup;
private boolean disableEntryGroupMap;
public PackageBlock() {
super(new PackageHeader(), 3);
@ -103,7 +104,7 @@ package com.reandroid.arsc.chunk;
return getHeaderBlock().getTypeIdOffset();
}
public BlockList<UnknownChunk> getUnknownChunkList(){
return mBody.getUnknownChunkList();
return mBody.getUnknownChunkList();
}
public StagedAliasEntry searchByStagedResId(int stagedResId){
@ -142,8 +143,8 @@ package com.reandroid.arsc.chunk;
return getHeaderBlock().getPackageId().get();
}
public void setId(byte id){
setId(0xff & id);
}
setId(0xff & id);
}
public void setId(int id){
getHeaderBlock().getPackageId().set(id);
}
@ -175,7 +176,7 @@ package com.reandroid.arsc.chunk;
return getTableBlock();
}
public PackageBody getPackageBody() {
return mBody;
return mBody;
}
public SpecTypePairArray getSpecTypePairArray(){
return mBody.getSpecTypePairArray();
@ -213,6 +214,13 @@ package com.reandroid.arsc.chunk;
public TypeBlock getTypeBlock(byte typeId, String qualifiers){
return getSpecTypePairArray().getTypeBlock(typeId, qualifiers);
}
public boolean isDisableEntryGroupMap() {
return disableEntryGroupMap;
}
public void setDisableEntryGroupMap(boolean disable) {
this.disableEntryGroupMap = disable;
}
public Map<Integer, EntryGroup> getEntriesGroupMap(){
return mEntriesGroup;
}
@ -240,35 +248,36 @@ package com.reandroid.arsc.chunk;
return null;
}
public void updateEntry(Entry entry){
if(entry ==null|| entry.isNull()){
if(isDisableEntryGroupMap()){
return;
}
updateEntryGroup(entry);
}
public void removeEntryGroup(Entry entry){
if(entry ==null){
if(entry == null || entry.isNull()){
return;
}
int id= entry.getResourceId();
EntryGroup group=getEntriesGroupMap().get(id);
if(group==null){
return;
}
group.remove(entry);
if(group.size()==0){
getEntriesGroupMap().remove(id);
}
}
private void updateEntryGroup(Entry entry){
int resId= entry.getResourceId();
EntryGroup group=getEntriesGroupMap().get(resId);
if(group==null){
group=new EntryGroup(resId);
getEntriesGroupMap().put(resId, group);
int resourceId = entry.getResourceId();
Map<Integer, EntryGroup> map = getEntriesGroupMap();
EntryGroup group = map.get(resourceId);
if(group == null){
group = new EntryGroup(resourceId);
map.put(resourceId, group);
}
group.add(entry);
}
public void removeEntryGroup(Entry entry){
if(entry == null){
return;
}
int resourceId = entry.getResourceId();
Map<Integer, EntryGroup> map = getEntriesGroupMap();
EntryGroup group = map.get(resourceId);
if(group == null){
return;
}
group.remove(entry);
if(group.size() == 0){
map.remove(resourceId);
}
}
public List<Entry> listEntries(byte typeId, int entryId){
List<Entry> results=new ArrayList<>();
for(SpecTypePair pair:listSpecTypePair(typeId)){

View File

@ -1,18 +1,18 @@
/*
* Copyright (C) 2022 github.com/REAndroid
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* Copyright (C) 2022 github.com/REAndroid
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.reandroid.arsc.chunk;
import com.reandroid.arsc.ApkFile;
@ -35,21 +35,34 @@ import java.io.*;
import java.util.*;
import java.util.function.Predicate;
public class TableBlock extends Chunk<TableHeader>
public class TableBlock extends Chunk<TableHeader>
implements MainChunk, JSONConvert<JSONObject>, EntryStore {
private final TableStringPool mTableStringPool;
private final PackageArray mPackageArray;
private final List<TableBlock> mFrameWorks=new ArrayList<>();
private final List<TableBlock> mFrameWorks;
private ApkFile mApkFile;
private ReferenceResolver referenceResolver;
private boolean disableEntryGroupMap;
public TableBlock() {
super(new TableHeader(), 2);
TableHeader header = getHeaderBlock();
this.mTableStringPool=new TableStringPool(true);
this.mPackageArray=new PackageArray(header.getPackageCount());
this.mTableStringPool = new TableStringPool(true);
this.mPackageArray = new PackageArray(header.getPackageCount());
this.mFrameWorks = new ArrayList<>();
addChild(mTableStringPool);
addChild(mPackageArray);
}
public boolean isDisableEntryGroupMap() {
return disableEntryGroupMap;
}
public void setDisableEntryGroupMap(boolean disable) {
this.disableEntryGroupMap = disable;
for(PackageBlock packageBlock : listPackages()){
packageBlock.setDisableEntryGroupMap(disable);
}
}
public List<Entry> resolveReference(int referenceId){
return resolveReference(referenceId, null);
}
@ -83,7 +96,7 @@ import java.util.function.Predicate;
return getPackageArray().pickOne();
}
public PackageBlock pickOne(int packageId){
return getPackageArray().pickOne(packageId);
return getPackageArray().pickOne(packageId);
}
public void sortPackages(){
getPackageArray().sort();