Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/pyvex/lifting/lifter.py: 97%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

32 statements  

1from pyvex.block import IRSB 

2from pyvex.types import Arch, LiftSource 

3 

4# pylint:disable=attribute-defined-outside-init 

5 

6 

7class Lifter: 

8 __slots__ = ( 

9 "data", 

10 "bytes_offset", 

11 "opt_level", 

12 "traceflags", 

13 "allow_arch_optimizations", 

14 "strict_block_end", 

15 "collect_data_refs", 

16 "max_inst", 

17 "max_bytes", 

18 "skip_stmts", 

19 "irsb", 

20 "arch", 

21 "addr", 

22 "cross_insn_opt", 

23 "load_from_ro_regions", 

24 "const_prop", 

25 "disasm", 

26 "dump_irsb", 

27 ) 

28 

29 """ 

30 A lifter is a class of methods for processing a block. 

31 

32 :ivar data: The bytes to lift as either a python string of bytes or a cffi buffer object. 

33 :ivar bytes_offset: The offset into `data` to start lifting at. 

34 :ivar max_bytes: The maximum number of bytes to lift. If set to None, no byte limit is used. 

35 :ivar max_inst: The maximum number of instructions to lift. If set to None, no instruction limit is used. 

36 :ivar opt_level: The level of optimization to apply to the IR, 0-2. Most likely will be ignored in any lifter 

37 other then LibVEX. 

38 :ivar traceflags: The libVEX traceflags, controlling VEX debug prints. Most likely will be ignored in any 

39 lifter other than LibVEX. 

40 :ivar allow_arch_optimizations: Should the LibVEX lifter be allowed to perform lift-time preprocessing 

41 optimizations (e.g., lookback ITSTATE optimization on THUMB) 

42 Most likely will be ignored in any lifter other than LibVEX. 

43 :ivar strict_block_end: Should the LibVEX arm-thumb split block at some instructions, for example CB{N}Z. 

44 :ivar skip_stmts: Should LibVEX ignore statements. 

45 """ 

46 REQUIRE_DATA_C = False 

47 REQUIRE_DATA_PY = False 

48 

49 def __init__(self, arch: Arch, addr: int): 

50 self.arch: Arch = arch 

51 self.addr: int = addr 

52 

53 def lift( 

54 self, 

55 data: LiftSource, 

56 bytes_offset: int | None = None, 

57 max_bytes: int | None = None, 

58 max_inst: int | None = None, 

59 opt_level: int | float = 1, 

60 traceflags: int | None = None, 

61 allow_arch_optimizations: bool | None = None, 

62 strict_block_end: bool | None = None, 

63 skip_stmts: bool = False, 

64 collect_data_refs: bool = False, 

65 cross_insn_opt: bool = True, 

66 load_from_ro_regions: bool = False, 

67 const_prop: bool = False, 

68 disasm: bool = False, 

69 dump_irsb: bool = False, 

70 ): 

71 """ 

72 Wrapper around the `_lift` method on Lifters. Should not be overridden in child classes. 

73 

74 :param data: The bytes to lift as either a python string of bytes or a cffi buffer object. 

75 :param bytes_offset: The offset into `data` to start lifting at. 

76 :param max_bytes: The maximum number of bytes to lift. If set to None, no byte limit is used. 

77 :param max_inst: The maximum number of instructions to lift. If set to None, no instruction limit is 

78 used. 

79 :param opt_level: The level of optimization to apply to the IR, 0-2. Most likely will be ignored in 

80 any lifter other then LibVEX. 

81 :param traceflags: The libVEX traceflags, controlling VEX debug prints. Most likely will be ignored in 

82 any lifter other than LibVEX. 

83 :param allow_arch_optimizations: Should the LibVEX lifter be allowed to perform lift-time preprocessing 

84 optimizations (e.g., lookback ITSTATE optimization on THUMB) Most likely will be 

85 ignored in any lifter other than LibVEX. 

86 :param strict_block_end: Should the LibVEX arm-thumb split block at some instructions, for example CB{N}Z. 

87 :param skip_stmts: Should the lifter skip transferring IRStmts from C to Python. 

88 :param collect_data_refs: Should the LibVEX lifter collect data references in C. 

89 :param cross_insn_opt: If cross-instruction-boundary optimizations are allowed or not. 

90 :param disasm: Should the GymratLifter generate disassembly during lifting. 

91 :param dump_irsb: Should the GymratLifter log the lifted IRSB. 

92 """ 

93 irsb: IRSB = IRSB.empty_block(self.arch, self.addr) 

94 self.data = data 

95 self.bytes_offset = bytes_offset 

96 self.opt_level = opt_level 

97 self.traceflags = traceflags 

98 self.allow_arch_optimizations = allow_arch_optimizations 

99 self.strict_block_end = strict_block_end 

100 self.collect_data_refs = collect_data_refs 

101 self.max_inst = max_inst 

102 self.max_bytes = max_bytes 

103 self.skip_stmts = skip_stmts 

104 self.irsb = irsb 

105 self.cross_insn_opt = cross_insn_opt 

106 self.load_from_ro_regions = load_from_ro_regions 

107 self.const_prop = const_prop 

108 self.disasm = disasm 

109 self.dump_irsb = dump_irsb 

110 self._lift() 

111 return self.irsb 

112 

113 def _lift(self): 

114 """ 

115 Lifts the data using the information passed into _lift. Should be overridden in child classes. 

116 

117 Should set the lifted IRSB to self.irsb. 

118 If a lifter raises a LiftingException on the data, this signals that the lifter cannot lift this data and arch 

119 and the lifter is skipped. 

120 If a lifter can lift any amount of data, it should lift it and return the lifted block with a jumpkind of 

121 Ijk_NoDecode, signalling to pyvex that other lifters should be used on the undecodable data. 

122 

123 """ 

124 raise NotImplementedError()