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-gitdep
cwe_checker
Commits
7d8a67d4
Commit
7d8a67d4
authored
Sep 28, 2020
by
Enkelmann
Committed by
Enkelmann
Nov 03, 2020
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 {
}
}
/// Compute the bitsize of the value that the expression computes.
/// Return zero for `Store` expressions.
pub
fn
bitsize
(
&
self
)
->
BitSize
{
use
Expression
::
*
;
match
self
{
...
...
@@ -234,6 +236,9 @@ impl Expression {
}
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
{
use
Expression
::
*
;
match
expr
{
...
...
@@ -373,6 +378,7 @@ pub enum BinOpType {
}
impl
From
<
BinOpType
>
for
IrBinOpType
{
/// Translate binary operation types.
fn
from
(
op
:
BinOpType
)
->
IrBinOpType
{
use
BinOpType
::
*
;
use
IrBinOpType
::
*
;
...
...
@@ -407,6 +413,7 @@ pub enum UnOpType {
}
impl
From
<
UnOpType
>
for
IrUnOpType
{
/// Translate unary operation types.
fn
from
(
op
:
UnOpType
)
->
IrUnOpType
{
use
UnOpType
::
*
;
match
op
{
...
...
cwe_checker_rs/src/term/mod.rs
View file @
7d8a67d4
...
...
@@ -54,6 +54,12 @@ pub struct 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
>
{
match
self
.rhs
{
Expression
::
Load
{
address
,
..
}
=>
{
...
...
@@ -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
{
if
let
Expression
::
Load
{
address
,
..
}
=
self
.rhs
{
IrDef
::
Load
{
...
...
@@ -168,6 +176,7 @@ pub enum JmpKind {
}
impl
From
<
Jmp
>
for
IrJmp
{
/// Translate jump types.
fn
from
(
jmp
:
Jmp
)
->
IrJmp
{
match
jmp
.kind
{
JmpKind
::
Goto
(
Label
::
Direct
(
tid
))
=>
IrJmp
::
Branch
(
tid
),
...
...
@@ -218,6 +227,7 @@ pub struct Blk {
}
impl
From
<
Blk
>
for
IrBlk
{
/// Translates block types.
fn
from
(
blk
:
Blk
)
->
IrBlk
{
let
mut
ir_def_terms
=
Vec
::
new
();
for
def_term
in
blk
.defs
{
...
...
@@ -278,6 +288,7 @@ pub struct Sub {
}
impl
From
<
Sub
>
for
IrSub
{
/// Translate `Sub` types.
fn
from
(
sub
:
Sub
)
->
IrSub
{
let
blocks
=
sub
.blocks
...
...
@@ -302,6 +313,7 @@ pub struct Program {
}
impl
From
<
Program
>
for
IrProgram
{
/// Translate program types.
fn
from
(
program
:
Program
)
->
IrProgram
{
let
subs
=
program
.subs
...
...
@@ -370,6 +382,7 @@ impl Project {
}
impl
From
<
Project
>
for
IrProject
{
/// Translate project types.
fn
from
(
project
:
Project
)
->
IrProject
{
let
program
=
Term
{
tid
:
project
.program.tid
,
...
...
@@ -424,6 +437,7 @@ impl ArgIntent {
}
impl
From
<
Arg
>
for
IrArg
{
/// Translate extern symbol argument types.
fn
from
(
arg
:
Arg
)
->
IrArg
{
match
arg
.location
{
Expression
::
Var
(
var
)
=>
IrArg
::
Register
(
var
.into
()),
...
...
@@ -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
)
{
use
Expression
::
*
;
match
expr
{
...
...
@@ -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
>
)
{
let
mut
counter
=
0
;
let
mut
defs
=
Vec
::
new
();
...
...
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