handling of string arrays and string-string maps
This commit is contained in:
@ -34,6 +34,25 @@ def uint32_to_id(val):
|
||||
def read_nbo(pCh):
|
||||
return struct.unpack('!I', pCh[:4])[0]
|
||||
|
||||
def read_string(data, start_index):
|
||||
# Helper function to read an unsigned 32-bit integer from the data (big-endian)
|
||||
def read_uint32(data, index):
|
||||
return int.from_bytes(data[index:index+4], byteorder='big')
|
||||
|
||||
# Determine the string length
|
||||
string_length = read_uint32(data, start_index)
|
||||
start_index += 4
|
||||
|
||||
# Read the string based on the determined length
|
||||
result = data[start_index:start_index + string_length].rstrip(b'\0').decode('utf-8')
|
||||
start_index += string_length
|
||||
|
||||
# Calculate the allocated space for the string
|
||||
string_space_allocation = 4 * (1 + ((string_length - 1) // 4))
|
||||
bytes_read = 4 + string_space_allocation
|
||||
|
||||
return bytes_read, result
|
||||
|
||||
def bmms_index_bin_block_pos(pcDataBuf):
|
||||
|
||||
GenBlockList = []
|
||||
@ -164,21 +183,35 @@ def bmms_bin_entry_genericparser(pcDataBuf):
|
||||
|
||||
mEntry['Val'] = mList
|
||||
|
||||
case 0x05000000 | 0xa5000000 :
|
||||
# string and string array
|
||||
|
||||
sList = pcDataBuf[st_ReadedBytes:st_ReadedBytes + uiSize-8].split(b'\b')
|
||||
case 0x05000000 :
|
||||
# string
|
||||
mEntry['Val'] = pcDataBuf[st_ReadedBytes:st_ReadedBytes + uiSize-8].rstrip(b'\0').decode('utf-8')
|
||||
|
||||
case 0xa5000000 :
|
||||
# string array
|
||||
nStrings = read_nbo(pcDataBuf[st_ReadedBytes:st_ReadedBytes + 4])
|
||||
st_ReadedBytes+=4
|
||||
mList = []
|
||||
for mStr in sList:
|
||||
mList.append(mStr.rstrip(b'\0').decode('utf-8'))
|
||||
for _ in range (nStrings):
|
||||
bytes_read, sString = read_string(pcDataBuf,st_ReadedBytes)
|
||||
mList.append(sString)
|
||||
st_ReadedBytes += bytes_read
|
||||
|
||||
if uiType == 0xa5000000 and len(mList)>0:
|
||||
mList.pop(0)
|
||||
mEntry['Val'] = mList
|
||||
|
||||
|
||||
case 0xc5000000 :
|
||||
# string-string map
|
||||
mEntry['Val'] = pcDataBuf[st_ReadedBytes:st_ReadedBytes + uiSize-8]
|
||||
nStrings = read_nbo(pcDataBuf[st_ReadedBytes:st_ReadedBytes + 4])
|
||||
st_ReadedBytes+=4
|
||||
mList = []
|
||||
for _ in range (int(nStrings/2)):
|
||||
bytes_read, sString_1 = read_string(pcDataBuf,st_ReadedBytes)
|
||||
st_ReadedBytes += bytes_read
|
||||
bytes_read, sString_2 = read_string(pcDataBuf,st_ReadedBytes)
|
||||
st_ReadedBytes += bytes_read
|
||||
mList.append(tuple([sString_1,sString_2]))
|
||||
mEntry['Val'] = mList
|
||||
|
||||
case other:
|
||||
return mEntry
|
||||
|
@ -134,12 +134,34 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 9,
|
||||
"execution_count": 13,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"{'Type': 'SWVE',\n",
|
||||
" 'Val': [('1-System-Version', 'G2_R4.3.1'),\n",
|
||||
" ('2-TcsFramework-Version', 'TF_R5.3.1'),\n",
|
||||
" ('3-Foundation-Version', 'FO_R4.2.2'),\n",
|
||||
" ('4-SVN-Revision', '31259')]}"
|
||||
]
|
||||
},
|
||||
"execution_count": 13,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"parsed_all[0]['entries'][16]"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"#parsed_all"
|
||||
]
|
||||
"source": []
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
|
Reference in New Issue
Block a user