This commit is contained in:
gregorni 2023-09-16 15:32:48 +02:00
commit 8dc0abd0ca
2 changed files with 15 additions and 5 deletions

View file

@ -18,6 +18,7 @@
# SPDX-License-Identifier: LGPL-3.0-or-later # SPDX-License-Identifier: LGPL-3.0-or-later
import os import os
import sys
import typing as T import typing as T
from functools import cached_property from functools import cached_property
@ -948,8 +949,8 @@ class Repository(GirNode):
return self.lookup_namespace(ns).get_type(dir_entry.DIR_ENTRY_NAME) return self.lookup_namespace(ns).get_type(dir_entry.DIR_ENTRY_NAME)
def _resolve_type_id(self, type_id: int) -> GirType: def _resolve_type_id(self, type_id: int) -> GirType:
if type_id & 0xFFFFFF == 0: if type_id & (0xFFFFFF if sys.byteorder == "little" else 0xFFFFFF00) == 0:
type_id = (type_id >> 27) & 0x1F type_id = ((type_id >> 27) if sys.byteorder == "little" else type_id) & 0x1F
# simple type # simple type
if type_id == typelib.TYPE_BOOLEAN: if type_id == typelib.TYPE_BOOLEAN:
return BoolType() return BoolType()

View file

@ -61,7 +61,14 @@ class Field:
def __init__(self, offset: int, type: str, shift=0, mask=None): def __init__(self, offset: int, type: str, shift=0, mask=None):
self._offset = offset self._offset = offset
self._type = type self._type = type
self._shift = shift if not mask or sys.byteorder == "little":
self._shift = shift
elif self._type == "u8" or self._type == "i8":
self._shift = 8 - (shift + mask)
elif self._type == "u16" or self._type == "i16":
self._shift = 16 - (shift + mask)
else:
self._shift = 32 - (shift + mask)
self._mask = (1 << mask) - 1 if mask else None self._mask = (1 << mask) - 1 if mask else None
self._name = f"{offset}__{type}__{shift}__{mask}" self._name = f"{offset}__{type}__{shift}__{mask}"
@ -174,7 +181,7 @@ class Typelib:
OBJ_FINAL = Field(0x02, "u16", 3, 1) OBJ_FINAL = Field(0x02, "u16", 3, 1)
OBJ_GTYPE_NAME = Field(0x08, "string") OBJ_GTYPE_NAME = Field(0x08, "string")
OBJ_PARENT = Field(0x10, "dir_entry") OBJ_PARENT = Field(0x10, "dir_entry")
OBJ_GTYPE_STRUCT = Field(0x14, "string") OBJ_GTYPE_STRUCT = Field(0x12, "string")
OBJ_N_INTERFACES = Field(0x14, "u16") OBJ_N_INTERFACES = Field(0x14, "u16")
OBJ_N_FIELDS = Field(0x16, "u16") OBJ_N_FIELDS = Field(0x16, "u16")
OBJ_N_PROPERTIES = Field(0x18, "u16") OBJ_N_PROPERTIES = Field(0x18, "u16")
@ -259,7 +266,9 @@ class Typelib:
def _int(self, size, signed) -> int: def _int(self, size, signed) -> int:
return int.from_bytes( return int.from_bytes(
self._typelib_file[self._offset : self._offset + size], sys.byteorder self._typelib_file[self._offset : self._offset + size],
sys.byteorder,
signed=signed,
) )