Skip to content

Commit 8823ced

Browse files
committed
pypanda: add optional bits arg to to_unsigned_guest
1 parent 6c98cd7 commit 8823ced

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

panda/python/core/pandare/panda.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,24 +1001,27 @@ def read_str(self, cpu, ptr, max_length=None):
10011001
idx += 1
10021002
return r.decode("utf8", "ignore")
10031003

1004-
def to_unsigned_guest(self, x):
1004+
def to_unsigned_guest(self, x, bits=None):
10051005
'''
10061006
Convert a singed python int to an unsigned int32/unsigned int64
10071007
depending on guest bit-size
10081008
10091009
Args:
10101010
x (int): Python integer
1011+
bits (int): Number of bits to treat this value as. If unset, uses architecture default
10111012
10121013
Returns:
10131014
int: Python integer representing x as an unsigned value in the guest's pointer-size.
10141015
'''
10151016
import ctypes
1016-
if self.bits == 32:
1017+
if bits is None:
1018+
bits = self.bits
1019+
if bits == 32:
10171020
return ctypes.c_uint32(x).value
1018-
elif self.bits == 64:
1021+
elif bits == 64:
10191022
return ctypes.c_uint64(x).value
10201023
else:
1021-
raise ValueError("Unsupported number of bits")
1024+
raise ValueError(f"Unsupported number of bits {bits}")
10221025

10231026
def from_unsigned_guest(self, x):
10241027
'''

0 commit comments

Comments
 (0)