python能解密java的,在python中解码Java对象

这篇博客讨论了如何在Python中解析收到的Java对象,这些对象以'Transfer-Encoding: chunked'格式返回。内容涉及Java序列化协议,以及如何在Python中处理这种数据,包括可能需要进行的Java到Python的数据字段映射。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Is it possible to decode java objects in python? I know the structure of the java class that returns the data. The data is returned with the header of 'Transfer-Encoding: chunked'

Or do I need to get the return data sent as xml / json?

This is an example of the response I get;

(Note some of the control characters are removed by pasting)

-- response --

200 OK

Server: Apache-Coyote/1.1

Transfer-Encoding: chunked

Date: Tue, 22 Nov 2011 13:24:41 GMT

��srjava.util.ArrayListx����a�IsizexpGwXsr,com.blah.blah.data.ClientInfos����8d�LdbNametLjava/lang/String;Ldescriptionq~xptdbname1t Customername1q~tdbname2tCustomername2sq~t

This example returns two clients in the format of client, databasename

dbname1,customername1

dbname2,customername2

解决方案

--- Edited as more details became available ---

The content of this HTTP response is a serialized Java object.

Java serialization is a process by which an in-memory object gets packed into transport-friendly bytes for the purpose of being read by another JVM. In short, you need to read the serialization format. Assuming that they didn't add a custom serializer, the actual protocol is documented here.

The rest is just assuring that you do a sensible Java to Python mapping of the data fields. If you want to support "round trip" data handling, you should cache the sometimes discarded "java information" in special "areas" of your data structure so you can serialize back to the same java constructs.

--- Original Post follows ---

Either you are disassembling a class (which is easy to do as Java has a very rigid class structure and an easy to reverse byte code to source code mapping) or you are processing data.

If it is processing data, you're not really decoding Java, and the ease of doing what you want depends heavily on the ability to gather knowledge about how the data is encoded. Since you mentioned a "Transfer-Encoding: Chunked" header, I am guessing you are reading a HTTP response (complete with headers).

Nearly every language has a library to handle HTTP responses due to the popularity of web services. Python already has a HTTP client as indicated here.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值