本文整理汇总了Java中org.objectweb.asm.tree.ClassNode类的典型用法代码示例。如果您正苦于以下问题:Java ClassNode类的具体用法?Java ClassNode怎么用?Java ClassNode使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ClassNode类属于org.objectweb.asm.tree包,在下文中一共展示了ClassNode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readJar
import org.objectweb.asm.tree.ClassNode; //导入依赖的package包/类
public static Application readJar(Path path) throws IOException {
Application application = new Application();
try (JarInputStream in = new JarInputStream(new BufferedInputStream(Files.newInputStream(path)))) {
JarEntry entry;
while ((entry = in.getNextJarEntry()) != null) {
String name = entry.getName();
if (!name.endsWith(".class")) continue;
name = name.replaceAll(".class$", "");
ClassNode node = new ClassNode();
ClassReader reader = new ClassReader(in);
reader.accept(node, ClassReader.SKIP_DEBUG);
application.classes.put(name, node);
}
}
return application;
}
示例2: getNode
import org.objectweb.asm.tree.ClassNode; //导入依赖的package包/类
/**
* Creates a ClassNode from the given class.
*
* @param c
* The target class.
* @return Node generated from the given class.
* @throws IOException
* If an exception occurs while loading the class.
*/
public static ClassNode getNode(Class<?> c) throws IOException {
String name = c.getName();
String path = name.replace('.', '/') + ".class";
ClassLoader loader = c.getClassLoader();
if (loader == null) {
loader = ClassLoader.getSystemClassLoader();
}
InputStream is = loader.getResourceAsStream(path);
ClassReader cr = new ClassReader(is);
return getNode(cr);
}
示例3: main
import org.objectweb.asm.tree.ClassNode; //导入依赖的package包/类
public static void main(String[] args) throws IOException {
if (args.length >= 1) {
JarFile file = new JarFile(args[0]);
Map<String, ClassNode> classes = JarUtil.readJar(file, false);
classes.values().forEach(c -> {
c.fields.forEach(m -> {
if (m.name.length() > 2) {
System.out.println("Non-renamed field: " + c.name + "." + m.name);
}
});
});
} else {
System.out.println("Example arguments: \"gamepack_127.jar\"");
}
}
示例4: createClassNode
import org.objectweb.asm.tree.ClassNode; //导入依赖的package包/类
public static ClassNode createClassNode(Class<?> clazz)
{
ClassNode node = new ClassNode();
try
{
String fileName = clazz.getName().replace('.', '/') + ".class";
ClassReader reader = new ClassReader(clazz.getClassLoader().getResourceAsStream(fileName));
reader.accept(node, 0);
return node;
} catch (IOException e)
{
e.printStackTrace();
}
throw new RuntimeException("Couldn't create ClassNode for class " + clazz.getName());
}
示例5: transform
import org.objectweb.asm.tree.ClassNode; //导入依赖的package包/类
@Override
public byte[] transform(String name, String transformedName, byte[] basicClass) {
List<ITransformer> transformers = getTransformers(transformedName);
if (!transformers.isEmpty()) {
ClassNode cn = getClassNode(basicClass);
if (cn == null)
return basicClass;
// Run all transformers on the Class
transformers.forEach(transformer -> transformer.transform(cn));
// Return transformed class bytecode
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);
cn.accept(cw);
return cw.toByteArray();
}
return basicClass;
}
示例6: detectOuterClass
import org.objectweb.asm.tree.ClassNode; //导入依赖的package包/类
private static void detectOuterClass(ClassInstance cls, ClassNode cn) {
if (cn.outerClass != null) {
addOuterClass(cls, cn.outerClass, true);
} else if (cn.outerMethod != null) {
throw new UnsupportedOperationException();
} else { // determine outer class by outer$inner name pattern
for (InnerClassNode icn : cn.innerClasses) {
if (icn.name.equals(cn.name)) {
addOuterClass(cls, icn.outerName, true);
return;
}
}
int pos;
if ((pos = cn.name.lastIndexOf('$')) > 0 && pos < cn.name.length() - 1) {
addOuterClass(cls, cn.name.substring(0, pos), false);
}
}
}
示例7: transform
import org.objectweb.asm.tree.ClassNode; //导入依赖的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]);
}
示例8: rewriteClass
import org.objectweb.asm.tree.ClassNode; //导入依赖的package包/类
/**
* Writes a modified *.class file to the output JAR file.
*/
private void rewriteClass(
JarEntry entry,
InputStream inputStream,
JarOutputStream outputStream) throws IOException {
ClassReader classReader = new ClassReader(inputStream);
ClassNode classNode = new ClassNode(Opcodes.ASM5);
classReader.accept(classNode, EMPTY_FLAGS);
modifyClass(classNode);
ClassWriter classWriter = new ClassWriter(0);
classNode.accept(classWriter);
outputStream.putNextEntry(new ZipEntry(entry.getName()));
outputStream.write(classWriter.toByteArray());
}
示例9: createSubClass
import org.objectweb.asm.tree.ClassNode; //导入依赖的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);
}
示例10: attrRemover
import org.objectweb.asm.tree.ClassNode; //导入依赖的package包/类
private static void attrRemover(ClassNode classNode) {
if (classNode.superName.equals("org/bukkit/plugin/java/JavaPlugin") || classNode.superName.equals("net/md_5/bungee/api/plugin/Plugin")) {
if (classNode.attrs != null) {
Iterator<Attribute> attributeIterator = classNode.attrs.iterator();
while (attributeIterator.hasNext()) {
Attribute attribute = attributeIterator.next();
if (attribute.type.equalsIgnoreCase("PluginVersion")) {
attributeIterator.remove();
}
if (attribute.type.equalsIgnoreCase("CompileVersion")) {
attributeIterator.remove();
}
}
}
}
}
示例11: viewByteCode
import org.objectweb.asm.tree.ClassNode; //导入依赖的package包/类
/**
* 格式化输出字节码
* @param bytecode
*/
public static void viewByteCode(byte[] bytecode) {
ClassReader cr = new ClassReader(bytecode);
ClassNode cn = new ClassNode();
cr.accept(cn, 0);
final List<MethodNode> mns = cn.methods;
Printer printer = new Textifier();
TraceMethodVisitor mp = new TraceMethodVisitor(printer);
for (MethodNode mn : mns) {
InsnList inList = mn.instructions;
System.out.println(mn.name);
for (int i = 0; i < inList.size(); i++) {
inList.get(i).accept(mp);
StringWriter sw = new StringWriter();
printer.print(new PrintWriter(sw));
printer.getText().clear();
System.out.print(sw.toString());
}
}
}
示例12: getMethodTransformers
import org.objectweb.asm.tree.ClassNode; //导入依赖的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};
}
示例13: findID
import org.objectweb.asm.tree.ClassNode; //导入依赖的package包/类
private static void findID(ClassNode classNode) throws Throwable {
for (MethodNode methodNode : classNode.methods) {
Iterator<AbstractInsnNode> insnIterator = methodNode.instructions.iterator();
while (insnIterator.hasNext()) {
AbstractInsnNode insnNode = insnIterator.next();
String str;
if ((insnNode.getType() == 9)) {
Object cst = ((LdcInsnNode) insnNode).cst;
if (cst instanceof String) {
str = ((LdcInsnNode) insnNode).cst.toString();
Matcher matcher = NONCEID_PATTERN.matcher(str);
if (matcher.find()) {
possiblenonces.add(str);
}
}
}
}
}
}
示例14: indexJar
import org.objectweb.asm.tree.ClassNode; //导入依赖的package包/类
private List<ClassNode> indexJar() {
ArrayList<ClassNode> classNodes = new ArrayList<ClassNode>();
Enumeration<JarEntry> enumeration = jarFile.entries();
while (enumeration.hasMoreElements()) {
JarEntry jarEntry = enumeration.nextElement();
if (jarEntry != null) {
if (jarEntry.getName().endsWith(".class")) {
try {
byte[] classBytes = IOUtils.readFully(jarFile.getInputStream(jarEntry), -1,
false);
ClassReader classReader = new ClassReader(classBytes);
ClassNode classNode = new ClassNode();
classReader.accept(classNode, 0);
classNodes.add(classNode);
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
return classNodes;
}
示例15: transform
import org.objectweb.asm.tree.ClassNode; //导入依赖的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));
}