use of org.jf.dexlib2.iface.instruction.Instruction in project smali by JesusFreke.
the class MutableMethodImplementation method newBuilderSparseSwitchPayload.
@Nonnull
private BuilderSparseSwitchPayload newBuilderSparseSwitchPayload(@Nonnull MethodLocation location, @Nonnull int[] codeAddressToIndex, @Nonnull SparseSwitchPayload instruction) {
List<? extends SwitchElement> switchElements = instruction.getSwitchElements();
if (switchElements.size() == 0) {
return new BuilderSparseSwitchPayload(null);
}
MethodLocation switchLocation = findSwitchForPayload(location);
int baseAddress;
if (switchLocation == null) {
baseAddress = 0;
} else {
baseAddress = switchLocation.codeAddress;
}
List<SwitchLabelElement> labelElements = Lists.newArrayList();
for (SwitchElement element : switchElements) {
labelElements.add(new SwitchLabelElement(element.getKey(), newLabel(codeAddressToIndex, element.getOffset() + baseAddress)));
}
return new BuilderSparseSwitchPayload(labelElements);
}
use of org.jf.dexlib2.iface.instruction.Instruction in project smali by JesusFreke.
the class MutableMethodImplementation method removeInstruction.
public void removeInstruction(int index) {
if (index >= instructionList.size() - 1) {
throw new IndexOutOfBoundsException();
}
MethodLocation toRemove = instructionList.get(index);
toRemove.instruction = null;
MethodLocation next = instructionList.get(index + 1);
toRemove.mergeInto(next);
instructionList.remove(index);
int codeAddress = toRemove.codeAddress;
for (int i = index; i < instructionList.size(); i++) {
MethodLocation location = instructionList.get(i);
location.index = i;
location.codeAddress = codeAddress;
Instruction instruction = location.getInstruction();
if (instruction != null) {
codeAddress += instruction.getCodeUnits();
} else {
assert i == instructionList.size() - 1;
}
}
this.fixInstructions = true;
}
use of org.jf.dexlib2.iface.instruction.Instruction in project smali by JesusFreke.
the class MutableMethodImplementation method replaceInstruction.
public void replaceInstruction(int index, @Nonnull BuilderInstruction replacementInstruction) {
if (index >= instructionList.size() - 1) {
throw new IndexOutOfBoundsException();
}
MethodLocation replaceLocation = instructionList.get(index);
replacementInstruction.location = replaceLocation;
BuilderInstruction old = replaceLocation.instruction;
assert old != null;
old.location = null;
replaceLocation.instruction = replacementInstruction;
// TODO: factor out index/address fix up loop
int codeAddress = replaceLocation.codeAddress + replaceLocation.instruction.getCodeUnits();
for (int i = index + 1; i < instructionList.size(); i++) {
MethodLocation location = instructionList.get(i);
location.codeAddress = codeAddress;
Instruction instruction = location.getInstruction();
if (instruction != null) {
codeAddress += instruction.getCodeUnits();
} else {
assert i == instructionList.size() - 1;
}
}
this.fixInstructions = true;
}
use of org.jf.dexlib2.iface.instruction.Instruction in project smali by JesusFreke.
the class MutableMethodImplementation method newBuilderPackedSwitchPayload.
@Nonnull
private BuilderPackedSwitchPayload newBuilderPackedSwitchPayload(@Nonnull MethodLocation location, @Nonnull int[] codeAddressToIndex, @Nonnull PackedSwitchPayload instruction) {
List<? extends SwitchElement> switchElements = instruction.getSwitchElements();
if (switchElements.size() == 0) {
return new BuilderPackedSwitchPayload(0, null);
}
MethodLocation switchLocation = findSwitchForPayload(location);
int baseAddress;
if (switchLocation == null) {
baseAddress = 0;
} else {
baseAddress = switchLocation.codeAddress;
}
List<Label> labels = Lists.newArrayList();
for (SwitchElement element : switchElements) {
labels.add(newLabel(codeAddressToIndex, element.getOffset() + baseAddress));
}
return new BuilderPackedSwitchPayload(switchElements.get(0).getKey(), labels);
}
use of org.jf.dexlib2.iface.instruction.Instruction in project atlas by alibaba.
the class DexCompareUtils method equalsInstruction.
/**
* 比较method重的tryBlock块
*
* @param a
* @param b
* @return
*/
private static boolean equalsInstruction(List<Instruction> a, List<Instruction> b) {
if (a.size() != b.size()) {
return false;
}
Instruction at, bt;
for (int i = 0; i < a.size(); i++) {
at = a.get(i);
bt = b.get(i);
if (!at.getOpcode().equals(bt.getOpcode()) || !(at.getCodeUnits() == bt.getCodeUnits())) {
return false;
}
}
return true;
}
Aggregations