Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
cwe_checker
Overview
Overview
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
fact-depend
cwe_checker
Commits
b70f9910
Commit
b70f9910
authored
Sep 22, 2020
by
Enkelmann
Committed by
Enkelmann
Nov 03, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
implement conversion for blocks and subs
parent
c11a21e9
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
104 additions
and
0 deletions
+104
-0
term.rs
cwe_checker_rs/src/intermediate_representation/term.rs
+6
-0
term.rs
cwe_checker_rs/src/pcode/term.rs
+41
-0
mod.rs
cwe_checker_rs/src/term/mod.rs
+57
-0
No files found.
cwe_checker_rs/src/intermediate_representation/term.rs
View file @
b70f9910
...
...
@@ -46,3 +46,9 @@ pub struct Blk {
pub
defs
:
Vec
<
Term
<
Def
>>
,
pub
jmps
:
Vec
<
Term
<
Jmp
>>
,
}
#[derive(Serialize,
Deserialize,
Debug,
PartialEq,
Eq,
Hash,
Clone)]
pub
struct
Sub
{
pub
name
:
String
,
pub
blocks
:
Vec
<
Term
<
Blk
>>
,
}
cwe_checker_rs/src/pcode/term.rs
View file @
b70f9910
use
super
::{
Expression
,
Variable
};
use
crate
::
intermediate_representation
::
Blk
as
IrBlk
;
use
crate
::
intermediate_representation
::
Def
as
IrDef
;
use
crate
::
intermediate_representation
::
Expression
as
IrExpression
;
use
crate
::
intermediate_representation
::
Jmp
as
IrJmp
;
use
crate
::
intermediate_representation
::
Sub
as
IrSub
;
use
crate
::
prelude
::
*
;
use
crate
::
term
::{
Term
,
Tid
};
...
...
@@ -151,6 +153,28 @@ pub struct Blk {
pub
jmps
:
Vec
<
Term
<
Jmp
>>
,
}
impl
From
<
Blk
>
for
IrBlk
{
fn
from
(
blk
:
Blk
)
->
IrBlk
{
let
defs
:
Vec
<
Term
<
IrDef
>>
=
blk
.defs
.into_iter
()
.map
(|
def_term
|
Term
{
tid
:
def_term
.tid
,
term
:
def_term
.term
.into
(),
})
.collect
();
let
jmps
:
Vec
<
Term
<
IrJmp
>>
=
blk
.jmps
.into_iter
()
.map
(|
jmp_term
|
Term
{
tid
:
jmp_term
.tid
,
term
:
jmp_term
.term
.into
(),
})
.collect
();
IrBlk
{
defs
,
jmps
}
}
}
// TODO: We need a unit test for stack parameter (that use location instead of var)!
#[derive(Serialize,
Deserialize,
Debug,
PartialEq,
Eq,
Hash,
Clone)]
pub
struct
Arg
{
...
...
@@ -172,6 +196,23 @@ pub struct Sub {
pub
blocks
:
Vec
<
Term
<
Blk
>>
,
}
impl
From
<
Sub
>
for
IrSub
{
fn
from
(
sub
:
Sub
)
->
IrSub
{
let
blocks
=
sub
.blocks
.into_iter
()
.map
(|
block_term
|
Term
{
tid
:
block_term
.tid
,
term
:
block_term
.term
.into
(),
})
.collect
();
IrSub
{
name
:
sub
.name
,
blocks
,
}
}
}
#[derive(Serialize,
Deserialize,
Debug,
PartialEq,
Eq,
Hash,
Clone)]
pub
struct
ExternSymbol
{
pub
tid
:
Tid
,
...
...
cwe_checker_rs/src/term/mod.rs
View file @
b70f9910
use
crate
::
bil
::
*
;
use
crate
::
intermediate_representation
::
Blk
as
IrBlk
;
use
crate
::
intermediate_representation
::
Def
as
IrDef
;
use
crate
::
intermediate_representation
::
Expression
as
IrExpression
;
use
crate
::
intermediate_representation
::
Jmp
as
IrJmp
;
use
crate
::
intermediate_representation
::
Sub
as
IrSub
;
use
serde
::{
Deserialize
,
Serialize
};
pub
mod
symbol
;
...
...
@@ -178,12 +180,67 @@ pub struct Blk {
pub
jmps
:
Vec
<
Term
<
Jmp
>>
,
}
impl
From
<
Blk
>
for
IrBlk
{
fn
from
(
blk
:
Blk
)
->
IrBlk
{
let
mut
ir_def_terms
=
Vec
::
new
();
for
def_term
in
blk
.defs
{
let
ir_defs
=
def_term
.term
.to_ir_defs
();
assert
!
(
!
ir_defs
.is_empty
());
if
ir_defs
.len
()
==
1
{
ir_def_terms
.push
(
Term
{
tid
:
def_term
.tid
,
term
:
ir_defs
.into_iter
()
.next
()
.unwrap
(),
});
}
else
{
for
(
counter
,
ir_def
)
in
ir_defs
.into_iter
()
.enumerate
()
{
ir_def_terms
.push
(
Term
{
tid
:
Tid
{
id
:
format!
(
"{}_{}"
,
def_term
.tid.id
,
counter
),
address
:
def_term
.tid.address
.clone
(),
},
term
:
ir_def
,
});
}
}
}
let
ir_jmp_terms
=
blk
.jmps
.into_iter
()
.map
(|
jmp_term
|
Term
{
tid
:
jmp_term
.tid
,
term
:
jmp_term
.term
.into
(),
})
.collect
();
IrBlk
{
defs
:
ir_def_terms
,
jmps
:
ir_jmp_terms
,
}
}
}
#[derive(Serialize,
Deserialize,
Debug,
PartialEq,
Eq,
Hash,
Clone)]
pub
struct
Sub
{
pub
name
:
String
,
pub
blocks
:
Vec
<
Term
<
Blk
>>
,
}
impl
From
<
Sub
>
for
IrSub
{
fn
from
(
sub
:
Sub
)
->
IrSub
{
let
blocks
=
sub
.blocks
.into_iter
()
.map
(|
block_term
|
Term
{
tid
:
block_term
.tid
,
term
:
block_term
.term
.into
(),
})
.collect
();
IrSub
{
name
:
sub
.name
,
blocks
,
}
}
}
#[derive(Serialize,
Deserialize,
Debug,
PartialEq,
Eq,
Hash,
Clone)]
pub
struct
Program
{
pub
subs
:
Vec
<
Term
<
Sub
>>
,
...
...
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