angr/pyvex

Error when adding lifters and no max_bytes

Closed this issue · 2 comments

Hello!

I have some extra lifters for instructions not handled by pyvex, I recently updated the package (after a while of not doing it) and I got an error:

Traceback (most recent call last):
  File "test.py", line 22, in <module>
    irsb = pyvex.IRSB(b'\x80\x00\x0C\xF1', 0x1001, archinfo.ArchARM())
  File "/home/user/.virtualenvs/env/lib/python3.8/site-packages/pyvex/block.py", line 106, in __init__
    irsb = lift(data, mem_addr, arch,
  File "/home/noutoff/.virtualenvs/env/lib/python3.8/site-packages/pyvex/lifting/__init__.py", line 102, in lift
    u_data = py_data[skip : skip + max_bytes]
TypeError: unsupported operand type(s) for +: 'int' and 'NoneType'

Minimal code to reproduce the error:

import pyvex
import archinfo
from pyvex.lifting.util import *
from pyvex.lifting import lifters

class Instruction_CPSID(Instruction):
    bin_format = '11110001000011000000000aif000000'
    name = 'cpsid'
    def compute_result(self):
        pass
    def disassemble(self):
        return self.addr, 'CPSID', [self.rawbits]

class LifterThumb(GymratLifter):
        instrs = [Instruction_CPSID]

lifters['ARMEL'].insert(0, LifterThumb)
irsb = pyvex.IRSB(b'\x80\x00\x0C\xF1', 0x1001, archinfo.ArchARM())

I "fixed" it by ignoring both skip and max_bytes if max_bytes is None but I'm not sure it's the correct way to do it.

diff --git a/pyvex/lifting/__init__.py b/pyvex/lifting/__init__.py
index e856123..c29fbe2 100644
--- a/pyvex/lifting/__init__.py
+++ b/pyvex/lifting/__init__.py
@@ -99,7 +99,10 @@ def lift(data, addr, arch, max_bytes=None, max_inst=None, bytes_offset=0, opt_le
                         continue
                     u_data = ffi.buffer(c_data + skip, max_bytes)[:]
                 else:
-                    u_data = py_data[skip : skip + max_bytes]
+                    if not max_bytes:
+                        u_data = py_data
+                    else:
+                        u_data = py_data[skip : skip + max_bytes]
             else:
                 raise RuntimeError("Incorrect lifter configuration. What type of data does %s expect?"
                                    % lifter.__class__)

This issue has been marked as stale because it has no recent activity. Please comment or add the pinned tag to prevent this issue from being closed.

I've added a version of your patch to master, and it seems to be fixed. Thanks!