Compare commits
4 commits
174c4e8143
...
07e6fd821e
Author | SHA1 | Date | |
---|---|---|---|
Théophile Bastian | 07e6fd821e | ||
Théophile Bastian | ad07f1d30f | ||
Théophile Bastian | e7c007e811 | ||
Théophile Bastian | 8d49af7be8 |
|
@ -581,7 +581,7 @@ let process_blk
|
|||
exception Inconsistent of BStd.tid
|
||||
|
||||
let get_entry_blk graph =
|
||||
let entry = BStd.Seq.min_elt (CFG.nodes graph) ~cmp:(fun x y ->
|
||||
let entry = BStd.Seq.min_elt (CFG.nodes graph) ~compare:(fun x y ->
|
||||
let ax = opt_addr_of @@ CFG.Node.label x
|
||||
and ay = opt_addr_of @@ CFG.Node.label y in
|
||||
match ax, ay with
|
||||
|
@ -732,11 +732,14 @@ let process_sub sub next_instr_graph : subroutine_cfa_data =
|
|||
let changes_map = with_rbp_if_needed initial_offset in
|
||||
|
||||
let merged_changes = TIdMap.fold
|
||||
(fun _ (cfa_changes, _) accu -> AddrMap.union (fun _ v1 v2 ->
|
||||
(fun _ (cfa_changes, _) accu -> AddrMap.union (fun addr v1 v2 ->
|
||||
if v1 = v2 then
|
||||
Some v1
|
||||
else
|
||||
assert false)
|
||||
else (
|
||||
Format.eprintf "Inconsistency: 0x%Lx: cannot merge %a - %a@."
|
||||
addr pp_reg_pos v1 pp_reg_pos v2 ;
|
||||
Some (CfaLostTrack, RbpUndef))
|
||||
)
|
||||
cfa_changes accu)
|
||||
changes_map
|
||||
AddrMap.empty in
|
||||
|
|
10
Makefile
10
Makefile
|
@ -2,14 +2,22 @@ OCAMLBUILD=bapbuild -no-hygiene
|
|||
BAPBUNDLE=bapbundle
|
||||
ROOT_MODULE=dwarfsynth
|
||||
|
||||
LIBDWARFW_SO=libdwarfw/build/libdwarfw.so
|
||||
LIBDWARFW_SO_MESON=libdwarfw/build/build.ninja
|
||||
|
||||
|
||||
all: install ml_dwarf_write.bin
|
||||
|
||||
.PHONY: ml_dwarf_write.bin
|
||||
ml_dwarf_write.bin:
|
||||
ml_dwarf_write.bin: $(LIBDWARFW_SO)
|
||||
$(MAKE) -C DwarfSynth/c_bindings
|
||||
ln -fs DwarfSynth/c_bindings/ml_dwarf_write.bin .
|
||||
|
||||
.PHONY: $(LIBDWARFW_SO)
|
||||
$(LIBDWARFW_SO):
|
||||
cd libdwarfw && test -d build || meson build
|
||||
ninja -C libdwarfw/build
|
||||
|
||||
.PHONY: $(ROOT_MODULE).plugin
|
||||
$(ROOT_MODULE).plugin:
|
||||
$(OCAMLBUILD) $(ROOT_MODULE).plugin
|
||||
|
|
18
README.md
18
README.md
|
@ -8,8 +8,22 @@ examine its assembly code and, based solely on that, generate the corresponding
|
|||
|
||||
## Dependencies
|
||||
|
||||
This tool relies on [BAP](https://github.com/BinaryAnalysisPlatform/bap), which
|
||||
is available through OPAM.
|
||||
This tool relies on
|
||||
|
||||
* [BAP](https://github.com/BinaryAnalysisPlatform/bap) version 1.6 as of today,
|
||||
which is available through OPAM;
|
||||
* `objcopy`, often packaged as `binutils`
|
||||
* `libelf`
|
||||
* `libdwarf`
|
||||
* `libdwarfw`, packaged as submodule
|
||||
|
||||
### Installing dependencies
|
||||
|
||||
You should be able to easily install `objcopy` (`binutils`), `libelf`,
|
||||
`libdwarf` and `opam` via your package manager. Once
|
||||
[`opam` is set up](https://opam.ocaml.org/doc/Install.html), you should be able
|
||||
to simply `opam install bap`. We recommand that you use a fresh `opam switch`
|
||||
in case you already have installed packages with `opam`.
|
||||
|
||||
## Compiling
|
||||
|
||||
|
|
|
@ -172,17 +172,7 @@ def parse_fde(lines):
|
|||
for line in lines[2:]:
|
||||
rows.append(parse_fde_row(line, reg_cols))
|
||||
|
||||
# if pc_beg == 0x1160:
|
||||
# print("===== FDE: {}..{} ====".format(hex(pc_beg), hex(pc_end)))
|
||||
# print("BEFORE:")
|
||||
# for row in rows:
|
||||
# print(row)
|
||||
rows = detect_clang_flat_to_pyramid(rows)
|
||||
# if pc_beg == 0x1160:
|
||||
# print("AFTER:")
|
||||
# for row in rows:
|
||||
# print(row)
|
||||
|
||||
return {"beg": pc_beg, "end": pc_end, "rows": clean_rows(rows)}
|
||||
|
||||
|
||||
|
@ -282,6 +272,7 @@ def match_fde(orig, synth):
|
|||
rowchanges.sort(key=loc_of)
|
||||
|
||||
mismatch_count = 0
|
||||
match_count = 0
|
||||
for rowid, rowch in enumerate(rowchanges):
|
||||
typ, row = rowch[0], rowch[1]
|
||||
cur_val[typ] = vals_of(row)
|
||||
|
@ -297,8 +288,10 @@ def match_fde(orig, synth):
|
|||
)
|
||||
)
|
||||
mismatch_count += 1
|
||||
else:
|
||||
match_count += 1
|
||||
|
||||
return mismatch_count
|
||||
return mismatch_count, match_count
|
||||
|
||||
|
||||
def parse_sym_table(handle):
|
||||
|
@ -347,11 +340,14 @@ def main():
|
|||
# dump_light_fdes(unmatched_synth)
|
||||
|
||||
mismatches = 0
|
||||
good_match = 0
|
||||
for (orig, synth) in matched:
|
||||
mismatches += match_fde(orig, synth)
|
||||
cur_mismatch, cur_match = match_fde(orig, synth)
|
||||
mismatches += cur_mismatch
|
||||
good_match += cur_match
|
||||
reports = []
|
||||
if mismatches > 0:
|
||||
reports.append("{} mismatches".format(mismatches))
|
||||
reports.append("{} mismatches - {} well matched".format(mismatches, good_match))
|
||||
if unmatched_orig:
|
||||
worth_reporting = False
|
||||
for unmatched in unmatched_orig:
|
||||
|
@ -374,6 +370,8 @@ def main():
|
|||
)
|
||||
|
||||
if reports:
|
||||
# If we had some errors to report, let's report positive data too
|
||||
reports.append("{} matched".format(len(matched)))
|
||||
print("{}: {}".format(test_name, "; ".join(reports)))
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue