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
ca67076f
Unverified
Commit
ca67076f
authored
Feb 10, 2021
by
Enkelmann
Committed by
GitHub
Feb 10, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Parse bitvectors larger than 64 bits (#144)
parent
d926369b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
9 deletions
+35
-9
expressions.rs
cwe_checker_rs/src/pcode/expressions.rs
+35
-9
No files found.
cwe_checker_rs/src/pcode/expressions.rs
View file @
ca67076f
...
...
@@ -45,16 +45,12 @@ impl Variable {
pub
fn
parse_to_bitvector
(
&
self
)
->
Bitvector
{
match
(
&
self
.value
,
&
self
.address
)
{
(
Some
(
hex_value
),
None
)
|
(
None
,
Some
(
hex_value
))
=>
{
// TODO: Implement parsing for large hex values.
if
u64
::
from
(
self
.size
)
>
8
{
panic!
(
"Parsing of immediates greater than 8 bytes not yet implemented: {}"
,
hex_value
);
let
mut
bitvector
=
Bitvector
::
from_str_radix
(
16
,
hex_value
)
.unwrap
();
match
bitvector
.width
()
.cmp
(
&
self
.size
.into
())
{
std
::
cmp
::
Ordering
::
Greater
=>
bitvector
.truncate
(
self
.size
)
.unwrap
(),
std
::
cmp
::
Ordering
::
Less
=>
bitvector
.zero_extend
(
self
.size
)
.unwrap
(),
std
::
cmp
::
Ordering
::
Equal
=>
(),
}
let
val
:
u64
=
u64
::
from_str_radix
(
&
hex_value
,
16
)
.unwrap
();
let
mut
bitvector
:
Bitvector
=
Bitvector
::
from_u64
(
val
);
bitvector
.truncate
(
self
.size
)
.unwrap
();
bitvector
}
_
=>
panic!
(),
...
...
@@ -380,4 +376,34 @@ mod tests {
)
.unwrap
();
}
#[test]
fn
parse_to_bitvector
()
{
let
mut
var
=
Variable
{
name
:
None
,
value
:
Some
(
"0"
.to_string
()),
address
:
None
,
size
:
ByteSize
::
new
(
8
),
is_virtual
:
false
,
};
assert_eq!
(
var
.parse_to_bitvector
(),
Bitvector
::
from_u64
(
0
));
var
.value
=
Some
(
"0010f"
.to_string
());
assert_eq!
(
var
.parse_to_bitvector
(),
Bitvector
::
from_u64
(
271
));
var
.value
=
Some
(
"1ff"
.to_string
());
var
.size
=
ByteSize
::
new
(
1
);
assert_eq!
(
var
.parse_to_bitvector
(),
Bitvector
::
from_u8
(
255
));
var
.size
=
ByteSize
::
new
(
16
);
assert_eq!
(
var
.parse_to_bitvector
(),
Bitvector
::
from_u128
(
511
));
var
.value
=
Some
(
"00_ffffffffffffffff_ffffffffffffffff"
.to_string
());
var
.size
=
ByteSize
::
new
(
16
);
assert_eq!
(
var
.parse_to_bitvector
(),
Bitvector
::
from_i128
(
-
1
));
var
.size
=
ByteSize
::
new
(
10
);
assert_eq!
(
var
.parse_to_bitvector
(),
Bitvector
::
from_i128
(
-
1
)
.into_truncate
(
ByteSize
::
new
(
10
))
.unwrap
()
);
}
}
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