ContainerHelper does not look right that .container returns None
t-wy opened this issue · comments
Code
ObjectReader.py
@property
def container(self):
return (
self.assets_file._container[self.path_id]
if self.path_id in self.assets_file._container
else None
)
SerializedFile.py
class ContainerHelper:
"""Helper class to allow multidict containers
without breaking compatibility with old versions"""
def __init__(self, container) -> None:
self.container = container
# support for getitem
self.container_dict = {key: value.asset for key, value in container}
self.path_dict = {value.asset.path_id: value.asset for key, value in container}
...
def __getitem__(self, key):
return self.container_dict[key]
Bug
Expected: the container path, just as the non-null values before ContainerHelper was implemented
Actual: None
container property retrieves the value from ContainerHelper by path_id as key, which in ContainerHelper find the key from container_dict
internally.
However, container_dict
uses the container path as key, so path_id probably does not exist in the key list.
The supposed routine is to retrieve the container path from path_id. container_dict returns the object by container path, and path_dict returns the object by path_id.
Therefore, probably a dict mapping path_id to key is needed instead.
Something like
{value.asset.path_id: key for key, value in container}
To Reproduce
Calling .container property for objects with container path.
Minimal example:
f = UnityPy.load(content)
print([x.container for x in f.objects])
Return value:
[None, None, None, None, None, None, None, None, None, None, None, None, None, None]
- UnityPy version 1.10.2