Skip to content

Commit

Permalink
panda arch: special case retval from aarch64
Browse files Browse the repository at this point in the history
  • Loading branch information
lacraig2 committed Jan 21, 2025
1 parent 0ae118a commit 0385009
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
6 changes: 5 additions & 1 deletion panda/python/core/pandare/arch.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,11 @@ def get_retval(self, cpu, convention='default'):
rv = self.get_reg(cpu, reg)

if convention == 'syscall':
rv = self.panda.from_unsigned_guest(rv)
bits = None
if self.panda.arch_name == "aarch64":
if cpu.env_ptr.aarch64 == 0:
bits = 32
rv = self.panda.from_unsigned_guest(rv, bits=bits)
return rv


Expand Down
8 changes: 5 additions & 3 deletions panda/python/core/pandare/panda.py
Original file line number Diff line number Diff line change
Expand Up @@ -1057,7 +1057,7 @@ def to_unsigned_guest(self, x):
else:
raise ValueError("Unsupported number of bits")

def from_unsigned_guest(self, x):
def from_unsigned_guest(self, x, bits=None):
'''
Convert an unsigned int32/unsigned int64 from the guest
(depending on guest bit-size) to a (signed) python int
Expand All @@ -1068,8 +1068,10 @@ def from_unsigned_guest(self, x):
Returns:
int: Python integer representing x as a signed value
'''
if x >= 2**(self.bits-1): # If highest bit is set, it's negative
return (x - 2**self.bits)
if bits is None:
bits = self.bits
if x >= 2**(bits-1): # If highest bit is set, it's negative
return (x - 2**bits)
else: # Else it's positive
return x

Expand Down

0 comments on commit 0385009

Please sign in to comment.