title: Disassemble, modify, and reassemble executable
body: <p>How can I disassemble an executable on my mac using ndisasm and reassemble and link it using nasm and ld?
  This is what I tried (I'm running MacOS X btw):</p>
  
  <pre><code> *ndisasm a.out | cut -c 29- &gt; main.asm*
  </code></pre>
  
  <p>this generated clean assembler code with all the processor instructions in main.asm</p>
  
  <pre><code> *nasm -f macho main.asm*
  </code></pre>
  
  <p>this generated an object file main.o which I then tried to link</p>
  
  <pre><code> *ld main.o*
  </code></pre>
  
  <p>... this is where I'm stuck. I don't know why it generates the following error:</p>
  
  <p>ld: in section __TEXT,__text reloc 0: R_ABS reloc but no absolute symbol at target adress file 'main.o' for inferred architecture i386.</p>
  
  <p>I also tried specifying the architecture (ld -arch x86_64 main.o) but that didn't work either.</p>
  
  <p><strong>My goal is to disassemble any executable, modify it and then reassemble it again.</strong></p>
  
  <p>What am I doing wrong?</p>