Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
0703fc3
CHB: summaries
sipma Nov 28, 2024
c35f32d
CHB: allow named functions without listing in userdata
sipma Nov 29, 2024
ab8cdf0
CHB: moving global variable handling to GlobalMemoryMap
sipma Dec 2, 2024
3ce0e56
CHB:ARM: add symbolic names to assembly listing
sipma Dec 2, 2024
e85b400
Merge branch 'master' into summaries
sipma Dec 2, 2024
ee49135
CHB:ARM: abstract global variables across calls
sipma Dec 5, 2024
f432c9d
CHB:ELF: add check for read-only data sections
sipma Dec 5, 2024
af3ec25
CHB: aggregate for LSL/ASR
sipma Dec 13, 2024
93875f3
CHB:ARM: add predicate assignment instruction
sipma Dec 14, 2024
4403904
CHB: move functionality to global memory map
sipma Dec 18, 2024
b8ec55f
Merge branch 'master' into summaries
sipma Dec 18, 2024
64ac6bb
Merge branch 'master' into summaries
sipma Dec 19, 2024
0849ccc
CHB:CIL: update for change in global variables
sipma Dec 28, 2024
b95b52c
CHB:ELF: update for change in global variables
sipma Dec 28, 2024
616854d
CHB:ARM: update for change in global variables
sipma Dec 28, 2024
51d1547
CHB: updates for changes in global variables
sipma Dec 28, 2024
2cedce5
CHT:updates for changes in global variables
sipma Dec 28, 2024
6b03359
CHB: change base variable into base expression for array and struct
sipma Dec 28, 2024
0d2b661
CHB: do not make unknown basevar
sipma Dec 28, 2024
94d011a
CHB:add error logging
sipma Dec 28, 2024
24c678f
CHB:remove redundant method
sipma Dec 29, 2024
0a3320a
CHB: add error handling
sipma Dec 29, 2024
5da9830
CHB: remove types from functioninfo
sipma Dec 29, 2024
8681db4
CHB: remove recording of return values and side effects
sipma Dec 29, 2024
46ab5ba
CHB: redo resolution of fixed-offset indirect memory access
sipma Dec 29, 2024
db5eae8
CHB: add error-enabled assign commands
sipma Jan 2, 2025
09a3758
CHB:ARM: convert to error-enabled operands in translation
sipma Jan 2, 2025
13f212d
CHB:ARM: convert to error-enabled operands in value transmission
sipma Jan 6, 2025
4fbcb1c
CHB:ARM: conversion to error-enabled operands in type inference
sipma Jan 6, 2025
7471111
CHT: update for change in global variables
sipma Jan 6, 2025
0b69ad3
CHT:ARM: update tests for result types
sipma Jan 7, 2025
8ad2594
CHB: add result types for reading binary
sipma Jan 7, 2025
d140186
CHB:convert memory offset to result type
sipma Jan 8, 2025
3c834eb
CHB:ARM: add more identification to xdata values
sipma Jan 11, 2025
71e8a9e
CHB: add error handling
sipma Jan 15, 2025
fb6e54d
CHB:ARM: updates for result types
sipma Jan 25, 2025
5cfb456
CHT:ARM: updates for global veriables
sipma Jan 25, 2025
e81bcfe
CHB: add error handling
sipma Jan 26, 2025
046d5f6
CHB: add function annotations
sipma Feb 2, 2025
9e45c19
CHB: more support for function annotations
sipma Feb 4, 2025
f5ca9f5
CHB:update version
sipma Feb 4, 2025
66ed2e2
GITHUB: update workflows
sipma Feb 4, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/dune.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
- name: Prepare tar file for upload
run: tar -hcvf artifacts.tar CodeHawk/_build/install/default/bin/*
- name: Upload artifacts tar file
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: artifacts-${{ matrix.ocaml-compiler }}
path: artifacts.tar
Expand All @@ -54,7 +54,7 @@ jobs:
- name: Delete submitted prebuilts
run: rm -f chb/bin/binaries/linux/chx86_analyze
- name: Download artifacts tar
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: artifacts-${{ matrix.ocaml-compiler }}
- name: Extract artifacts
Expand Down Expand Up @@ -84,7 +84,7 @@ jobs:
rm -f chc/bin/linux/parseFile
rm -f chc/bin/linux/canalyzer
- name: Download artifacts tar
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: artifacts-${{ matrix.ocaml-compiler }}
- name: Extract artifacts
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/makefiles.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- name: Prepare tar file for upload
run: tar -cvf artifacts.tar CodeHawk/CHB/bchcmdline/chx86_analyze CodeHawk/CHC/cchcil/parseFile CodeHawk/CHC/cchcmdline/canalyzer
- name: Upload artifacts tar file
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: artifacts-${{ matrix.ocaml-compiler }}
path: artifacts.tar
Expand All @@ -45,7 +45,7 @@ jobs:
- name: Delete submitted prebuilts
run: rm -f chb/bin/binaries/linux/chx86_analyze
- name: Download artifacts tar
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: artifacts-${{ matrix.ocaml-compiler }}
- name: Extract artifacts
Expand Down Expand Up @@ -73,7 +73,7 @@ jobs:
rm -f chc/bin/linux/parseFile
rm -f chc/bin/linux/canalyzer
- name: Download artifacts tar
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: artifacts-${{ matrix.ocaml-compiler }}
- name: Extract artifacts
Expand Down
28 changes: 27 additions & 1 deletion CodeHawk/CH/chutil/cHLogger.ml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

Copyright (c) 2005-2019 Kestrel Technology LLC
Copyright (c) 2020 Henny B. Sipma
Copyright (c) 2021-2024 Aarno Labs LLC
Copyright (c) 2021-2025 Aarno Labs LLC

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -226,3 +226,29 @@ let log_tfold_default
log_tracelog_error logspec e;
d
end


let log_error_result
?(msg="")
?(tag="")
(filename: string)
(linenumber: int)
(error: string list) =
let tag = if tag = "" then tag else tag ^ ":" in
let msg = if msg = "" then msg else msg ^ ": " in
ch_error_log#add
(tag ^ filename ^ ":" ^ (string_of_int linenumber))
(LBLOCK [STR msg; STR (String.concat "; " error)])


let log_result
?(msg="")
?(tag="")
(filename: string)
(linenumber: int)
(error: string list) =
let tag = if tag = "" then tag else tag ^ ":" in
let msg = if msg = "" then msg else msg ^ ":" in
chlog#add
(tag ^ filename ^ ":" ^ (string_of_int linenumber))
(LBLOCK [STR msg; STR (String.concat "; " error)])
18 changes: 17 additions & 1 deletion CodeHawk/CH/chutil/cHLogger.mli
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

Copyright (c) 2005-2019 Kestrel Technology LLC
Copyright (c) 2020-2021 Henny B. Sipma
Copyright (c) 2022-2024 Aarno Labs LLC
Copyright (c) 2022-2025 Aarno Labs LLC

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -112,3 +112,19 @@ val log_tfold:
[e] is logged according [tls].*)
val log_tfold_default:
tracelogspec_t -> ('a -> 'c) -> 'c -> 'a traceresult -> 'c


(** [log_error_result msg tag filename linenumber error] writes an entry to
[ch_error_log] with a tag that combines [tag], [filename], and [linenumber].
The entry is the concatenation of [msg] and the list of error messages
making up [error].*)
val log_error_result:
?msg:string -> ?tag:string -> string -> int -> string list -> unit


(** [log_result msg tag filename linenumber error] writes an entry to
[chlog] with a tag that combines [tag], [filename], and [linenumber].
The entry is the concatenation of [msg] and the list of error messages
making up [error].*)
val log_result:
?msg:string -> ?tag:string -> string -> int -> string list -> unit
29 changes: 27 additions & 2 deletions CodeHawk/CH/chutil/cHTraceResult.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
------------------------------------------------------------------------------
The MIT License (MIT)

Copyright (c) 2023-2024 Aarno Labs LLC
Copyright (c) 2023-2025 Aarno Labs LLC

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -61,6 +61,25 @@ let tmap2
| Error e1, Error e2 -> Error (msg1 :: msg2 :: (e1 @ e2))


let tmap3
?(msg1="")
?(msg2="")
?(msg3="")
(f: 'a -> 'b -> 'c -> 'd)
(r1: 'a traceresult)
(r2: 'b traceresult)
(r3: 'c traceresult): 'd traceresult =
match r1, r2, r3 with
| Ok v1, Ok v2, Ok v3 -> Ok (f v1 v2 v3)
| Error e1, Ok _, Ok _ -> Error (msg1 :: e1)
| Ok _, Error e2, Ok _ -> Error (msg2 :: e2)
| Ok _, Ok _, Error e3 -> Error (msg3 :: e3)
| Error e1, Error e2, Ok _ -> Error (msg1 :: msg2 :: (e1 @ e2))
| Error e1, Ok _, Error e3 -> Error (msg1 :: msg3 :: (e1 @ e3))
| Ok _, Error e2, Error e3 -> Error (msg2 :: msg3 :: (e2 @ e3))
| Error e1, Error e2, Error e3 -> Error (msg1 :: msg2 :: msg3 :: (e1 @ e2 @ e3))


let tbind ?(msg="") (f: 'a -> 'c traceresult) (r: 'a traceresult) =
match r with
| Ok v -> f v
Expand All @@ -86,7 +105,13 @@ let tprop (r: 'a traceresult) (msg: string): 'a traceresult =
| Error e -> Error (msg :: e)


let titer (f: 'a -> unit) (r: 'a traceresult) =
let titer ~(ok:'a -> unit) ~(error: string list -> unit) (r: 'a traceresult) =
match r with
| Ok v -> ok v
| Error e -> error e


let titer_default (f: 'a -> unit) (r: 'a traceresult) =
match r with
| Ok v -> f v
| Error _ -> ()
Expand Down
23 changes: 21 additions & 2 deletions CodeHawk/CH/chutil/cHTraceResult.mli
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,20 @@ val tmap2:
-> 'c traceresult


(** [tmap3 f r1 r2 r3] is [Ok (f v1 v2 v3)] if [r1] is [Ok v1] and [r2] is
[Ok v2] and [r3] is [Ok v3]; otherwise it returns an [Error] appending
the messages corresponding to the error value as appropriate.*)
val tmap3:
?msg1:string
-> ?msg2:string
-> ?msg3:string
-> ('a -> 'b -> 'c -> 'd)
-> 'a traceresult
-> 'b traceresult
-> 'c traceresult
-> 'd traceresult


(** [tfold ~ok ~error r] is [ok v] if [r] is [Ok v] and [error e] if [r] is
[Error e].*)
val tfold: ok:('a -> 'c) -> error:(string list -> 'c) -> 'a traceresult -> 'c
Expand All @@ -86,8 +100,13 @@ val tbind:
?msg:string -> ('a -> 'c traceresult) -> ('a traceresult) -> 'c traceresult


(** [titer f r] is [f v] if [r] is [Ok v] and [()] otherwise.*)
val titer: ('a -> unit) -> ('a traceresult) -> unit
(** [titer ~ok ~error r] is [ok v] if [r] is [Ok v] and [error e] if [r] is
[Error e].*)
val titer: ok:('a -> unit) -> error:(string list -> unit) -> ('a traceresult) -> unit


(** [titer_default f r] is [f v] if [r] is [Ok v] and [()] otherwise.*)
val titer_default: ('a -> unit) -> 'a traceresult -> unit


(** [tfold_list ~ok init rl] folds [Ok] values left to right, starting from
Expand Down
13 changes: 13 additions & 0 deletions CodeHawk/CHB/bchanalyze/bCHFileIO.ml
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,19 @@ let save_global_state () =
file_output#saveFile filename doc#toPretty
end


let save_global_memory_map () =
let filename = get_global_memory_map_filename () in
let doc = xmlDocument () in
let root = get_bch_root "global-locations" in
let gNode = xmlElement "global-locations" in
begin
BCHGlobalMemoryMap.global_memory_map#write_xml gNode;
doc#setNode root;
root#appendChildren [gNode];
file_output#saveFile filename doc#toPretty
end

let save_system_info () =
let filename = get_system_info_filename () in
let doc = xmlDocument () in
Expand Down
1 change: 1 addition & 0 deletions CodeHawk/CHB/bchanalyze/bCHFileIO.mli
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ val save_functions_list: unit -> unit
val save_arm_functions_list: unit -> unit

val save_global_state: unit -> unit
val save_global_memory_map: unit -> unit
val save_system_info: unit -> unit
val save_resultmetrics: xml_element_int -> unit
val save_disassembly_status: unit -> unit
Expand Down
13 changes: 8 additions & 5 deletions CodeHawk/CHB/bchanalyze/bCHTrace.ml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

Copyright (c) 2005-2020 Kestrel Technology LLC
Copyright (c) 2020 Henny Sipma
Copyright (c) 2021-2024 Aarno Labs LLC
Copyright (c) 2021-2025 Aarno Labs LLC

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -76,10 +76,13 @@ let se_address_is_referenced
if floc#is_address x then
let (memref,memoffset) = floc#decompose_address x in
if is_constant_offset memoffset then
let memv =
finfo#env#mk_memory_variable memref (get_total_constant_offset memoffset) in
let memx = floc#rewrite_variable_to_external memv in
var_is_referenced finfo memx v
TR.tfold_default
(fun offset ->
let memv = finfo#env#mk_memory_variable memref offset in
let memx = floc#rewrite_variable_to_external memv in
var_is_referenced finfo memx v)
false
(get_total_constant_offset memoffset)
else
false
else
Expand Down
33 changes: 14 additions & 19 deletions CodeHawk/CHB/bchcil/bCHParseCilFile.ml
Original file line number Diff line number Diff line change
Expand Up @@ -38,30 +38,25 @@ open CHLogger
(* bchlib *)
open BCHBCFiles
open BCHBCTypes
open BCHBCTypePretty
open BCHBCTypeUtil
open BCHCilToCBasic
open BCHConstantDefinitions


let update_symbolic_address_types () =
let globalvarnames = get_untyped_symbolic_address_names () in
begin
List.iter (fun name ->
if bcfiles#has_varinfo name then
let vinfo = bcfiles#get_varinfo name in
begin
update_symbolic_address_btype name vinfo.bvtype;
chlog#add
"symbolic address: update with vinfo"
(LBLOCK [STR name; STR ": "; STR (btype_to_string vinfo.bvtype)])
end
else
chlog#add "symbolic address: no update" (STR name)) globalvarnames;
chlog#add
"symbolic address updates"
(LBLOCK [STR "Names: "; STR (String.concat ", " globalvarnames)])
end
let gfunnames = bcfiles#get_gfun_names in
let varinfos = bcfiles#get_varinfos in
List.iter
(fun vinfo ->
if List.mem vinfo.bvname gfunnames then
()
else
match BCHGlobalMemoryMap.update_global_location_type vinfo with
| Error e ->
ch_error_log#add
"update-global-location-type"
(LBLOCK [
STR "varinfo: "; STR vinfo.bvname; STR (String.concat "; " e)])
| _ -> ()) varinfos


let parse_cil_file ?(computeCFG=true) ?(removeUnused=true) (filename: string) =
Expand Down
19 changes: 16 additions & 3 deletions CodeHawk/CHB/bchcmdline/bCHXBinaryAnalyzer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,9 @@ let main () =
let t = ref (Unix.gettimeofday ()) in
let _ = load_elf_files () in
let _ = pr_timing [STR "elf files loaded"] in
let _ = List.iter parse_cil_file system_info#ifiles in
let _ =
List.iter (fun f ->
parse_cil_file ~removeUnused:false f) system_info#ifiles in
let _ =
if (List.length system_info#ifiles) > 0 then
pr_timing [STR "c header files loaded"] in
Expand Down Expand Up @@ -600,6 +602,8 @@ let main () =
pr_timing [STR "system_info saved"];
save_arm_dictionary ();
pr_timing [STR "dictionary saved"];
save_global_memory_map ();
pr_timing [STR "global-locations saved"];
save_interface_dictionary ();
pr_timing [STR "interface dictionary saved"];
save_bcdictionary ();
Expand Down Expand Up @@ -843,8 +847,6 @@ let main () =
let _ = pr_timing [STR "bdictionary loaded"] in
let _ = load_bc_files () in
let _ = pr_timing [STR "bc files loaded"] in
let _ = system_info#initialize in
let _ = pr_timing [STR "system info initialized"] in
let _ = load_interface_dictionary () in
let _ = pr_timing [STR "interface dictionary loaded"] in
let _ = load_arm_dictionary () in
Expand All @@ -859,12 +861,21 @@ let main () =
STR ")"] in
let _ = load_elf_files () in
let _ = pr_timing [STR "elf files loaded"] in

(* symbolic addresses in userdata should be loaded before the header
files are parsed. *)
let _ = system_info#initialize in
let _ = pr_timing [STR "system info initialized"] in
let _ =
List.iter
(fun f -> parse_cil_file ~removeUnused:false f) system_info#ifiles in
let _ =
if (List.length system_info#ifiles > 0) then
pr_timing [STR "c header files parsed"] in
(* function annotations in userdata should be loaded after the header
files are parsed, so types in the function annotations can be resolved.*)
let _ = system_info#initialize_function_annotations in

let index = file_metrics#get_index in
let logcmd = "analyze_" ^ (string_of_int index) in
let analysisstart = Unix.gettimeofday () in
Expand Down Expand Up @@ -896,6 +907,8 @@ let main () =
(* save_arm_assembly_instructions (); *)
save_arm_dictionary ();
pr_timing [STR "arm dictionary saved"];
save_global_memory_map ();
pr_timing [STR "global-locations saved"];
save_bc_files ();
pr_timing [STR "bc files saved"];
save_interface_dictionary ();
Expand Down
3 changes: 1 addition & 2 deletions CodeHawk/CHB/bchcmdline/bCHXInspectSummaries.ml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ open CHLogger

(* bchlib *)
open BCHBasicTypes
open BCHConstantDefinitions
open BCHFunctionSummaryLibrary
open BCHLibTypes
open BCHSystemInfo
Expand Down Expand Up @@ -126,7 +125,7 @@ let print_statistics () =
STR "Type definitions: "; NL; type_definitions#toPretty; NL;
STR "IO action categories: "; INT (List.length pActions); NL;
STR "Parameter roles : "; INT nParamRoles; NL;
constant_statistics_to_pretty (); NL]
BCHConstantDefinitions.constant_statistics_to_pretty (); NL]
end

let main () =
Expand Down
Loading