bcel

BCEL - Get Class name,element names ,and method names

跟風遠走 提交于 2019-12-12 04:34:38
问题 how to using bcel classparaser to get class names ,element names and method names ? ive already find a way to get class names but element and method names give me something wrong . Anyone can help me with that ? here is my code (with some errors there, and not completed): import java.io.IOException; import java.util.Enumeration; import java.util.jar.JarEntry; import java.util.jar.JarFile; import org.apache.bcel.classfile.ClassParser; import org.apache.bcel.generic.ConstantPoolGen; public

Determining the Efferent coupling between objects (CBO Metric) using the parsed byte-code generated by BCEL

旧街凉风 提交于 2019-12-11 06:51:41
问题 I have built a program, which takes in a provided ".class" file and parses it using the BCEL, I've learnt how to calculate the LCOM4 value now. Now I would like to know how to calculate the CBO(Coupling between object) value of the class file. I've scoured the whole web, trying to find a proper tutorial about it, but I've been unable so far (I've read the whole javadoc regarding the BCEL as well and there was a similar question on stackoverflow but it has been removed). So I would like some

VerifyError: Stack size too large (what does it mean?)

拥有回忆 提交于 2019-12-11 00:02:04
问题 I'm fairly new to Java bytecode. I'm using BCEL to generate bytecode, but I get an error message when I try to use the generated code. (In hindsight, it looks like ObjectWeb ASM is more advanced and more commonly used than BCEL.) Here is the error message: Exception in thread "main" java.lang.VerifyError: (class: cb/io/FileDescriptor, method: set signature: (I)J) Stack size too large Here is the method: // Method descriptor #4 (I)J // Stack: 0, Locals: 1 private static long set(int arg1); 0

Replacing statically referenced method in Java

独自空忆成欢 提交于 2019-12-10 16:13:56
问题 I have a class like below with a method that just returns a String, but I want to modify what it returns from another class, without hardcoding it myself. public class Name { public static String getName() { return "MyName"; } } Is there any way to do this? I tried BCEL but that didn't seem to change the return value. Edit: This is for a mod. I'm trying to make it completely independant from the existing code, by not modifying it. Thanks. 回答1: Are you sure you've tried BCEL? I created a fully

How can one tell if a local variable is 'final' from Java bytecode? (Related to BCEL)

ε祈祈猫儿з 提交于 2019-12-10 14:45:00
问题 Where is information such as if a local variable is "final" stored in Java bytecode? I know that for fields (global variables) and methods these are found in the access flag bits, but cannot seem to find the equivalent in the local variable table. I am interested in this question as I am using BCEL to check if a local variable is final, and have found the equivalent for fields, methods and classes in the class AccessFlags. Thanks in advance. 回答1: The finality of local variables is checked by

Java 运行时获取方法参数名

Deadly 提交于 2019-12-09 19:01:21
本文整理 Java 运行时获取方法参数名的两种方法,Java 8 的最新的方法和 Java 8 之前的方法。 Java 8 的新特性 翻阅 Java 8 的 新特性 ,可以看到有这么一条“ JEP 118 : Access to Parameter Names at Runtime”。这个特性就是为了能运行时获取参数名新加的。这个 JEP 只是功能增强的提案,并没有最终实现的 JDK 相关的 API 的介绍。查看“ Enhancements to the Reflection API ” 会看到如下介绍: Enhancements in Java SE 8 Method Parameter Reflection: You can obtain the names of the formal parameters of any method or constructor with the method java.lang.reflect.Executable.getParameters . However, .class files do not store formal parameter names by default. To store formal parameter names in a particular .class file, and thus enable

Construct the stackmap of method while using bcel

风格不统一 提交于 2019-12-08 10:59:59
问题 I am trying bcel to modify a method by inserting invoke before specific instructions. It seems that my instrumentation would result in a different stackmap table, which can not be auto-generated by the bcel package itself. So, my instrumented class file contains the old stackmap table, which would cause error with jvm. I haved tried with removeCodeAttributes, the method of MethodGen, that can remove all the code attributes. It can work in simple cases, a wrapped function, for example. And it

post-compilation removal of annotations from byte code

有些话、适合烂在心里 提交于 2019-12-04 12:09:51
问题 we are using a library that contains beans that are annotated with JAXB annotations. nothing in the way we use these classes depends on JAXB. in other words, we don't need JAXB and do not depend on the annotations. however, because the annotations exist, they end up being referenced by other classes that process annotations. this requires me to bundle JAXB in our application, which isn't allowed, because JAXB is in the javax.* package (android doesn't allow "core libraries" to be included in

java字节码开源软件

走远了吗. 提交于 2019-12-03 18:34:32
asm :ASM 是一个 Java 字节码操纵框架。它可以直接以二进制形式动态地生成 stub 类或其他代理类,或者在装载时动态地修改类。ASM 提供类似于 BCEL 之类的工具包的功能,但是被设计得更小巧、更快速,这使它适用于实时代码插装。spring实现aop底层依赖cglib,cglib依赖asm。 bcel :Byte Code Engineering Library (BCEL),这是Apache Software Foundation 的Jakarta 项目的一部分。BCEL是 Java classworking 最广泛使用的一种框架,它可以让您深入 JVM 汇编语言进行类操作的细节。BCEL与Javassist 有不同的处理字节码方法,BCEL在实际的JVM 指令层次上进行操作(BCEL拥有丰富的JVM 指令级支持)而Javassist 所强调的源代码级别的工作。 javassit :Javassist是一个开源的分析、编辑和创建Java 字节码 的类库。是由东京工业大学的数学和计算机科学系的 Shigeru Chiba (千叶 滋)所创建的。它已加入了开放源代码JBoss 应用服务器 项目,通过使用Javassist对字节码操作为JBoss实现动态"AOP"框架。 关于java字节码的处理,目前有很多工具,如bcel, asm 。不过这些都需要直接跟 虚拟机

post-compilation removal of annotations from byte code

跟風遠走 提交于 2019-12-03 08:02:27
we are using a library that contains beans that are annotated with JAXB annotations. nothing in the way we use these classes depends on JAXB. in other words, we don't need JAXB and do not depend on the annotations. however, because the annotations exist, they end up being referenced by other classes that process annotations. this requires me to bundle JAXB in our application, which isn't allowed, because JAXB is in the javax.* package (android doesn't allow "core libraries" to be included in your application). so, with this in mind, i'm looking for a way to remove the annotations from the