I'm working on Linux and I've just heard that there was a command objcopy
, I've found the relative command on my x86_64 PC: x86_64-linux-gnu-objcopy
.
With its help, I can convert a file into an obj file: x86_64-linux-gnu-objcopy -I binary -O elf64-x86-64 custom.config custom.config.o
The file custom.config
is a human-readable file. It contains two lines:
name titi
password 123
Now I can execute objdump -x -s custom.config.o
to check its information.
custom.config.o: file format elf64-little
custom.config.o
architecture: UNKNOWN!, flags 0x00000010:
HAS_SYMS
start address 0x0000000000000000
Sections:
Idx Name Size VMA LMA File off Algn
0 .data 00000017 0000000000000000 0000000000000000 00000040 2**0
CONTENTS, ALLOC, LOAD, DATA
SYMBOL TABLE:
0000000000000000 l d .data 0000000000000000 .data
0000000000000000 g .data 0000000000000000 _binary_custom_config_start
0000000000000017 g .data 0000000000000000 _binary_custom_config_end
0000000000000017 g *ABS* 0000000000000000 _binary_custom_config_size
Contents of section .data:
0000 6e616d65 20746974 690a7061 7373776f name titi.passwo
0010 72642031 32330a rd 123.
As all we know, we can open, read or write a file, such as custom.config
in any C/C++ project. Now, I'm thinking if it's possible to use this obj file custom.config.o
immediately in a C/C++ project. For example, is it possible to read the content of the file custom.config.o
immediately without calling the I/O functions, such as open
, read
or write
. If possible, I think this might become some kind of hardcoding style and avoid calling the I/O functions?