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

introduces the BIL code slot and a few convenience functions #1266

Merged

Conversation

ivg
Copy link
Member

@ivg ivg commented Jan 13, 2021

This PR adds a few convenience functions and gives access to internals
for build BIR graph. It is now very easy to go from BIL to blk term,
sub term or even program term. Details follow.

Enables representation of an instruction as a BIL program

We used BIL as a language for specifying the semantics of an
instruction, but we may also (and now can) represent the instruction
itself using BIL.

The rules of the knowledge base are adopted and split accordingly, so
that the rule that uses the old lifters to produce the BIL code is
separated from the rule that computes the semantics of the BIL code.

It is now possible to get easily an Insn.t value from bil and even
to go from bil to sub or program term.

E.g., to get the semantics of BIL just create a new program object and
set its bil code,

let create_insn bil  =
  KB.Object.create Theory.Program.cls >>= fun obj ->
  KB.provide Bil.code obj bil >>| fun () ->
  obj

You can run this computation, for example, in the BAP toplevel
knowledge base, e.g.,

let insn_of_bil bil : insn =
  Toplevel.eval Theory.Semantics.slot @@ create_insn bil

To get IR from insn use the Blk.from_insn function, so the full path
from BIL to BIR will be

let bir_of_bil : blk term list =
  Blk.from_insn insn_of_bil @@ create_insn bil

Adds some sugar to IR term building functions.

It is now possible to pass the parts of compound terms to their create
function, e.g.,

Sub.create () ~blks:[
  Blk.create () ~defs:[
    ...
  ]
]

Adds the Blk.from_insns function

This function translate a sequence of machine instructions that
represent a basic block into IR and preserves as much as possible the
original structure trying to keep at minimum the number of generated
IR blks.

Uses the special encodings as much as possible

This will enable more seamless translation of the system calls and interrupts.

ivg added 4 commits January 11, 2021 14:39
This function translate a sequence of machine instructions that
represent a basic block into IR and preserves as much as possible the
original structure trying to keep at minimum the number of generated
IR blks.
We used BIL as a language for specifying the semantics of an
instruction, but we may also (and now can) represent the instruction
itself using BIL.

The rules of the knowledge base are adopted and split accordingly, so
that the rule that uses the old lifters to produce the BIL code is
separated from the rule that computes the semantics of the BIL code.

It is now possible to get easily an `Insn.t` value from `bil` and even
to go from bil to sub or program term.

E.g., to get the semantics of BIL just create a new program object and
set its bil code,

```ocaml
let create_insn bil  =
  KB.Object.create Theory.Program.cls >>= fun obj ->
  KB.provide Bil.code obj bil >>| fun () ->
  obj
```

You can run this computation, for example, in the BAP toplevel
knowledge base, e.g.,

```ocaml
let insn_of_bil bil : insn =
  Toplevel.eval Theory.Semantics.slot @@ create_insn bil
```

To get IR from insn use the `Blk.from_insn` function, so the full path
from BIL to BIR will be

```
let bir_of_bil : blk term list =
  Blk.from_insn insn_of_bil @@ create_insn bil
```
It is now possible to pass the parts of compound terms to their create
function, e.g.,
```
Sub.create () ~blks:[
  Blk.create () ~defs:[
    ...
  ]
]
```
@ivg ivg merged commit aacced7 into BinaryAnalysisPlatform:master Jan 13, 2021
@ivg ivg deleted the adds-bil-code-and-convience-functions branch December 1, 2021 19:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant