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
7d8a67d4
Commit
7d8a67d4
authored
4 years ago
by
Enkelmann
Committed by
Enkelmann
4 years ago
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add some missing doc strings
parent
babf80f5
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
0 deletions
+28
-0
mod.rs
cwe_checker_rs/src/bil/mod.rs
+7
-0
mod.rs
cwe_checker_rs/src/term/mod.rs
+21
-0
No files found.
cwe_checker_rs/src/bil/mod.rs
View file @
7d8a67d4
...
@@ -203,6 +203,8 @@ impl Expression {
...
@@ -203,6 +203,8 @@ impl Expression {
}
}
}
}
/// Compute the bitsize of the value that the expression computes.
/// Return zero for `Store` expressions.
pub
fn
bitsize
(
&
self
)
->
BitSize
{
pub
fn
bitsize
(
&
self
)
->
BitSize
{
use
Expression
::
*
;
use
Expression
::
*
;
match
self
{
match
self
{
...
@@ -234,6 +236,9 @@ impl Expression {
...
@@ -234,6 +236,9 @@ impl Expression {
}
}
impl
From
<
Expression
>
for
IrExpression
{
impl
From
<
Expression
>
for
IrExpression
{
/// Convert a BAP IR expression to an internal IR expression.
/// Panics on expressions that are not expressions in the internal IR.
/// Replaces `IfThenElse` expressions with `Unknown` expressions (thus losing some information).
fn
from
(
expr
:
Expression
)
->
IrExpression
{
fn
from
(
expr
:
Expression
)
->
IrExpression
{
use
Expression
::
*
;
use
Expression
::
*
;
match
expr
{
match
expr
{
...
@@ -373,6 +378,7 @@ pub enum BinOpType {
...
@@ -373,6 +378,7 @@ pub enum BinOpType {
}
}
impl
From
<
BinOpType
>
for
IrBinOpType
{
impl
From
<
BinOpType
>
for
IrBinOpType
{
/// Translate binary operation types.
fn
from
(
op
:
BinOpType
)
->
IrBinOpType
{
fn
from
(
op
:
BinOpType
)
->
IrBinOpType
{
use
BinOpType
::
*
;
use
BinOpType
::
*
;
use
IrBinOpType
::
*
;
use
IrBinOpType
::
*
;
...
@@ -407,6 +413,7 @@ pub enum UnOpType {
...
@@ -407,6 +413,7 @@ pub enum UnOpType {
}
}
impl
From
<
UnOpType
>
for
IrUnOpType
{
impl
From
<
UnOpType
>
for
IrUnOpType
{
/// Translate unary operation types.
fn
from
(
op
:
UnOpType
)
->
IrUnOpType
{
fn
from
(
op
:
UnOpType
)
->
IrUnOpType
{
use
UnOpType
::
*
;
use
UnOpType
::
*
;
match
op
{
match
op
{
...
...
This diff is collapsed.
Click to expand it.
cwe_checker_rs/src/term/mod.rs
View file @
7d8a67d4
...
@@ -54,6 +54,12 @@ pub struct Def {
...
@@ -54,6 +54,12 @@ pub struct Def {
}
}
impl
Def
{
impl
Def
{
/// Convert one `Def` into one or more `Def`s of the internal IR.
///
/// `Load` expressions get transferred to their own `Def`,
/// since they are not representable as expressions in the internal IR.
/// `IfThenElse` expressions are translated to `Unknown` expressions in the process,
/// thus resulting in possible information loss.
fn
into_ir_defs
(
self
)
->
Vec
<
IrDef
>
{
fn
into_ir_defs
(
self
)
->
Vec
<
IrDef
>
{
match
self
.rhs
{
match
self
.rhs
{
Expression
::
Load
{
address
,
..
}
=>
{
Expression
::
Load
{
address
,
..
}
=>
{
...
@@ -141,6 +147,8 @@ impl Def {
...
@@ -141,6 +147,8 @@ impl Def {
}
}
}
}
/// Translate a `Load` into its internal IR representation.
/// Panics if right hand side expression is not a `Load`.
fn
into_ir_load
(
self
)
->
IrDef
{
fn
into_ir_load
(
self
)
->
IrDef
{
if
let
Expression
::
Load
{
address
,
..
}
=
self
.rhs
{
if
let
Expression
::
Load
{
address
,
..
}
=
self
.rhs
{
IrDef
::
Load
{
IrDef
::
Load
{
...
@@ -168,6 +176,7 @@ pub enum JmpKind {
...
@@ -168,6 +176,7 @@ pub enum JmpKind {
}
}
impl
From
<
Jmp
>
for
IrJmp
{
impl
From
<
Jmp
>
for
IrJmp
{
/// Translate jump types.
fn
from
(
jmp
:
Jmp
)
->
IrJmp
{
fn
from
(
jmp
:
Jmp
)
->
IrJmp
{
match
jmp
.kind
{
match
jmp
.kind
{
JmpKind
::
Goto
(
Label
::
Direct
(
tid
))
=>
IrJmp
::
Branch
(
tid
),
JmpKind
::
Goto
(
Label
::
Direct
(
tid
))
=>
IrJmp
::
Branch
(
tid
),
...
@@ -218,6 +227,7 @@ pub struct Blk {
...
@@ -218,6 +227,7 @@ pub struct Blk {
}
}
impl
From
<
Blk
>
for
IrBlk
{
impl
From
<
Blk
>
for
IrBlk
{
/// Translates block types.
fn
from
(
blk
:
Blk
)
->
IrBlk
{
fn
from
(
blk
:
Blk
)
->
IrBlk
{
let
mut
ir_def_terms
=
Vec
::
new
();
let
mut
ir_def_terms
=
Vec
::
new
();
for
def_term
in
blk
.defs
{
for
def_term
in
blk
.defs
{
...
@@ -278,6 +288,7 @@ pub struct Sub {
...
@@ -278,6 +288,7 @@ pub struct Sub {
}
}
impl
From
<
Sub
>
for
IrSub
{
impl
From
<
Sub
>
for
IrSub
{
/// Translate `Sub` types.
fn
from
(
sub
:
Sub
)
->
IrSub
{
fn
from
(
sub
:
Sub
)
->
IrSub
{
let
blocks
=
sub
let
blocks
=
sub
.blocks
.blocks
...
@@ -302,6 +313,7 @@ pub struct Program {
...
@@ -302,6 +313,7 @@ pub struct Program {
}
}
impl
From
<
Program
>
for
IrProgram
{
impl
From
<
Program
>
for
IrProgram
{
/// Translate program types.
fn
from
(
program
:
Program
)
->
IrProgram
{
fn
from
(
program
:
Program
)
->
IrProgram
{
let
subs
=
program
let
subs
=
program
.subs
.subs
...
@@ -370,6 +382,7 @@ impl Project {
...
@@ -370,6 +382,7 @@ impl Project {
}
}
impl
From
<
Project
>
for
IrProject
{
impl
From
<
Project
>
for
IrProject
{
/// Translate project types.
fn
from
(
project
:
Project
)
->
IrProject
{
fn
from
(
project
:
Project
)
->
IrProject
{
let
program
=
Term
{
let
program
=
Term
{
tid
:
project
.program.tid
,
tid
:
project
.program.tid
,
...
@@ -424,6 +437,7 @@ impl ArgIntent {
...
@@ -424,6 +437,7 @@ impl ArgIntent {
}
}
impl
From
<
Arg
>
for
IrArg
{
impl
From
<
Arg
>
for
IrArg
{
/// Translate extern symbol argument types.
fn
from
(
arg
:
Arg
)
->
IrArg
{
fn
from
(
arg
:
Arg
)
->
IrArg
{
match
arg
.location
{
match
arg
.location
{
Expression
::
Var
(
var
)
=>
IrArg
::
Register
(
var
.into
()),
Expression
::
Var
(
var
)
=>
IrArg
::
Register
(
var
.into
()),
...
@@ -457,6 +471,11 @@ impl From<Arg> for IrArg {
...
@@ -457,6 +471,11 @@ impl From<Arg> for IrArg {
}
}
}
}
/// Substitute each `Load` subexpression with a temporary variable
/// and a `Def` containing the `Load` into said variable.
///
/// The function is recursive and the counter is needed to keep track how many `Load` expressions
/// have already been extracted (which is used to generate unique names for the temporary variables).
fn
extract_loads_from_expression
(
expr
:
Expression
,
counter
:
u64
)
->
(
Vec
<
Def
>
,
Expression
,
u64
)
{
fn
extract_loads_from_expression
(
expr
:
Expression
,
counter
:
u64
)
->
(
Vec
<
Def
>
,
Expression
,
u64
)
{
use
Expression
::
*
;
use
Expression
::
*
;
match
expr
{
match
expr
{
...
@@ -580,6 +599,8 @@ fn extract_loads_from_expression(expr: Expression, counter: u64) -> (Vec<Def>, E
...
@@ -580,6 +599,8 @@ fn extract_loads_from_expression(expr: Expression, counter: u64) -> (Vec<Def>, E
}
}
}
}
/// Substitutes each `Load` expression in the target or conditition fields of a jump
/// with a temporary variable and a `Def` containing the `Load` into said variable.
fn
extract_loads_from_jump
(
mut
jmp
:
Jmp
)
->
(
Jmp
,
Vec
<
Def
>
)
{
fn
extract_loads_from_jump
(
mut
jmp
:
Jmp
)
->
(
Jmp
,
Vec
<
Def
>
)
{
let
mut
counter
=
0
;
let
mut
counter
=
0
;
let
mut
defs
=
Vec
::
new
();
let
mut
defs
=
Vec
::
new
();
...
...
This diff is collapsed.
Click to expand it.
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