本文整理汇总了Java中org.jf.dexlib2.builder.BuilderInstruction类的典型用法代码示例。如果您正苦于以下问题:Java BuilderInstruction类的具体用法?Java BuilderInstruction怎么用?Java BuilderInstruction使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BuilderInstruction类属于org.jf.dexlib2.builder包,在下文中一共展示了BuilderInstruction类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getRealInsns
import org.jf.dexlib2.builder.BuilderInstruction; //导入依赖的package包/类
public List<BuilderInstruction> getRealInsns(LabelAssigner labelAssigner) {
List<BuilderInstruction> finalInsns = new ArrayList<BuilderInstruction>();
for (Insn i : insns) {
if (i instanceof AddressInsn) {
continue; // skip non-insns
}
BuilderInstruction realInsn = i.getRealInsn(labelAssigner);
finalInsns.add(realInsn);
if (insnStmtMap.containsKey(i)) { // get tags
instructionInsnMap.put(realInsn, i);
}
if (insnRegisterMap.containsKey(i)) {
instructionRegisterMap.put(realInsn, insnRegisterMap.get(i));
}
if (i instanceof SwitchPayload)
instructionPayloadMap.put(realInsn, (SwitchPayload) i);
}
return finalInsns;
}
示例2: modifyMethodAndFix
import org.jf.dexlib2.builder.BuilderInstruction; //导入依赖的package包/类
private static MethodImplementation modifyMethodAndFix(@Nonnull MethodImplementation implementation, Method method) {
MutableMethodImplementation mutableImplementation = new MutableMethodImplementation(implementation);
System.out.println(mutableImplementation.getRegisterCount());
List<BuilderInstruction> instructions = mutableImplementation.getInstructions();
mutableImplementation.addInstruction(0,
new BuilderInstruction21c(Opcode.CONST_STRING, 0,
new ImmutableStringReference("AndFix:" + method.getDefiningClass().replace("/", "."))));
mutableImplementation.addInstruction(1,
new BuilderInstruction35c(Opcode.INVOKE_STATIC, 1,
0, 0, 0, 0, 0,
new ImmutableMethodReference("Landroid/util/Log;", "e",
Lists.newArrayList("Ljava/lang/String;", "Ljava/lang/String;"), "I")));
return mutableImplementation;
}
示例3: modifyMethodTpatch
import org.jf.dexlib2.builder.BuilderInstruction; //导入依赖的package包/类
private static MethodImplementation modifyMethodTpatch(@Nonnull MethodImplementation implementation, Method method) {
MutableMethodImplementation mutableImplementation = new MutableMethodImplementation(implementation);
System.out.println(mutableImplementation.getRegisterCount());
List<BuilderInstruction> instructions = mutableImplementation.getInstructions();
boolean isModified = false;
for (int i = 0; i < instructions.size(); i++) {
isModified = false;
if (instructions.get(i).getOpcode() == Opcode.INVOKE_DIRECT) {
if (!isModified) {
mutableImplementation.addInstruction(i++,
new BuilderInstruction21c(Opcode.CONST_STRING, 0,
new ImmutableStringReference("tpatch:" + method.getDefiningClass().replace("/", "."))));
mutableImplementation.addInstruction(i++,
new BuilderInstruction35c(Opcode.INVOKE_STATIC, 1,
0, 0, 0, 0, 0,
new ImmutableMethodReference("Landroid/util/Log;", "e",
Lists.newArrayList("Ljava/lang/String;", "Ljava/lang/String;"), "I")));
isModified = true;
break;
}
}
// mutableImplementation.addInstruction(instructions.get(i));
}
return mutableImplementation;
}
示例4: getDistanceBetween
import org.jf.dexlib2.builder.BuilderInstruction; //导入依赖的package包/类
private int getDistanceBetween(List<BuilderInstruction> instructions,
int i, int j) {
if (i == j)
return 0;
int dist = 0;
for (int idx = Math.min(i, j); idx < Math.max(i, j); idx++) {
BuilderInstruction bi = instructions.get(idx);
dist += (bi.getFormat().size / 2);
}
return dist;
}
示例5: getRealInsn0
import org.jf.dexlib2.builder.BuilderInstruction; //导入依赖的package包/类
@Override
protected BuilderInstruction getRealInsn0(LabelAssigner assigner) {
List<SwitchLabelElement> elements = new ArrayList<SwitchLabelElement>();
for (int i = 0; i < keys.length; i++)
elements.add(new SwitchLabelElement(keys[i],
assigner.getOrCreateLabel((Stmt) targets.get(i))));
return new BuilderSparseSwitchPayload(elements);
}
示例6: getRealInsn0
import org.jf.dexlib2.builder.BuilderInstruction; //导入依赖的package包/类
@Override
protected BuilderInstruction getRealInsn0(LabelAssigner assigner) {
int[] realRegNumbers = getRealRegNumbers();
byte regDNumber = (byte) realRegNumbers[REG_D_IDX];
byte regENumber = (byte) realRegNumbers[REG_E_IDX];
byte regFNumber = (byte) realRegNumbers[REG_F_IDX];
byte regGNumber = (byte) realRegNumbers[REG_G_IDX];
byte regANumber = (byte) realRegNumbers[REG_A_IDX];
return new BuilderInstruction35c(opc, regCount, regDNumber, regENumber,
regFNumber, regGNumber, regANumber, referencedItem);
}
示例7: getRealInsn0
import org.jf.dexlib2.builder.BuilderInstruction; //导入依赖的package包/类
@Override
protected BuilderInstruction getRealInsn0(LabelAssigner assigner) {
List<Label> elements = new ArrayList<Label>();
for (int i = 0; i < targets.size(); i++)
elements.add(assigner.getOrCreateLabel((Stmt) targets.get(i)));
return new BuilderPackedSwitchPayload(firstKey, elements);
}
示例8: getRealInsn
import org.jf.dexlib2.builder.BuilderInstruction; //导入依赖的package包/类
@Override
public BuilderInstruction getRealInsn(LabelAssigner assigner) {
if (hasIncompatibleRegs()) {
throw new RuntimeException("the instruction still has incompatible registers: " + getIncompatibleRegs());
}
return getRealInsn0(assigner);
}
示例9: fixLongJumps
import org.jf.dexlib2.builder.BuilderInstruction; //导入依赖的package包/类
private void fixLongJumps(List<BuilderInstruction> instructions,
LabelAssigner labelAssigner, StmtVisitor stmtV) {
boolean hasChanged = true;
l0 : while (hasChanged) {
hasChanged = false;
// Build a mapping between labels and offsets
Map<Label, Integer> labelToInsOffset = new HashMap<Label, Integer>();
for (int i = 0; i < instructions.size(); i++) {
BuilderInstruction bi = instructions.get(i);
Stmt origStmt = stmtV.getStmtForInstruction(bi);
if (origStmt != null) {
Label lbl = labelAssigner.getLabelUnsafe(origStmt);
if (lbl != null) {
labelToInsOffset.put(lbl, i);
}
}
}
// Look for references to labels
for (int j = 0; j < instructions.size(); j++) {
BuilderInstruction bj = instructions.get(j);
if (bj instanceof BuilderOffsetInstruction) {
BuilderOffsetInstruction boj = (BuilderOffsetInstruction) bj;
Label targetLbl = boj.getTarget();
Integer offset = labelToInsOffset.get(targetLbl);
if (offset == null)
continue;
// Compute the distance between the instructions
Insn jumpInsn = stmtV.getInsnForInstruction(boj);
if (jumpInsn instanceof InsnWithOffset) {
InsnWithOffset offsetInsn = (InsnWithOffset) jumpInsn;
int distance = getDistanceBetween(instructions, j, offset);
if (Math.abs(distance) > offsetInsn.getMaxJumpOffset()) {
// We need intermediate jumps
insertIntermediateJump(offset, j, stmtV, instructions,
labelAssigner);
hasChanged = true;
continue l0;
}
}
}
}
}
}
示例10: insertIntermediateJump
import org.jf.dexlib2.builder.BuilderInstruction; //导入依赖的package包/类
/**
* Creates an intermediate jump instruction between the original jump
* instruction and its target
* @param targetInsPos The jump target index
* @param jumpInsPos The position of the jump instruction
* @param stmtV The statement visitor used for constructing the instructions
* @param instructions The list of Dalvik instructions
* @param labelAssigner The label assigner to be used for creating new labels
*/
private void insertIntermediateJump(int targetInsPos, int jumpInsPos,
StmtVisitor stmtV, List<BuilderInstruction> instructions,
LabelAssigner labelAssigner) {
// Get the original jump instruction
BuilderInstruction originalJumpInstruction = instructions.get(jumpInsPos);
Insn originalJumpInsn = stmtV.getInsnForInstruction(originalJumpInstruction);
if (originalJumpInsn == null)
return;
if (!(originalJumpInsn instanceof InsnWithOffset))
throw new RuntimeException("Unexpected jump instruction target");
InsnWithOffset offsetInsn = (InsnWithOffset) originalJumpInsn;
// Find a position where we can jump to
int distance = Math.max(targetInsPos, jumpInsPos) - Math.min(targetInsPos, jumpInsPos);
if (distance == 0)
return;
int newJumpIdx = Math.min(targetInsPos, jumpInsPos) + (distance / 2);
int sign = (int) Math.signum(targetInsPos - jumpInsPos);
if (distance > offsetInsn.getMaxJumpOffset())
newJumpIdx = jumpInsPos + sign;
// There must be a statement at the instruction after the jump target
while (stmtV.getStmtForInstruction(instructions.get(newJumpIdx)) == null) {
newJumpIdx += sign;
if (newJumpIdx < 0 || newJumpIdx >= instructions.size())
throw new RuntimeException("No position for inserting intermediate "
+ "jump instruction found");
}
// Create a jump instruction from the middle to the end
NopStmt nop = Jimple.v().newNopStmt();
Insn30t newJump = new Insn30t(Opcode.GOTO_32);
newJump.setTarget(stmtV.getStmtForInstruction(instructions.get(targetInsPos)));
BuilderInstruction newJumpInstruction = newJump.getRealInsn(labelAssigner);
instructions.add(newJumpIdx, newJumpInstruction);
stmtV.fakeNewInsn(nop, newJump, newJumpInstruction);
// We have added something, so we need to fix indices
if (newJumpIdx < jumpInsPos)
jumpInsPos++;
if (newJumpIdx < targetInsPos)
targetInsPos++;
// Jump from the original instruction to the new one in the middle
offsetInsn.setTarget(nop);
BuilderInstruction replacementJumpInstruction = offsetInsn.getRealInsn(labelAssigner);
instructions.add(jumpInsPos, replacementJumpInstruction);
instructions.remove(originalJumpInstruction);
stmtV.fakeNewInsn(stmtV.getStmtForInstruction(originalJumpInstruction),
originalJumpInsn, replacementJumpInstruction);
// Our indices are still fine, because we just replaced something
Stmt afterNewJump = stmtV.getStmtForInstruction(instructions.get(newJumpIdx + 1));
// Make the original control flow jump around the new artificial jump instruction
Insn10t jumpAround = new Insn10t(Opcode.GOTO);
jumpAround.setTarget(afterNewJump);
BuilderInstruction jumpAroundInstruction = jumpAround.getRealInsn(labelAssigner);
instructions.add(newJumpIdx, jumpAroundInstruction);
}
示例11: getRealInsn0
import org.jf.dexlib2.builder.BuilderInstruction; //导入依赖的package包/类
@Override
protected BuilderInstruction getRealInsn0(LabelAssigner assigner) {
return null;
}
示例12: getRealInsn0
import org.jf.dexlib2.builder.BuilderInstruction; //导入依赖的package包/类
@Override
protected BuilderInstruction getRealInsn0(LabelAssigner assigner) {
return new BuilderInstruction11x(opc, (short) getRegA().getNumber());
}
示例13: getRealInsn0
import org.jf.dexlib2.builder.BuilderInstruction; //导入依赖的package包/类
@Override
protected BuilderInstruction getRealInsn0(LabelAssigner assigner) {
return new BuilderInstruction21t(opc, (short) getRegA().getNumber(),
assigner.getOrCreateLabel(target));
}
示例14: getRealInsn0
import org.jf.dexlib2.builder.BuilderInstruction; //导入依赖的package包/类
@Override
protected BuilderInstruction getRealInsn0(LabelAssigner assigner) {
return new BuilderInstruction12x(opc, (byte) getRegA().getNumber(), (byte) getRegB().getNumber());
}
示例15: getRealInsn0
import org.jf.dexlib2.builder.BuilderInstruction; //导入依赖的package包/类
@Override
protected BuilderInstruction getRealInsn0(LabelAssigner assigner) {
Register startReg = regs.get(0);
return new BuilderInstruction3rc(opc, startReg.getNumber(), regCount, referencedItem);
}