私が取得したいMethodNode
のmain()
機能を
public class TestMethodNode {
public void main() {
}
}
だから私はこれを試しました
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.tree.MethodNode;
import static org.objectweb.asm.Opcodes.ASM7;
import java.io.IOException;
public class Instrumentation {
public byte[] editFunction(String className) throws IOException {
byte[] modifiedClass = null;
try {
ClassReader classReader = new ClassReader(className);
ClassWriter classWriter = new ClassWriter(classReader, ClassWriter.COMPUTE_FRAMES);
ClassVisitor classAdapter = new ClassVisitor(ASM7, classWriter) {
public MethodVisitor visitMethod(
int access,
String name,
String desc,
String signature,
String[] exceptions) {
if (name.equals("main")) {
final MethodVisitor methodVisitor = super.visitMethod(access, name, desc, signature, exceptions);
MethodNode methodNode = new MethodNode(access, name, desc, signature, exceptions) {
public void visitEnd() {
// transform / analyze method here
accept(methodVisitor);
}
};
return methodNode;
} else {
return super.visitMethod(access, name, desc, signature, exceptions);
}
}
};
classReader.accept(classAdapter, 0);
modifiedClass = classWriter.toByteArray();
} catch (IOException ex) {
throw ex;
}
return modifiedClass;
}
}
IllegalStateException
作成中に... / asm / tree / MethodNode.javaから取得MethodNode
public MethodNode(
final int access,
final String name,
final String descriptor,
final String signature,
final String[] exceptions) {
this(Opcodes.ASM7, access, name, descriptor, signature, exceptions);
if (getClass() != MethodNode.class) {
throw new IllegalStateException();
}
}
私は何を間違っているのですか?(私はMinecraftをハックしたくないので、実行時にバイトコード操作を使用するワークフローエンジンのラムダ式とネストされた/内部クラスを含むコールスタックを調査して操作しようとしています。)
コンストラクタMethodNode(int access, String name, String descriptor, String signature, String[] exceptions)
のドキュメントから:
… サブクラスはこのコンストラクタを使用してはなりません。代わりに、
MethodNode(int, int, String, String, String, String[])
バージョンを使用する必要があります。
サブクラスを作成しているので、呼び出しを変更する必要があります
new MethodNode(access, name, desc, signature, exceptions) {
…
}
に
new MethodNode(ASM7, access, name, desc, signature, exceptions) {
…
}
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加