From 47015d65f0f884f8156704f267f4cd52442707c8 Mon Sep 17 00:00:00 2001 From: REAndroid Date: Tue, 5 Nov 2024 11:08:33 +0100 Subject: [PATCH] [DEX] Rename to DexLayoutBlock --- .../com/reandroid/dex/header/DexChecksum.java | 8 +-- .../com/reandroid/dex/header/Signature.java | 8 +-- .../dex/ins/InstructionException.java | 8 +-- .../java/com/reandroid/dex/model/DexFile.java | 54 +++++++++---------- .../reandroid/dex/model/DexMergeOptions.java | 14 ++--- .../reandroid/dex/sections/DexContainer.java | 10 ++-- .../{DexLayout.java => DexLayoutBlock.java} | 14 ++--- .../com/reandroid/dex/sections/MapItem.java | 2 +- .../reandroid/dex/sections/MergeOptions.java | 22 ++++---- .../reandroid/dex/sections/SectionList.java | 20 +++---- 10 files changed, 80 insertions(+), 80 deletions(-) rename src/main/java/com/reandroid/dex/sections/{DexLayout.java => DexLayoutBlock.java} (97%) diff --git a/src/main/java/com/reandroid/dex/header/DexChecksum.java b/src/main/java/com/reandroid/dex/header/DexChecksum.java index 316b79e2d..fb596bc50 100644 --- a/src/main/java/com/reandroid/dex/header/DexChecksum.java +++ b/src/main/java/com/reandroid/dex/header/DexChecksum.java @@ -15,7 +15,7 @@ */ package com.reandroid.dex.header; -import com.reandroid.dex.sections.DexLayout; +import com.reandroid.dex.sections.DexLayoutBlock; import com.reandroid.utils.Alder32OutputStream; import com.reandroid.utils.HexUtil; @@ -36,14 +36,14 @@ public void setValue(long checksum){ putInteger(0, (int)checksum); } public boolean update() { - DexLayout dexLayout = getParentInstance(DexLayout.class); - if (dexLayout == null) { + DexLayoutBlock dexLayoutBlock = getParentInstance(DexLayoutBlock.class); + if (dexLayoutBlock == null) { return false; } int previous = getValue(); Alder32OutputStream outputStream = new Alder32OutputStream(); try { - dexLayout.writeBytes(outputStream); + dexLayoutBlock.writeBytes(outputStream); } catch (IOException exception) { // will not reach here throw new RuntimeException(exception); diff --git a/src/main/java/com/reandroid/dex/header/Signature.java b/src/main/java/com/reandroid/dex/header/Signature.java index 6ef36dfe6..f48eaa872 100644 --- a/src/main/java/com/reandroid/dex/header/Signature.java +++ b/src/main/java/com/reandroid/dex/header/Signature.java @@ -15,7 +15,7 @@ */ package com.reandroid.dex.header; -import com.reandroid.dex.sections.DexLayout; +import com.reandroid.dex.sections.DexLayoutBlock; import com.reandroid.utils.HexUtil; import com.reandroid.utils.Sha1OutputStream; @@ -29,13 +29,13 @@ public Signature(){ } public void update() { - DexLayout dexLayout = getParentInstance(DexLayout.class); - if (dexLayout == null) { + DexLayoutBlock dexLayoutBlock = getParentInstance(DexLayoutBlock.class); + if (dexLayoutBlock == null) { return; } Sha1OutputStream outputStream = new Sha1OutputStream(); try { - dexLayout.writeBytes(outputStream); + dexLayoutBlock.writeBytes(outputStream); } catch (IOException exception) { // will not reach here throw new RuntimeException(exception); diff --git a/src/main/java/com/reandroid/dex/ins/InstructionException.java b/src/main/java/com/reandroid/dex/ins/InstructionException.java index a9a754085..bf401c025 100644 --- a/src/main/java/com/reandroid/dex/ins/InstructionException.java +++ b/src/main/java/com/reandroid/dex/ins/InstructionException.java @@ -20,7 +20,7 @@ import com.reandroid.dex.data.CodeItem; import com.reandroid.dex.data.InstructionList; import com.reandroid.dex.data.MethodDef; -import com.reandroid.dex.sections.DexLayout; +import com.reandroid.dex.sections.DexLayoutBlock; public class InstructionException extends DexException { @@ -71,11 +71,11 @@ private boolean appendMethod(StringBuilder builder){ return true; } private void appendDex(StringBuilder builder){ - DexLayout dexLayout = getIns().getParentInstance(DexLayout.class); - if(dexLayout == null){ + DexLayoutBlock dexLayoutBlock = getIns().getParentInstance(DexLayoutBlock.class); + if(dexLayoutBlock == null){ return; } - String simpleName = dexLayout.getSimpleName(); + String simpleName = dexLayoutBlock.getSimpleName(); if(simpleName == null){ return; } diff --git a/src/main/java/com/reandroid/dex/model/DexFile.java b/src/main/java/com/reandroid/dex/model/DexFile.java index 2e00cd181..ca1d85fdb 100644 --- a/src/main/java/com/reandroid/dex/model/DexFile.java +++ b/src/main/java/com/reandroid/dex/model/DexFile.java @@ -47,13 +47,13 @@ public class DexFile implements DexClassRepository, Closeable, Iterable, FullRefresh { - private final DexLayout dexLayout; + private final DexLayoutBlock dexLayoutBlock; private DexDirectory dexDirectory; private boolean closed; - public DexFile(DexLayout dexLayout){ - this.dexLayout = dexLayout; - dexLayout.setTag(this); + public DexFile(DexLayoutBlock dexLayoutBlock){ + this.dexLayoutBlock = dexLayoutBlock; + dexLayoutBlock.setTag(this); } public int getVersion(){ @@ -100,9 +100,9 @@ public DexDirectory getDexDirectory() { } public void setDexDirectory(DexDirectory dexDirectory) { this.dexDirectory = dexDirectory; - DexLayout dexLayout = getDexLayout(); - dexLayout.setTag(this); - dexLayout.setSimpleName(getSimpleName()); + DexLayoutBlock dexLayoutBlock = getDexLayout(); + dexLayoutBlock.setTag(this); + dexLayoutBlock.setSimpleName(getSimpleName()); } public Iterator getSubTypes(TypeKey typeKey){ @@ -313,8 +313,8 @@ public Section getSection(SectionType sectionTy public void refresh() { getDexLayout().refresh(); } - public DexLayout getDexLayout() { - return dexLayout; + public DexLayoutBlock getDexLayout() { + return dexLayoutBlock; } public boolean isEmpty(){ @@ -353,7 +353,7 @@ public void parseSmaliDirectory(File dir) throws IOException { FileIterator iterator = new FileIterator(dir, FileIterator.getExtensionFilter(".smali")); FileByteSource byteSource = new FileByteSource(); SmaliReader reader = new SmaliReader(byteSource); - DexLayout layout = getDexLayout(); + DexLayoutBlock layout = getDexLayout(); while (iterator.hasNext()) { reader.reset(); File file = iterator.next(); @@ -501,25 +501,25 @@ public static DexFile read(File file) throws IOException { return read(new BlockReader(file)); } public static DexFile read(BlockReader reader) throws IOException { - DexLayout dexLayout = new DexLayout(); - dexLayout.readBytes(reader); + DexLayoutBlock dexLayoutBlock = new DexLayoutBlock(); + dexLayoutBlock.readBytes(reader); reader.close(); - return new DexFile(dexLayout); + return new DexFile(dexLayoutBlock); } public static DexFile readStrings(BlockReader reader) throws IOException { - DexLayout dexLayout = new DexLayout(); - dexLayout.readStrings(reader); - return new DexFile(dexLayout); + DexLayoutBlock dexLayoutBlock = new DexLayoutBlock(); + dexLayoutBlock.readStrings(reader); + return new DexFile(dexLayoutBlock); } public static DexFile readClassIds(BlockReader reader) throws IOException { - DexLayout dexLayout = new DexLayout(); - dexLayout.readClassIds(reader); - return new DexFile(dexLayout); + DexLayoutBlock dexLayoutBlock = new DexLayoutBlock(); + dexLayoutBlock.readClassIds(reader); + return new DexFile(dexLayoutBlock); } public static DexFile readSections(BlockReader reader, Predicate> filter) throws IOException { - DexLayout dexLayout = new DexLayout(); - dexLayout.readSections(reader, filter); - return new DexFile(dexLayout); + DexLayoutBlock dexLayoutBlock = new DexLayoutBlock(); + dexLayoutBlock.readSections(reader, filter); + return new DexFile(dexLayoutBlock); } public static DexFile readStrings(InputStream inputStream) throws IOException { return readStrings(new BlockReader(inputStream)); @@ -529,20 +529,20 @@ public static DexFile readClassIds(InputStream inputStream) throws IOException { } public static DexFile createDefault(){ - return new DexFile(DexLayout.createDefault()); + return new DexFile(DexLayoutBlock.createDefault()); } public static DexFile findDexFile(ClassId classId){ if(classId == null){ return null; } - return DexFile.findDexFile(classId.getParentInstance(DexLayout.class)); + return DexFile.findDexFile(classId.getParentInstance(DexLayoutBlock.class)); } - public static DexFile findDexFile(DexLayout dexLayout){ - if(dexLayout == null){ + public static DexFile findDexFile(DexLayoutBlock dexLayoutBlock){ + if(dexLayoutBlock == null){ return null; } - Object obj = dexLayout.getTag(); + Object obj = dexLayoutBlock.getTag(); if(!(obj instanceof DexFile)){ return null; } diff --git a/src/main/java/com/reandroid/dex/model/DexMergeOptions.java b/src/main/java/com/reandroid/dex/model/DexMergeOptions.java index b04ffabf7..e8ffb61a5 100644 --- a/src/main/java/com/reandroid/dex/model/DexMergeOptions.java +++ b/src/main/java/com/reandroid/dex/model/DexMergeOptions.java @@ -17,7 +17,7 @@ import com.reandroid.dex.id.ClassId; import com.reandroid.dex.key.TypeKey; -import com.reandroid.dex.sections.DexLayout; +import com.reandroid.dex.sections.DexLayoutBlock; import com.reandroid.dex.sections.MergeOptions; import com.reandroid.dex.sections.SectionList; @@ -50,18 +50,18 @@ public void onDuplicate(ClassId classId) { mergedSet.add(classId.getKey()); } @Override - public void onMergeError(DexLayout dexLayout, ClassId classId, String message) { + public void onMergeError(DexLayoutBlock dexLayoutBlock, ClassId classId, String message) { } @Override - public void onMergeError(DexLayout dexLayout, SectionList sectionList, String message) { + public void onMergeError(DexLayoutBlock dexLayoutBlock, SectionList sectionList, String message) { } @Override - public void onDexFull(DexLayout dexLayout, ClassId classId) { + public void onDexFull(DexLayoutBlock dexLayoutBlock, ClassId classId) { DexFile coming = DexFile.findDexFile(classId); if(coming == null){ return; } - DexFile dexFile = DexFile.findDexFile(dexLayout); + DexFile dexFile = DexFile.findDexFile(dexLayoutBlock); if(dexFile == null){ return; } @@ -69,7 +69,7 @@ public void onDexFull(DexLayout dexLayout, ClassId classId) { if(directory == null || directory == coming.getDexDirectory()){ return; } - onCreateNext(dexLayout); + onCreateNext(dexLayoutBlock); } @Override public void onMergeSuccess(ClassId classId, TypeKey key) { @@ -91,7 +91,7 @@ public void setMergeStartDexFile(int mergeStartDexFile) { } @Override - public DexLayout onCreateNext(DexLayout last) { + public DexLayoutBlock onCreateNext(DexLayoutBlock last) { DexFile dexFile = DexFile.findDexFile(last); if(dexFile == null){ return null; diff --git a/src/main/java/com/reandroid/dex/sections/DexContainer.java b/src/main/java/com/reandroid/dex/sections/DexContainer.java index 2ab59a37f..b9b323907 100644 --- a/src/main/java/com/reandroid/dex/sections/DexContainer.java +++ b/src/main/java/com/reandroid/dex/sections/DexContainer.java @@ -26,15 +26,15 @@ * Unfinished work, this is for multi-dex layout as noticed in dex version 41 * */ -public class DexContainer extends BlockList implements Iterable { +public class DexContainer extends BlockList implements Iterable { - private DexLayout current; + private DexLayoutBlock current; public DexContainer(){ super(); - this.current = new DexLayout(); + this.current = new DexLayoutBlock(); add(current); } - public DexLayout getDexLayout(){ + public DexLayoutBlock getDexLayout(){ return current; } @@ -56,6 +56,6 @@ public Section getSection(SectionType sectionTy return null; } public Iterator getSectionLists(){ - return ComputeIterator.of(iterator(), DexLayout::getSectionList); + return ComputeIterator.of(iterator(), DexLayoutBlock::getSectionList); } } diff --git a/src/main/java/com/reandroid/dex/sections/DexLayout.java b/src/main/java/com/reandroid/dex/sections/DexLayoutBlock.java similarity index 97% rename from src/main/java/com/reandroid/dex/sections/DexLayout.java rename to src/main/java/com/reandroid/dex/sections/DexLayoutBlock.java index 24382fbe9..7453c79df 100644 --- a/src/main/java/com/reandroid/dex/sections/DexLayout.java +++ b/src/main/java/com/reandroid/dex/sections/DexLayoutBlock.java @@ -38,7 +38,7 @@ import java.util.Iterator; import java.util.function.Predicate; -public class DexLayout extends FixedBlockContainer implements FullRefresh { +public class DexLayoutBlock extends FixedBlockContainer implements FullRefresh { private final SectionList sectionList; @@ -49,7 +49,7 @@ public class DexLayout extends FixedBlockContainer implements FullRefresh { private Object mTag; - public DexLayout() { + public DexLayoutBlock() { super(1); this.sectionList = new SectionList(); addChild(0, sectionList); @@ -246,7 +246,7 @@ public boolean isEmpty(){ public boolean merge(MergeOptions options, ClassId classId){ return getSectionList().merge(options, classId); } - public boolean merge(MergeOptions options, DexLayout dexFile){ + public boolean merge(MergeOptions options, DexLayoutBlock dexFile){ if(dexFile == this){ options.onMergeError(this, getSectionList(), "Can not merge dex file to self"); return false; @@ -333,9 +333,9 @@ public void setSimpleName(String simpleName) { this.mSimpleName = simpleName; } - public static DexLayout createDefault(){ - DexLayout dexLayout = new DexLayout(); - SectionList sectionList = dexLayout.getSectionList(); + public static DexLayoutBlock createDefault(){ + DexLayoutBlock dexLayoutBlock = new DexLayoutBlock(); + SectionList sectionList = dexLayoutBlock.getSectionList(); MapList mapList = sectionList.getMapList(); mapList.getOrCreate(SectionType.HEADER); mapList.getOrCreate(SectionType.MAP_LIST); @@ -346,7 +346,7 @@ public static DexLayout createDefault(){ sectionList.getMapList().linkHeader(sectionList.getHeader()); - return dexLayout; + return dexLayoutBlock; } public static boolean isDexFile(File file){ if(file == null || !file.isFile()){ diff --git a/src/main/java/com/reandroid/dex/sections/MapItem.java b/src/main/java/com/reandroid/dex/sections/MapItem.java index d2edd3594..bfc55957d 100644 --- a/src/main/java/com/reandroid/dex/sections/MapItem.java +++ b/src/main/java/com/reandroid/dex/sections/MapItem.java @@ -65,7 +65,7 @@ public Section createNewSection(){ parent = getParent(MapList.class); } if(parent == null){ - parent = getParent(DexLayout.class); + parent = getParent(DexLayoutBlock.class); } if(parent == null){ parent = getParent(); diff --git a/src/main/java/com/reandroid/dex/sections/MergeOptions.java b/src/main/java/com/reandroid/dex/sections/MergeOptions.java index 330f06fed..7150a1356 100644 --- a/src/main/java/com/reandroid/dex/sections/MergeOptions.java +++ b/src/main/java/com/reandroid/dex/sections/MergeOptions.java @@ -22,9 +22,9 @@ public interface MergeOptions { boolean skipMerging(ClassId classId, TypeKey typeKey); void onDuplicate(ClassId classId); - void onMergeError(DexLayout dexLayout, ClassId classId, String message); - void onMergeError(DexLayout dexLayout, SectionList sectionList, String message); - void onDexFull(DexLayout dexLayout, ClassId classId); + void onMergeError(DexLayoutBlock dexLayoutBlock, ClassId classId, String message); + void onMergeError(DexLayoutBlock dexLayoutBlock, SectionList sectionList, String message); + void onDexFull(DexLayoutBlock dexLayoutBlock, ClassId classId); void onMergeSuccess(ClassId classId, TypeKey key); boolean relocateClass(); default int getMergeStartDexFile(){ @@ -32,12 +32,12 @@ default int getMergeStartDexFile(){ } default void setMergeStartDexFile(int startDexFile){ } - DexLayout onCreateNext(DexLayout last); - default boolean isEmptyDexFile(DexLayout dexLayout){ - if(dexLayout == null || dexLayout.isEmpty()){ + DexLayoutBlock onCreateNext(DexLayoutBlock last); + default boolean isEmptyDexFile(DexLayoutBlock dexLayoutBlock){ + if(dexLayoutBlock == null || dexLayoutBlock.isEmpty()){ return true; } - Section section = dexLayout.get(SectionType.CLASS_ID); + Section section = dexLayoutBlock.get(SectionType.CLASS_ID); for(ClassId classId : section){ if(!skipMerging(classId, classId.getKey())){ return false; @@ -56,13 +56,13 @@ public void onDuplicate(ClassId classId) { classId.removeSelf(); } @Override - public void onMergeError(DexLayout dexLayout, ClassId classId, String message) { + public void onMergeError(DexLayoutBlock dexLayoutBlock, ClassId classId, String message) { } @Override - public void onMergeError(DexLayout dexLayout, SectionList sectionList, String message) { + public void onMergeError(DexLayoutBlock dexLayoutBlock, SectionList sectionList, String message) { } @Override - public void onDexFull(DexLayout dexLayout, ClassId classId) { + public void onDexFull(DexLayoutBlock dexLayoutBlock, ClassId classId) { } @Override public void onMergeSuccess(ClassId classId, TypeKey key) { @@ -72,7 +72,7 @@ public boolean relocateClass() { return true; } @Override - public DexLayout onCreateNext(DexLayout last) { + public DexLayoutBlock onCreateNext(DexLayoutBlock last) { return null; } }; diff --git a/src/main/java/com/reandroid/dex/sections/SectionList.java b/src/main/java/com/reandroid/dex/sections/SectionList.java index a8a42ac9f..aac5ae700 100644 --- a/src/main/java/com/reandroid/dex/sections/SectionList.java +++ b/src/main/java/com/reandroid/dex/sections/SectionList.java @@ -473,15 +473,15 @@ private boolean canAddAll(Collection idItemCollection) { } public boolean merge(MergeOptions options, ClassId classId){ if(classId == null){ - options.onMergeError(getParentInstance(DexLayout.class), classId, "Null class id"); + options.onMergeError(getParentInstance(DexLayoutBlock.class), classId, "Null class id"); return false; } if(classId.getParent() == null){ - options.onMergeError(getParentInstance(DexLayout.class), classId, "Destroyed class id"); + options.onMergeError(getParentInstance(DexLayoutBlock.class), classId, "Destroyed class id"); return false; } if(classId.getParent(SectionList.class) == this){ - options.onMergeError(getParentInstance(DexLayout.class), classId, "Class id is on same section"); + options.onMergeError(getParentInstance(DexLayoutBlock.class), classId, "Class id is on same section"); return false; } if(options.skipMerging(classId, classId.getKey())){ @@ -493,7 +493,7 @@ public boolean merge(MergeOptions options, ClassId classId){ } ArrayCollection collection = classId.listUsedIds(); if(!canAddAll(collection)){ - options.onDexFull(getParentInstance(DexLayout.class), classId); + options.onDexFull(getParentInstance(DexLayoutBlock.class), classId); return false; } Section mySection = getOrCreateSection(SectionType.CLASS_ID); @@ -508,11 +508,11 @@ public boolean merge(MergeOptions options, ClassId classId){ } public boolean merge(MergeOptions options, SectionList sectionList){ if(sectionList == this){ - options.onMergeError(getParentInstance(DexLayout.class), sectionList, "Can not merge with self"); + options.onMergeError(getParentInstance(DexLayoutBlock.class), sectionList, "Can not merge with self"); return false; } if(sectionList.getParent() == null){ - options.onMergeError(getParentInstance(DexLayout.class), sectionList, "Destroyed section list"); + options.onMergeError(getParentInstance(DexLayoutBlock.class), sectionList, "Destroyed section list"); return false; } Section comingSection = sectionList.getSection(SectionType.CLASS_ID); @@ -537,7 +537,7 @@ public boolean merge(MergeOptions options, SectionList sectionList){ ArrayCollection collection = coming.listUsedIds(); if(!canAddAll(collection)){ mergedAll = false; - options.onDexFull(this.getParentInstance(DexLayout.class), coming); + options.onDexFull(this.getParentInstance(DexLayoutBlock.class), coming); break; } ClassId classId = mySection.getOrCreate(coming.getKey()); @@ -550,9 +550,9 @@ public boolean merge(MergeOptions options, SectionList sectionList){ } if(comingSection.getCount() == 0){ SectionList comingSectionSectionList = comingSection.getSectionList(); - DexLayout dexLayout = comingSectionSectionList - .getParentInstance(DexLayout.class); - dexLayout.clear(); + DexLayoutBlock dexLayoutBlock = comingSectionSectionList + .getParentInstance(DexLayoutBlock.class); + dexLayoutBlock.clear(); } if(mergedOnce){ refresh();