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
676e27a0
Commit
676e27a0
authored
Sep 29, 2020
by
Enkelmann
Committed by
Enkelmann
Nov 03, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed some more special case for the IR conversion from BAP
parent
7d8a67d4
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
94 additions
and
23 deletions
+94
-23
mod.rs
cwe_checker_rs/src/bil/mod.rs
+42
-8
mod.rs
cwe_checker_rs/src/term/mod.rs
+46
-13
symbol.rs
cwe_checker_rs/src/term/symbol.rs
+6
-2
No files found.
cwe_checker_rs/src/bil/mod.rs
View file @
676e27a0
...
...
@@ -266,20 +266,34 @@ impl From<Expression> for IrExpression {
use
CastType
::
*
;
match
kind
{
UNSIGNED
=>
{
assert
!
(
width
%
8
==
0
);
if
width
%
8
==
0
{
IrExpression
::
Cast
{
arg
:
Box
::
new
(
IrExpression
::
from
(
*
arg
)),
op
:
IrCastOpType
::
IntZExt
,
size
:
width
.into
(),
}
}
else
{
IrExpression
::
Unknown
{
description
:
serde_json
::
to_string
(
&
Cast
{
kind
,
width
,
arg
})
.unwrap
(),
size
:
width
.into
(),
}
}
}
SIGNED
=>
{
assert
!
(
width
%
8
==
0
);
if
width
%
8
==
0
{
IrExpression
::
Cast
{
arg
:
Box
::
new
(
IrExpression
::
from
(
*
arg
)),
op
:
IrCastOpType
::
IntSExt
,
size
:
width
.into
(),
}
}
else
{
IrExpression
::
Unknown
{
description
:
serde_json
::
to_string
(
&
Cast
{
kind
,
width
,
arg
})
.unwrap
(),
size
:
width
.into
(),
}
}
}
HIGH
=>
{
if
width
==
1
{
...
...
@@ -290,14 +304,19 @@ impl From<Expression> for IrExpression {
))),
rhs
:
Box
::
new
(
IrExpression
::
from
(
*
arg
)),
}
}
else
{
assert
!
(
width
%
8
==
0
);
}
else
if
width
%
8
==
0
{
let
low_byte
=
(
arg
.bitsize
()
-
width
)
.into
();
IrExpression
::
Subpiece
{
arg
:
Box
::
new
(
IrExpression
::
from
(
*
arg
)),
low_byte
,
size
:
width
.into
(),
}
}
else
{
IrExpression
::
Unknown
{
description
:
serde_json
::
to_string
(
&
Cast
{
kind
,
width
,
arg
})
.unwrap
(),
size
:
width
.into
(),
}
}
}
LOW
=>
{
...
...
@@ -313,13 +332,18 @@ impl From<Expression> for IrExpression {
rhs
:
Box
::
new
(
IrExpression
::
from
(
*
arg
)),
}),
}
}
else
{
assert
!
(
width
%
8
==
0
);
}
else
if
width
%
8
==
0
{
IrExpression
::
Subpiece
{
arg
:
Box
::
new
(
IrExpression
::
from
(
*
arg
)),
low_byte
:
(
0
as
u64
)
.into
(),
size
:
width
.into
(),
}
}
else
{
IrExpression
::
Unknown
{
description
:
serde_json
::
to_string
(
&
Cast
{
kind
,
width
,
arg
})
.unwrap
(),
size
:
width
.into
(),
}
}
}
}
...
...
@@ -329,13 +353,23 @@ impl From<Expression> for IrExpression {
high_bit
,
arg
,
}
=>
{
assert
!
(
low_bit
%
8
==
0
);
assert
!
((
high_bit
+
1
)
%
8
==
0
);
if
low_bit
%
8
==
0
&&
(
high_bit
+
1
)
%
8
==
0
{
IrExpression
::
Subpiece
{
size
:
(
high_bit
-
low_bit
+
1
)
.into
(),
low_byte
:
low_bit
.into
(),
arg
:
Box
::
new
(
IrExpression
::
from
(
*
arg
)),
}
}
else
{
IrExpression
::
Unknown
{
description
:
serde_json
::
to_string
(
&
Extract
{
low_bit
,
high_bit
,
arg
,
})
.unwrap
(),
size
:
(
high_bit
-
low_bit
+
1
)
.into
(),
}
}
}
Concat
{
left
,
right
}
=>
IrExpression
::
BinOp
{
op
:
IrBinOpType
::
Piece
,
...
...
cwe_checker_rs/src/term/mod.rs
View file @
676e27a0
...
...
@@ -436,37 +436,46 @@ impl ArgIntent {
}
}
impl
From
<
Arg
>
for
Ir
Arg
{
impl
Arg
{
/// Translate extern symbol argument types.
fn
from
(
arg
:
Arg
)
->
IrArg
{
match
arg
.location
{
Expression
::
Var
(
var
)
=>
IrArg
::
Register
(
var
.into
()),
pub
fn
into_ir_args
(
self
)
->
Vec
<
IrArg
>
{
match
self
.location
{
Expression
::
Var
(
var
)
=>
vec!
[
IrArg
::
Register
(
var
.into
())],
Expression
::
Concat
{
left
,
right
}
=>
match
(
*
left
,
*
right
)
{
(
Expression
::
Var
(
var_left
),
Expression
::
Var
(
var_right
))
=>
vec!
[
IrArg
::
Register
(
var_left
.into
()),
IrArg
::
Register
(
var_right
.into
()),
],
_
=>
panic!
(),
},
Expression
::
Load
{
address
,
size
:
bitsize
,
..
}
=>
{
let
offset
=
match
*
address
{
}
=>
match
*
address
{
Expression
::
Var
(
_
)
=>
vec!
[
IrArg
::
Stack
{
offset
:
0
,
size
:
bitsize
.into
(),
}],
Expression
::
BinOp
{
op
:
BinOpType
::
PLUS
,
lhs
,
rhs
,
}
=>
{
assert
!
(
matches!
(
*
lhs
,
Expression
::
Var
(
_
)));
if
let
Expression
::
Const
(
bitvec
)
=
*
rhs
{
let
offset
=
if
let
Expression
::
Const
(
bitvec
)
=
*
rhs
{
bitvec
.try_to_i64
()
.unwrap
()
}
else
{
panic!
()
}
}
_
=>
panic!
(),
};
IrArg
::
Stack
{
vec!
[
IrArg
::
Stack
{
offset
,
size
:
bitsize
.into
(),
}
}]
}
_
=>
panic!
(),
},
_
=>
panic!
(),
}
}
}
...
...
@@ -505,7 +514,31 @@ fn extract_loads_from_expression(expr: Expression, counter: u64) -> (Vec<Def>, E
(
defs
,
Var
(
temp_var
),
counter
)
}
Var
(
_
)
|
Const
(
_
)
|
Unknown
{
..
}
=>
(
Vec
::
new
(),
expr
,
counter
),
Store
{
..
}
|
Let
{
..
}
=>
panic!
(),
Let
{
..
}
=>
panic!
(),
Store
{
memory
,
address
,
value
,
endian
,
size
,
}
=>
{
let
(
mut
defs
,
cleaned_address
,
counter
)
=
extract_loads_from_expression
(
*
address
,
counter
);
let
(
mut
more_defs
,
cleaned_value
,
counter
)
=
extract_loads_from_expression
(
*
value
,
counter
);
defs
.append
(
&
mut
more_defs
);
(
defs
,
Store
{
address
:
Box
::
new
(
cleaned_address
),
value
:
Box
::
new
(
cleaned_value
),
memory
,
endian
,
size
,
},
counter
,
)
}
IfThenElse
{
condition
,
true_exp
,
...
...
cwe_checker_rs/src/term/symbol.rs
View file @
676e27a0
...
...
@@ -61,13 +61,17 @@ impl From<ExternSymbol> for IrExternSymbol {
arg
.intent
,
ArgIntent
::
Input
|
ArgIntent
::
Both
|
ArgIntent
::
Unknown
)
{
parameters
.push
(
arg
.clone
()
.into
());
for
ir_arg
in
arg
.clone
()
.into_ir_args
()
{
parameters
.push
(
ir_arg
);
}
}
if
matches!
(
arg
.intent
,
ArgIntent
::
Output
|
ArgIntent
::
Both
|
ArgIntent
::
Unknown
)
{
return_values
.push
(
arg
.into
());
for
ir_arg
in
arg
.into_ir_args
()
{
return_values
.push
(
ir_arg
);
}
}
}
IrExternSymbol
{
...
...
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