<commit_before># BAP Bindings

This project provides a C interface to BAP library and other
components of the infrastructure. The interface is rather complete,
although some functions may be omitted for a reason or accidentaly.
By desing, everything that is possible to do in OCaml with the Bap.Std
interface should be possible to implement in C, using `bap.h`. If you
find any violations of this rule, please don't hesitate to file an
issue.


## Quick start

The following simple program is a good test that your installation
works fine.

```c
int main(int argc, const char *argv) {
    bap_init(argc, argv);
    printf("Welcome to BAP %s", bap_version());
}

```

The `examples` folder contains a set of small programs, that can be
viewed as tutorials to BAP and BAP bindings. The following order is
suggested:

1. lift_insn - teaches how to disassemble, lift and print code;
2. print_reachable - explains how to write simple analysis;
3. show_image - uncovers low-level details of file parsing.

## Requirements

* BAP 1.x.x
* OCaml 4.03+ with PIC runtime
  (usually available by default, if a compiler is from OPAM)
* GCC
* Patience (it takes some time to generate the bindings)

BAP should be installed, and `_pic` runtime shou

## Compilation

Just type `make` and hit enter :)


## Installation

Two files will be created after the compilation finishes:

* `_build/libbap.so` - a shared object that contains
  - BAP runtime (including code of the bap library)
  - OCaml runtime
* `_build/generated/bap.h` - a header file that describes BAP API.


Currently the installation is totally manual, just copy these files to
appropriate places. We will provide a proper `./configure; make; make
install` trio ASAP.


# Documentation

Lacks. The long story is the following. There is an official
searchable documentation for OCaml library. You should consult it as a
primary source of information. Although it is for OCaml, it should be
understandable without a dictionary. We were trying to follow some
conventions to make it easier to map C functions to their OCaml
counterpart.

1. Module namespaces are translated to the underscore delimited
   prefixes, with exception to Bap.Std that is translated just to
   `bap`, e.g., `Project.Input.file` is `project_input_file`. So to
   get the documentation for the `project_input_file` just type
   `Project.Input.file` in the search window of the OCaml
   documentation. The same is true for types. A type `Project.t` is
   defined as an opaque data structure `bap_project_t`. The name is
   typedefed into from the structure tag namespace to the symbol
   namespace, so no `struct` word is needed.

2. The order of function parameters is preserved, except that optional
   parameters (prefixed with `?` in OCaml) are specified after all
   required parameters. For example,
   `Project.Input.file ?loader:string -> filename:string -> t`
   is translated into `project_input_file(char *filename, char *loader)`.
   The `NULL` value can be passed as an argument to the optional parameter.

3. If there are too many optional parameters, then they are passed<commit_msg>updated README with new build/install instructions<commit_after># BAP Bindings

This project provides a C interface to BAP library and other
components of the infrastructure. The interface is rather complete,
although some functions may be omitted for a reason or accidentaly.
By desing, everything that is possible to do in OCaml with the Bap.Std
interface should be possible to implement in C, using `bap.h`. If you
find any violations of this rule, please don't hesitate to file an
issue.


## Quick start

The following simple program is a good test that your installation
works fine.

```c
int main(int argc, const char *argv) {
    bap_init(argc, argv);
    printf("Welcome to BAP %s", bap_version());
}

```

The `examples` folder contains a set of small programs, that can be
viewed as tutorials to BAP and BAP bindings. The following order is
suggested:

1. lift_insn - teaches how to disassemble, lift and print code;
2. print_reachable - explains how to write simple analysis;
3. show_image - uncovers low-level details of file parsing.

## Requirements

* BAP 1.x.x
* OCaml 4.03+ with PIC runtime
  (usually available by default, if a compiler is from OPAM)
* GCC
* Patience (it takes some time to generate the bindings)


## Compilation and installation

Nothing new here:

```
./configure
make
make install
```

You can parametrize installation variables, e.g., prefix using the
configure script, see `./configure --help` for more information.

If the `configure` script is not available (e.g., when you just cloned
the repo), then use `autoconf` to generate it.


# Documentation

Lacks. The long story is the following. There is an official
searchable documentation for OCaml library. You should consult it as a
primary source of information. Although it is for OCaml, it should be
understandable without a dictionary. We were trying to follow some
conventions to make it easier to map C functions to their OCaml
counterpart.

1. Module namespaces are translated to the underscore delimited
   prefixes, with exception to Bap.Std that is translated just to
   `bap`, e.g., `Project.Input.file` is `project_input_file`. So to
   get the documentation for the `project_input_file` just type
   `Project.Input.file` in the search window of the OCaml
   documentation. The same is true for types. A type `Project.t` is
   defined as an opaque data structure `bap_project_t`. The name is
   typedefed into from the structure tag namespace to the symbol
   namespace, so no `struct` word is needed.

2. The order of function parameters is preserved, except that optional
   parameters (prefixed with `?` in OCaml) are specified after all
   required parameters. For example,
   `Project.Input.file ?loader:string -> filename:string -> t`
   is translated into `project_input_file(char *filename, char *loader)`.
   The `NULL` value can be passed as an argument to the optional parameter.

3. If there are too many optional parameters, then they are passed
{'fraction_non_alphanumeric': 0.06183193553691827, 'fraction_numerical': 0.00328893274132544, 'mean_word_length': 4.085284280936455, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2418197', 'n_tokens_mistral': 1701, 'n_tokens_neox': 1645, 'n_words': 880}