use of org.jf.dexlib2.builder.BuilderInstruction in project tinker by Tencent.
the class BuilderMutableMethodImplementation 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.builder.BuilderInstruction in project tinker by Tencent.
the class BuilderMutableMethodImplementation method swapInstructions.
public void swapInstructions(int index1, int index2) {
if (index1 >= instructionList.size() - 1 || index2 >= instructionList.size() - 1) {
throw new IndexOutOfBoundsException();
}
MethodLocation first = instructionList.get(index1);
MethodLocation second = instructionList.get(index2);
// only the last MethodLocation may have a null instruction
assert first.instruction != null;
assert second.instruction != null;
first.instruction.location = second;
second.instruction.location = first;
{
BuilderInstruction tmp = second.instruction;
second.instruction = first.instruction;
first.instruction = tmp;
}
if (index2 < index1) {
int tmp = index2;
index2 = index1;
index1 = tmp;
}
int codeAddress = first.codeAddress + first.instruction.getCodeUnits();
for (int i = index1 + 1; i <= index2; i++) {
MethodLocation location = instructionList.get(i);
location.codeAddress = codeAddress;
Instruction instruction = location.instruction;
assert instruction != null;
codeAddress += location.instruction.getCodeUnits();
}
this.fixInstructions = true;
}
use of org.jf.dexlib2.builder.BuilderInstruction in project smali by JesusFreke.
the class MutableMethodImplementation method swapInstructions.
public void swapInstructions(int index1, int index2) {
if (index1 >= instructionList.size() - 1 || index2 >= instructionList.size() - 1) {
throw new IndexOutOfBoundsException();
}
MethodLocation first = instructionList.get(index1);
MethodLocation second = instructionList.get(index2);
// only the last MethodLocation may have a null instruction
assert first.instruction != null;
assert second.instruction != null;
first.instruction.location = second;
second.instruction.location = first;
{
BuilderInstruction tmp = second.instruction;
second.instruction = first.instruction;
first.instruction = tmp;
}
if (index2 < index1) {
int tmp = index2;
index2 = index1;
index1 = tmp;
}
int codeAddress = first.codeAddress + first.instruction.getCodeUnits();
for (int i = index1 + 1; i <= index2; i++) {
MethodLocation location = instructionList.get(i);
location.codeAddress = codeAddress;
Instruction instruction = location.instruction;
assert instruction != null;
codeAddress += location.instruction.getCodeUnits();
}
this.fixInstructions = true;
}
Aggregations