本文整理汇总了Java中org.objectweb.asm.tree.InsnList.iterator方法的典型用法代码示例。如果您正苦于以下问题:Java InsnList.iterator方法的具体用法?Java InsnList.iterator怎么用?Java InsnList.iterator使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.objectweb.asm.tree.InsnList
的用法示例。
在下文中一共展示了InsnList.iterator方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findMethodCallInstruction
import org.objectweb.asm.tree.InsnList; //导入方法依赖的package包/类
@SuppressWarnings("unchecked") // ASM API
@Nullable
private static AbstractInsnNode findMethodCallInstruction(
@NonNull InsnList instructions,
@NonNull String owner,
@NonNull String name,
@NonNull String desc) {
ListIterator<AbstractInsnNode> iterator = instructions.iterator();
while (iterator.hasNext()) {
AbstractInsnNode insnNode = iterator.next();
if (insnNode.getType() == AbstractInsnNode.METHOD_INSN) {
MethodInsnNode methodInsnNode = (MethodInsnNode) insnNode;
if ((methodInsnNode.owner.equals(owner))
&& (methodInsnNode.name.equals(name))
&& (methodInsnNode.desc.equals(desc))) {
return methodInsnNode;
}
}
}
return null;
}
示例2: findJumpTargets
import org.objectweb.asm.tree.InsnList; //导入方法依赖的package包/类
private static Set<AbstractInsnNode> findJumpTargets(final InsnList instructions) {
final Set<AbstractInsnNode> jumpTargets = new HashSet<AbstractInsnNode>();
final ListIterator<AbstractInsnNode> it = instructions.iterator();
while (it.hasNext()) {
final AbstractInsnNode o = it.next();
if (o instanceof JumpInsnNode) {
jumpTargets.add(((JumpInsnNode) o).label);
} else if (o instanceof TableSwitchInsnNode) {
final TableSwitchInsnNode twn = (TableSwitchInsnNode) o;
jumpTargets.add(twn.dflt);
jumpTargets.addAll(twn.labels);
} else if (o instanceof LookupSwitchInsnNode) {
final LookupSwitchInsnNode lsn = (LookupSwitchInsnNode) o;
jumpTargets.add(lsn.dflt);
jumpTargets.addAll(lsn.labels);
}
}
return jumpTargets;
}
示例3: addTraceReturn
import org.objectweb.asm.tree.InsnList; //导入方法依赖的package包/类
private void addTraceReturn() {
InsnList il = this.mn.instructions;
Iterator<AbstractInsnNode> it = il.iterator();
while (it.hasNext()) {
AbstractInsnNode abstractInsnNode = it.next();
switch (abstractInsnNode.getOpcode()) {
case Opcodes.RETURN:
il.insertBefore(abstractInsnNode, getVoidReturnTraceInstructions());
break;
case Opcodes.IRETURN:
case Opcodes.LRETURN:
case Opcodes.FRETURN:
case Opcodes.ARETURN:
case Opcodes.DRETURN:
il.insertBefore(abstractInsnNode, getReturnTraceInstructions());
}
}
}
示例4: addTraceThrow
import org.objectweb.asm.tree.InsnList; //导入方法依赖的package包/类
private void addTraceThrow() {
InsnList il = this.mn.instructions;
Iterator<AbstractInsnNode> it = il.iterator();
while (it.hasNext()) {
AbstractInsnNode abstractInsnNode = it.next();
switch (abstractInsnNode.getOpcode()) {
case Opcodes.ATHROW:
il.insertBefore(abstractInsnNode, getThrowTraceInstructions());
break;
}
}
}
示例5: handleMethodNode
import org.objectweb.asm.tree.InsnList; //导入方法依赖的package包/类
/**
* Add all possible calls for a given method
*
* @param callGraph
* @param mn
*/
@SuppressWarnings("unchecked")
private static void handleMethodNode(GetStaticGraph staticUsageTree,
ClassNode cn, MethodNode mn, int depth) {
InsnList instructions = mn.instructions;
Iterator<AbstractInsnNode> iterator = instructions.iterator();
// TODO: This really shouldn't be here but in its own class
while (iterator.hasNext()) {
AbstractInsnNode insn = iterator.next();
if (insn instanceof MethodInsnNode) {
handleMethodInsnNode(staticUsageTree, cn, mn,
(MethodInsnNode) insn, depth + 1);
} else if (insn instanceof FieldInsnNode) {
handleFieldInsnNode(staticUsageTree, cn, mn,
(FieldInsnNode) insn, depth + 1);
}
}
}
示例6: handleMethodNode
import org.objectweb.asm.tree.InsnList; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private void handleMethodNode(Set<String> calledClasses, ClassNode cn, MethodNode mn,
Set<String> targetClasses) throws IOException {
InsnList instructions = mn.instructions;
Iterator<AbstractInsnNode> iterator = instructions.iterator();
while (iterator.hasNext()) {
AbstractInsnNode insn = iterator.next();
if (insn instanceof MethodInsnNode) {
String name = ResourceList.getClassNameFromResourcePath(((MethodInsnNode) insn).owner);
if (!targetClasses.contains(name))
continue;
if (isValidClass(name))
calledClasses.add(name);
}
}
}
示例7: searchForOpcodes
import org.objectweb.asm.tree.InsnList; //导入方法依赖的package包/类
/**
* Find instructions in a certain class that are of a certain set of opcodes.
* @param insnList instruction list to search through
* @param opcodes opcodes to search for
* @return list of instructions that contain the opcodes being searched for
* @throws NullPointerException if any argument is {@code null}
* @throws IllegalArgumentException if {@code opcodes} is empty
*/
public static List<AbstractInsnNode> searchForOpcodes(InsnList insnList, int ... opcodes) {
Validate.notNull(insnList);
Validate.notNull(opcodes);
Validate.isTrue(opcodes.length > 0);
List<AbstractInsnNode> ret = new LinkedList<>();
Set<Integer> opcodeSet = new HashSet<>();
Arrays.stream(opcodes).forEach((x) -> opcodeSet.add(x));
Iterator<AbstractInsnNode> it = insnList.iterator();
while (it.hasNext()) {
AbstractInsnNode insnNode = it.next();
if (opcodeSet.contains(insnNode.getOpcode())) {
ret.add(insnNode);
}
}
return ret;
}
示例8: findLineNumberForInstruction
import org.objectweb.asm.tree.InsnList; //导入方法依赖的package包/类
/**
* Find line number associated with an instruction.
* @param insnList instruction list for method
* @param insnNode instruction within method being searched against
* @throws NullPointerException if any argument is {@code null} or contains {@code null}
* @throws IllegalArgumentException if arguments aren't all from the same method
* @return line number node associated with the instruction, or {@code null} if no line number exists
*/
public static LineNumberNode findLineNumberForInstruction(InsnList insnList, AbstractInsnNode insnNode) {
Validate.notNull(insnList);
Validate.notNull(insnNode);
int idx = insnList.indexOf(insnNode);
Validate.isTrue(idx != -1);
// Get index of labels and insnNode within method
ListIterator<AbstractInsnNode> insnIt = insnList.iterator(idx);
while (insnIt.hasPrevious()) {
AbstractInsnNode node = insnIt.previous();
if (node instanceof LineNumberNode) {
return (LineNumberNode) node;
}
}
return null;
}
示例9: findNode
import org.objectweb.asm.tree.InsnList; //导入方法依赖的package包/类
public AbstractInsnNode findNode(InsnList instructions, AbstractInsnNode node) {
ListIterator<AbstractInsnNode> iterator = instructions.iterator();
while (iterator.hasNext()) {
AbstractInsnNode insn = iterator.next();
if (areNodesEqual(insn, node)) {
return insn;
}
}
return null;
}
示例10: asList
import org.objectweb.asm.tree.InsnList; //导入方法依赖的package包/类
public static List<AbstractInsnNode> asList(final InsnList instructions) {
final List<AbstractInsnNode> list = new ArrayList<AbstractInsnNode>(instructions.size());
final Iterator<AbstractInsnNode> iterator = (Iterator<AbstractInsnNode>)instructions.iterator();
while (iterator.hasNext()) {
list.add(iterator.next());
}
return list;
}
示例11: isSimpleGetter
import org.objectweb.asm.tree.InsnList; //导入方法依赖的package包/类
/**
* Return true if the instructions are supposed to be a simple getter.
*
* <code>
* 1 (IRRELEVANT INTERNAL INSTRUCTION)
* 2 (IRRELEVANT INTERNAL INSTRUCTION)
* 3 ALOAD
* 4 GETFIELD
* 5 xRETURN
* 6 (IRRELEVANT INTERNAL INSTRUCTION)
* </code>
*/
private boolean isSimpleGetter(InsnList instructionList) {
if (instructionList.size() != 6) {
return false;
}
@SuppressWarnings("unchecked")
Iterator<AbstractInsnNode> it = instructionList.iterator();
AbstractInsnNode node;
// drop instruction 1 (irrelevant)
it.next();
// drop instruction 2 (irrelevant)
it.next();
// instruction 3
node = it.next();
if (node.getOpcode() != Opcodes.ALOAD) {
return false;
}
// instruction 4
node = it.next();
if (node.getOpcode() != Opcodes.GETFIELD) {
return false;
}
// instruction 5
node = it.next();
if (!OpcodesUtility.isXRETURN(node.getOpcode())) {
return false;
}
return true;
}
示例12: isSimpleConstantGetter
import org.objectweb.asm.tree.InsnList; //导入方法依赖的package包/类
/**
* Return true if the instructions are supposed to be a simple constant
* getter. <code>
* 1 (IRRELEVANT INTERNAL INSTRUCTION)
* 2 (IRRELEVANT INTERNAL INSTRUCTION)
* 3 xCONST_x | xPUSH | LDC | LDC_W | LDC2_W
* 4 xRETURN 5 (IRRELEVANT INTERNAL INSTRUCTION)
* </code>
*/
private boolean isSimpleConstantGetter(InsnList instructionList) {
if (instructionList.size() != 5) {
return false;
} else {
@SuppressWarnings("unchecked")
Iterator<AbstractInsnNode> it = instructionList.iterator();
AbstractInsnNode node;
// drop instruction 1 (irrelevant)
it.next();
// drop instruction 2 (irrelevant)
it.next();
// instruction 3
node = it.next();
if (node.getOpcode() > 20) {
return false;
}
// instruction 4
node = it.next();
if (!OpcodesUtility.isXRETURN(node.getOpcode())) {
return false;
}
return true;
}
}
示例13: handleMethodNode
import org.objectweb.asm.tree.InsnList; //导入方法依赖的package包/类
/**
* Add all possible calls for a given method
*
* @param callGraph
* @param mn
*/
@SuppressWarnings("unchecked")
private static void handleMethodNode(CallGraph callGraph, ClassNode cn, MethodNode mn, int depth) {
handlePublicMethodNode(callGraph, cn, mn);
// TODO: Integrate this properly - it is currently an unexpected side-effect
if(!ExceptionTransformationClassAdapter.methodExceptionMap.containsKey(cn.name))
ExceptionTransformationClassAdapter.methodExceptionMap.put(cn.name, new LinkedHashMap<>());
String methodNameDesc = mn.name + mn.desc;
Set<Type> exceptionTypes = new LinkedHashSet<>();
if(mn.exceptions != null) {
for (String exceptionName : ((List<String>)mn.exceptions)) {
exceptionTypes.add(Type.getType(exceptionName));
}
}
ExceptionTransformationClassAdapter.methodExceptionMap.get(cn.name).put(methodNameDesc, exceptionTypes);
InsnList instructions = mn.instructions;
Iterator<AbstractInsnNode> iterator = instructions.iterator();
// TODO: This really shouldn't be here but in its own class
while (iterator.hasNext()) {
AbstractInsnNode insn = iterator.next();
if (insn instanceof MethodInsnNode) {
handleMethodInsnNode(callGraph, cn, mn, (MethodInsnNode) insn, depth + 1);
}
}
}
示例14: findInvocationsOf
import org.objectweb.asm.tree.InsnList; //导入方法依赖的package包/类
/**
* Find invocations of a certain method.
* @param insnList instruction list to search through
* @param expectedMethod type of method being invoked
* @return list of invocations (may be nodes of type {@link MethodInsnNode} or {@link InvokeDynamicInsnNode})
* @throws NullPointerException if any argument is {@code null}
* @throws NullPointerException if {@code expectedMethodType} isn't of sort {@link Type#METHOD}
*/
public static List<AbstractInsnNode> findInvocationsOf(InsnList insnList, Method expectedMethod) {
Validate.notNull(insnList);
Validate.notNull(expectedMethod);
List<AbstractInsnNode> ret = new ArrayList<>();
Type expectedMethodDesc = Type.getType(expectedMethod);
Type expectedMethodOwner = Type.getType(expectedMethod.getDeclaringClass());
String expectedMethodName = expectedMethod.getName();
Iterator<AbstractInsnNode> it = insnList.iterator();
while (it.hasNext()) {
AbstractInsnNode instructionNode = it.next();
Type methodDesc;
Type methodOwner;
String methodName;
if (instructionNode instanceof MethodInsnNode) {
MethodInsnNode methodInsnNode = (MethodInsnNode) instructionNode;
methodDesc = Type.getType(methodInsnNode.desc);
methodOwner = Type.getObjectType(methodInsnNode.owner);
methodName = expectedMethod.getName();
} else {
continue;
}
if (methodDesc.equals(expectedMethodDesc) && methodOwner.equals(expectedMethodOwner) && methodName.equals(expectedMethodName)) {
ret.add(instructionNode);
}
}
return ret;
}
示例15: findMatchingCallSites
import org.objectweb.asm.tree.InsnList; //导入方法依赖的package包/类
List<Result> findMatchingCallSites(final InsnList instructions, final List<LocalVariableAnnotationNode> varAnnotations, final Map<Integer, List<AnnotationNode>> paramAnnotations) {
final List<Result> result = new ArrayList<>();
for (@SuppressWarnings("unchecked") Iterator<AbstractInsnNode> i = instructions.iterator(); i.hasNext(); ) {
final AbstractInsnNode ins = i.next();
if (ins instanceof MethodInsnNode) {
final MethodInsnNode mins = (MethodInsnNode)ins;
final Result entry = findMatchingCallSite(mins, varAnnotations, paramAnnotations);
if (entry != null) {
result.add(entry);
}
}
}
return result;
}