以编程方式检查 .class 文件

发布于 2024-07-06 10:09:57 字数 296 浏览 8 评论 0原文

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

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

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.

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

剩一世无双 2024-07-13 10:09:57

我用过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.

长不大的小祸害 2024-07-13 10:09:57

我过去使用过 BCEL,它非常容易使用。 那是几年前的事了,所以现在可能有更好的东西。

Apache Jakarta BCEL

I have used BCEL in the past and it was pretty easy to use. It was a few years ago so there may be something better now.

Apache Jakarta BCEL

来日方长 2024-07-13 10:09:57

从您的描述来看,这听起来像是 简单反射< /a> 就足够了。 您可以发现类的所有静态结构,以及访问特定实例的字段。

如果您尝试翻译方法指令,我只会转向 BCEL。 (如果这就是您想要实现自动化的目标,祝您好运!)

From your description, it sounds like simple reflection would suffice. You can discover all of the static structure of the class, as well as accessing the fields of a particular instance.

I would only move on to BCEL if you are trying to translate method instructions. (And if that's what you're trying to automate, good luck!)

倦话 2024-07-13 10:09:57

令我震惊的是,还没有人提到 ASM。 这是你的钱能买到的最好的字节码库。 嗯,好吧,它是免费的。

I'm shocked that no one has mentioned ASM yet. It's the best bytecode library your money can buy. Well, ok it's free.

黑白记忆 2024-07-13 10:09:57

JAD 是一个不允许编程访问的 java 反编译器。 它不再可用,并且可能不适用于使用 Java7 字节码的新项目。

JAD is a java decompiler that doesn't allow programmatic access. It isn't readily available anymore, and probably won't work for newer projects with Java7 bytecodes.

未央 2024-07-13 10:09:57

我认为 javassist 也可能对你有帮助。

http://www.jboss.org/javassist/

我从来没有需要使用它,但是如果您尝试一下,您能让我们知道您对此的评论吗?

尽管我认为它更多的是用于字节码操作而不是 .class 检查。

I think javassist might help you too.

http://www.jboss.org/javassist/

I have never had the need of using it, but if you give it a try, would you let us know your comments about it?

Although I think it is more for bytecode manipulation than .class inspection.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文