0

I want to be able to write in pure machine code, aka. writing the bytes myself and not using assembly (why? just for fun). For starters, I have this very simple assembly program.

Linux x86-64 Assembly:

section .text
global _start
_start:
    mov rax, 60
    mov rdi, 0
    syscall

Using nasm and ld to compile gives me a 5 KB executable. On looking into the file, I realised that most of the space was just occupied by zeroeszeroes.

Is it possible to remove these zeroes and to filter everything unnecessary so that I could somehow copy the commands for mov instructions, etc and write in machine code from scratch?

avighnac
  • 376
  • 4
  • 12
  • Have you tried using a hex editor? An ELF is an ordinary binary file, hex editors let you create arbitrary binary files, ipso facto you can use them to create an executable. Read the ELF specifications, read the Intel manual and you can easily do it. Then you'll see that it is indeed a trivial task and hard at all, just tedious. – Margaret Bloom Sep 01 '22 at 11:09
  • @MargaretBloom could you please provide me with some links on where to start? – avighnac Sep 01 '22 at 11:36
  • Looks like a duplicate of [Is it possible write an executable program from start to finish?](https://stackoverflow.com/q/73170016), which has links to doing this for various platforms including Linux. Also see http://www.muppetlabs.com/~breadbox/software/tiny/teensy.html . Re: bloat from modern linker defaults, see [Minimal executable size now 10x larger after linking than 2 years ago, for tiny programs?](https://stackoverflow.com/q/65037919) – Peter Cordes Sep 01 '22 at 14:10

0 Answers0