FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
pyt/pyt/lattice.py at 8githubScanRefactor · python-security/pyt · GitHub
python-security
pyt
Repository navigation
Code
Issues
26
(26)
Pull requests
2
(2)
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
pyt
/
pyt
/
lattice.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
51 lines (39 loc) · 1.42 KB
Breadcrumbs
pyt
/
pyt
/
lattice.py
Copy path
File metadata and controls
51 lines (39 loc) · 1.42 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from
.
constraint_table
import
constraint_table
class
Lattice
:
def
__init__
(
self
,
cfg_nodes
,
analysis_type
):
self
.
el2bv
=
dict
()
# Element to bitvector dictionary
self
.
bv2el
=
list
()
# Bitvector to element list
for
i
,
e
in
enumerate
(
analysis_type
.
get_lattice_elements
(
cfg_nodes
)):
self
.
el2bv
[
e
]
=
0b1
<<
i
self
.
bv2el
.
append
(
e
)
self
.
bv2el
=
list
(
reversed
(
self
.
bv2el
))
def
get_elements
(
self
,
number
):
r
=
list
()
if
number
==
0
:
return
r
for
i
,
x
in
enumerate
(
format
(
number
,
'0'
+
str
(
len
(
self
.
bv2el
))
+
'b'
)):
if
x
==
'1'
:
r
.
append
(
self
.
bv2el
[
i
])
return
r
def
in_constraint
(
self
,
node1
,
node2
):
"""Checks if node1 is in node2's constraints
For instance node1 = 010 and node2 = 110:
010 & 110 = 010 -> has the element."""
constraint
=
constraint_table
[
node2
]
try
:
value
=
self
.
el2bv
[
node1
]
except
KeyError
:
value
=
0b0
if
constraint
==
0b0
or
value
==
0b0
:
return
False
return
constraint
&
value
!=
0
def
print_lattice
(
cfg_list
,
analysis_type
):
nodes
=
list
()
for
cfg
in
cfg_list
:
nodes
.
extend
(
cfg
.
nodes
)
l
=
Lattice
(
nodes
,
analysis_type
)
print
(
'Lattice:'
)
for
k
,
v
in
l
.
el2bv
.
items
():
print
(
str
(
k
)
+
': '
+
bin
(
v
))
return
l
Back
|
FazBrowse Home
|
New Git URL