1
1
import copy
2
- import sys
3
2
import itertools
3
+ import logging
4
4
from typing import List , Optional
5
5
6
- from pyvex .expr import IRExpr
7
- from pyvex .stmt import IRStmt
8
-
9
- from . import VEXObject
10
6
from . import expr , stmt
11
7
from .const import get_type_size
12
- from .stmt import WrTmp , LoadG , LLSC , Dirty , CAS , get_enum_from_int , get_int_from_enum , Exit , IMark
13
- from .expr import RdTmp
14
8
from .data_ref import DataRef
9
+ from .enums import VEXObject
15
10
from .errors import SkipStatementsError
11
+ from .expr import RdTmp
12
+ from .native import pvc
13
+ from .stmt import CAS , LLSC , Dirty , Exit , IMark , IRExpr , IRStmt , LoadG , WrTmp , get_enum_from_int , get_int_from_enum
16
14
17
-
18
- import logging
19
-
20
- l = logging .getLogger ("pyvex.block" )
15
+ log = logging .getLogger ("pyvex.block" )
21
16
22
17
23
18
class IRSB (VEXObject ):
@@ -88,8 +83,10 @@ def __init__(
88
83
:type arch: :class:`archinfo.Arch`
89
84
:param max_inst: The maximum number of instructions to lift. (See note below)
90
85
:param max_bytes: The maximum number of bytes to use.
91
- :param num_inst: Replaces max_inst if max_inst is None. If set to None as well, no instruction limit is used.
92
- :param num_bytes: Replaces max_bytes if max_bytes is None. If set to None as well, no byte limit is used.
86
+ :param num_inst: Replaces max_inst if max_inst is None. If set to None as well, no instruction limit
87
+ is used.
88
+ :param num_bytes: Replaces max_bytes if max_bytes is None. If set to None as well, no byte limit is
89
+ used.
93
90
:param bytes_offset: The offset into `data` to start lifting at. Note that for ARM THUMB mode, both
94
91
`mem_addr` and `bytes_offset` must be odd (typically `bytes_offset` is set to 1).
95
92
:param traceflags: The libVEX traceflags, controlling VEX debug prints.
@@ -117,10 +114,10 @@ def __init__(
117
114
self .addr = mem_addr
118
115
self .arch = arch
119
116
120
- self .statements = [] # type: List[IRStmt ]
121
- self .next = None # type : Optional[IRExpr]
117
+ self .statements : List [ IRStmt ] = [ ]
118
+ self .next : Optional [IRExpr ] = None
122
119
self ._tyenv = None
123
- self .jumpkind = None # type : Optional[str]
120
+ self .jumpkind : Optional [str ] = None
124
121
self ._direct_next = None
125
122
self ._size = None
126
123
self ._instructions = None
@@ -133,6 +130,8 @@ def __init__(
133
130
# This is the slower path (because we need to call _from_py() to copy the content in the returned IRSB to
134
131
# the current IRSB instance. You should always call `lift()` directly. This method is kept for compatibility
135
132
# concerns.
133
+ from pyvex .lifting import lift
134
+
136
135
irsb = lift (
137
136
data ,
138
137
mem_addr ,
@@ -225,8 +224,8 @@ def convert_tmp(tmp):
225
224
226
225
def convert_expr (expr_ ):
227
226
"""
228
- Converts a VEX expression to use tmps in the appended-block instead of the appended-to-block. Used to prevent
229
- collisions in tmp numbers between the two blocks.
227
+ Converts a VEX expression to use tmps in the appended-block instead of the appended-to-block. Used to
228
+ prevent collisions in tmp numbers between the two blocks.
230
229
:param tmp: The VEX expression to convert
231
230
:vartype expr: :class:`IRExpr`
232
231
"""
@@ -304,7 +303,7 @@ def typecheck(self):
304
303
assert self .next is not None , "Missing next expression"
305
304
assert self .jumpkind is not None , "Missing jumpkind"
306
305
307
- # type assertions
306
+ # Type assertions
308
307
assert isinstance (self .next , expr .IRExpr ), "Next expression is not an expression"
309
308
assert type (self .jumpkind is str ), "Jumpkind is not a string"
310
309
assert self .jumpkind .startswith ("Ijk_" ), "Jumpkind is not a jumpkind enum"
@@ -316,7 +315,7 @@ def typecheck(self):
316
315
assert isinstance (st , stmt .IRStmt ), "Statement %d is not an IRStmt" % i
317
316
try :
318
317
assert st .typecheck (self .tyenv ), "Statement %d failed to typecheck" % i
319
- except : # pylint: disable=bare-except
318
+ except Exception : # pylint: disable=bare-except
320
319
assert False , "Statement %d errored in typechecking" % i
321
320
322
321
if type (st ) is stmt .NoOp :
@@ -331,7 +330,7 @@ def typecheck(self):
331
330
332
331
assert last_imark is not None , "No IMarks present in block"
333
332
except AssertionError as e :
334
- l .debug (e .args [0 ])
333
+ log .debug (e .args [0 ])
335
334
return False
336
335
return True
337
336
@@ -433,7 +432,8 @@ def operations(self):
433
432
@property
434
433
def all_constants (self ):
435
434
"""
436
- Returns all constants in the block (including incrementing of the program counter) as :class:`pyvex.const.IRConst`.
435
+ Returns all constants in the block (including incrementing of the program counter) as
436
+ :class:`pyvex.const.IRConst`.
437
437
"""
438
438
return sum ((e .constants for e in self .expressions ), [])
439
439
@@ -634,7 +634,7 @@ def lookup(self, tmp):
634
634
Return the type of temporary variable `tmp` as an enum string
635
635
"""
636
636
if tmp < 0 or tmp > self .types_used :
637
- l .debug ("Invalid temporary number %d" , tmp )
637
+ log .debug ("Invalid temporary number %d" , tmp )
638
638
raise IndexError (tmp )
639
639
return self .types [tmp ]
640
640
@@ -670,7 +670,3 @@ def typecheck(self):
670
670
except ValueError :
671
671
return False
672
672
return True
673
-
674
-
675
- from . import pvc
676
- from .lifting import lift
0 commit comments