以编程方式检查.class文件 [英] Programmatically inspect .class files

查看:88
本文介绍了以编程方式检查.class文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个项目,我们在Java服务和用其他各种语言编写的客户端之间进行大量的远程对象传输。鉴于我们目前的限制,我决定看看基于现有Java类生成代码需要什么。基本上我需要一个 .class 文件(或它们的集合)解析字节码以确定所有数据成员和可能的getter / setter然后写一些可以用不同的语言输出代码来创建一个具有相同结构的类。

I'm working on a project where we're doing a lot of remote object transfer between a Java service and clients written in other various languages. Given our current constraints I've decided to see what it would take to generate code based on an existing Java class. Basically I need to take a .class file (or a collection of them) parse the bytecode to determine all of the data members and perhaps getters/setters and then write something that can output code in a different language to create a class with the same structure.

我不是在寻找标准的反编译器,比如JAD。我需要能够获取 .class 文件并创建其数据成员和方法的对象模型。这有可能吗?

I'm not looking for standard decompilers such as JAD. I need to be able to take a .class file and create an object model of its data members and methods. Is this possible at all?

推荐答案

我使用BCEL并发现它真的很尴尬。 ASM 要好得多。它非常广泛地使用访问者(这可能有点令人困惑)并且不会创建对象模型。不创建对象模型是一个奖励,因为您想要创建的任何模型都不太可能看起来像是对所有数据的字面解释。

I've used BCEL and find it really quite awkward. ASM is much better. It very extensively uses visitors (which can be a little confusing) and does not create an object model. Not creating an object model turns out to be a bonus, as any model you do want to create is unlikely to look like a literal interpretation of all the data.

这篇关于以编程方式检查.class文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆