Open gbdngb12 opened 9 months ago
def get_offset(self, member_name):
offset = 0
for attr in self.__dict__:
if attr == member_name:
return offset
else:
val = getattr(self, attr)
if isinstance(val, int):
offset += struct.calcsize("P") # for 64-bit system
elif isinstance(val, str):
offset += len(val)
else:
offset += struct.calcsize("P") # default to pointer size
return "No such member in the class"
def get_member(self, offset_target):
offset = 0
for attr in self.__dict__:
val = getattr(self, attr)
if isinstance(val, int):
size = struct.calcsize("P") # for 64-bit system
elif isinstance(val, str):
size = len(val)
else:
size = struct.calcsize("P") # default to pointer size
if offset <= offset_target < offset + size:
return attr
offset += size
return "No member found at the given offset"