I am aiming to create a raw x86 binary executable from C code. So far, I am able to create a raw binary file using the method described here (The rest of this question assumes you have read the other question). However, I want to use data like strings too. Since strings are stored in a different section of the object file, which isn't being copied over to the raw binary (when running this command: objcopy -j .text -O binary main.o binfile
), I can't use strings though. How would I best embed static data like strings in my binary? (Ideally with a similar method to the one linked)
Asked
Active
Viewed 97 times
0

Ian Rehwinkel
- 2,486
- 5
- 22
- 56
-
1*Since strings are stored in a different section of the object file, which obviously isn't being copied over to the raw binary* - this is not true. You can also explicitly specify the sections to be copied as explained in the comments to the answer for the referenced question. – Eugene Sh. Apr 22 '20 at 15:12
-
Does adding `-j .rodata` to your objcopy invocation work? – S.S. Anne Apr 22 '20 at 15:13
-
First examine the file to see where the literal strings are really stored. Then just add that section when copying. – Some programmer dude Apr 22 '20 at 15:17
-
@S.S.Anne that seems to overwrite part of the instructions. I assume because Both sections are copied to offset 0. – Ian Rehwinkel Apr 22 '20 at 15:20
-
1Please read `objcopy`'s documentation, or at least its on-line help, produced by option`--help`. There are options to changes addresses. – the busybee Apr 23 '20 at 05:51