本文整理汇总了Java中org.jf.dexlib2.iface.instruction.Instruction.getOpcode方法的典型用法代码示例。如果您正苦于以下问题:Java Instruction.getOpcode方法的具体用法?Java Instruction.getOpcode怎么用?Java Instruction.getOpcode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jf.dexlib2.iface.instruction.Instruction
的用法示例。
在下文中一共展示了Instruction.getOpcode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: makeInstructionFormatMethodItem
import org.jf.dexlib2.iface.instruction.Instruction; //导入方法依赖的package包/类
public static InstructionMethodItem makeInstructionFormatMethodItem(
MethodDefinition methodDef, int codeAddress, Instruction instruction) {
if (instruction instanceof OffsetInstruction) {
return new OffsetInstructionFormatMethodItem(methodDef.classDef.options, methodDef, codeAddress,
(OffsetInstruction)instruction);
}
if (instruction instanceof UnresolvedOdexInstruction) {
return new UnresolvedOdexInstructionMethodItem(methodDef, codeAddress,
(UnresolvedOdexInstruction)instruction);
}
switch (instruction.getOpcode().format) {
case ArrayPayload:
return new ArrayDataMethodItem(methodDef, codeAddress, (ArrayPayload)instruction);
case PackedSwitchPayload:
return new PackedSwitchMethodItem(methodDef, codeAddress, (PackedSwitchPayload)instruction);
case SparseSwitchPayload:
return new SparseSwitchMethodItem(methodDef, codeAddress, (SparseSwitchPayload)instruction);
default:
return new InstructionMethodItem<Instruction>(methodDef, codeAddress, instruction);
}
}
示例2: fixInstructions
import org.jf.dexlib2.iface.instruction.Instruction; //导入方法依赖的package包/类
private void fixInstructions(@Nonnull MutableMethodImplementation methodImplementation) {
List<? extends Instruction> instructions = methodImplementation.getInstructions();
for (int i=0; i<instructions.size(); i++) {
Instruction instruction = instructions.get(i);
if (instruction.getOpcode() == Opcode.CONST_STRING) {
if (stringSection.getItemIndex(
(StringRef)((ReferenceInstruction)instruction).getReference()) >= 65536) {
methodImplementation.replaceInstruction(i, new BuilderInstruction31c(Opcode.CONST_STRING_JUMBO,
((OneRegisterInstruction)instruction).getRegisterA(),
((ReferenceInstruction)instruction).getReference()));
}
}
}
}
示例3: rewrite
import org.jf.dexlib2.iface.instruction.Instruction; //导入方法依赖的package包/类
@Nonnull @Override public Instruction rewrite(@Nonnull Instruction instruction) {
if (instruction instanceof ReferenceInstruction) {
switch (instruction.getOpcode().format) {
case Format20bc:
return new RewrittenInstruction20bc((Instruction20bc)instruction);
case Format21c:
return new RewrittenInstruction21c((Instruction21c)instruction);
case Format22c:
return new RewrittenInstruction22c((Instruction22c)instruction);
case Format31c:
return new RewrittenInstruction31c((Instruction31c)instruction);
case Format35c:
return new RewrittenInstruction35c((Instruction35c)instruction);
case Format3rc:
return new RewrittenInstruction3rc((Instruction3rc)instruction);
default:
throw new IllegalArgumentException();
}
}
return instruction;
}
示例4: fixInstructions
import org.jf.dexlib2.iface.instruction.Instruction; //导入方法依赖的package包/类
private void fixInstructions( MutableMethodImplementation methodImplementation) {
List<? extends Instruction> instructions = methodImplementation.getInstructions();
for (int i=0; i<instructions.size(); i++) {
Instruction instruction = instructions.get(i);
if (instruction.getOpcode() == Opcode.CONST_STRING) {
if (stringSection.getItemIndex(
(StringRef)((ReferenceInstruction)instruction).getReference()) >= 65536) {
methodImplementation.replaceInstruction(i, new BuilderInstruction31c(Opcode.CONST_STRING_JUMBO,
((OneRegisterInstruction)instruction).getRegisterA(),
((ReferenceInstruction)instruction).getReference()));
}
}
}
}
示例5: rewrite
import org.jf.dexlib2.iface.instruction.Instruction; //导入方法依赖的package包/类
@Override public Instruction rewrite( Instruction instruction) {
if (instruction instanceof ReferenceInstruction) {
switch (instruction.getOpcode().format) {
case Format20bc:
return new RewrittenInstruction20bc((Instruction20bc)instruction);
case Format21c:
return new RewrittenInstruction21c((Instruction21c)instruction);
case Format22c:
return new RewrittenInstruction22c((Instruction22c)instruction);
case Format31c:
return new RewrittenInstruction31c((Instruction31c)instruction);
case Format35c:
return new RewrittenInstruction35c((Instruction35c)instruction);
case Format3rc:
return new RewrittenInstruction3rc((Instruction3rc)instruction);
default:
throw new IllegalArgumentException();
}
}
return instruction;
}
示例6: analyze
import org.jf.dexlib2.iface.instruction.Instruction; //导入方法依赖的package包/类
private void analyze(@Nonnull DexBackedMethodImplementation implementation) {
cyclomaticComplexity = calculateComplexity(implementation);
registerCount = implementation.getRegisterCount();
tryCatchCount = implementation.getTryBlocks().size();
debugItemCount = Utils.makeCollection(implementation.getDebugItems()).size();
for (Instruction instruction : implementation.getInstructions()) {
instructionCount++;
Opcode op = instruction.getOpcode();
opCounts.adjustOrPutValue(op, 1, 1);
if (instruction instanceof ReferenceInstruction) {
ReferenceInstruction refInstr = (ReferenceInstruction) instruction;
switch (op.referenceType) {
case ReferenceType.METHOD:
MethodReference methodRef = (MethodReference) refInstr.getReference();
if (fullMethodSignatures) {
apiCounts.adjustOrPutValue(methodRef, 1, 1);
} else {
ShortMethodReference shortMethodRef = new ShortMethodReference(methodRef);
apiCounts.adjustOrPutValue(shortMethodRef, 1, 1);
}
break;
case ReferenceType.FIELD:
FieldReference fieldRef = (FieldReference) refInstr.getReference();
fieldReferenceCounts.adjustOrPutValue(fieldRef, 1, 1);
break;
case ReferenceType.STRING:
StringReference stringRef = (StringReference) refInstr.getReference();
stringReferenceCounts.adjustOrPutValue(stringRef, 1, 1);
break;
}
}
}
}
示例7: findSwitchPayload
import org.jf.dexlib2.iface.instruction.Instruction; //导入方法依赖的package包/类
public Instruction findSwitchPayload(int targetOffset, Opcode type) {
int targetIndex;
try {
targetIndex = instructionOffsetMap.getInstructionIndexAtCodeOffset(targetOffset);
} catch (InvalidInstructionOffset ex) {
throw new InvalidSwitchPayload(targetOffset);
}
//TODO: does dalvik let you pad with multiple nops?
//TODO: does dalvik let a switch instruction point to a non-payload instruction?
Instruction instruction = instructions.get(targetIndex);
if (instruction.getOpcode() != type) {
// maybe it's pointing to a NOP padding instruction. Look at the next instruction
if (instruction.getOpcode() == Opcode.NOP) {
targetIndex += 1;
if (targetIndex < instructions.size()) {
instruction = instructions.get(targetIndex);
if (instruction.getOpcode() == type) {
return instruction;
}
}
}
throw new InvalidSwitchPayload(targetOffset);
} else {
return instruction;
}
}
示例8: findPayloadOffset
import org.jf.dexlib2.iface.instruction.Instruction; //导入方法依赖的package包/类
public int findPayloadOffset(int targetOffset, Opcode type) {
int targetIndex;
try {
targetIndex = instructionOffsetMap.getInstructionIndexAtCodeOffset(targetOffset);
} catch (InvalidInstructionOffset ex) {
throw new InvalidSwitchPayload(targetOffset);
}
//TODO: does dalvik let you pad with multiple nops?
//TODO: does dalvik let a switch instruction point to a non-payload instruction?
Instruction instruction = instructions.get(targetIndex);
if (instruction.getOpcode() != type) {
// maybe it's pointing to a NOP padding instruction. Look at the next instruction
if (instruction.getOpcode() == Opcode.NOP) {
targetIndex += 1;
if (targetIndex < instructions.size()) {
instruction = instructions.get(targetIndex);
if (instruction.getOpcode() == type) {
return instructionOffsetMap.getInstructionCodeOffset(targetIndex);
}
}
}
throw new InvalidSwitchPayload(targetOffset);
} else {
return targetOffset;
}
}
示例9: findSwitchPayload
import org.jf.dexlib2.iface.instruction.Instruction; //导入方法依赖的package包/类
public int findSwitchPayload(int targetOffset, Opcode type) {
int targetIndex;
try {
targetIndex = instructionOffsetMap.getInstructionIndexAtCodeOffset(targetOffset);
} catch (InvalidInstructionOffset ex) {
throw new InvalidSwitchPayload(targetOffset);
}
//TODO: does dalvik let you pad with multiple nops?
//TODO: does dalvik let a switch instruction point to a non-payload instruction?
Instruction instruction = instructions.get(targetIndex);
if (instruction.getOpcode() != type) {
// maybe it's pointing to a NOP padding instruction. Look at the next instruction
if (instruction.getOpcode() == Opcode.NOP) {
targetIndex += 1;
if (targetIndex < instructions.size()) {
instruction = instructions.get(targetIndex);
if (instruction.getOpcode() == type) {
return instructionOffsetMap.getInstructionCodeOffset(targetIndex);
}
}
}
throw new InvalidSwitchPayload(targetOffset);
} else {
return targetOffset;
}
}
示例10: calculateComplexity
import org.jf.dexlib2.iface.instruction.Instruction; //导入方法依赖的package包/类
private static int calculateComplexity(@Nonnull DexBackedMethodImplementation implementation) {
// Cyclomatic complexity = <branches> - <exits> + 2
int branches = 0;
int exits = 0;
for (Instruction instruction : implementation.getInstructions()) {
switch (instruction.getOpcode()) {
case IF_EQ:
case IF_EQZ:
case IF_GE:
case IF_GEZ:
case IF_GT:
case IF_GTZ:
case IF_LE:
case IF_LEZ:
case IF_LT:
case IF_LTZ:
case IF_NE:
case IF_NEZ:
branches += 2;
break;
case PACKED_SWITCH_PAYLOAD:
branches += ((PackedSwitchPayload) instruction).getSwitchElements().size();
break;
case RETURN:
case RETURN_OBJECT:
case RETURN_VOID:
case RETURN_VOID_BARRIER:
case RETURN_VOID_NO_BARRIER:
case RETURN_WIDE:
exits += 1;
break;
case SPARSE_SWITCH_PAYLOAD:
branches += ((SparseSwitchPayload) instruction).getSwitchElements().size();
break;
case THROW:
case THROW_VERIFICATION_ERROR:
exits += 1;
break;
}
}
return branches - exits + 2;
}
示例11: writeDebugAndCodeItems
import org.jf.dexlib2.iface.instruction.Instruction; //导入方法依赖的package包/类
private void writeDebugAndCodeItems(@Nonnull DexDataWriter offsetWriter,
@Nonnull DeferredOutputStream temp) throws IOException {
ByteArrayOutputStream ehBuf = new ByteArrayOutputStream();
debugSectionOffset = offsetWriter.getPosition();
DebugWriter<StringKey, TypeKey> debugWriter =
new DebugWriter<StringKey, TypeKey>(stringSection, typeSection, offsetWriter);
DexDataWriter codeWriter = new DexDataWriter(temp, 0);
List<CodeItemOffset<MethodKey>> codeOffsets = Lists.newArrayList();
for (ClassKey classKey: classSection.getSortedClasses()) {
Collection<? extends MethodKey> directMethods = classSection.getSortedDirectMethods(classKey);
Collection<? extends MethodKey> virtualMethods = classSection.getSortedVirtualMethods(classKey);
Iterable<MethodKey> methods = Iterables.concat(directMethods, virtualMethods);
for (MethodKey methodKey: methods) {
List<? extends TryBlock<? extends ExceptionHandler>> tryBlocks =
classSection.getTryBlocks(methodKey);
Iterable<? extends Instruction> instructions = classSection.getInstructions(methodKey);
Iterable<? extends DebugItem> debugItems = classSection.getDebugItems(methodKey);
if (instructions != null && stringSection.hasJumboIndexes()) {
boolean needsFix = false;
for (Instruction instruction: instructions) {
if (instruction.getOpcode() == Opcode.CONST_STRING) {
if (stringSection.getItemIndex(
(StringRef)((ReferenceInstruction)instruction).getReference()) >= 65536) {
needsFix = true;
break;
}
}
}
if (needsFix) {
MutableMethodImplementation mutableMethodImplementation =
classSection.makeMutableMethodImplementation(methodKey);
fixInstructions(mutableMethodImplementation);
instructions = mutableMethodImplementation.getInstructions();
tryBlocks = mutableMethodImplementation.getTryBlocks();
debugItems = mutableMethodImplementation.getDebugItems();
}
}
int debugItemOffset = writeDebugItem(offsetWriter, debugWriter,
classSection.getParameterNames(methodKey), debugItems);
int codeItemOffset = writeCodeItem(codeWriter, ehBuf, methodKey, tryBlocks, instructions, debugItemOffset);
if (codeItemOffset != -1) {
codeOffsets.add(new CodeItemOffset<MethodKey>(methodKey, codeItemOffset));
}
}
}
offsetWriter.align();
codeSectionOffset = offsetWriter.getPosition();
codeWriter.close();
temp.writeTo(offsetWriter);
temp.close();
for (CodeItemOffset<MethodKey> codeOffset: codeOffsets) {
classSection.setCodeItemOffset(codeOffset.method, codeSectionOffset + codeOffset.codeOffset);
}
}
示例12: internCode
import org.jf.dexlib2.iface.instruction.Instruction; //导入方法依赖的package包/类
private void internCode(@Nonnull Method method) {
// this also handles parameter names, which aren't directly tied to the MethodImplementation, even though the debug items are
boolean hasInstruction = false;
MethodImplementation methodImpl = method.getImplementation();
if (methodImpl != null) {
for (Instruction instruction: methodImpl.getInstructions()) {
hasInstruction = true;
if (instruction instanceof ReferenceInstruction) {
Reference reference = ((ReferenceInstruction)instruction).getReference();
switch (instruction.getOpcode().referenceType) {
case ReferenceType.STRING:
stringPool.intern((StringReference)reference);
break;
case ReferenceType.TYPE:
typePool.intern((TypeReference)reference);
break;
case ReferenceType.FIELD:
fieldPool.intern((FieldReference) reference);
break;
case ReferenceType.METHOD:
methodPool.intern((MethodReference)reference);
break;
default:
throw new ExceptionWithContext("Unrecognized reference type: %d",
instruction.getOpcode().referenceType);
}
}
}
List<? extends TryBlock> tryBlocks = methodImpl.getTryBlocks();
if (!hasInstruction && tryBlocks.size() > 0) {
throw new ExceptionWithContext("Method %s has no instructions, but has try blocks.",
ReferenceUtil.getMethodDescriptor(method));
}
for (TryBlock<? extends ExceptionHandler> tryBlock: methodImpl.getTryBlocks()) {
for (ExceptionHandler handler: tryBlock.getExceptionHandlers()) {
typePool.internNullable(handler.getExceptionType());
}
}
}
}
示例13: of
import org.jf.dexlib2.iface.instruction.Instruction; //导入方法依赖的package包/类
public static ImmutableInstruction of(Instruction instruction) {
if (instruction instanceof ImmutableInstruction) {
return (ImmutableInstruction)instruction;
}
switch (instruction.getOpcode().format) {
case Format10t:
return ImmutableInstruction10t.of((Instruction10t)instruction);
case Format10x:
if (instruction instanceof UnknownInstruction) {
return ImmutableUnknownInstruction.of((UnknownInstruction)instruction);
}
return ImmutableInstruction10x.of((Instruction10x)instruction);
case Format11n:
return ImmutableInstruction11n.of((Instruction11n)instruction);
case Format11x:
return ImmutableInstruction11x.of((Instruction11x)instruction);
case Format12x:
return ImmutableInstruction12x.of((Instruction12x)instruction);
case Format20bc:
return ImmutableInstruction20bc.of((Instruction20bc)instruction);
case Format20t:
return ImmutableInstruction20t.of((Instruction20t)instruction);
case Format21c:
return ImmutableInstruction21c.of((Instruction21c)instruction);
case Format21ih:
return ImmutableInstruction21ih.of((Instruction21ih)instruction);
case Format21lh:
return ImmutableInstruction21lh.of((Instruction21lh)instruction);
case Format21s:
return ImmutableInstruction21s.of((Instruction21s)instruction);
case Format21t:
return ImmutableInstruction21t.of((Instruction21t)instruction);
case Format22b:
return ImmutableInstruction22b.of((Instruction22b)instruction);
case Format22c:
return ImmutableInstruction22c.of((Instruction22c)instruction);
case Format22cs:
return ImmutableInstruction22cs.of((Instruction22cs)instruction);
case Format22s:
return ImmutableInstruction22s.of((Instruction22s)instruction);
case Format22t:
return ImmutableInstruction22t.of((Instruction22t)instruction);
case Format22x:
return ImmutableInstruction22x.of((Instruction22x)instruction);
case Format23x:
return ImmutableInstruction23x.of((Instruction23x)instruction);
case Format30t:
return ImmutableInstruction30t.of((Instruction30t)instruction);
case Format31c:
return ImmutableInstruction31c.of((Instruction31c)instruction);
case Format31i:
return ImmutableInstruction31i.of((Instruction31i)instruction);
case Format31t:
return ImmutableInstruction31t.of((Instruction31t)instruction);
case Format32x:
return ImmutableInstruction32x.of((Instruction32x)instruction);
case Format35c:
return ImmutableInstruction35c.of((Instruction35c)instruction);
case Format35mi:
return ImmutableInstruction35mi.of((Instruction35mi)instruction);
case Format35ms:
return ImmutableInstruction35ms.of((Instruction35ms)instruction);
case Format3rc:
return ImmutableInstruction3rc.of((Instruction3rc)instruction);
case Format3rmi:
return ImmutableInstruction3rmi.of((Instruction3rmi)instruction);
case Format3rms:
return ImmutableInstruction3rms.of((Instruction3rms)instruction);
case Format51l:
return ImmutableInstruction51l.of((Instruction51l)instruction);
case PackedSwitchPayload:
return ImmutablePackedSwitchPayload.of((PackedSwitchPayload) instruction);
case SparseSwitchPayload:
return ImmutableSparseSwitchPayload.of((SparseSwitchPayload) instruction);
case ArrayPayload:
return ImmutableArrayPayload.of((ArrayPayload) instruction);
default:
throw new RuntimeException("Unexpected instruction type");
}
}
示例14: writeDebugAndCodeItems
import org.jf.dexlib2.iface.instruction.Instruction; //导入方法依赖的package包/类
private void writeDebugAndCodeItems( DexDataWriter offsetWriter,
DeferredOutputStream temp) throws IOException {
ByteArrayOutputStream ehBuf = new ByteArrayOutputStream();
debugSectionOffset = offsetWriter.getPosition();
DebugWriter<StringKey, TypeKey> debugWriter =
new DebugWriter<StringKey, TypeKey>(stringSection, typeSection, offsetWriter);
DexDataWriter codeWriter = new DexDataWriter(temp, 0);
List<CodeItemOffset<MethodKey>> codeOffsets = Lists.newArrayList();
for (ClassKey classKey: classSection.getSortedClasses()) {
Collection<? extends MethodKey> directMethods = classSection.getSortedDirectMethods(classKey);
Collection<? extends MethodKey> virtualMethods = classSection.getSortedVirtualMethods(classKey);
Iterable<MethodKey> methods = Iterables.concat(directMethods, virtualMethods);
for (MethodKey methodKey: methods) {
List<? extends TryBlock<? extends ExceptionHandler>> tryBlocks =
classSection.getTryBlocks(methodKey);
Iterable<? extends Instruction> instructions = classSection.getInstructions(methodKey);
Iterable<? extends DebugItem> debugItems = classSection.getDebugItems(methodKey);
if (instructions != null && stringSection.hasJumboIndexes()) {
boolean needsFix = false;
for (Instruction instruction: instructions) {
if (instruction.getOpcode() == Opcode.CONST_STRING) {
if (stringSection.getItemIndex(
(StringRef)((ReferenceInstruction)instruction).getReference()) >= 65536) {
needsFix = true;
break;
}
}
}
if (needsFix) {
MutableMethodImplementation mutableMethodImplementation =
classSection.makeMutableMethodImplementation(methodKey);
fixInstructions(mutableMethodImplementation);
instructions = mutableMethodImplementation.getInstructions();
tryBlocks = mutableMethodImplementation.getTryBlocks();
debugItems = mutableMethodImplementation.getDebugItems();
}
}
int debugItemOffset = writeDebugItem(offsetWriter, debugWriter,
classSection.getParameterNames(methodKey), debugItems);
int codeItemOffset;
try {
codeItemOffset = writeCodeItem(
codeWriter, ehBuf, methodKey, tryBlocks, instructions, debugItemOffset);
} catch (RuntimeException ex) {
throw new ExceptionWithContext(ex, "Exception occurred while writing code_item for method %s",
methodSection.getMethodReference(methodKey));
}
if (codeItemOffset != -1) {
codeOffsets.add(new CodeItemOffset<MethodKey>(methodKey, codeItemOffset));
}
}
}
offsetWriter.align();
codeSectionOffset = offsetWriter.getPosition();
codeWriter.close();
temp.writeTo(offsetWriter);
temp.close();
for (CodeItemOffset<MethodKey> codeOffset: codeOffsets) {
classSection.setCodeItemOffset(codeOffset.method, codeSectionOffset + codeOffset.codeOffset);
}
}
示例15: internCode
import org.jf.dexlib2.iface.instruction.Instruction; //导入方法依赖的package包/类
private void internCode( Method method) {
// this also handles parameter names, which aren't directly tied to the MethodImplementation, even though the debug items are
boolean hasInstruction = false;
MethodImplementation methodImpl = method.getImplementation();
if (methodImpl != null) {
for (Instruction instruction: methodImpl.getInstructions()) {
hasInstruction = true;
if (instruction instanceof ReferenceInstruction) {
Reference reference = ((ReferenceInstruction)instruction).getReference();
switch (instruction.getOpcode().referenceType) {
case ReferenceType.STRING:
dexPool.stringSection.intern((StringReference)reference);
break;
case ReferenceType.TYPE:
dexPool.typeSection.intern((TypeReference)reference);
break;
case ReferenceType.FIELD:
dexPool.fieldSection.intern((FieldReference) reference);
break;
case ReferenceType.METHOD:
dexPool.methodSection.intern((MethodReference)reference);
break;
default:
throw new ExceptionWithContext("Unrecognized reference type: %d",
instruction.getOpcode().referenceType);
}
}
}
List<? extends TryBlock> tryBlocks = methodImpl.getTryBlocks();
if (!hasInstruction && tryBlocks.size() > 0) {
throw new ExceptionWithContext("Method %s has no instructions, but has try blocks.",
ReferenceUtil.getMethodDescriptor(method));
}
for (TryBlock<? extends ExceptionHandler> tryBlock: methodImpl.getTryBlocks()) {
for (ExceptionHandler handler: tryBlock.getExceptionHandlers()) {
dexPool.typeSection.internNullable(handler.getExceptionType());
}
}
}
}