Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/pyvex/lifting/lifter.py: 96%
27 statements
« prev ^ index » next coverage.py v7.3.1, created at 2023-09-25 06:15 +0000
« prev ^ index » next coverage.py v7.3.1, created at 2023-09-25 06:15 +0000
1from pyvex.block import IRSB
3# pylint:disable=attribute-defined-outside-init
6class Lifter:
7 __slots__ = (
8 "data",
9 "bytes_offset",
10 "opt_level",
11 "traceflags",
12 "allow_arch_optimizations",
13 "strict_block_end",
14 "collect_data_refs",
15 "max_inst",
16 "max_bytes",
17 "skip_stmts",
18 "irsb",
19 "arch",
20 "addr",
21 "cross_insn_opt",
22 "load_from_ro_regions",
23 )
25 """
26 A lifter is a class of methods for processing a block.
28 :ivar data: The bytes to lift as either a python string of bytes or a cffi buffer object.
29 :ivar bytes_offset: The offset into `data` to start lifting at.
30 :ivar max_bytes: The maximum number of bytes to lift. If set to None, no byte limit is used.
31 :ivar max_inst: The maximum number of instructions to lift. If set to None, no instruction limit is used.
32 :ivar opt_level: The level of optimization to apply to the IR, 0-2. Most likely will be ignored in any lifter
33 other then LibVEX.
34 :ivar traceflags: The libVEX traceflags, controlling VEX debug prints. Most likely will be ignored in any
35 lifter other than LibVEX.
36 :ivar allow_arch_optimizations: Should the LibVEX lifter be allowed to perform lift-time preprocessing
37 optimizations (e.g., lookback ITSTATE optimization on THUMB)
38 Most likely will be ignored in any lifter other than LibVEX.
39 :ivar strict_block_end: Should the LibVEX arm-thumb split block at some instructions, for example CB{N}Z.
40 :ivar skip_stmts: Should LibVEX ignore statements.
41 """
42 REQUIRE_DATA_C = False
43 REQUIRE_DATA_PY = False
45 def __init__(self, arch, addr):
46 self.arch = arch
47 self.addr = addr
49 def lift(
50 self,
51 data,
52 bytes_offset=None,
53 max_bytes=None,
54 max_inst=None,
55 opt_level=1,
56 traceflags=None,
57 allow_arch_optimizations=None,
58 strict_block_end=None,
59 skip_stmts=False,
60 collect_data_refs=False,
61 cross_insn_opt=True,
62 load_from_ro_regions=False,
63 ):
64 """
65 Wrapper around the `_lift` method on Lifters. Should not be overridden in child classes.
67 :param data: The bytes to lift as either a python string of bytes or a cffi buffer object.
68 :param bytes_offset: The offset into `data` to start lifting at.
69 :param max_bytes: The maximum number of bytes to lift. If set to None, no byte limit is used.
70 :param max_inst: The maximum number of instructions to lift. If set to None, no instruction limit is
71 used.
72 :param opt_level: The level of optimization to apply to the IR, 0-2. Most likely will be ignored in
73 any lifter other then LibVEX.
74 :param traceflags: The libVEX traceflags, controlling VEX debug prints. Most likely will be ignored in
75 any lifter other than LibVEX.
76 :param allow_arch_optimizations: Should the LibVEX lifter be allowed to perform lift-time preprocessing
77 optimizations (e.g., lookback ITSTATE optimization on THUMB) Most likely will be
78 ignored in any lifter other than LibVEX.
79 :param strict_block_end: Should the LibVEX arm-thumb split block at some instructions, for example CB{N}Z.
80 :param skip_stmts: Should the lifter skip transferring IRStmts from C to Python.
81 :param collect_data_refs: Should the LibVEX lifter collect data references in C.
82 :param cross_insn_opt: If cross-instruction-boundary optimizations are allowed or not.
83 """
84 irsb = IRSB.empty_block(self.arch, self.addr)
85 self.data = data
86 self.bytes_offset = bytes_offset
87 self.opt_level = opt_level
88 self.traceflags = traceflags
89 self.allow_arch_optimizations = allow_arch_optimizations
90 self.strict_block_end = strict_block_end
91 self.collect_data_refs = collect_data_refs
92 self.max_inst = max_inst
93 self.max_bytes = max_bytes
94 self.skip_stmts = skip_stmts
95 self.irsb = irsb
96 self.cross_insn_opt = cross_insn_opt
97 self.load_from_ro_regions = load_from_ro_regions
98 self._lift()
99 return self.irsb
101 def _lift(self):
102 """
103 Lifts the data using the information passed into _lift. Should be overridden in child classes.
105 Should set the lifted IRSB to self.irsb.
106 If a lifter raises a LiftingException on the data, this signals that the lifter cannot lift this data and arch
107 and the lifter is skipped.
108 If a lifter can lift any amount of data, it should lift it and return the lifted block with a jumpkind of
109 Ijk_NoDecode, signalling to pyvex that other lifters should be used on the undecodable data.
111 """
112 raise NotImplementedError()