use of org.objectweb.asm.tree.ClassNode in project LogisticsPipes by RS485.
the class LogisticsPipesClassInjector method transform.
@Override
@SuppressWarnings("unchecked")
public byte[] transform(String name, String transformedName, byte[] bytes) {
if (bytes != null) {
if (name.startsWith("logisticspipes.")) {
final ClassReader reader = new ClassReader(bytes);
final ClassNode node = new ClassNode();
reader.accept(node, 0);
if (node.visibleAnnotations != null) {
for (AnnotationNode a : node.visibleAnnotations) {
if (a.desc.equals("Llogisticspipes/asm/ModVersionedClass;")) {
if (a.values.size() == 8 && a.values.get(0).equals("modId") && a.values.get(2).equals("version") && a.values.get(4).equals("classData") && a.values.get(6).equals("classDataDev")) {
String modId = a.values.get(1).toString();
String version = a.values.get(3).toString();
String classData = a.values.get(5).toString();
String classDataDev = a.values.get(7).toString();
if (ModStatusHelper.isModLoaded(modId) && !ModStatusHelper.isModVersionEqualsOrHigher(modId, version)) {
if (isObfEnv == null) {
try {
isObfEnv = (Class.forName("net.minecraft.world.World").getDeclaredField("chunkProvider") == null);
} catch (Throwable e) {
isObfEnv = true;
}
}
bytes = transform(name, transformedName, DatatypeConverter.parseBase64Binary(isObfEnv ? classData : classDataDev));
}
} else {
throw new UnsupportedOperationException("Can't parse the annotations correctly");
}
}
}
}
}
return bytes;
}
try {
if (name.startsWith("logisticspipes.proxy.opencomputers.asm.BaseWrapperClass$") && name.endsWith("$OpenComputersWrapper")) {
String correctName = name.substring(56, name.length() - 21);
Class<?> clazz = Launch.classLoader.findClass(correctName);
bytes = ClassCreator.getWrappedClassAsBytes(CCObjectWrapper.getWrapperInformation(clazz), clazz.getName());
Set<String> set = new TreeSet<>();
set.add(name);
Launch.classLoader.clearNegativeEntries(set);
Map<String, byte[]> map = (Map<String, byte[]>) fResourceCache.get(Launch.classLoader);
map.put(name, bytes);
return bytes;
}
} catch (Exception e) {
if (LPConstants.DEBUG) {
// For better Debugging
e.printStackTrace();
return bytes;
}
throw new RuntimeException(e);
}
return bytes;
}
use of org.objectweb.asm.tree.ClassNode in project pinpoint by naver.
the class ASMMethodNodeAdapterRenameTest method rename.
@Test
public void rename() throws Exception {
final String targetClassName = "com.navercorp.pinpoint.profiler.instrument.mock.NormalClass";
classLoader.setTrace(false);
classLoader.setTargetClassName(targetClassName);
classLoader.setCallbackHandler(new ASMClassNodeLoader.CallbackHandler() {
@Override
public void handle(ClassNode classNode) {
List<MethodNode> methodNodes = classNode.methods;
for (MethodNode methodNode : methodNodes) {
ASMMethodNodeAdapter adapter = new ASMMethodNodeAdapter(classNode.name, methodNode);
if (!adapter.isConstructor()) {
adapter.rename(adapter.getName() + "_rename");
}
}
}
});
Class<?> clazz = classLoader.loadClass(targetClassName);
Method method = clazz.getDeclaredMethod("sum_rename", int.class);
method.invoke(clazz.newInstance(), 10);
}
use of org.objectweb.asm.tree.ClassNode in project pinpoint by naver.
the class ASMMethodNodeTest method addInterceptor.
@Test
public void addInterceptor() throws Exception {
final int interceptorId = interceptorRegistryBinder.getInterceptorRegistryAdaptor().addInterceptor(new ArgsArrayInterceptor());
final String targetClassName = "com.navercorp.pinpoint.profiler.instrument.mock.NormalClass";
final ASMClass declaringClass = mock(ASMClass.class);
when(declaringClass.getName()).thenReturn(targetClassName);
final ObjectBinderFactory objectBinderFactory = mock(ObjectBinderFactory.class);
ASMClassNodeLoader.TestClassLoader classLoader = ASMClassNodeLoader.getClassLoader();
classLoader.setTrace(false);
classLoader.setVerify(false);
classLoader.setTargetClassName(targetClassName);
classLoader.setCallbackHandler(new ASMClassNodeLoader.CallbackHandler() {
@Override
public void handle(ClassNode classNode) {
List<MethodNode> methodNodes = classNode.methods;
for (MethodNode methodNode : methodNodes) {
ASMMethod method = new ASMMethod(objectBinderFactory, pluginContext, apiMetaDataService, interceptorRegistryBinder, declaringClass, methodNode);
try {
method.addInterceptor(interceptorId);
} catch (InstrumentException e) {
e.printStackTrace();
}
}
}
});
Class<?> clazz = classLoader.loadClass(targetClassName);
Method method = clazz.getDeclaredMethod("sum", int.class);
assertEquals(55, method.invoke(clazz.newInstance(), 10));
}
use of org.objectweb.asm.tree.ClassNode in project pinpoint by naver.
the class ASMClassWriterTest method accept.
@Test
public void accept() throws Exception {
final String className = "com.navercorp.pinpoint.profiler.instrument.mock.SampleClass";
ClassNode classNode = ASMClassNodeLoader.get(JavaAssistUtils.javaNameToJvmName(className));
ASMClassWriter cw = new ASMClassWriter(pluginContext, classNode.name, classNode.superName, 0, null);
TraceClassVisitor tcv = new TraceClassVisitor(cw, new PrintWriter(System.out));
classNode.accept(tcv);
}
use of org.objectweb.asm.tree.ClassNode in project pinpoint by naver.
the class ASMFieldNodeAdapterTest method getName.
@Test
public void getName() throws Exception {
ClassNode classNode = ASMClassNodeLoader.get("com.navercorp.pinpoint.profiler.instrument.mock.FieldClass");
List<FieldNode> fieldNodes = classNode.fields;
for (FieldNode fieldNode : fieldNodes) {
ASMFieldNodeAdapter adapter = new ASMFieldNodeAdapter(fieldNode);
assertNotNull(adapter.getName());
assertNotNull(adapter.getClassName());
assertNotNull(adapter.getDesc());
}
}
Aggregations