-
Notifications
You must be signed in to change notification settings - Fork 275
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WIP] overhauls the target/architecture abstraction (3/n)
In this episode, we liberate `bap mc` and `bap objdump` from the bonds of the `Arch.t` representation. We also add the systemz lifter for demonstration purposes. Of course, the lifter is minimal and far from being usable, but that serves well its didactic purposes. The interface of the `bap mc` command is preserved but is extended with a few more command-line options that provide a great deal of flexibility. Not only it is now possible to specify the target and encoding, but it is now possible to pass options directly to the backend, which is useful for disassembling targets that are not yet known to BAP. Below is an excerpt from the bap-mc man page (see bap mc --help) ``` SETTING ARCHITECHTURE The target architecture is controlled by several groups of options that can not be used together: - arch; - target and encoding; - triple, backend, cpu, bits, and order. The arch option provides the least control but is easiest to use. It relies on the dependency-injection mechanism and lets the target support packages (plugins that implement support for the given architecture) do their best to guess the target and encoding that matches the provided name. Use the common names for the architecture and it should work. You can use the bits and order options to give more hints to the target support packages. They default to 32 and little correspondingly. The target and encoding provides precise control over the selection of the target and the encoding that is used to represent machine instructions. The encoding field can be omitted and will be deduced from the target. Use bap list targets and bap list encodings to get the list of supported targets and encodings respectivly. Finally, the triple, backend, cpu,... group of options provides the full control over the disassembler backend and bypasses the dependency-injection mechanism to pass the specified options directly to the corresponding backends. This enables disassembling of targets and encodings that are not yet supported by BAP. The meanings of the options totally depend on the selected backend and they are passed as is to the corresponding arguments of the Disasm_expert.Basic.create function. The bits and order defaults to 32 and little corresondingly and are used to specify the number of bits in the target's addresses and the order of bytes in the word. This group of options is useful during the implementation and debugging of new targets and thus is reserved for experts. Note, when this group is used the semantics of the instructions will not be provided as it commonly requires the target specification. ```
- Loading branch information
Showing
22 changed files
with
568 additions
and
42 deletions.
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
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
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
open Core_kernel | ||
open Bap_core_theory | ||
|
||
let package = "bap" | ||
|
||
type r64 and r32 and r16 and r8 | ||
|
||
type 'a bitv = 'a Theory.Bitv.t Theory.Value.sort | ||
|
||
let r64 : r64 bitv = Theory.Bitv.define 64 | ||
let r32 : r32 bitv = Theory.Bitv.define 32 | ||
let r16 : r16 bitv = Theory.Bitv.define 16 | ||
let r8 : r8 bitv = Theory.Bitv.define 8 | ||
let bool = Theory.Bool.t | ||
|
||
let reg t n = Theory.Var.define t n | ||
|
||
let array ?(index=string_of_int) t pref size = | ||
List.init size ~f:(fun i -> reg t (pref ^ index i)) | ||
|
||
let untyped = List.map ~f:Theory.Var.forget | ||
let (@<) xs ys = untyped xs @ untyped ys | ||
|
||
let mems = Theory.Mem.define r64 r8 | ||
|
||
let gpr = array r64 "R" 16 | ||
let fpr = array r64 "F" 16 | ||
let mem = reg mems "mem" | ||
|
||
let vars = gpr @< fpr @< [mem] | ||
|
||
let parent = Theory.Target.declare ~package "systemz" | ||
|
||
let z9 = Theory.Target.declare ~package "systemz9" ~parent | ||
~bits:64 | ||
~code:mem | ||
~data:mem | ||
~vars | ||
|
||
let llvm_encoding = Theory.Language.declare ~package "llvm-systemz" |
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,21 @@ | ||
open Bap_core_theory | ||
|
||
|
||
type r64 and r32 and r16 and r8 | ||
|
||
type 'a bitv = 'a Theory.Bitv.t Theory.Value.sort | ||
|
||
val r64 : r64 bitv | ||
val r32 : r32 bitv | ||
val r16 : r16 bitv | ||
val r8 : r8 bitv | ||
|
||
val mem : (r64, r8) Theory.Mem.t Theory.var | ||
val gpr : r64 Theory.Bitv.t Theory.var list | ||
val fpr : r64 Theory.Bitv.t Theory.var list | ||
|
||
val parent : Theory.Target.t | ||
|
||
val z9 : Theory.Target.t | ||
|
||
val llvm_encoding : Theory.Language.t |
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
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
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
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
Flag systemz | ||
Description: Build Systemz lifter | ||
Default: false | ||
|
||
Library "bap-systemz" | ||
Build$: flag(everything) || flag(systemz) | ||
XMETADescription: common definitions for Systemz targets | ||
Path: lib/bap_systemz | ||
BuildDepends: core_kernel, bap-knowledge, bap-core-theory | ||
FindlibName: bap-systemz | ||
Modules: Bap_systemz_target | ||
|
||
Library systemz_plugin | ||
XMETADescription: provide Systemz lifter | ||
Path: plugins/systemz | ||
Build$: flag(everything) || flag(systemz) | ||
BuildDepends: core_kernel, ppx_jane, ogre, | ||
bap-core-theory, bap-knowledge, bap-main, | ||
bap, bap-systemz | ||
FindlibName: bap-plugin-systemz | ||
InternalModules: Systemz_main, Systemz_lifter | ||
XMETAExtraLines: tags="systemz, lifter, z9" |
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
Oops, something went wrong.