This binary data正在通过包含ctype结构的python解析器文件进行解析。不幸的是,它没有返回正确的值。这很可能是因为我不能100%确定如何解释这些数据。
This spec概述了二进制数据的组织方式。我不是100%确定如何解释这个规范。
这是我的python解析器的样子:
from binascii import unhexlify
from ctypes import *
data = 'FE A5 11 11 3F A5 A1 A3 FE 9A A5 A4 8E A6 A2 89 A1 FE A3 A5 8A FE A5 A4 A5 35 8A 31 04 3C 07 1E 31 31 7A 59 23 01 4D 5E 11 0E 70 0D 41 64 27 63 57 0F 3A 59 47 29 2A 43 3B 66 02 0A 70 5D 56 5B 01 FE 4E 57 34 65 94 2E 52 66 5A 63 03 50 53 98 4E 6C 35 71 10 7B 57 0F 64 8A 70 4B 61 1B 07 3C 55 7A 46 48 3D 3D 20 02 62 65 69 09 03 3F 40 1D 61 45 22 15 39 42 4E 4C 13 12 1A 6F 59 63 8C 5A 28 67 15 2E 55 2A 59 16 0B 3C 68 08 09 42 1B 2D 0D 4A 0A 2E 82 6A 37 1C 2C 11 54 4E 57 56 25 50 09 17 5F 5F 0C 1E 6A 1F 85 28 5A 08 3B 19 79 65 13 6C 39 15 05 14 23 FE 47 04 32 52 52 61 1B FE 13 2D 40 4C 43 9D 44 78 73 7E 43 35 06 15 5A 67 21 34 4B 58 8E 68 1A 81 4B 24 75 64 50 58 5F 6B 7E 42 5F 8B 56 77 62 05 57 2C 72 53 1E 4A 50 5C 4D 45 1C 63 23 58 53 03 06 34 5A 37 58 44 4A 6C 7A 55 1E 59 66 68 69 05 6E 35 16 35 6C 15 84 1A 72 5A 18 3F 1D 65 7C 38 52 53 43 32 40 2A 6C 4C 77 4D 37 1E 0F 45 19 66 38 21 3D 6B 63 6D 06 37 1E 18 44 32 45 24 05 6E 1E 5C 6B 0D 09 93 1E 30 6E 30 52 D5 1C 6B 63 15 53 27 24 16 1B 16 20 33 7B 40 23 00 38 17 09 68 38 8F 1B 32 75 5F 48 5A 5D 52 45 75 5E 92 15 A3 21 81 1F 51 27 42 93 59 63 44 1D 40 18 05 0E 6A 4D 39 52 6F 53 26 6C 73 0A 10 26 8F 77 30 24 59 1C 66 45 5E 6B 8F 34 73 2A 7B 1F 48 2A 18 54 55 89 6F 58 16 85 4B 07 59 68 2B 3E 89 32 40 5F 81 94 6E 4E 22 99 2C 73 B0 18 7D 2E 3C 49 01 3C 50 97 96 1F 5F 6F 21 67 51 91 3F 2C 61 51 2E 91 48 0D 5F 20 56 2F 20 7E FE FE FE 3E 39 4C 06 24 0F 02 16 47 7C 47 30 FE FE 69 18 17 58 FE 13 28 55 FE 60 01 FE 08 23 0D 23 FE FE FE FE FE FE FE FE 00 00 05 BD 00 00 6C A6'
buffer = unhexlify(datahex.replace(' ',''))
bad_block = 0xFE
def getBlockCountUnion(numBlocks, buffer, version):
class sysblock_entry_struct(Structure):
_pack_ = 1
_fields_ = [("SysBlock", c_uint16),
("SysBlkCnt", c_uint32)]
def __str__(self):
retStr = ""
retStr += "SysBlock: %8.8Xh\n" % self.SysBlock
retStr += "SysBlkCnt: %8.8Xh\n" % self.SysBlkCnt
return retStr
class block_count_struct(Structure):
_pack_ = 1
_fields_ = [("Block", c_uint8 * numBlocks),
("GlobalCntOffset", c_uint32),
("GlobalCntOffsetSLC", c_uint32),
("TLCStartBlock", c_uint16),
("SysBlkCntInfo", sysblock_entry_struct * 6)]
def __str__(self):
retstr = "Block Count:\n"
for index, block in enumerate(self.Block):
blockStr = "0x%d" % block
if block == bad_block:
blockStr = "0 -- (Bad Block)"
retstr += "Block[" + str(index) + "]: " + blockStr + "\n"
retstr += "GlobalCntOffset: 0x08X\n" % self.GlobalCntOffset
retstr += "GlobalCntOffsetSLC: 0x08%X\n" % self.GlobalCntOffsetSLC
retstr += "SysBlock and SysBlkCnt:\n"
for idx, itm in enumerate(self.SysBlkCntInfo):
retstr += "[%d]:\n%s\n" % (idx, itm)
return retstr
block_count_union = type(getUnionFromStruct(block_count_struct()))
unionType = eval("block_count_%d_union" % version)
据我所知,这是我自己的。我无法弄清楚出了什么问题。最有可能的原因是我不熟悉使用固件,二进制数据等。没有追溯。乍一看,它看起来是正确的。但是,将它与正确的解析输出进行比较时,由于从缓冲区中的错误位置读取,我看起来可能无法正确解析。也许有一个我不考虑的偏差?
这是正确输出的示例:
---------SLC Block--------- FBlock= 0001(0x0001) Count= 27979 FBlock= 0002(0x0002) Count= 27831 -- Min Erase Cnt(SLC) FBlock= 0003(0x0003) Count= 27831 -- Min Erase Cnt(SLC) FBlock= 0004(0x0004) Count= 27877 FBlock= 0005(0x0005) Count= 27979 FBlock= 0006(0x0006) Count= 27975 FBlock= 0007(0x0007) Count= 27977 FBlock= 0008(0x0008) Count= 0000 -- Bad Block FBlock= 0009(0x0009) Count= 27968 FBlock= 0010(0x000A) Count= 27979 ... ... ... FBlock= 0024(0x0018) Count= 27979 FBlock= 0025(0x0019) Count= 27867 FBlock= 0026(0x001A) Count= 27952 ---------TLC Block--------- FBlock= 0027(0x001B) Count= 1518 FBlock= 0028(0x001C) Count= 1473 FBlock= 0029(0x001D) Count= 1529 ... ... ... FBlock= 0494(0x01EE) Count= 1482 FBlock= 0495(0x01EF) Count= 1504 FBlock= 0496(0x01F0) Count= 0000 -- Bad Block FBlock= 0497(0x01F1) Count= 0000 -- Bad Block FBlock= 0498(0x01F2) Count= 0000 -- Bad Block FBlock= 0499(0x01F3) Count= 0000 -- Bad Block FBlock= 0500(0x01F4) Count= 0000 -- Bad Block FBlock= 0501(0x01F5) Count= 0000 -- Bad Block FBlock= 0502(0x01F6) Count= 0000 -- Bad Block FBlock= 0503(0x01F7) Count= 0000 -- Bad Block GlobalCntOffset= 0x5BD(1469) GlobalCntOffset_SLC= 0x6CA6(27814) System Block 0 Count = 0x0(0) System Block 1 Count = 0x0(0) System Block 2 Count = 0x2(2) System Block 3 Count = 0x2(2) System Block 4 Count = 0x4B(75) System Block 5 Count = 0x42(66)
这是我输出的一个示例:
Block[0]: 0 -- (Bad Block) Block[1]: 0x165 Block[2]: 0x17 Block[3]: 0x17 Block[4]: 0x63 Block[5]: 0x165 Block[6]: 0x161 Block[7]: 0x163 Block[8]: 0 -- (Bad Block) Block[9]: 0x154 Block[10]: 0x165 ... ... ... Block[24]: 0x165 Block[25]: 0x53 Block[26]: 0x138 Block[27]: 0x49 Block[28]: 0x4 Block[29]: 0x60 ... ... ... Block[494]: 0x13 Block[495]: 0x35 Block[496]: 0 -- (Bad Block) Block[497]: 0 -- (Bad Block) Block[498]: 0 -- (Bad Block) Block[499]: 0 -- (Bad Block) Block[500]: 0 -- (Bad Block) Block[501]: 0 -- (Bad Block) Block[502]: 0 -- (Bad Block) Block[503]: 0 -- (Bad Block) GlobalCntOffset: 0xBD050000 GlobalCntOffsetSLC: 0xA66C0000 SysBlock and SysBlkEraseCnt: [0]: SysBlock: 00000000h SysBlkCnt: 00000000h [1]: SysBlock: 00000000h SysBlkCnt: 00000000h [2]: SysBlock: 00000000h SysBlkCnt: 00000002h [3]: SysBlock: 00000200h SysBlkCnt: 00000000h [4]: SysBlock: 0000004Bh SysBlkCnt: 42000000h [5]: SysBlock: 00000000h SysBlkCnt: 00000000h
只是从我的输出中比较GlobalCntOffset
和GlobalCntOffset_SLC
的值以及正确的输出,您可以看到我在那里有正确的值,但顺序错误且略有偏差。我觉得我非常接近,但我不能排好它。
旁注:
SLC全局计数偏移量为0x1FC~0x1FF(4字节)
TLC全局计数偏移量为0x1F8~0x1FB(4字节)
从偏移0~0x1F7开始,每个字节表示每个超级块的计数。
如果块计数值为0xFE
(例如块0,1,8 ......),则它们将被标记为坏块。
例如:
SLC Global Count (0x24e7)
= 0x2594(9620)TLC Global Count (0x0221)
= 0x27A(634)二进制数据:
00000000 FE A5 11 11 3F A5 A1 A3 FE 9A A5 A4 8E A6 A2 89
00000010 A1 FE A3 A5 8A FE A5 A4 A5 35 8A 31 04 3C 07 1E
00000020 31 31 7A 59 23 01 4D 5E 11 0E 70 0D 41 64 27 63
00000030 57 0F 3A 59 47 29 2A 43 3B 66 02 0A 70 5D 56 5B
00000040 01 FE 4E 57 34 65 94 2E 52 66 5A 63 03 50 53 98
00000050 4E 6C 35 71 10 7B 57 0F 64 8A 70 4B 61 1B 07 3C
00000060 55 7A 46 48 3D 3D 20 02 62 65 69 09 03 3F 40 1D
00000070 61 45 22 15 39 42 4E 4C 13 12 1A 6F 59 63 8C 5A
00000080 28 67 15 2E 55 2A 59 16 0B 3C 68 08 09 42 1B 2D
00000090 0D 4A 0A 2E 82 6A 37 1C 2C 11 54 4E 57 56 25 50
000000a0 09 17 5F 5F 0C 1E 6A 1F 85 28 5A 08 3B 19 79 65
000000b0 13 6C 39 15 05 14 23 FE 47 04 32 52 52 61 1B FE
000000c0 13 2D 40 4C 43 9D 44 78 73 7E 43 35 06 15 5A 67
000000d0 21 34 4B 58 8E 68 1A 81 4B 24 75 64 50 58 5F 6B
000000e0 7E 42 5F 8B 56 77 62 05 57 2C 72 53 1E 4A 50 5C
000000f0 4D 45 1C 63 23 58 53 03 06 34 5A 37 58 44 4A 6C
00000100 7A 55 1E 59 66 68 69 05 6E 35 16 35 6C 15 84 1A
00000110 72 5A 18 3F 1D 65 7C 38 52 53 43 32 40 2A 6C 4C
00000120 77 4D 37 1E 0F 45 19 66 38 21 3D 6B 63 6D 06 37
00000130 1E 18 44 32 45 24 05 6E 1E 5C 6B 0D 09 93 1E 30
00000140 6E 30 52 D5 1C 6B 63 15 53 27 24 16 1B 16 20 33
00000150 7B 40 23 00 38 17 09 68 38 8F 1B 32 75 5F 48 5A
00000160 5D 52 45 75 5E 92 15 A3 21 81 1F 51 27 42 93 59
00000170 63 44 1D 40 18 05 0E 6A 4D 39 52 6F 53 26 6C 73
00000180 0A 10 26 8F 77 30 24 59 1C 66 45 5E 6B 8F 34 73
00000190 2A 7B 1F 48 2A 18 54 55 89 6F 58 16 85 4B 07 59
000001a0 68 2B 3E 89 32 40 5F 81 94 6E 4E 22 99 2C 73 B0
000001b0 18 7D 2E 3C 49 01 3C 50 97 96 1F 5F 6F 21 67 51
000001c0 91 3F 2C 61 51 2E 91 48 0D 5F 20 56 2F 20 7E FE
000001d0 FE FE 3E 39 4C 06 24 0F 02 16 47 7C 47 30 FE FE
000001e0 69 18 17 58 FE 13 28 55 FE 60 01 FE 08 23 0D 23
000001f0 FE FE FE FE FE FE FE FE 00 00 05 BD 00 00 6C A6
00000200