use of com.taobao.android.dx.rop.type.TypeList in project atlas by alibaba.
the class ClassDefItem method writeTo.
/** {@inheritDoc} */
@Override
public void writeTo(DexFile file, AnnotatedOutput out) {
boolean annotates = out.annotates();
TypeIdsSection typeIds = file.getTypeIds();
int classIdx = typeIds.indexOf(thisClass);
int superIdx = (superclass == null) ? -1 : typeIds.indexOf(superclass);
int interOff = OffsettedItem.getAbsoluteOffsetOr0(interfaces);
int annoOff = annotationsDirectory.isEmpty() ? 0 : annotationsDirectory.getAbsoluteOffset();
int sourceFileIdx = (sourceFile == null) ? -1 : file.getStringIds().indexOf(sourceFile);
int dataOff = classData.isEmpty() ? 0 : classData.getAbsoluteOffset();
int staticValuesOff = OffsettedItem.getAbsoluteOffsetOr0(staticValuesItem);
if (annotates) {
out.annotate(0, indexString() + ' ' + thisClass.toHuman());
out.annotate(4, " class_idx: " + Hex.u4(classIdx));
out.annotate(4, " access_flags: " + AccessFlags.classString(accessFlags));
out.annotate(4, " superclass_idx: " + Hex.u4(superIdx) + " // " + ((superclass == null) ? "<none>" : superclass.toHuman()));
out.annotate(4, " interfaces_off: " + Hex.u4(interOff));
if (interOff != 0) {
TypeList list = interfaces.getList();
int sz = list.size();
for (int i = 0; i < sz; i++) {
out.annotate(0, " " + list.getType(i).toHuman());
}
}
out.annotate(4, " source_file_idx: " + Hex.u4(sourceFileIdx) + " // " + ((sourceFile == null) ? "<none>" : sourceFile.toHuman()));
out.annotate(4, " annotations_off: " + Hex.u4(annoOff));
out.annotate(4, " class_data_off: " + Hex.u4(dataOff));
out.annotate(4, " static_values_off: " + Hex.u4(staticValuesOff));
}
out.writeInt(classIdx);
out.writeInt(accessFlags);
out.writeInt(superIdx);
out.writeInt(interOff);
out.writeInt(sourceFileIdx);
out.writeInt(annoOff);
out.writeInt(dataOff);
out.writeInt(staticValuesOff);
}
use of com.taobao.android.dx.rop.type.TypeList in project atlas by alibaba.
the class BasicBlockList method catchesEqual.
/**
* Compares the catches of two blocks for equality. This includes
* both the catch types and target labels.
*
* @param block1 {@code non-null;} one block to compare
* @param block2 {@code non-null;} the other block to compare
* @return {@code true} if the two blocks' non-primary successors
* are identical
*/
public boolean catchesEqual(BasicBlock block1, BasicBlock block2) {
TypeList catches1 = block1.getExceptionHandlerTypes();
TypeList catches2 = block2.getExceptionHandlerTypes();
if (!StdTypeList.equalContents(catches1, catches2)) {
return false;
}
IntList succ1 = block1.getSuccessors();
IntList succ2 = block2.getSuccessors();
// Both are guaranteed to be the same size.
int size = succ1.size();
int primary1 = block1.getPrimarySuccessor();
int primary2 = block2.getPrimarySuccessor();
if (((primary1 == -1) || (primary2 == -1)) && (primary1 != primary2)) {
/*
* For the current purpose, both blocks in question must
* either both have a primary or both not have a primary to
* be considered equal, and it turns out here that that's not
* the case.
*/
return false;
}
for (int i = 0; i < size; i++) {
int label1 = succ1.get(i);
int label2 = succ2.get(i);
if (label1 == primary1) {
/*
* It should be the case that block2's primary is at the
* same index. If not, we consider the blocks unequal for
* the current purpose.
*/
if (label2 != primary2) {
return false;
}
continue;
}
if (label1 != label2) {
return false;
}
}
return true;
}
use of com.taobao.android.dx.rop.type.TypeList in project atlas by alibaba.
the class ClassReferenceListBuilder method addClassWithHierachy.
private void addClassWithHierachy(String classBinaryName) {
if (classNames.contains(classBinaryName)) {
return;
}
try {
DirectClassFile classFile = path.getClass(classBinaryName + CLASS_EXTENSION);
classNames.add(classBinaryName);
CstType superClass = classFile.getSuperclass();
if (superClass != null) {
addClassWithHierachy(superClass.getClassType().getClassName());
}
TypeList interfaceList = classFile.getInterfaces();
int interfaceNumber = interfaceList.size();
for (int i = 0; i < interfaceNumber; i++) {
addClassWithHierachy(interfaceList.getType(i).getClassName());
}
} catch (FileNotFoundException e) {
// Ignore: The referenced type is not in the path it must be part of the libraries.
}
}
use of com.taobao.android.dx.rop.type.TypeList in project atlas by alibaba.
the class Ropper method addReturnBlock.
/**
* Constructs and adds the return block, if necessary. The return
* block merely contains an appropriate {@code return}
* instruction.
*/
private void addReturnBlock() {
Rop returnOp = machine.getReturnOp();
if (returnOp == null) {
/*
* The method being converted never returns normally, so there's
* no need for a return block.
*/
return;
}
SourcePosition returnPos = machine.getReturnPosition();
int label = getSpecialLabel(RETURN);
if (isSynchronized()) {
InsnList insns = new InsnList(1);
Insn insn = new ThrowingInsn(Rops.MONITOR_EXIT, returnPos, RegisterSpecList.make(getSynchReg()), StdTypeList.EMPTY);
insns.set(0, insn);
insns.setImmutable();
int nextLabel = getSpecialLabel(SYNCH_RETURN);
BasicBlock bb = new BasicBlock(label, insns, IntList.makeImmutable(nextLabel), nextLabel);
addBlock(bb, IntList.EMPTY);
label = nextLabel;
}
InsnList insns = new InsnList(1);
TypeList sourceTypes = returnOp.getSources();
RegisterSpecList sources;
if (sourceTypes.size() == 0) {
sources = RegisterSpecList.EMPTY;
} else {
RegisterSpec source = RegisterSpec.make(0, sourceTypes.getType(0));
sources = RegisterSpecList.make(source);
}
Insn insn = new PlainInsn(returnOp, returnPos, null, sources);
insns.set(0, insn);
insns.setImmutable();
BasicBlock bb = new BasicBlock(label, insns, IntList.EMPTY, -1);
addBlock(bb, IntList.EMPTY);
}
use of com.taobao.android.dx.rop.type.TypeList in project atlas by alibaba.
the class StdCatchBuilder method handlersFor.
/**
* Makes the {@link CatchHandlerList} for the given basic block.
*
* @param block {@code non-null;} block to get entries for
* @param addresses {@code non-null;} address objects for each block
* @return {@code non-null;} array of entries
*/
private static CatchHandlerList handlersFor(BasicBlock block, BlockAddresses addresses) {
IntList successors = block.getSuccessors();
int succSize = successors.size();
int primary = block.getPrimarySuccessor();
TypeList catches = block.getLastInsn().getCatches();
int catchSize = catches.size();
if (catchSize == 0) {
return CatchHandlerList.EMPTY;
}
if (((primary == -1) && (succSize != catchSize)) || ((primary != -1) && ((succSize != (catchSize + 1)) || (primary != successors.get(catchSize))))) {
/*
* Blocks that throw are supposed to list their primary
* successor -- if any -- last in the successors list, but
* that constraint appears to be violated here.
*/
throw new RuntimeException("shouldn't happen: weird successors list");
}
/*
* Reduce the effective catchSize if we spot a catch-all that
* isn't at the end.
*/
for (int i = 0; i < catchSize; i++) {
Type type = catches.getType(i);
if (type.equals(Type.OBJECT)) {
catchSize = i + 1;
break;
}
}
CatchHandlerList result = new CatchHandlerList(catchSize);
for (int i = 0; i < catchSize; i++) {
CstType oneType = new CstType(catches.getType(i));
CodeAddress oneHandler = addresses.getStart(successors.get(i));
result.set(i, oneType, oneHandler.getAddress());
}
result.setImmutable();
return result;
}
Aggregations