Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unsupported opcode fallback #22

Merged
merged 6 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
8 changes: 5 additions & 3 deletions bin/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -127,19 +127,21 @@ let do_module (m: Module.t): Module.t =
(* TODO: change argument of to_asli to follow this convention. *)
let opnum = Int32.to_int Bytes.(get_int32_be opcode_be 0) in
let opnum_str = Printf.sprintf "0x%08lx" Int32.(of_int opnum) in
let opnum_dec_str = Printf.sprintf "%lu" Int32.(of_int opnum) in

let opcode_list : char list = List.(rev @@ of_seq @@ Bytes.to_seq opcode_be) in
let opcode_str = String.concat " " List.(map p_byte opcode_list) in
let _opcode : bytes = Bytes.of_seq List.(to_seq opcode_list) in
let unsupported op = let open Asl_ast in Stmt_TCall (FIdent ("unsupported_opcode", 0), [], [Expr_LitInt op], Unknown) in
let do_dis () =
(match Dis.retrieveDisassembly ?address env (Dis.build_env env) opnum_str with
| res -> (List.map p_raw res, List.map p_pretty res)
| exception exc ->
Printf.eprintf
"error during aslp disassembly (opcode %s, bytes %s):\n\nFatal error: exception %s\n"
"error during aslp disassembly (unsupported opcode %s, bytes %s):\n\nException : %s\n"
opnum_str opcode_str (Printexc.to_string exc);
Printexc.print_backtrace stderr;
exit 1)
(* Printexc.print_backtrace stderr; *)
([p_raw @@ unsupported opnum_dec_str], [p_pretty @@ unsupported opnum_dec_str]))
in fst @@ do_dis ()
in
let rec asts opcodes addr =
Expand Down
2 changes: 1 addition & 1 deletion dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
(name gtirb_semantics)
(synopsis "Add semantic information to the IR of a disassembled ARM64 binary")
(description "A longer description")
(depends ocaml dune yojson asli ocaml-protoc-plugin base64)
(depends ocaml dune yojson asli (ocaml-protoc-plugin (>= 6.1.0)) base64)
(tags
(decompilers instruction-lifters static-analysis)))

Expand Down
2 changes: 1 addition & 1 deletion gtirb_semantics.opam
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ depends: [
"dune" {>= "3.6"}
"yojson"
"asli"
"ocaml-protoc-plugin"
"ocaml-protoc-plugin" {>= "6.1.0"}
"base64"
"odoc" {with-doc}
]
Expand Down
2 changes: 1 addition & 1 deletion lib/dune
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
(libraries ocaml-protoc-plugin asli.libASL base64))

(rule
(targets AuxData.ml ByteInterval.ml CFG.ml CodeBlock.ml DataBlock.ml IR.ml Module.ml Offset.ml ProxyBlock.ml Section.ml Symbol.ml SymbolicExpression.ml)
(targets auxData.ml byteInterval.ml cFG.ml codeBlock.ml dataBlock.ml iR.ml module.ml offset.ml proxyBlock.ml section.ml symbol.ml symbolicExpression.ml)
katrinafyi marked this conversation as resolved.
Show resolved Hide resolved
(deps
(:proto AuxData.proto ByteInterval.proto CFG.proto CodeBlock.proto DataBlock.proto IR.proto Module.proto Offset.proto ProxyBlock.proto Section.proto Symbol.proto SymbolicExpression.proto))
(action
Expand Down