Convert binary file to csv and then back to the binary format

Hello *nix specialists,

Im working for a non profit organisation in Germany to transport DSL over WLAN to people in areas without no DSL. We are using Linksys WRT 54 router with DD-WRT firmware There are at the moment over 180 router running but we have to change some settings next time. So my idea is, to use the firmware modification kit. After decompressing the original firmware, I get a file calling defaults.bin (inside the attaced file) in which are stored all variables with the correspondending values. I have no informations about the binary format but maybe it would help to take a look in to the C-source: (inside the attaced file)
I think at the end of the code is a function to read the parameters.

Okay back tot the topic.

I want to convert the defaults.bin into a csv text file. Then a script reads from a database the required parameters like IP address, username, password ... and change so the csv file. Then a script should make from the csv file a new (specially for one router) defaults.bin file. At the end, the firmaware modification kit compress all to the firmware file what we can send to each router.

Is this workaround to crazy?

best regards and merry X-mas,
Frank

It seems simple enough in C, where you can access the structure. You might want to put things like IP in dotted decimal, e.g., "255.1.2.3" if humans are to read them.

Thanks for reply. So I have to learn C now. Where can I find informtions about the structure of the binary file?

Thanks in advance, Frank

It is at the top of your C file. A struct is a structure of data, and the file seems to be a pile of structures, except an empty structure is legal. The binary image has a structure count at the front, and then each structure has a length, and if it is zero, that structure is empty. There may be other flags in the structure to identify what is in the length. The confusing thing is all the #define type stuff in the structure definition, which is most of the file. I might be good to make a preprocessed file (cc -E) where that stuff is resolved. Once you have the C, you may find it is easier enough to get configuration from some other file type. XML is also popular for C++/JAVA to represent objects in collection objects ad infinitim.

Many fine C tutorials online for free, and gcc is free, too.

Okay, I have now written a small program in C to read the binary file and take the output to stdout. But the output is divided in crazy parts. I will now ask and the C forum.

Thanks everybody for helping me and merry x-mas.

Frank

Well, for CSV you need to decide the order of all fields and any binary conversion from say int to ascii digits (straight, hex, octal, dotted decimal)or boolean to true/false or 1/0 or 0/1 !

So I can see, the fields are defined as chars:

struct nvram_tuple {
    char *name;
    char *value;
    struct nvram_tuple *next;
};

So the output should look like:

"ip_addr","192.168.1.1"\n
"wan_ip","10.23.354.21"\n
"wan_dns","8.8.8.8"\n

(...)

I have now opened a topic at the C-forum:

thank, Frank

That looks familiar! Sure, CSV is one way to make it easier to deal with, as you can put it in a spreadsheet or RDBMS table and sort it and such.