當前位置: 首頁>>代碼示例>>Java>>正文


Java IllegalClassFormatException類代碼示例

本文整理匯總了Java中java.lang.instrument.IllegalClassFormatException的典型用法代碼示例。如果您正苦於以下問題:Java IllegalClassFormatException類的具體用法?Java IllegalClassFormatException怎麽用?Java IllegalClassFormatException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


IllegalClassFormatException類屬於java.lang.instrument包,在下文中一共展示了IllegalClassFormatException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: patchByteCode

import java.lang.instrument.IllegalClassFormatException; //導入依賴的package包/類
public static byte[] patchByteCode(ClassLoader l, String className, ProtectionDomain pd, byte[] arr) throws IllegalClassFormatException {
    if (ACTIVE == null) {
        return arr;
    }
    if (Boolean.TRUE.equals(IN.get())) {
        return arr;
    }
    try {
        IN.set(Boolean.TRUE);
        for (NbInstrumentation inst : ACTIVE) {
            for (ClassFileTransformer t : inst.transformers) {
                arr = t.transform(l, className, null, pd, arr);
            }
        }
    } finally {
        IN.set(null);
    }
    return arr;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:20,代碼來源:NbInstrumentation.java

示例2: transform

import java.lang.instrument.IllegalClassFormatException; //導入依賴的package包/類
@Override
public byte[] transform(
    ClassLoader loader, String className, Class<?> classBeingRedefined,
    ProtectionDomain protectionDomain, byte[] arr
) throws IllegalClassFormatException {
    byte[] ret = arr;
    for (int i = 0; i < arr.length - 4; i++) {
        if (arr[i] == 'H' && arr[i + 1] == 'e' && arr[i + 2] == 'l' && 
            arr[i + 3] == 'o'
        ) {
            ret = ret.clone();
            ret[i] = 'A';
            ret[i + 1] = 'h';
            ret[i + 2] = 'o';
            ret[i + 3] = 'j';
        }
    }
    return ret;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:20,代碼來源:HelloWorldAgent.java

示例3: transform

import java.lang.instrument.IllegalClassFormatException; //導入依賴的package包/類
public byte[] transform(ClassLoader loader,
                        String className,
                        Class classBeingRedefined,
                        ProtectionDomain protectionDomain,
                        byte[] classfileBuffer) throws IllegalClassFormatException {
    try {
        pool.insertClassPath(new ByteArrayClassPath(className, classfileBuffer));
        CtClass cclass = pool.get(className.replaceAll("/", "."));

        if (!cclass.getName().startsWith("ru.otus.")) {
            return null; // the same as return classfileBuffer; without changes
        }

        for (CtMethod currentMethod : cclass.getDeclaredMethods()) {
            AddLog annotation = (AddLog) currentMethod.getAnnotation(AddLog.class);
            if (annotation != null) {
                currentMethod.insertBefore("{System.out.println(\"" + annotation.message() + "\");}");
            }
        }

        return cclass.toBytecode();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
 
開發者ID:vitaly-chibrikov,項目名稱:otus_java_2017_06,代碼行數:27,代碼來源:MyClassTransformer.java

示例4: transform

import java.lang.instrument.IllegalClassFormatException; //導入依賴的package包/類
@Override
public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined,
		ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException {

	String classNameFinal = className.replace('/', '.');
	byte[] retorno = classfileBuffer;

	ClassPool cp = ClassPool.getDefault();
	cp.appendClassPath(new LoaderClassPath(loader));

	Iterator<String> iterator = this.mapClasse.keySet().iterator();
	while (iterator.hasNext()) {
		String classNameParam = iterator.next();
		if (classNameFinal.equals(classNameParam)) {
			Clazz classe = this.mapClasse.get(classNameFinal);
			this.mapClasse.remove(classNameParam);
			return instrumentalize(cp, classNameFinal, retorno, classe);
		}
	}

	return retorno;
}
 
開發者ID:remartins,項目名稱:byte-chameleon,代碼行數:23,代碼來源:Transformer.java

示例5: transformIfNecessary

import java.lang.instrument.IllegalClassFormatException; //導入依賴的package包/類
/**
 * Apply transformation on a given class byte definition.
 * The method will always return a non-null byte array (if no transformation has taken place
 * the array content will be identical to the original one).
 * @param className the full qualified name of the class in dot format (i.e. some.package.SomeClass)
 * @param internalName class name internal name in / format (i.e. some/package/SomeClass)
 * @param bytes class byte definition
 * @param pd protection domain to be used (can be null)
 * @return (possibly transformed) class byte definition
 */
public byte[] transformIfNecessary(String className, String internalName, byte[] bytes, ProtectionDomain pd) {
	byte[] result = bytes;
	for (ClassFileTransformer cft : this.transformers) {
		try {
			byte[] transformed = cft.transform(this.classLoader, internalName, null, pd, result);
			if (transformed != null) {
				result = transformed;
			}
		}
		catch (IllegalClassFormatException ex) {
			throw new IllegalStateException("Class file transformation failed", ex);
		}
	}
	return result;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:26,代碼來源:WeavingTransformer.java

示例6: applyTransformers

import java.lang.instrument.IllegalClassFormatException; //導入依賴的package包/類
private byte[] applyTransformers(String name, byte[] bytes) {
	String internalName = StringUtils.replace(name, ".", "/");
	try {
		for (ClassFileTransformer transformer : this.classFileTransformers) {
			byte[] transformed = transformer.transform(this, internalName, null, null, bytes);
			bytes = (transformed != null ? transformed : bytes);
		}
		return bytes;
	}
	catch (IllegalClassFormatException ex) {
		throw new IllegalStateException(ex);
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:14,代碼來源:ShadowingClassLoader.java

示例7: main

import java.lang.instrument.IllegalClassFormatException; //導入依賴的package包/類
public static void main(String[] args) throws IllegalClassFormatException {

        Scanner scanner = new Scanner(System.in);
        String driverName = scanner.nextLine();

        Car ferrari = new Ferrari(driverName);

        System.out.println(ferrari);

        String ferrariName = Ferrari.class.getSimpleName();
        String carInterface = Car.class.getSimpleName();
        boolean isCreated = Car.class.isInterface();
        if (!isCreated) {
            throw new IllegalClassFormatException("No interface created!");
        }
    }
 
開發者ID:kostovhg,項目名稱:SoftUni,代碼行數:17,代碼來源:Main.java

示例8: transform

import java.lang.instrument.IllegalClassFormatException; //導入依賴的package包/類
@Override public byte[] transform(ClassLoader loader, String className,
        Class<?> classBeingRedefined,
        ProtectionDomain protectionDomain, byte[] classfileBuffer)
    throws IllegalClassFormatException {

    if (className.contains("TypeAnnotatedTestClass")) {
        try {
            // Here we remove and re-add the dummy fields. This shuffles the constant pool
            return asm(loader, className, classBeingRedefined, protectionDomain, classfileBuffer);
        } catch (Throwable e) {
            // The retransform native code that called this method does not propagate
            // exceptions. Instead of getting an uninformative generic error, catch
            // problems here and print it, then exit.
            e.printStackTrace();
            System.exit(1);
        }
    }
    return null;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:20,代碼來源:RedefineAnnotations.java

示例9: transform

import java.lang.instrument.IllegalClassFormatException; //導入依賴的package包/類
public byte[] transform(ClassLoader loader, String className, Class classBeingRedefined,
                        ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException {

    byte[] byteCode = classfileBuffer;

    if (className.equals("beans/Sleeping")) {

        try {
            ClassPool cp = ClassPool.getDefault();
            CtClass cc = cp.get("beans.Sleeping");
            CtMethod m = cc.getDeclaredMethod("sleepNow");
            m.addLocalVariable("elapsedTime", CtClass.longType);
            m.insertBefore("elapsedTime = System.currentTimeMillis();");
            m.insertAfter("{elapsedTime = System.currentTimeMillis() - elapsedTime;"
                    + "System.out.println(\"Method Executed in ms: \" + elapsedTime);}");
            byteCode = cc.toBytecode();
            cc.detach();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    return byteCode;
}
 
開發者ID:vitaly-chibrikov,項目名稱:otus_java_2017_10,代碼行數:25,代碼來源:SleepTransformer.java

示例10: transform

import java.lang.instrument.IllegalClassFormatException; //導入依賴的package包/類
@Override
public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined,
                        ProtectionDomain pd, byte[] byteCode) throws IllegalClassFormatException {
    if (className.replace("/", ".").equals(clazzName)) {
        System.out.println("Agent: instrumenting " + className);
        try {
            ClassPool classPool = ClassPool.getDefault();
            CtClass clazz = classPool.get(clazzName);
            addTiming(clazz, method);

            byte[] instrumentedByteCode = clazz.toBytecode();
            clazz.detach();

            saveByteCode(instrumentedByteCode, clazz.getSimpleName());

            System.out.println("Agent: instrumented successfully " + clazzName + "." + method);
            return instrumentedByteCode;
        } catch (Throwable t) {
            t.printStackTrace();
        }
    }

    return byteCode;
}
 
開發者ID:kslisenko,項目名稱:java-performance,代碼行數:25,代碼來源:ClassTransformer.java

示例11: transform

import java.lang.instrument.IllegalClassFormatException; //導入依賴的package包/類
@Override
public byte[] transform(String name, String transformedName, byte[] classBuffer) {
	String internalClassName = name.replace('.', '/');
	for (ClassFileTransformer transformer : AuthlibInjectorTweaker.transformers) {
		byte[] result = null;
		try {
			result = transformer.transform(Launch.classLoader, internalClassName, null, null, classBuffer);
		} catch (IllegalClassFormatException e) {
			log("exception while invoking {0}: {1}", transformer, e);
			e.printStackTrace();
		}
		if (result != null) {
			classBuffer = result;
		}
	}
	return classBuffer;
}
 
開發者ID:to2mbn,項目名稱:authlib-injector,代碼行數:18,代碼來源:TweakerTransformerAdapter.java

示例12: transform

import java.lang.instrument.IllegalClassFormatException; //導入依賴的package包/類
@Override
public byte[] transform(ClassLoader loader, String internalClassName, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException {
	if (internalClassName != null && classfileBuffer != null) {
		try {
			String className = internalClassName.replace('/', '.');
			for (String prefix : ignores)
				if (className.startsWith(prefix)) return null;

			TransformHandle handle = new TransformHandle(className, classfileBuffer);
			units.forEach(handle::accept);
			if (handle.getResult().isPresent()) {
				byte[] classBuffer = handle.getResult().get();
				if (debug) {
					saveClassFile(className, classBuffer);
				}
				return classBuffer;
			} else {
				return null;
			}
		} catch (Throwable e) {
			log("unable to transform {0}: {1}", internalClassName, e);
			e.printStackTrace();
		}
	}
	return null;
}
 
開發者ID:to2mbn,項目名稱:authlib-injector,代碼行數:27,代碼來源:ClassTransformer.java

示例13: transform

import java.lang.instrument.IllegalClassFormatException; //導入依賴的package包/類
@Override
    public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException {

        if(className.startsWith(TransformConfig.getInstance().getPackageScan())) {
            logger.log(Level.INFO, "-------------------CLASS---------------------");
            logger.log(Level.INFO, "className: " + className);
            ClassReader cr = new ClassReader(classfileBuffer);
            ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);

            ClassVisitor classVisitor = new HookClassAdapter(Opcodes.ASM5, cw);
            cr.accept(classVisitor, ClassReader.SKIP_FRAMES);
//            try {
//                FileOutputStream fos = new FileOutputStream(new File("classMod.class"));
//                fos.write(cw.toByteArray());
//                fos.close();
//            } catch (IOException e) {
//                e.printStackTrace();
//            }

            return cw.toByteArray();
        }
        return null;

    }
 
開發者ID:acmerli,項目名稱:fastAOP,代碼行數:25,代碼來源:CatchBlockClassTransformer.java

示例14: transform

import java.lang.instrument.IllegalClassFormatException; //導入依賴的package包/類
/**
 * Transformation method - implemented by a ClassFileTransformer in order to change classes' bytecode as they are loaded.
 * @param classLoader The ClassLoader of the class being transformed.
 * @param className The class name passed from the JVM.
 * @param classBeingTransformed The Class object of the class being transformed.
 * @param protectionDomain The protection domain of the class being transformed.
 * @param bytes The bytecode of the class being transformed.
 * @return The redefined array of bytes.
 * @throws IllegalClassFormatException
 */
@Override
public byte[] transform(ClassLoader classLoader, String className, Class<?> classBeingTransformed, ProtectionDomain protectionDomain, byte[] bytes) throws IllegalClassFormatException {
    try {
        if (className != null) {
            className = className.replace("/", ".");
            if (className.equals("io.netty.bootstrap.Bootstrap")) {
                ClassPool pool = ClassPool.getDefault();
                pool.appendClassPath(new ByteArrayClassPath(className, bytes));

                CtClass ctClass = pool.get(className);
                CtMethod method = ctClass.getMethod("isBlockedServerHostName", "(Ljava/lang/String;)Z");
                method.setBody("{ return false; }");

                System.out.println("[MojangBlacklistBypass] Successfully retransformed server blacklist!");
                return ctClass.toBytecode();
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
 
開發者ID:half-cambodian-hacker-man,項目名稱:MojangBlacklistBypass,代碼行數:33,代碼來源:BypassAgent.java

示例15: transform

import java.lang.instrument.IllegalClassFormatException; //導入依賴的package包/類
@Override
public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined,
        ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException {
    if(MethodDatabase.isJavaCore(className)) {
        return null;
    }
    if(className.startsWith("org/objectweb/asm/")) {
        return null;
    }

    db.log(LogLevel.INFO, "TRANSFORM: %s", className);

    try {
        return instrumentClass(db, classfileBuffer, check);
    } catch(Exception ex) {
        db.error("Unable to instrument", ex);
        return null;
    }
}
 
開發者ID:oltolm,項目名稱:continuations,代碼行數:20,代碼來源:JavaAgent.java


注:本文中的java.lang.instrument.IllegalClassFormatException類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。