-
Notifications
You must be signed in to change notification settings - Fork 271
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
adds integration with ida 7 #893
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,4 @@ REC | |
|
||
B ../../_build/lib/bap_ida | ||
B ../../_build/plugins/ida | ||
S. | ||
S . |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,193 @@ | ||
open Core_kernel | ||
open Bap.Std | ||
include Self() | ||
|
||
type version = Vold | Vnew [@@deriving sexp] | ||
type old_kind = [ `idal | `idal64 | `idaq | `idaq64 ] [@@deriving sexp, enumerate] | ||
type new_kind = [ `idat | `idat64 | `ida | `ida64 ] [@@deriving sexp, enumerate] | ||
type ida_kind = [ old_kind | new_kind ] [@@deriving sexp] | ||
|
||
type ida = { | ||
headless : ida_kind; | ||
graphical : ida_kind; | ||
headless64 : ida_kind; | ||
graphical64 : ida_kind; | ||
version : version; | ||
} [@@deriving sexp] | ||
|
||
type t = { | ||
path : string; | ||
ida : ida; | ||
is_headless : bool; | ||
} | ||
|
||
type mode = [ `m32 | `m64 ] | ||
|
||
type failure = | ||
| Ida_not_exists | ||
| Non_dir_path | ||
| File_not_found of string | ||
| Unexpected_kind | ||
| Headless_win32 | ||
| Ida_python_missed | ||
|
||
let (/) = Filename.concat | ||
|
||
let string_of_kind k = Sexp.to_string (sexp_of_ida_kind k) | ||
|
||
let code_of_failure = function | ||
| Ida_not_exists -> 0 | ||
| Non_dir_path -> 1 | ||
| File_not_found _ -> 2 | ||
| Unexpected_kind -> 3 | ||
| Headless_win32 -> 4 | ||
| Ida_python_missed-> 5 | ||
|
||
let string_of_failure = function | ||
| Ida_not_exists -> "IDA path not exists" | ||
| Non_dir_path -> "IDA path is not a directory" | ||
| File_not_found k -> k ^ " must exist" | ||
| Unexpected_kind -> "can't infer IDA version. Check IDA installation" | ||
| Headless_win32 -> "can't use headless on windows" | ||
| Ida_python_missed -> "bap-ida-python is not installed" | ||
|
||
module Check = struct | ||
|
||
type error = (unit, failure) Result.t | ||
|
||
let require = Result.ok_if_true | ||
|
||
let require_path path = require (Sys.file_exists path) | ||
let require_dir path = require (Sys.is_directory path) ~error:Non_dir_path | ||
|
||
let require_ida path = | ||
let open Result in | ||
require_path path ~error:Ida_not_exists >>= fun () -> | ||
require_dir path | ||
|
||
let require_ida_python path = | ||
require_path ~error:Ida_python_missed | ||
(path / "plugins" / "plugin_loader_bap.py") | ||
|
||
let require_kind path k = | ||
let file = path / string_of_kind k in | ||
require_path ~error:(File_not_found file) file | ||
|
||
let run {path; ida} = | ||
let require_kind = require_kind path in | ||
Result.all_ignore [ | ||
require_ida path; | ||
require_ida_python path; | ||
require_kind ida.graphical; | ||
require_kind ida.graphical64; | ||
require_kind ida.headless; | ||
require_kind ida.headless64; ] | ||
|
||
let check_integrity ida = | ||
let files = [ida.graphical; ida.headless; | ||
ida.graphical64; ida.headless64;] in | ||
let is_of kinds = List.mem (kinds :> ida_kind list) ~equal:(=) in | ||
let check version = List.for_all files ~f:(is_of version) in | ||
let expected = match ida.headless with | ||
| `idal -> (all_of_old_kind :> ida_kind list) | ||
| _ -> (all_of_new_kind :> ida_kind list) in | ||
let checked = check expected in | ||
require checked ~error:Unexpected_kind | ||
|
||
let check_headless is_headless = | ||
require (is_headless ==> not Sys.win32) ~error:Headless_win32 | ||
|
||
end | ||
|
||
let check ida = | ||
match Check.run ida with | ||
| Ok () as ok -> ok | ||
| Error fail -> | ||
Or_error.errorf "IDA check failed with error code %d" | ||
(code_of_failure fail) | ||
|
||
let exists_kind path kind = | ||
Sys.file_exists (path / string_of_kind kind) | ||
|
||
let create_ida path = | ||
let find_kind ~is_headless mode = | ||
let kinds = match mode with | ||
| `m32 when is_headless -> [`idal; `idat] | ||
| `m64 when is_headless -> [`idal64; `idat64] | ||
| `m32 -> [`idaq; `ida] | ||
| `m64 -> [`idaq64; `ida64] in | ||
List.find ~f:(exists_kind path) kinds |> | ||
function | ||
| Some k -> Ok k | ||
| None -> | ||
let kinds = List.map ~f:string_of_kind kinds in | ||
let files = String.concat ~sep:"/" kinds in | ||
Error (File_not_found files) in | ||
let version_of_headless = function | ||
| `idal -> Vold | ||
| _ -> Vnew in | ||
Result.( | ||
find_kind ~is_headless:true `m32 >>= fun headless -> | ||
find_kind ~is_headless:false `m32 >>= fun graphical -> | ||
find_kind ~is_headless:true `m64 >>= fun headless64 -> | ||
find_kind ~is_headless:false `m64 >>= fun graphical64 -> | ||
let version = version_of_headless headless in | ||
Ok { headless; graphical; headless64; graphical64; version }) | ||
|
||
let create' path is_headless = | ||
let open Check in | ||
Result.( | ||
require_ida path >>= fun () -> | ||
require_ida_python path >>= fun () -> | ||
check_headless is_headless >>= fun () -> | ||
create_ida path >>= fun ida -> | ||
check_integrity ida >>= fun () -> | ||
Ok {ida; path; is_headless}) | ||
|
||
let create path is_headless = | ||
match create' path is_headless with | ||
| Ok r -> Ok r | ||
| Error fail -> | ||
warning "%s" (string_of_failure fail); | ||
Or_error.errorf "IDA detection failed with error code %d" (code_of_failure fail) | ||
|
||
(* Note, we always launch headless ida in case of IDA Pro 7 *) | ||
let ida32 info = match info.ida.version with | ||
| Vnew -> info.ida.headless | ||
| Vold -> | ||
if info.is_headless then info.ida.headless | ||
else info.ida.graphical | ||
|
||
let ida64 info = match info.ida.version with | ||
| Vnew -> info.ida.headless64 | ||
| Vold -> | ||
if info.is_headless then info.ida.headless64 | ||
else info.ida.graphical64 | ||
|
||
let ida_of_suffix info filename = | ||
let ext = FilePath.replace_extension in | ||
let exists suf = Sys.file_exists (ext filename suf) in | ||
if exists "i64" then Some (ida64 info) | ||
else if exists "idb" then Some (ida32 info) | ||
else None | ||
|
||
let ida_of_mode info = function | ||
| `m32 -> ida32 info | ||
| `m64 -> ida64 info | ||
|
||
let find_ida info mode target = | ||
let kind = match mode with | ||
| Some mode -> ida_of_mode info mode | ||
| None -> | ||
match ida_of_suffix info target with | ||
| Some ida -> ida | ||
| None -> ida64 info in | ||
let s = Sexp.to_string (sexp_of_ida_kind kind) in | ||
let ida = Filename.concat info.path s in | ||
Filename.quote ida | ||
|
||
let is_headless t = t.is_headless | ||
let path t = t.path | ||
|
||
let require_ncurses t = | ||
Sys.os_type = "Unix" && t.is_headless && t.ida.version = Vold |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
open Core_kernel | ||
|
||
type mode = [ `m32 | `m64 ] | ||
|
||
type t | ||
|
||
(** [create path is_headless] *) | ||
val create : string -> bool -> t Or_error.t | ||
|
||
(** [find_ida info mode target] - returns a full path | ||
to ida executable depending on [mode] and [target] name *) | ||
val find_ida : t -> mode option -> string -> string | ||
|
||
val is_headless : t -> bool | ||
|
||
val check : t -> unit Or_error.t | ||
|
||
(** [require_ncurses ida] returns true if [ida] need ncureses lib to operate*) | ||
val require_ncurses : t -> bool |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
type ida_kind = [`idal | `idal64 | `idaq | `idaq64] | ||
|
||
(** [register ida_path ida_kind is_headless] registers the IDA service with | ||
(** [register ida_info ida_mode] registers the IDA service with | ||
Bap_ida library *) | ||
val register : string -> ida_kind option -> bool -> unit | ||
val register : Bap_ida_info.t -> Bap_ida_info.mode option -> unit |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doesn't exist