Skip to content

Commit

Permalink
[DEX] Rename to DexLayoutBlock
Browse files Browse the repository at this point in the history
  • Loading branch information
REAndroid committed Nov 5, 2024
1 parent f816379 commit 47015d6
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 80 deletions.
8 changes: 4 additions & 4 deletions src/main/java/com/reandroid/dex/header/DexChecksum.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/reandroid/dex/header/Signature.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/reandroid/dex/ins/InstructionException.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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;
}
Expand Down
54 changes: 27 additions & 27 deletions src/main/java/com/reandroid/dex/model/DexFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@
public class DexFile implements DexClassRepository, Closeable,
Iterable<DexClass>, 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(){
Expand Down Expand Up @@ -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<DexClass> getSubTypes(TypeKey typeKey){
Expand Down Expand Up @@ -313,8 +313,8 @@ public <T1 extends SectionItem> Section<T1> getSection(SectionType<T1> sectionTy
public void refresh() {
getDexLayout().refresh();
}
public DexLayout getDexLayout() {
return dexLayout;
public DexLayoutBlock getDexLayout() {
return dexLayoutBlock;
}

public boolean isEmpty(){
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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<SectionType<?>> 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));
Expand All @@ -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;
}
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/com/reandroid/dex/model/DexMergeOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -50,26 +50,26 @@ 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;
}
DexDirectory directory = dexFile.getDexDirectory();
if(directory == null || directory == coming.getDexDirectory()){
return;
}
onCreateNext(dexLayout);
onCreateNext(dexLayoutBlock);
}
@Override
public void onMergeSuccess(ClassId classId, TypeKey key) {
Expand All @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/com/reandroid/dex/sections/DexContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@
* Unfinished work, this is for multi-dex layout as noticed in dex version 41
* */

public class DexContainer extends BlockList<DexLayout> implements Iterable<DexLayout> {
public class DexContainer extends BlockList<DexLayoutBlock> implements Iterable<DexLayoutBlock> {

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;
}

Expand All @@ -56,6 +56,6 @@ public <T1 extends SectionItem> Section<T1> getSection(SectionType<T1> sectionTy
return null;
}
public Iterator<SectionList> getSectionLists(){
return ComputeIterator.of(iterator(), DexLayout::getSectionList);
return ComputeIterator.of(iterator(), DexLayoutBlock::getSectionList);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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()){
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/reandroid/dex/sections/MapItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public<T1 extends SectionItem> Section<T1> createNewSection(){
parent = getParent(MapList.class);
}
if(parent == null){
parent = getParent(DexLayout.class);
parent = getParent(DexLayoutBlock.class);
}
if(parent == null){
parent = getParent();
Expand Down
22 changes: 11 additions & 11 deletions src/main/java/com/reandroid/dex/sections/MergeOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,22 @@ 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(){
return 0;
}
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<ClassId> section = dexLayout.get(SectionType.CLASS_ID);
Section<ClassId> section = dexLayoutBlock.get(SectionType.CLASS_ID);
for(ClassId classId : section){
if(!skipMerging(classId, classId.getKey())){
return false;
Expand All @@ -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) {
Expand All @@ -72,7 +72,7 @@ public boolean relocateClass() {
return true;
}
@Override
public DexLayout onCreateNext(DexLayout last) {
public DexLayoutBlock onCreateNext(DexLayoutBlock last) {
return null;
}
};
Expand Down
Loading

0 comments on commit 47015d6

Please sign in to comment.