Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swap Lifter.lift and Lifter._lift to respect public/private semantics #344

Merged
merged 1 commit into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pyvex/lifting/gym/arm_spotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,12 +415,12 @@ def __init__(self, *args):
super().__init__(*args)
self.thumb: bool = False

def lift(self, disassemble=False, dump_irsb=False):
def _lift(self, disassemble=False, dump_irsb=False):
if self.irsb.addr & 1:
# Thumb!
self.instrs = self.thumb_instrs
self.thumb = True
else:
self.instrs = self.arm_instrs
self.thumb = False
super().lift(disassemble, dump_irsb)
super()._lift(disassemble, dump_irsb)
2 changes: 1 addition & 1 deletion pyvex/lifting/libvex.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class LibVEXLifter(Lifter):
def get_vex_log():
return bytes(ffi.buffer(pvc.msg_buffer, pvc.msg_current_size)).decode() if pvc.msg_buffer != ffi.NULL else None

def lift(self):
def _lift(self):
try:
_libvex_lock.acquire()

Expand Down
4 changes: 2 additions & 2 deletions pyvex/lifting/lift_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def lift(
)

try:
final_irsb = lifter(arch, addr)._lift(
final_irsb = lifter(arch, addr).lift(
u_data,
bytes_offset - skip,
max_bytes,
Expand All @@ -142,7 +142,7 @@ def lift(
)
except SkipStatementsError:
assert skip_stmts is True
final_irsb = lifter(arch, addr)._lift(
final_irsb = lifter(arch, addr).lift(
u_data,
bytes_offset - skip,
max_bytes,
Expand Down
8 changes: 4 additions & 4 deletions pyvex/lifting/lifter.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def __init__(self, arch, addr):
self.arch = arch
self.addr = addr

def _lift(
def lift(
self,
data,
bytes_offset=None,
Expand All @@ -62,7 +62,7 @@ def _lift(
load_from_ro_regions=False,
):
"""
Wrapper around the `lift` method on Lifters. Should not be overridden in child classes.
Wrapper around the `_lift` method on Lifters. Should not be overridden in child classes.

:param data: The bytes to lift as either a python string of bytes or a cffi buffer object.
:param bytes_offset: The offset into `data` to start lifting at.
Expand Down Expand Up @@ -95,10 +95,10 @@ def _lift(
self.irsb = irsb
self.cross_insn_opt = cross_insn_opt
self.load_from_ro_regions = load_from_ro_regions
self.lift()
self._lift()
return self.irsb

def lift(self):
def _lift(self):
"""
Lifts the data using the information passed into _lift. Should be overridden in child classes.

Expand Down
2 changes: 1 addition & 1 deletion pyvex/lifting/util/lifter_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def decode(self):
log.exception(f"Error decoding block at offset {bytepos:#x} (address {addr:#x}):")
raise

def lift(self, disassemble=False, dump_irsb=False):
def _lift(self, disassemble=False, dump_irsb=False):
self.thedata = (
self.data[: self.max_bytes]
if isinstance(self.data, (bytes, bytearray, memoryview))
Expand Down
2 changes: 1 addition & 1 deletion tests/test_lift.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class NOPLifter(GymratLifter):

lifter = NOPLifter(archinfo.ArchAMD64(), 0)
# this should not throw an exception
block = lifter._lift("\x0F\x0Fa")
block = lifter.lift("\x0F\x0Fa")
assert block.size == 2
assert block.instructions == 1
assert block.jumpkind == JumpKind.NoDecode
Expand Down
Loading