New release Ada BFD 1.2.0
The new release is a cleanup and update of the library to support newer version of GNU binutils. The main changes are below:
- Cleanup build process and use gprinstall for installation
- Fix build with binutils > 2.34
- Remove invalid API: `Bfd.Set_Error_Handler`
- Remove fake API: `Bfd.Symbols.Is_Local_Label_Name`
- Installation
To use the Ada BFD library, you may either build it from the sources ada-bfd-1.2.0.tar.gz(https://download.vacs.fr/ada-bfd/ada-bfd-1.2.0.tar.gz) or install the Debian packages.
To build from the sources, you need to have a working GNAT Ada compiler as well as the `binutils-dev` Debian package installed. Then, run the following commands:
```sh git clone https://github.com/stcarrez/ada-bfd.git cd ada-bfd ./configure make build check install ```
For the Debian package installation, use the configuration that corresponds to your setup:
``` deb https://apt.vacs.fr/ubuntu-bionic bionic main deb https://apt.vacs.fr/ubuntu-focal focal main deb https://apt.vacs.fr/debian-buster buster main ```
and then run:
``` sudo apt-get update
- Bionic: sudo apt-get install libbfdada1-dev
- Focal: sudo apt-get install libbfdada2-dev
- Buster: sudo apt-get install libbfdada3-dev
```
- Reading the ELF sections
Using the Ada BFD library in a projet is quite easy, the first step is to add the following line in your GNAT project file:
``` Ada with "bfdada"; ```
To access the information of a binary, you must first define an instance of the `File_Type` and open the file. You will do this as follows:
``` Ada with Bfd.Files;
...
Path : constant String := "..."; -- the binary to load
File : Bfd.Files.File_Type;
...
Bfd.Files.Open (File, Path, "");
```
Looking at the ELF section is easily made by using the `Section_Iterator` provided by the `Bfd.Sections` package.
```ada with Bfd.Sections;
...
Iter : Bfd.Sections.Section_Iterator := Bfd.Sections.Get_Sections (File);
...
while Bfd.Sections.Has_Element (Iter) loop
declare
S : constant Bfd.Sections.Section := Bfd.Sections.Element (Iter);
begin
Ada.Text_IO.Put_Line (Bfd.Sections.Get_Name (S));
end;
Bfd.Sections.Next (Iter);
end loop;
```
The library contains several examples that show different features of the Ada BFD library:
| bfdinfo.adb(https://github.com/stcarrez/ada-bfd/blob/master/samples/bfdinfo.adb) | ./bin/bfdinfo ./bin/bfdgen | Open BFD file, get flags, list sections and symbols | | sections.adb(https://github.com/stcarrez/ada-bfd/blob/master/samples/sections.adb) | ./bin/sections ./bin/bfdgen | Display the ELF sections with the `Bfd.Sections` | | symbol.adb(https://github.com/stcarrez/ada-bfd/blob/master/samples/symbol.adb) | ./bin/symbol ./bin/bfdgen main | Read the symbol table with `Bfd.Symbols` | | disassemble.adb(https://github.com/stcarrez/ada-bfd/blob/master/samples/disassemble.adb) | ./bin/disassemble ./bin/bfdgen | Disassemble the text section with `Bfd.Disassemble` |