Skip to content

lou1306/absentee

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Absentee 👤

Absentee (A Bare-bones C iNstrumenter/Transformer) is a collection of common (and less so) source-to-source transformations for C. So far, it can:

  • Rename/remove function calls
  • Change type declarations (e.g. change all chars to ints)
  • Remove typedefs
  • Replace arithmetic operators (e.g., & -> &&)
  • Prepend/append custom code to the input program (e.g., preprocessor directives)
  • Turn an array-based program in an array-free equivalent

Basic usage

absentee takes as input a C program and a configuration file, which specifies the transformations to be performed:

$ python3 -m absentee --conf path/to/conf path/to/file

The result is printed to standard output: use output redirection > to save the result to a file.

You may check out further options with -h or --help:

$ python -m absentee --help
Usage: python - m absentee [OPTIONS] FILE

  absentee C transformation tool

Options:
  --conf PATH  The path to the configuration file.
  --show-ast   Show the syntax tree of FILE and exit.  [default: False]
  --version    Show the version and exit.
  -h, --help   Show this message and exit.

Example configuration

Configurations are in a simplified s-expression format. Here is an example:

; Print code before the input program
(add-text-before "int pow2(int x) { return x * x; }")
; Change all char variables to int
(replace-types (char int))
; Remove the 2nd and 4th argument from all calls to function f
(remove-args (f 1 3)) ; indices are 0-based
(replace-calls 
  (f g) ; Turn all calls to f into calls to g 
  (badfunction ()) ; Remove all calls to badfunction
)

If we run absentee with this configuration on the following file:

int main(void) {
  char x = 1;
  f(1, 2, 3, 4);
  badfunction(x);
  return 0;
}

We obtain this:

int pow2(int x) { return x * x; }

int main(void) {
  char x = 1;
  g(1, 3);
  return 0;
}

Known limitations

Absentee is based on pycparser. This means that:

  • C extensions are unsupported.

  • Absentee can only accept preprocessed input files. As a consequence, absentee's output will lack comments, preprocessor directives, etc. that were present in the original source code. One can preprocess a generic C file (with gcc -E, for instance) and feed the output to absentee like this:

gcc -E program.c | ./absentee.py - --conf <...>

Similar software

Absentee shares some similarities with Coccinelle. Coccinelle aims at handling collateral evolution (such as API changes) and automated bug finding/fixing. Absentee's goal, on the other hand, is to automate instrumentation of code for analysis purposes.

CIL is a subset of C for program analysis and transformation, and a tool to reduce arbitrary C programs into said subset. The tool, however, seems to be hardly maintained anymore.

ROSE is a framework to develop source-to-source transformation and analysis tools. It is a huge project, supporting multiple languages (C, C++, Fortran, Java, ...) as well as executable (binary) files.

Releases

No releases published

Packages

No packages published

Languages