-1

How would I go about having a resource file in Linux assembly? I would like to read it byte by byte and everything that I have found has been with Windows. I have just started learning assembly and it seems to have very few good resources. I use the NASM assembler.

Peyto
  • 105
  • 7
  • Why the down-vote? – Peyto Aug 12 '17 at 02:09
  • This question is very similar to this other [SO question](https://stackoverflow.com/questions/42235175/how-do-i-add-contents-of-text-file-as-a-section-in-an-elf-file) . One of the answers show how you can use NASM (one of the examples) using `objcopy` . Although it is about text files it also works with binary files just as well. – Michael Petch Aug 12 '17 at 04:11

1 Answers1

1

Generally speaking, you don't. Linux doesn't embed resource data in executables like Windows does.

It's technically possible to embed data into an executable -- the easiest way is by using objcopy:

objcopy --input binary \
    --output elf32-i386 \
    --binary-architecture i386 \
    data.bin data.o

However, don't expect anything except your own executable to read that data. This isn't how you attach an icon to a GUI executable, for instance; that's done using entirely different methods.

  • How would I read the file? The example on your link was in C. – Peyto Aug 12 '17 at 04:00
  • 1
    So in NASM, you'll need `extern _binary_data_txt_start` followed by `mov rsi, _binary_data_txt_start` to get a pointer to the data in `rsi`. Or `mov al, [_binary_data_txt_start]` to get the first byte in `al`. – Nate Eldredge Aug 12 '17 at 04:20