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
a8fb540b
Unverified
Commit
a8fb540b
authored
May 14, 2020
by
Melvin Klimke
Committed by
GitHub
May 14, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactored Cconv
parent
4e30a70d
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
82 additions
and
3 deletions
+82
-3
dune
dune
+1
-0
cconv.ml
src/utils/cconv.ml
+0
-0
cconv.mli
src/utils/cconv.mli
+25
-0
json_utils.ml
src/utils/json_utils.ml
+23
-3
json_utils.mli
src/utils/json_utils.mli
+24
-0
registers.json
src/utils/registers.json
+0
-0
cconv_test.ml
test/unit/utils/cconv_test.ml
+9
-0
No files found.
dune
View file @
a8fb540b
...
...
@@ -2,6 +2,7 @@
(section etc)
(files
(src/config.json as config.json)
(src/utils/registers.json as registers.json)
)
)
...
...
src/utils/cconv.ml
View file @
a8fb540b
This diff is collapsed.
Click to expand it.
src/utils/cconv.mli
View file @
a8fb540b
...
...
@@ -2,6 +2,10 @@ open Bap.Std
open
Core_kernel
(** Returns a json object for registers.json. If not yet in memory, the json file is read. *)
val
get_json
:
unit
->
Yojson
.
Basic
.
t
(** Returns whether a variable is callee saved according to the calling convention
of the target architecture. Should only used for calls to functions outside
of the program, not for calls between functions inside the program. *)
...
...
@@ -22,3 +26,24 @@ val is_return_register: Var.t -> Project.t -> Bool.t
TODO: Since we do not do name demangling here, check whether bap name demangling
yields different function names for the symbols. *)
val
parse_dyn_syms
:
Project
.
t
->
String
.
Set
.
t
(** Returns a string list of supported architectures from the registers.json. *)
val
get_supported_architectures
:
unit
->
string
list
(** Calls objdump with customisable flag and error message. Returns output lines as string list. *)
val
call_objdump
:
Project
.
t
->
flag
:
string
->
err
:
string
->
string
list
(** Infers the binary format using the file's symbol table. *)
val
infer_bin_format_from_symbols
:
Project
.
t
->
string
(** Returns the binary format by either an objdump call or via the file's symbol table. *)
val
extract_bin_format
:
Project
.
t
->
string
(** Returns a list of registers based on the file's binary format, architecture,
calling_convention and context (e.g. callee saved, parameter etc.) *)
val
get_register_list
:
Project
.
t
->
string
->
string
list
src/utils/json_utils.ml
View file @
a8fb540b
...
...
@@ -10,23 +10,43 @@ An example looks like this:
"memcpy", "wmemcpy", "memmove", "wmemmove", "memcmp", "wmemcmp"],
"_comment": "any function that takes something of type size_t could be a possible candidate."
}, *)
let
get_symbols_from_json
json
cwe
=
let
get_symbols_from_json
(
json
:
Yojson
.
Basic
.
t
)
cwe
=
[
json
]
|>
filter_member
cwe
|>
filter_member
"symbols"
|>
flatten
|>
List
.
map
~
f
:
to_string
let
get_symbol_lists_from_json
json
cwe
=
let
get_symbol_lists_from_json
(
json
:
Yojson
.
Basic
.
t
)
cwe
=
[
json
]
|>
filter_member
cwe
|>
filter_member
"pairs"
|>
flatten
|>
List
.
map
~
f
:
(
fun
l
->
List
.
map
(
to_list
l
)
~
f
:
to_string
)
let
get_parameter_list_from_json
json
cwe
=
let
get_parameter_list_from_json
(
json
:
Yojson
.
Basic
.
t
)
cwe
=
[
json
]
|>
filter_member
cwe
|>
filter_member
"parameters"
|>
flatten
|>
List
.
map
~
f
:
to_string
let
get_arch_from_json
(
bin_format
:
Yojson
.
Basic
.
t
)
?
(
conv
:
string
=
""
)
(
arch
:
string
)
:
Yojson
.
Basic
.
t
=
match
arch
with
|
"x86"
->
bin_format
|>
member
arch
|>
member
conv
|
_
->
bin_format
|>
member
arch
let
get_bin_format_from_json
(
json
:
Yojson
.
Basic
.
t
)
(
bin_format
:
string
)
:
Yojson
.
Basic
.
t
=
json
|>
member
bin_format
let
get_registers_from_json
(
arch
:
Yojson
.
Basic
.
t
)
(
context
:
string
)
:
string
list
=
arch
|>
member
context
|>
to_list
|>
filter_string
let
get_arch_list_from_json
(
json
:
Yojson
.
Basic
.
t
)
(
bin_format
:
string
)
:
(
string
*
Yojson
.
Basic
.
t
)
list
=
json
|>
member
bin_format
|>
to_assoc
src/utils/json_utils.mli
View file @
a8fb540b
(* This module implements functionality related to parsing the JSON configuration file. *)
(** Returns pairs of symbols for a given CWE check. *)
val
get_symbol_lists_from_json
:
Yojson
.
Basic
.
t
->
string
->
string
list
list
(** Returns symbols for a given CWE check. *)
val
get_symbols_from_json
:
Yojson
.
Basic
.
t
->
string
->
string
list
(** Returns parameters for a given CWE check. *)
val
get_parameter_list_from_json
:
Yojson
.
Basic
.
t
->
string
->
string
list
(** Returns an architecture's registers based on calling convention. *)
val
get_arch_from_json
:
Yojson
.
Basic
.
t
->
?
conv
:
string
->
string
->
Yojson
.
Basic
.
t
(** Returns json object containing either PE or ELF calling conventions for all architectures. *)
val
get_bin_format_from_json
:
Yojson
.
Basic
.
t
->
string
->
Yojson
.
Basic
.
t
(** Returns registers for a given architecture and calling_convention specified by context. (e.g. callee saved, parameter etc.) *)
val
get_registers_from_json
:
Yojson
.
Basic
.
t
->
string
->
string
list
(** Returns a list of all architectures supported for a given binary format. (e.g. ELF) *)
val
get_arch_list_from_json
:
Yojson
.
Basic
.
t
->
string
->
(
string
*
Yojson
.
Basic
.
t
)
list
src/utils/registers.json
0 → 100644
View file @
a8fb540b
This diff is collapsed.
Click to expand it.
test/unit/utils/cconv_test.ml
View file @
a8fb540b
...
...
@@ -13,8 +13,12 @@ let test_callee_saved () =
let
project
=
Option
.
value_exn
!
example_project
in
let
register
=
Var
.
create
"RBX"
(
Bil
.
Imm
(
Symbol_utils
.
arch_pointer_size_in_bytes
project
*
8
))
in
let
()
=
check
"callee_saved_register"
(
is_callee_saved
register
project
)
in
let
register
=
Var
.
create
"R15"
(
Bil
.
Imm
(
Symbol_utils
.
arch_pointer_size_in_bytes
project
*
8
))
in
let
()
=
check
"callee_saved_register"
(
is_callee_saved
register
project
)
in
let
register
=
Var
.
create
"RAX"
(
Bil
.
Imm
(
Symbol_utils
.
arch_pointer_size_in_bytes
project
*
8
))
in
let
()
=
check
"caller_saved_register"
(
is_callee_saved
register
project
=
false
)
in
let
register
=
Var
.
create
"R8"
(
Bil
.
Imm
(
Symbol_utils
.
arch_pointer_size_in_bytes
project
*
8
))
in
let
()
=
check
"caller_saved_register"
(
is_callee_saved
register
project
=
false
)
in
()
let
test_parameter_register
()
=
...
...
@@ -22,8 +26,12 @@ let test_parameter_register () =
let
project
=
Option
.
value_exn
!
example_project
in
let
register
=
Var
.
create
"RDX"
(
Bil
.
Imm
(
Symbol_utils
.
arch_pointer_size_in_bytes
project
*
8
))
in
let
()
=
check
"return_register"
(
is_parameter_register
register
project
)
in
let
register
=
Var
.
create
"R9"
(
Bil
.
Imm
(
Symbol_utils
.
arch_pointer_size_in_bytes
project
*
8
))
in
let
()
=
check
"return_register"
(
is_parameter_register
register
project
)
in
let
register
=
Var
.
create
"RAX"
(
Bil
.
Imm
(
Symbol_utils
.
arch_pointer_size_in_bytes
project
*
8
))
in
let
()
=
check
"no_return_register"
(
is_parameter_register
register
project
=
false
)
in
let
register
=
Var
.
create
"R14"
(
Bil
.
Imm
(
Symbol_utils
.
arch_pointer_size_in_bytes
project
*
8
))
in
let
()
=
check
"no_return_register"
(
is_parameter_register
register
project
=
false
)
in
()
let
test_return_register
()
=
...
...
@@ -35,6 +43,7 @@ let test_return_register () =
let
()
=
check
"no_return_register"
(
is_return_register
register
project
=
false
)
in
()
let
test_parse_dyn_syms
()
=
(* this test assumes, that the example project is the arrays_x64.out binary from the artificial samples. *)
let
project
=
Option
.
value_exn
!
example_project
in
...
...
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