
com.reandroid.dex.model.DexIntegerVisitor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ARSCLib Show documentation
Show all versions of ARSCLib Show documentation
Android binary resources read/write library
The newest version!
/*
* 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.dex.model;
import com.reandroid.arsc.item.IntegerReference;
import com.reandroid.dex.data.*;
import com.reandroid.dex.ins.*;
import com.reandroid.dex.sections.SectionType;
import com.reandroid.dex.value.AnnotationValue;
import com.reandroid.dex.value.ArrayValue;
import com.reandroid.dex.value.DexValueBlock;
import com.reandroid.dex.value.IntValue;
import com.reandroid.utils.collection.*;
import java.util.Iterator;
public class DexIntegerVisitor extends CombiningIterator {
public DexIntegerVisitor(DexClassRepository classRepository) {
super(getEncodedArrayReferences(classRepository), getCodeItemReferences(classRepository));
}
private static Iterator getEncodedArrayReferences(DexClassRepository repository) {
return new IterableIterator(
repository.getItems(SectionType.ENCODED_ARRAY)
) {
@Override
public Iterator iterator(EncodedArray element) {
return DexIntegerVisitor.iterator(element);
}
};
}
private static Iterator getCodeItemReferences(DexClassRepository repository) {
return new IterableIterator(
repository.getItems(SectionType.CODE)
) {
@Override
public Iterator iterator(CodeItem element) {
return DexIntegerVisitor.iterator(element);
}
};
}
static Iterator iterator(CodeItem codeItem) {
return new IterableIterator(codeItem.getInstructionList().iterator()) {
@Override
public Iterator iterator(Ins element) {
return DexIntegerVisitor.iterator(element);
}
};
}
static Iterator iterator(Ins ins) {
if (ins instanceof ConstNumber) {
return SingleIterator.of((ConstNumber) ins);
} else if (ins instanceof PayloadData) {
return ((PayloadData) ins).getReferences();
} else {
return EmptyIterator.of();
}
}
static Iterator iterator(EncodedArray encodedArray) {
return new IterableIterator, IntegerReference>(encodedArray.iterator()) {
@Override
public Iterator iterator(DexValueBlock> element) {
return DexIntegerVisitor.iterator(element);
}
};
}
static Iterator iterator(DexValueBlock> valueBlock) {
if(valueBlock instanceof IntValue){
return SingleIterator.of((IntValue) valueBlock);
}else if(valueBlock instanceof ArrayValue) {
return iterator((ArrayValue) valueBlock);
}else if(valueBlock instanceof AnnotationValue) {
return iterator(((AnnotationValue) valueBlock).get());
}
return EmptyIterator.of();
}
private static Iterator iterator(ArrayValue arrayValue) {
return new IterableIterator, IntegerReference>(arrayValue.iterator()) {
@Override
public Iterator iterator(DexValueBlock> element) {
return DexIntegerVisitor.iterator(element);
}
};
}
private static Iterator iterator(AnnotationItem arrayValue) {
return new IterableIterator(arrayValue.iterator()) {
@Override
public Iterator iterator(AnnotationElement element) {
return DexIntegerVisitor.iterator(element.getValue());
}
};
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy