java format 二进制,Java二进制(.class)文件格式解析器?

博主正在寻找能够将.class文件解析为Java对象的工具,要求能够处理项目中的所有类,包括jar文件,并且关注性能。ASM被推荐为首选,因为它是最流行的Java字节码库,仍在维护中。其他选项如BCEL和ASM被认为过于复杂,而Eclipse AST只能处理源文件。尽管博主愿意编写代码,但没有找到满足需求的成熟解决方案,如适用于.class文件的ANTLR语法。
摘要由CSDN通过智能技术生成

I am looking for a tool (or chain of tools) that can parse a .class files to a Java object. Something like :

JavaClass parsed = myTool.parse("/some_folder/SomeClassFile.class");

The parsed object would have methods like :

List methods = parsed.getMethods();

List interfaces = parsed.getImplementedInterfaces();

List calls = someMethod.getCalls();

My constraints are :

The aim is to parse all classes of a project, including jars, so performance does matter.

The parser has to parse Java 8 .class files

Java is my main language so it's better for me if it's in Java.

Of course I can do some coding, so for example if the output is xml it's ok.

So here are the options I have found so far - none being satisfying as it is :

BCEL or ASM look like a weapon of choice, but they also look like they're not maintained anymore. Besides, they're a little overkill for my purpose.

Elipse AST would work, but from what I saw it's only for source files, and I need to parse binary files (jars...)

A grammar for a parsing engine like antlr, yacc, bison... would work, but I have yet to find a reference grammar for .class files ! Besides, antlr is for text files, and I don't know of another reference Java parser engine (as I said, I would like a Java tool better).

I first thought a class loader would do the job, and that I could just load the class and then use reflection. But actually I realized I need stuff that the Java reflection api doesn't provide, like getting calls from a particular method.

So here is where I am now ! Thanks in advance for your help !

解决方案

I'd recommend ASM. From what I've seen, it's by far the most popular Java bytecode library, and yes, it is still maintained. At time of writing, it looks like the most recent change was 41 days ago. So it's not constantly churning but it's not like it's abandoned either. And with such a commonly used library, support should be easy to find.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值