I have a file generated by an automated testing/fuzzing tool called AFL. The file represents one set of input data that can trigger a program bug in the program under test.
I know this file is supposed to contain exactly 7 floating-point numbers, but if I read the file with cat
, I got these.
6.5
06.5
088.1
16.5
08.3
12.6
0.88.1
16.5
08.3
12.6
0.7@��25
Apparently, the list above has more than 7 floats and even comes with unrecognized characters. So I suppose these are some sort of raw data. How can I write a python script (or bash command line) to get their original format, which, in this case, are 7 floating-point numbers?
For information, I can write a C program to do the work like this
#include <stdio.h>
int
main(void)
{
double x0, x1, x2, x3, x4, x5, x6;
if (scanf("%lf %lf %lf %lf %lf %lf %lf", &x0, &x1, &x2, &x3, &x4, &x5, &x6) != 7) return 2;
printf ("%g,%g,%g,%g,%g,%g,%g\n", x0, x1, x2, x3, x4, x5, x6);
return 0;
}
Running the C program with the input above indeed produces 7 floating-point numbers "6.5,6.5,88.1,16.5,8.3,12.6,0.88", but I am looking for a simpler, maybe more elegant python/bash solution. Any idea?
The best way to approach this is by using loops and making it robust; check for everything Here's a quick example