简体   繁体   English

二进制到CSV记录的会话

[英]Binary to CSV record Converstion

Hi Folks 嗨伙计
I have been working on a python module which will convert a binary string into a CSV record. 我一直在研究python模块,该模块会将二进制字符串转换为CSV记录。 A 3rd Party application does this usually, however I'm trying to build this logic into my code. 通常,第三方应用程序会执行此操作,但是我正在尝试将此逻辑构建到我的代码中。 The records before and after conversion are as follows: 转换前后的记录如下:

CSV Record After Conversion 转换后的CSV记录

0029.6,000.87,002.06,0029.2,0010.6,0010.0,0002.1,0002.3,00120,00168,00054,00111,00130,00000,00034,00000,00000,00039,00000,0313.1,11:09:01,06-06-2015,00000169

I'm trying to figure out the conversion logic that has been used by the 3rd party tool, if anyone can help me with some clues regarding this, it would be great! 我正在尝试找出第三方工具已使用的转换逻辑,如果有人可以帮助我提供一些有关此方面的线索,那就太好了!
One thing I have analysed is that each CSV value corresponds to an unsigned short in the byte stream. 我分析过的一件事是,每个CSV值对应于字节流中的无符号short。
TIA, cheers! TIA,加油!

As already mentioned, without knowing the binary protocol it will be difficult to guess the exact encoding that is being used. 如上所述,在不知道二进制协议的情况下,很难猜测正在使用的确切编码。 There may be special case logic that is not apparent in the given data. 在给定数据中可能存在不明显的特殊情况逻辑。

It would be useful to know the name of the 3rd party application or a least what field this relates to. 知道第三方应用程序的名称或至少与之相关的字段会很有用。 Anything to give an idea as to what the encoding could be. 关于编码可能是什么的任何想法。

The following are clues as you requested on how to proceed: 以下是您要求的有关如何进行的线索:

  1. The end of the CSV shows a date, this can be seen at the start CSV的结尾显示一个日期,可以在开始时看到它

31 08 11 06 06 15 20 AA A8 00 00 00 28 01 57 00 CE 00 24 01 6A 00 64 00 15 00 17 00 78 00 A8 00 36 00 6F 00 82 00 00 00 22 00 00 00 00 00 27 00 00 00 31 08 11 06 06 15 20 AA A8 00 00 00 28 01 57 00 CE 00 24 01 6A 00 64 00 15 00 17 00 78 00 A8 00 36 00 6F 00 82 00 00 00 22 00 00 00 00 00 00 27 00 00 00

  1. The end value 169 (hex A9) is suspiciously in between the next two hex values 最终值169(十六进制A9)可疑地位于接下来的两个十六进制值之间

31 08 11 06 06 15 20 AA A8 00 00 00 28 01 57 00 CE 00 24 01 6A 00 64 00 15 00 17 00 78 00 A8 00 36 00 6F 00 82 00 00 00 22 00 00 00 00 00 27 00 00 00 31 08 11 06 06 15 20 AA A8 00 00 00 28 01 57 00 CE 00 24 01 6A 00 64 00 15 00 17 00 78 00 A8 00 36 00 6F 00 82 00 00 00 22 00 00 00 00 00 00 27 00 00 00

  1. "00039," could refer to the last 4 digits “ 00039”可以指末4位数字

31 08 11 06 06 15 20 AA A8 00 00 00 28 01 57 00 CE 00 24 01 6A 00 64 00 15 00 17 00 78 00 A8 00 36 00 6F 00 82 00 00 00 22 00 00 00 00 00 27 00 00 00 31 08 11 06 06 15 20 AA A8 00 00 00 28 01 57 00 CE 00 24 01 6A 00 64 00 15 00 17 00 78 00 A8 00 36 00 6F 00 82 00 00 00 22 00 00 00 00 00 00 27 00 00 00

or: 要么:

31 08 11 06 06 15 20 AA A8 00 00 00 28 01 57 00 CE 00 24 01 6A 00 64 00 15 00 17 00 78 00 A8 00 36 00 6F 00 82 00 00 00 22 00 00 00 00 00 27 00 00 00 ....or 27 00 00 00 31 08 11 06 06 15 20 AA A8 00 00 00 28 01 57 00 CE 00 24 01 6A 00 64 00 15 00 17 00 78 00 A8 00 36 00 6F 00 82 00 00 00 22 00 00 00 00 00 00 27 00 00 00 ....或27 00 00 00

...you guess two bytes are used so perhaps the others are separate 0 value fields. ...您猜测使用了两个字节,所以也许其他字节是单独的0值字段。

  1. "00034," could refer to: “ 00034”可以表示:

31 08 11 06 06 15 20 AA A8 00 00 00 28 01 57 00 CE 00 24 01 6A 00 64 00 15 00 17 00 78 00 A8 00 36 00 6F 00 82 00 00 00 22 00 00 00 00 00 27 00 00 00 31 08 11 06 06 15 20 AA A8 00 00 00 28 01 57 00 CE 00 24 01 6A 00 64 00 15 00 17 00 78 00 A8 00 36 00 6F 00 82 00 00 00 22 00 00 00 00 00 00 27 00 00 00

and so on... simply convert some of the decimal numbers into hex and search for possible locations in the data. 依此类推...只需将一些十进制数字转换为十六进制,然后在数据中搜索可能的位置。 Consider that fields might be big or little endian or a combination thereof. 考虑字段可能是大字节序或小字节序或其组合。

You should take a look at the struct python library which can be useful in dealing with such conversions once you know the formatting that is being used. 您应该看看struct python库,一旦知道所使用的格式,该库对于处理此类转换将很有用。

With more data examples the above theories could then be tested. 通过更多的数据示例,可以验证上述理论。

从二进制到有意义的字符串,我们必须知道二进制代码协议我们不能凭空解决二进制问题。

Take a look at my Python script which converts a binary file to a CSV or BSV file given a C header file and a C struct name defining that binary record. 看一下我的Python脚本,该脚本将给定C头文件和C结构名称的二进制文件转换为CSV或BSV文件。 https://github.com/SShabtai/MsgGini . https://github.com/SShabtai/MsgGini Although not complete, it might give you some hints... 虽然不完整,但可能会给您一些提示...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM