FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
pyt/pyt/cfg.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
/
cfg.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
72 lines (55 loc) · 2.35 KB
Breadcrumbs
pyt
/
pyt
/
cfg.py
Copy path
File metadata and controls
72 lines (55 loc) · 2.35 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
"""This module contains classes for generating a Control Flow Graph
of a python program.
The class Visitor is the main entry point to this module.
It uses the visitor pattern implemented by the ast module from the
standard library.
"""
import
ast
from
collections
import
namedtuple
from
.
ast_helper
import
Arguments
,
generate_ast
,
get_call_names_as_string
from
.
label_visitor
import
LabelVisitor
from
.
module_definitions
import
(
LocalModuleDefinition
,
ModuleDefinition
,
ModuleDefinitions
)
from
.
project_handler
import
get_directory_modules
from
.
right_hand_side_visitor
import
RHSVisitor
CALL_IDENTIFIER
=
'¤'
SavedVariable
=
namedtuple
(
'SavedVariable'
,
'LHS RHS'
)
class
Visitor
(
ast
.
NodeVisitor
):
"""A Control Flow Graph containing a list of nodes."""
def
__init__
(
self
,
node
,
project_modules
,
local_modules
,
filename
,
module_definitions
=
None
,
intraprocedural
=
False
):
"""Create an empty CFG."""
self
.
nodes
=
list
()
self
.
function_index
=
0
self
.
undecided
=
False
self
.
project_modules
=
project_modules
self
.
local_modules
=
local_modules
self
.
function_names
=
list
()
self
.
function_return_stack
=
list
()
self
.
module_definitions_stack
=
list
()
self
.
filenames
=
[
filename
]
self
.
intraprocedural
=
intraprocedural
if
intraprocedural
:
self
.
init_intra_function_cfg
(
node
)
elif
module_definitions
:
self
.
init_function_cfg
(
node
,
module_definitions
)
else
:
self
.
init_cfg
(
node
)
def
init_intra_function_cfg
(
self
,
node
):
self
.
module_definitions_stack
.
append
(
ModuleDefinitions
())
self
.
function_names
.
append
(
node
.
name
)
self
.
function_return_stack
.
append
(
node
.
name
)
entry_node
=
self
.
append_node
(
EntryOrExitNode
(
"Entry module"
))
module_statements
=
self
.
stmt_star_handler
(
node
.
body
)
if
isinstance
(
module_statements
,
IgnoredNode
):
exit_node
=
self
.
append_node
(
EntryOrExitNode
(
"Exit module"
))
entry_node
.
connect
(
exit_node
)
return
first_node
=
module_statements
.
first_statement
if
CALL_IDENTIFIER
not
in
first_node
.
label
:
entry_node
.
connect
(
first_node
)
exit_node
=
self
.
append_node
(
EntryOrExitNode
(
"Exit module"
))
last_nodes
=
module_statements
.
last_statements
exit_node
.
connect_predecessors
(
last_nodes
)
Back
|
FazBrowse Home
|
New Git URL