m1n1.fw.dcp: Add OSSerialize parser for DCPAV properties

Signed-off-by: Hector Martin <marcan@marcan.st>
This commit is contained in:
Hector Martin 2021-09-15 17:08:00 +09:00
parent 9b91c90f3a
commit dfb10956bc
2 changed files with 69 additions and 0 deletions

View file

@ -433,6 +433,63 @@ class OSObject(Construct):
class OSDictionary(OSObject): class OSDictionary(OSObject):
TYPE = 'd' TYPE = 'd'
class OSSerialize(Construct):
def _parse(self, stream, context, path, recurse=False):
hdr = Int32ul.parse_stream(stream)
if hdr != 0xd3:
raise Exception("Bad header")
obj, last = self.parse_obj(stream)
assert last
return obj
def parse_obj(self, stream, level=0):
# align to 32 bits
pos = stream.tell()
if pos & 3:
stream.read(4 - (pos & 3))
tag = Int32ul.parse_stream(stream)
last = bool(tag & 0x80000000)
otype = (tag >> 24) & 0x1f
size = tag & 0xffffff
#print(f"{' '*level} @{stream.tell():#x} {otype} {last} {size}")
if otype == 1:
d = {}
for i in range(size):
k, l = self.parse_obj(stream, level + 1)
assert not l
v, l = self.parse_obj(stream, level + 1)
assert l == (i == size - 1)
d[k] = v
elif otype == 2:
d = []
for i in range(size):
v, l = self.parse_obj(stream, level + 1)
assert l == (i == size - 1)
d.append(v)
elif otype == 4:
d = Int64ul.parse_stream(stream)
elif otype == 9:
d = stream.read(size).decode("utf-8")
elif otype == 10:
d = stream.read(size)
elif otype == 11:
d = bool(size)
else:
raise Exception(f"Unknown tag {otype}")
#print(f"{' '*level} => {d}")
return d, last
def _build(self, obj, stream, context, path):
assert False
def _sizeof(self, context, path):
return None
void = None void = None

View file

@ -1,4 +1,5 @@
# SPDX-License-Identifier: MIT # SPDX-License-Identifier: MIT
import pprint
import struct, functools import struct, functools
from dataclasses import dataclass from dataclasses import dataclass
from enum import IntEnum from enum import IntEnum
@ -157,14 +158,25 @@ class DCPManager(DCPBaseManager):
def setDCPAVPropStart(self, length): def setDCPAVPropStart(self, length):
print(f"setDCPAVPropStart({length:#x})") print(f"setDCPAVPropStart({length:#x})")
self.dcpav_prop_len = length - 1 # off by one?
self.dcpav_prop_off = 0
self.dcpav_prop_data = []
return True return True
def setDCPAVPropChunk(self, data, offset, length): def setDCPAVPropChunk(self, data, offset, length):
print(f"setDCPAVPropChunk(..., {offset:#x}, {length:#x})") print(f"setDCPAVPropChunk(..., {offset:#x}, {length:#x})")
assert offset == self.dcpav_prop_off
self.dcpav_prop_data.append(data)
self.dcpav_prop_off += len(data)
return True return True
def setDCPAVPropEnd(self, key): def setDCPAVPropEnd(self, key):
print(f"setDCPAVPropEnd({key!r})") print(f"setDCPAVPropEnd({key!r})")
blob = b"".join(self.dcpav_prop_data)
assert self.dcpav_prop_len == len(blob)
self.dcpav_prop[key] = ipc.OSSerialize().parse(blob)
self.dcpav_prop_data = self.dcpav_prop_len = self.dcpav_prop_off = None
pprint.pprint(self.dcpav_prop[key])
return True return True
def set_boolean_property(self, key, value): def set_boolean_property(self, key, value):