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
|
exception Inconsistent of BStd.tid
|
||||||
|
|
||||||
let get_entry_blk graph =
|
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
|
let ax = opt_addr_of @@ CFG.Node.label x
|
||||||
and ay = opt_addr_of @@ CFG.Node.label y in
|
and ay = opt_addr_of @@ CFG.Node.label y in
|
||||||
match ax, ay with
|
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 changes_map = with_rbp_if_needed initial_offset in
|
||||||
|
|
||||||
let merged_changes = TIdMap.fold
|
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
|
if v1 = v2 then
|
||||||
Some v1
|
Some v1
|
||||||
else
|
else (
|
||||||
assert false)
|
Format.eprintf "Inconsistency: 0x%Lx: cannot merge %a - %a@."
|
||||||
|
addr pp_reg_pos v1 pp_reg_pos v2 ;
|
||||||
|
Some (CfaLostTrack, RbpUndef))
|
||||||
|
)
|
||||||
cfa_changes accu)
|
cfa_changes accu)
|
||||||
changes_map
|
changes_map
|
||||||
AddrMap.empty in
|
AddrMap.empty in
|
||||||
|
|
10
Makefile
10
Makefile
|
@ -2,14 +2,22 @@ OCAMLBUILD=bapbuild -no-hygiene
|
||||||
BAPBUNDLE=bapbundle
|
BAPBUNDLE=bapbundle
|
||||||
ROOT_MODULE=dwarfsynth
|
ROOT_MODULE=dwarfsynth
|
||||||
|
|
||||||
|
LIBDWARFW_SO=libdwarfw/build/libdwarfw.so
|
||||||
|
LIBDWARFW_SO_MESON=libdwarfw/build/build.ninja
|
||||||
|
|
||||||
|
|
||||||
all: install ml_dwarf_write.bin
|
all: install ml_dwarf_write.bin
|
||||||
|
|
||||||
.PHONY: ml_dwarf_write.bin
|
.PHONY: ml_dwarf_write.bin
|
||||||
ml_dwarf_write.bin:
|
ml_dwarf_write.bin: $(LIBDWARFW_SO)
|
||||||
$(MAKE) -C DwarfSynth/c_bindings
|
$(MAKE) -C DwarfSynth/c_bindings
|
||||||
ln -fs DwarfSynth/c_bindings/ml_dwarf_write.bin .
|
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
|
.PHONY: $(ROOT_MODULE).plugin
|
||||||
$(ROOT_MODULE).plugin:
|
$(ROOT_MODULE).plugin:
|
||||||
$(OCAMLBUILD) $(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
|
## Dependencies
|
||||||
|
|
||||||
This tool relies on [BAP](https://github.com/BinaryAnalysisPlatform/bap), which
|
This tool relies on
|
||||||
is available through OPAM.
|
|
||||||
|
* [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
|
## Compiling
|
||||||
|
|
||||||
|
|
|
@ -172,17 +172,7 @@ def parse_fde(lines):
|
||||||
for line in lines[2:]:
|
for line in lines[2:]:
|
||||||
rows.append(parse_fde_row(line, reg_cols))
|
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)
|
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)}
|
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)
|
rowchanges.sort(key=loc_of)
|
||||||
|
|
||||||
mismatch_count = 0
|
mismatch_count = 0
|
||||||
|
match_count = 0
|
||||||
for rowid, rowch in enumerate(rowchanges):
|
for rowid, rowch in enumerate(rowchanges):
|
||||||
typ, row = rowch[0], rowch[1]
|
typ, row = rowch[0], rowch[1]
|
||||||
cur_val[typ] = vals_of(row)
|
cur_val[typ] = vals_of(row)
|
||||||
|
@ -297,8 +288,10 @@ def match_fde(orig, synth):
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
mismatch_count += 1
|
mismatch_count += 1
|
||||||
|
else:
|
||||||
|
match_count += 1
|
||||||
|
|
||||||
return mismatch_count
|
return mismatch_count, match_count
|
||||||
|
|
||||||
|
|
||||||
def parse_sym_table(handle):
|
def parse_sym_table(handle):
|
||||||
|
@ -347,11 +340,14 @@ def main():
|
||||||
# dump_light_fdes(unmatched_synth)
|
# dump_light_fdes(unmatched_synth)
|
||||||
|
|
||||||
mismatches = 0
|
mismatches = 0
|
||||||
|
good_match = 0
|
||||||
for (orig, synth) in matched:
|
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 = []
|
reports = []
|
||||||
if mismatches > 0:
|
if mismatches > 0:
|
||||||
reports.append("{} mismatches".format(mismatches))
|
reports.append("{} mismatches - {} well matched".format(mismatches, good_match))
|
||||||
if unmatched_orig:
|
if unmatched_orig:
|
||||||
worth_reporting = False
|
worth_reporting = False
|
||||||
for unmatched in unmatched_orig:
|
for unmatched in unmatched_orig:
|
||||||
|
@ -374,6 +370,8 @@ def main():
|
||||||
)
|
)
|
||||||
|
|
||||||
if reports:
|
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)))
|
print("{}: {}".format(test_name, "; ".join(reports)))
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue