Add EndianIO.parse_pointer function
This is to parse in-memory pointer data bytes into an actual pointer value.
This commit is contained in:
parent
f2e28edc05
commit
eb69ca5632
@ -129,6 +129,20 @@ class EndianIO:
|
||||
return cls.read_ulong(fileobj)
|
||||
raise ValueError("unsupported pointer size %d" % pointer_size)
|
||||
|
||||
@classmethod
|
||||
def parse_pointer(cls, pointer_data: bytes):
|
||||
"""Parse bytes as a pointer value."""
|
||||
|
||||
pointer_size = len(pointer_data)
|
||||
try:
|
||||
typestruct = {
|
||||
4: cls.UINT,
|
||||
8: cls.ULONG,
|
||||
}[pointer_size]
|
||||
except KeyError:
|
||||
raise ValueError("unsupported pointer size %d" % pointer_size)
|
||||
return typestruct.unpack(pointer_data)[0]
|
||||
|
||||
@classmethod
|
||||
def write_pointer(cls, fileobj: typing.IO[bytes], pointer_size: int, value: int):
|
||||
"""Write a pointer to a file."""
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user