m1n1.constructutils: Keep a global addr->struct map

This allows easily identifying pointers to the beginning of structs.

Signed-off-by: Asahi Lina <lina@asahilina.net>
This commit is contained in:
Asahi Lina 2022-08-17 13:19:10 +09:00
parent 9a94937e3f
commit 2d1151041f

View file

@ -8,6 +8,7 @@ from construct.lib import HexDisplayedInteger
from .utils import * from .utils import *
g_struct_trace = set() g_struct_trace = set()
g_struct_addrmap = {}
g_depth = 0 g_depth = 0
def recusive_reload(obj, token=None): def recusive_reload(obj, token=None):
@ -80,6 +81,10 @@ def str_value(value, repr=False):
if isinstance(value, DecDisplayedInteger): if isinstance(value, DecDisplayedInteger):
return str(value) return str(value)
if isinstance(value, int): if isinstance(value, int):
if value in g_struct_addrmap:
desc = g_struct_addrmap[value]
return f"{value:#x} ({desc})"
else:
return f"{value:#x}" return f"{value:#x}"
if isinstance(value, ListContainer): if isinstance(value, ListContainer):
if len(value) <= 16: if len(value) <= 16:
@ -319,7 +324,9 @@ class ConstructClassBase(Reloadable, metaclass=ReloadableConstructMeta):
self._apply(obj) self._apply(obj)
if self._addr > 0x10000:
g_struct_trace.add((self._addr, f"{cls.name} (end: {self._addr + size:#x})")) g_struct_trace.add((self._addr, f"{cls.name} (end: {self._addr + size:#x})"))
g_struct_addrmap[self._addr] = f"{cls.name}"
return self return self
@classmethod @classmethod