Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
H
hostCompiledSimulation
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Gaurav Kukreja
hostCompiledSimulation
Commits
8be1f226
Commit
8be1f226
authored
Jun 26, 2014
by
Gaurav Kukreja
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed the conditional, and unconditional branch issue
Signed-off-by:
Gaurav Kukreja
<
gaurav@gauravk.in
>
parent
13d92f7a
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
9 deletions
+28
-9
construct_cfg_binary.py
cfg_binary/construct_cfg_binary.py
+28
-9
No files found.
cfg_binary/construct_cfg_binary.py
View file @
8be1f226
...
...
@@ -9,8 +9,8 @@ import re
re_sectionStart
=
re
.
compile
(
'Disassembly of section .(.*):'
)
re_Declaration
=
re
.
compile
(
'
\
s*([0-9a-f]*)
\
s*<(.*)>:'
)
re_instruction
=
re
.
compile
(
'
\
s*([0-9a-f]*):
\
s*([0-9a-f])*
\
s*(.*)'
)
re_
branchInst
=
re
.
compile
(
'
\
s*(b[l|x|lx|xj]
?)
\
s*([0-9a-f]*)
\
s*<(.*)>'
)
re_condition
BranchInst
=
re
.
compile
(
'
\
s*(b[l|x|lx|xj]?[eq|ne|mi|pl|hi|ls|ge|lt|gt|le]
)
\
s*([0-9a-f]*)
\
s*<(.*)>'
)
re_
unconditionalBranchInst
=
re
.
compile
(
'
\
s*(b(?:l|x|lx|xj)
?)
\
s*([0-9a-f]*)
\
s*<(.*)>'
)
re_condition
alBranchInst
=
re
.
compile
(
'
\
s*(b(?:l|x|lx|xj)?(?:eq|ne|mi|pl|hi|ls|ge|lt|gt|le)
)
\
s*([0-9a-f]*)
\
s*<(.*)>'
)
re_returnInst
=
re
.
compile
(
'
\
s*(bx)
\
s*(lr)'
)
re_startWithSemiColon
=
re
.
compile
(
'
\
s*_+.*'
)
...
...
@@ -116,10 +116,15 @@ class ControlFlowGraph:
for
block
in
self
.
listBlocks
:
blockEndAdd
=
block
.
endAdd
if
blockEndAdd
in
branchInstAtAdd
:
m
=
re_
b
ranchInst
.
match
(
branchInstAtAdd
[
blockEndAdd
])
m
=
re_
unconditionalB
ranchInst
.
match
(
branchInstAtAdd
[
blockEndAdd
])
if
m
is
not
None
:
# unconditional branch, add edge to target but not to next instruction
self
.
addEdge
(
blockEndAdd
,
m
.
group
(
2
))
else
:
m
=
re_conditionalBranchInst
.
match
(
branchInstAtAdd
[
blockEndAdd
])
if
m
is
not
None
:
# conditional branch, add edge to target and next instruction
self
.
addEdge
(
blockEndAdd
,
m
.
group
(
2
))
if
m
.
group
(
1
)
!=
"b"
:
self
.
addEdge
(
blockEndAdd
,
"
%
x"
%
(
int
(
blockEndAdd
,
16
)
+
4
))
else
:
m
=
re_returnInst
.
match
(
branchInstAtAdd
[
blockEndAdd
])
...
...
@@ -131,7 +136,7 @@ class ControlFlowGraph:
# For return instructions
# Fucking Ugly Code
for
address
in
branchInstAtAdd
:
m
=
re_
b
ranchInst
.
match
(
branchInstAtAdd
[
address
])
m
=
re_
unconditionalB
ranchInst
.
match
(
branchInstAtAdd
[
address
])
if
m
is
not
None
:
targetAddress
=
m
.
group
(
2
)
for
funcBody
in
listFunctionBodies
:
...
...
@@ -277,7 +282,21 @@ def matched_codeLine(address, inst):
#Algo 3.a
listBlockStartAdd
.
append
(
address
)
m
=
re_branchInst
.
match
(
inst
)
m
=
re_conditionalBranchInst
.
match
(
inst
)
if
m
is
not
None
:
branchInstAtAdd
[
address
]
=
inst
;
# Algo 3.b. End of a Basic Block at branch
listBlockEndAdd
.
append
(
address
)
# Algo 3.c. Start of a basic block from target address of branch inst.
listBlockStartAdd
.
append
(
m
.
group
(
2
))
# Algo 3.d. End of a basic block at inst before target address of branch
if
m
.
group
(
3
)
.
startswith
(
currentFunctionName
):
listBlockEndAdd
.
append
(
"
%
x"
%
(
int
(
m
.
group
(
2
),
16
)
-
4
))
# Algo 3.e Start of a basic block from next inst to the branch inst.
addOfNextInst
=
"
%
x"
%
(
int
(
address
,
16
)
+
4
)
listBlockStartAdd
.
append
(
addOfNextInst
)
m
=
re_unconditionalBranchInst
.
match
(
inst
)
if
m
is
not
None
:
branchInstAtAdd
[
address
]
=
inst
;
# Algo 3.b. End of a Basic Block at branch
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment