use of org.objectweb.asm.tree.MethodNode in project dex2jar by pxb1988.
the class TestUtils method verify.
@SuppressWarnings("rawtypes")
public static void verify(final ClassReader cr, PrintWriter out) throws AnalyzerException, IllegalArgumentException, IllegalAccessException {
ClassNode cn = new ClassNode();
cr.accept(new CheckClassAdapter(cn, false), ClassReader.SKIP_DEBUG);
List methods = cn.methods;
for (int i = 0; i < methods.size(); ++i) {
MethodNode method = (MethodNode) methods.get(i);
List tryCatchBlocks = method.tryCatchBlocks;
for (int j = 0; j < tryCatchBlocks.size(); j++) {
TryCatchBlockNode tcn = (TryCatchBlockNode) tryCatchBlocks.get(j);
if (tcn.start.equals(tcn.end)) {
throw new DexException("try/catch block %d in %s has same start(%s) and end(%s)", j, method.name, tcn.start.getLabel(), tcn.end.getLabel());
}
}
BasicVerifier verifier = new BasicVerifier();
Analyzer a = new Analyzer(verifier);
try {
a.analyze(cn.name, method);
} catch (Exception e) {
out.println(cr.getClassName() + "." + method.name + method.desc);
printAnalyzerResult(method, a, out);
e.printStackTrace(out);
out.flush();
throw new DexException("method " + method.name + " " + method.desc, e);
}
}
}
use of org.objectweb.asm.tree.MethodNode 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 EngineComponent engineComponent = mock(EngineComponent.class);
when(engineComponent.createInterceptorDefinition(any(Class.class))).thenAnswer(new Answer<InterceptorDefinition>() {
@Override
public InterceptorDefinition answer(InvocationOnMock invocation) throws Throwable {
Object[] arguments = invocation.getArguments();
Class<?> clazz = (Class) arguments[0];
return interceptorDefinitionFactory.createInterceptorDefinition(clazz);
}
});
ASMClassNodeLoader.TestClassLoader classLoader = ASMClassNodeLoader.getClassLoader();
final InstrumentException[] exception = new InstrumentException[1];
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(engineComponent, pluginContext, declaringClass, methodNode);
try {
method.addInterceptor(interceptorId);
} catch (InstrumentException e) {
exception[0] = e;
e.printStackTrace();
}
}
}
});
Class<?> clazz = classLoader.loadClass(targetClassName);
Method method = clazz.getDeclaredMethod("sum", int.class);
assertEquals(55, method.invoke(clazz.newInstance(), 10));
assertNull(exception[0]);
}
use of org.objectweb.asm.tree.MethodNode in project pinpoint by naver.
the class ASMClassNodeLoader method get.
public static MethodNode get(final String classInternalName, final String methodName) throws Exception {
ClassNode classNode = get(classInternalName);
List<MethodNode> methodNodes = classNode.methods;
for (MethodNode methodNode : methodNodes) {
if (methodNode.name.equals(methodName)) {
return methodNode;
}
}
return null;
}
use of org.objectweb.asm.tree.MethodNode in project pinpoint by naver.
the class ASMMethodNodeAdapterTest method hasAnnotation.
@Test
public void hasAnnotation() throws Exception {
final String targetClassName = "com.navercorp.pinpoint.profiler.instrument.mock.AnnotationClass";
final MethodNode methodNode = ASMClassNodeLoader.get(targetClassName, "pointCut");
ASMMethodNodeAdapter adapter = new ASMMethodNodeAdapter(JavaAssistUtils.javaNameToJvmName(targetClassName), methodNode);
assertEquals(true, adapter.hasAnnotation(PointCut.class));
assertEquals(false, adapter.hasAnnotation(JointPoint.class));
}
use of org.objectweb.asm.tree.MethodNode 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);
}
Aggregations