本文整理匯總了Java中org.objectweb.asm.tree.MethodNode類的典型用法代碼示例。如果您正苦於以下問題:Java MethodNode類的具體用法?Java MethodNode怎麽用?Java MethodNode使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
MethodNode類屬於org.objectweb.asm.tree包,在下文中一共展示了MethodNode類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: transform
import org.objectweb.asm.tree.MethodNode; //導入依賴的package包/類
@Override
public void transform(ClassNode clazz, MethodNode method, InsnMatcher matcher) {
AbstractInsnNode[] match = Iterators.getOnlyElement(matcher.match("BIPUSH ISTORE", m -> {
IntInsnNode push = (IntInsnNode) m[0];
if (push.operand != 50) {
return false;
}
VarInsnNode store = (VarInsnNode) m[1];
LocalVariableNode node = AsmUtils.getLocalVariable(method, store.var, store);
return node != null && node.name.equals("resource") && node.desc.equals("I");
}));
method.instructions.remove(match[0]);
method.instructions.remove(match[1]);
}
示例2: dump
import org.objectweb.asm.tree.MethodNode; //導入依賴的package包/類
private static void dump(MethodNode method) {
Textifier textifier = new Textifier();
method.accept(new TraceMethodVisitor(textifier));
StringWriter writer = new StringWriter();
try (PrintWriter pw = new PrintWriter(writer)) {
textifier.print(pw);
}
System.out.println(writer.toString());
}
示例3: getMethodText
import org.objectweb.asm.tree.MethodNode; //導入依賴的package包/類
private String getMethodText(MethodNode node) {
Type typeMethod = Type.getMethodType(node.desc);
// Args string
String args = "";
for (Type t : typeMethod.getArgumentTypes()) {
args += getTypeStr(t, options) + ", ";
}
if (args.endsWith(", ")) {
args = args.substring(0, args.length() - 2);
}
String s = italic(color(getTheme().memberReturnType, getTypeStr(typeMethod.getReturnType(), options))) + " ";
s += color(getTheme().memberName, escape(node.name)) + "(";
s += color(getTheme().memberParameterType, args);
s += ")";
return s;
}
示例4: transform
import org.objectweb.asm.tree.MethodNode; //導入依賴的package包/類
@Override
public void transform(ClassNode clazz, MethodNode method, InsnMatcher matcher) {
method.tryCatchBlocks.clear();
method.localVariables.clear();
method.instructions.clear();
/* this.loginHandlerList.put(SteamIdAsString, loginHandler); */
method.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0));
method.instructions.add(new FieldInsnNode(Opcodes.GETFIELD, "com/wurmonline/server/steam/SteamHandler", "loginHandlerList", "Ljava/util/Map;"));
method.instructions.add(new VarInsnNode(Opcodes.ALOAD, 1));
method.instructions.add(new VarInsnNode(Opcodes.ALOAD, 2));
method.instructions.add(new MethodInsnNode(Opcodes.INVOKEINTERFACE, "java/util/Map", "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;", true));
method.instructions.add(new InsnNode(Opcodes.POP));
/* return true; */
method.instructions.add(new InsnNode(Opcodes.ICONST_1));
method.instructions.add(new InsnNode(Opcodes.IRETURN));
}
示例5: createSubClass
import org.objectweb.asm.tree.MethodNode; //導入依賴的package包/類
public static <T> Class<? extends T> createSubClass(Class<T> superClass, String nameSuffix, int constructorParams)
{
ClassNode superNode = createClassNode(superClass);
MethodNode constructor = findConstructor(superNode, constructorParams);
String className = superClass.getName().replace('.', '/') + "_" + nameSuffix.replace(":", "_");
ClassWriter cw = new ClassWriter(0);
cw.visit(V1_7, ACC_PUBLIC + ACC_SUPER, className, null, Type.getInternalName(superClass), null);
// Constructor
MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, constructor.name, constructor.desc, null, null);
int[] opcodes = createLoadOpcodes(constructor);
for (int i = 0; i < opcodes.length; i++)
{
mv.visitVarInsn(opcodes[i], i);
}
mv.visitMethodInsn(INVOKESPECIAL, Type.getInternalName(superClass), constructor.name, constructor.desc, false);
mv.visitInsn(RETURN);
mv.visitMaxs(constructorParams + 1, constructorParams + 1);
mv.visitEnd();
byte[] byteCode = cw.toByteArray();
return (Class<? extends T>) createClassFromBytes(className, byteCode);
}
示例6: getMethodTransformers
import org.objectweb.asm.tree.MethodNode; //導入依賴的package包/類
@Override
public MethodTransformer[] getMethodTransformers() {
MethodTransformer transformLoadWorld = new MethodTransformer() {
@Override
public MethodName getName() {
return Names.Minecraft_loadWorld;
}
@Override
public void transform(ClassNode classNode, MethodNode method, boolean obfuscated) {
CLTLog.info("Found method: " + method.name + " " + method.desc);
CLTLog.info("begining at start of method " + getName().all());
InsnList toInsert = new InsnList();
toInsert.add(new VarInsnNode(ALOAD, 1)); //worldClientIn
toInsert.add(new MethodInsnNode(INVOKESTATIC, Type.getInternalName(RenderUtil.class),
"onWorldLoad", "(L" + Type.getInternalName(WorldClient.class) + ";)V", false));
method.instructions.insertBefore(method.instructions.getFirst(), toInsert);
}
};
return new MethodTransformer[] {transformLoadWorld};
}
示例7: getMethodTransformers
import org.objectweb.asm.tree.MethodNode; //導入依賴的package包/類
@Override
public MethodTransformer[] getMethodTransformers() {
MethodTransformer loadWorldTransformer = new MethodTransformer() {
public String getMethodName() {return CoreLoader.isObfuscated ? "a" : "loadWorld";}
public String getDescName() {return "(L" + (CoreLoader.isObfuscated ? "bnq" : Type.getInternalName(WorldClient.class)) + ";Ljava/lang/String;)V";}
public void transform(ClassNode classNode, MethodNode method, boolean obfuscated) {
CLTLog.info("Found method: " + method.name + " " + method.desc);
CLTLog.info("begining at start of method " + getMethodName());
//TransformerUtil.onWorldLoad(WorldClient worldClientIn)
InsnList toInsert = new InsnList();
toInsert.add(new VarInsnNode(ALOAD, 1)); //worldClientIn
toInsert.add(new MethodInsnNode(INVOKESTATIC, Type.getInternalName(TransformerUtil.class),
"onWorldLoad", "(L" + Type.getInternalName(WorldClient.class) + ";)V", false));
method.instructions.insertBefore(method.instructions.getFirst(), toInsert);
}
};
return new MethodTransformer[] {loadWorldTransformer};
}
示例8: checkArrayArgs
import org.objectweb.asm.tree.MethodNode; //導入依賴的package包/類
private void checkArrayArgs(MethodNode methodNode, Frame<BasicValue> logMessageFrame, Frame<BasicValue> arraySizeFrame,
int lineNumber, MethodInsnNode methodInsn, int messageIndex, int arrayIndex) {
BasicValue arraySizeObject = getStackValue(arraySizeFrame, methodInsn, arrayIndex);
if (arraySizeObject instanceof ArraySizeBasicValue == false) {
wrongUsageCallback.accept(new WrongLoggerUsage(className, methodNode.name, methodInsn.name, lineNumber,
"Could not determine size of array"));
return;
}
ArraySizeBasicValue arraySize = (ArraySizeBasicValue) arraySizeObject;
PlaceHolderStringBasicValue logMessageLength = checkLogMessageConsistency(methodNode, logMessageFrame, lineNumber, methodInsn,
messageIndex, arraySize.minValue);
if (logMessageLength == null) {
return;
}
if (arraySize.minValue != arraySize.maxValue) {
wrongUsageCallback.accept(new WrongLoggerUsage(className, methodNode.name, methodInsn.name, lineNumber,
"Multiple parameter arrays with conflicting sizes"));
return;
}
assert logMessageLength.minValue == logMessageLength.maxValue && arraySize.minValue == arraySize.maxValue;
if (logMessageLength.minValue != arraySize.minValue) {
wrongUsageCallback.accept(new WrongLoggerUsage(className, methodNode.name, methodInsn.name, lineNumber,
"Expected " + logMessageLength.minValue + " arguments but got " + arraySize.minValue));
return;
}
}
示例9: checkLogMessageConsistency
import org.objectweb.asm.tree.MethodNode; //導入依賴的package包/類
private PlaceHolderStringBasicValue checkLogMessageConsistency(MethodNode methodNode, Frame<BasicValue> logMessageFrame,
int lineNumber, MethodInsnNode methodInsn, int messageIndex,
int argsSize) {
BasicValue logMessageLengthObject = getStackValue(logMessageFrame, methodInsn, messageIndex);
if (logMessageLengthObject instanceof PlaceHolderStringBasicValue == false) {
if (argsSize > 0) {
wrongUsageCallback.accept(new WrongLoggerUsage(className, methodNode.name, methodInsn.name, lineNumber,
"First argument must be a string constant so that we can statically ensure proper place holder usage"));
} else {
// don't check logger usage for logger.warn(someObject)
}
return null;
}
PlaceHolderStringBasicValue logMessageLength = (PlaceHolderStringBasicValue) logMessageLengthObject;
if (logMessageLength.minValue != logMessageLength.maxValue) {
wrongUsageCallback.accept(new WrongLoggerUsage(className, methodNode.name, methodInsn.name, lineNumber,
"Multiple log messages with conflicting number of place holders"));
return null;
}
return logMessageLength;
}
示例10: replaceInvokeSpecial
import org.objectweb.asm.tree.MethodNode; //導入依賴的package包/類
private void replaceInvokeSpecial(ClassNode clazz, List<MethodNode> toReplace)
{
for (MethodNode method : clazz.methods)
{
for (Iterator<AbstractInsnNode> it = method.instructions.iterator(); it.hasNext();)
{
AbstractInsnNode insn = it.next();
if (insn.getOpcode() == INVOKESPECIAL)
{
MethodInsnNode mInsn = (MethodInsnNode) insn;
for (MethodNode n : toReplace)
{
if (n.name.equals(mInsn.name) && n.desc.equals(mInsn.desc))
{
mInsn.setOpcode(INVOKEVIRTUAL);
break;
}
}
}
}
}
}
示例11: callDetour
import org.objectweb.asm.tree.MethodNode; //導入依賴的package包/類
private Detour callDetour(ClassNode cn, MethodNode mn, AnnotationNode a) {
String owner = getFirstParameter(mn);
if (owner == null) {
_log.debug("Could not get parameter type for detour " + mn.name + mn.desc);
return null;
}
MethodInsnNode mi = getMethodInstruction(mn, owner, mn.name);
if (mi == null) {
_log.debug("Could not get method instruction for detour " + mn.name + mn.desc);
return null;
}
CallDetour detour = new CallDetour(_log);
detour.matchMethod = mn.name;
detour.matchDesc = mi.desc;
detour.owner = owner.replace('/', '.');
detour.detourOwner = cn.name;
detour.detourDesc = mn.desc;
return detour;
}
示例12: analyzeInnerClass
import org.objectweb.asm.tree.MethodNode; //導入依賴的package包/類
@SuppressWarnings(UNCHECKED)
void analyzeInnerClass(ClassNode innerClass) {
if (methodNode.name.equals(innerClass.outerMethod)
&& methodNode.desc.equals(innerClass.outerMethodDesc)) {
// s'il y a une classe interne créée dans cette méthode
// utilisant éventuellement une variable finale de cette méthode,
// alors on cherche les constantes de variables (et uniquement celles-ci) dans toutes ses méthodes
// (si ce n'est pas une constante, alors elle serait déjà détectée utilisée dans la méthode)
for (final MethodNode innerMethodNode : (List<MethodNode>) innerClass.methods) {
for (final Iterator<AbstractInsnNode> it = innerMethodNode.instructions
.iterator(); it.hasNext();) {
// CHECKSTYLE:OFF
final AbstractInsnNode instruction = it.next();
// CHECKSTYLE:ON
analyzeConstantInstruction(instruction);
if (localVariables.isEmpty()) {
// si toutes les variables ont été utilisées, inutile de continuer à lire les instructions
return;
}
}
}
}
}
示例13: analyzeClassesForLocalDeadCode
import org.objectweb.asm.tree.MethodNode; //導入依賴的package包/類
@SuppressWarnings("unchecked")
private void analyzeClassesForLocalDeadCode(String dir, Set<String> classesToVisit)
throws IOException, XMLStreamException {
for (final String className : classesToVisit) {
if (isInterrupted()) {
break;
}
// les classes *SoapBindingStub générées par Apache Axis
// contiennent beaucoup des variables locales non utilisées,
// mais il est inutile de le signaler puisque c'est généré par Axis
if (!className.endsWith("SoapBindingStub")) {
final ClassNode classNode = new ClassNode();
final ClassReader classReader = createClassReader(dir, className);
classReader.accept(classNode, ClassReader.EXPAND_FRAMES);
for (final MethodNode methodNode : (List<MethodNode>) classNode.methods) {
analyzeMethodForLocalDeadCode(dir, className, classNode, methodNode);
analyzeMethodForSelfAssignments(className, methodNode);
if (Factory.createStringToStringAnalyzer(methodNode).analyze()) {
report.reportStringToString(className, methodNode);
suspectCount++;
}
}
}
}
}
示例14: stripMethod
import org.objectweb.asm.tree.MethodNode; //導入依賴的package包/類
private void stripMethod(ClassNode classNode, String methodDescriptor)
{
if(classNode.name.endsWith("$class"))
{
String subName = classNode.name.substring(0, classNode.name.length() - 6);
int pos = methodDescriptor.indexOf('(') + 1;
methodDescriptor = methodDescriptor.substring(0, pos) + 'L' + subName + ';' + methodDescriptor.substring(pos);
}
for (ListIterator<MethodNode> iterator = classNode.methods.listIterator(); iterator.hasNext();)
{
MethodNode method = iterator.next();
if (methodDescriptor.equals(method.name+method.desc))
{
iterator.remove();
if (logDebugInfo) FMLRelaunchLog.finer("Optional removal - method %s removed", methodDescriptor);
return;
}
}
if (logDebugInfo) FMLRelaunchLog.finer("Optional removal - method %s NOT removed - not found", methodDescriptor);
}
示例15: MergeAdapter
import org.objectweb.asm.tree.MethodNode; //導入依賴的package包/類
private MergeAdapter(ClassSet set, ClassVisitor cv, ClassNode cn) {
super(CompilationConfig.ASM_API_VERSION, cv);
this.classToMerge = cn;
this.set = set;
boolean hasInit = false;
for (Object o : classToMerge.methods) {
String name = ((MethodNode)o).name;
if (name.equals("<init>")) {
continue;
}
if (name.equals(SignatureHolder.DRILL_INIT_METHOD)) {
hasInit = true;
}
mergingNames.add(name);
}
this.hasInit = hasInit;
}