Ada BFD is an Ada binding for the GNU Binutils BFD library. It allows to read binary ELF, COFF files by using the GNU BFD and allows your program to read ELF sections, get access to the symbol table and use the disassembler.
New release Ada BFD 1.2.0
By Stephane Carrez2021-04-11 18:37:21
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 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:
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:
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:
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.
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 | ./bin/bfdinfo ./bin/bfdgen | Open BFD file, get flags, list sections and symbols |
sections.adb | ./bin/sections ./bin/bfdgen | Display the ELF sections with the Bfd.Sections |
symbol.adb | ./bin/symbol ./bin/bfdgen main | Read the symbol table with Bfd.Symbols |
disassemble.adb | ./bin/disassemble ./bin/bfdgen | Disassemble the text section with Bfd.Disassemble |
Tags
- Facelet
- NetBSD
- framework
- Mysql
- generator
- files
- application
- gcc
- ReadyNAS
- Security
- binutils
- ELF
- JSF
- Java
- bacula
- Tutorial
- Apache
- COFF
- collaboration
- planning
- project
- upgrade
- AWA
- C
- EL
- J2EE
- UML
- php
- symfony
- Ethernet
- Ada
- FreeBSD
- Go
- KVM
- MDE
- Proxy
- STM32
- Servlet
- backup
- lvm
- multiprocessing
- web
- Bean
- Jenkins
- release
- OAuth
- ProjectBar
- REST
- Rewrite
- Sqlite
- Storage
- USB
- Ubuntu
- bison
- cache
- crash
- Linux
- firefox
- performance
- interview
Add a comment
To add a comment, you must be connected. Login